github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/loaduser_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "testing" 8 9 keybase1 "github.com/keybase/client/go/protocol/keybase1" 10 "golang.org/x/net/context" 11 ) 12 13 func TestLoadUserPlusKeys(t *testing.T) { 14 tc := SetupTest(t, "user plus keys", 1) 15 defer tc.Cleanup() 16 m := NewMetaContextForTest(tc) 17 18 // this is kind of pointless as there is no cache anymore 19 for i := 0; i < 10; i++ { 20 u, err := LoadUserPlusKeys(m.Ctx(), tc.G, "295a7eea607af32040647123732bc819", "") 21 if err != nil { 22 t.Fatal(err) 23 } 24 if u.Username != "t_alice" { 25 t.Errorf("username: %s, expected t_alice", u.Username) 26 } 27 if len(u.RevokedDeviceKeys) > 0 { 28 t.Errorf("t_alice found with %d revoked keys, expected 0", len(u.RevokedDeviceKeys)) 29 } 30 } 31 32 for _, uid := range []keybase1.UID{"295a7eea607af32040647123732bc819", "afb5eda3154bc13c1df0189ce93ba119", "9d56bd0c02ac2711e142faf484ea9519", "c4c565570e7e87cafd077509abf5f619", "561247eb1cc3b0f5dc9d9bf299da5e19"} { 33 _, err := LoadUserPlusKeys(m.Ctx(), tc.G, uid, "") 34 if err != nil { 35 t.Fatal(err) 36 } 37 } 38 } 39 40 func TestLoadUserPlusKeysNoKeys(t *testing.T) { 41 tc := SetupTest(t, "user plus keys", 1) 42 defer tc.Cleanup() 43 44 // t_ellen has no keys. There should be no error loading her. 45 u, err := LoadUserPlusKeys(context.Background(), tc.G, "561247eb1cc3b0f5dc9d9bf299da5e19", "") 46 if err != nil { 47 t.Fatal(err) 48 } 49 if u.Username != "t_ellen" { 50 t.Errorf("username: %s, expected t_ellen", u.Username) 51 } 52 } 53 54 func TestRevokedKeys(t *testing.T) { 55 tc := SetupTest(t, "revoked keys", 1) 56 defer tc.Cleanup() 57 58 u, err := LoadUserPlusKeys(context.Background(), tc.G, "ff261e3b26543a24ba6c0693820ead19", "") 59 if err != nil { 60 t.Fatal(err) 61 } 62 if u.Username != "t_mike" { 63 t.Errorf("username: %s, expected t_mike", u.Username) 64 } 65 if len(u.RevokedDeviceKeys) != 2 { 66 t.Errorf("t_mike found with %d revoked keys, expected 2", len(u.RevokedDeviceKeys)) 67 } 68 69 kid := keybase1.KID("012073f26b5996912393f7d2961ca90968e4e83d6140e9771ba890ff8ba6ea97777e0a") 70 for index, k := range u.RevokedDeviceKeys { 71 if k.By != kid { 72 t.Errorf("wrong revoking KID (index: %d) %s != %s", index, k.By, kid) 73 } 74 } 75 } 76 77 func BenchmarkLoadSigChains(b *testing.B) { 78 tc := SetupTest(b, "benchmark load user", 1) 79 defer tc.Cleanup() 80 81 u, err := LoadUser(NewLoadUserByNameArg(tc.G, "t_george")) 82 if err != nil { 83 b.Fatal(err) 84 } 85 if u == nil { 86 b.Fatal("no user") 87 } 88 u.sigChainMem = nil 89 b.ResetTimer() 90 for i := 0; i < b.N; i++ { 91 if err = u.LoadSigChains(NewMetaContextForTest(tc), &u.leaf, false, StubModeStubbed); err != nil { 92 b.Fatal(err) 93 } 94 u.sigChainMem = nil 95 } 96 } 97 98 func BenchmarkLoadUserPlusKeys(b *testing.B) { 99 tc := SetupTest(b, "bench_user_plus_keys", 1) 100 defer tc.Cleanup() 101 102 u, err := LoadUser(NewLoadUserByNameArg(tc.G, "t_george")) 103 if err != nil { 104 b.Fatal(err) 105 } 106 if u == nil { 107 b.Fatal("no user") 108 } 109 uid := u.GetUID() 110 111 b.ResetTimer() 112 for i := 0; i < b.N; i++ { 113 _, err := LoadUserPlusKeys(context.Background(), tc.G, uid, "") 114 if err != nil { 115 b.Fatal(err) 116 } 117 } 118 }