github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/systests/uidmap_test.go (about) 1 package systests 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/keybase/client/go/uidmap" 8 9 "github.com/keybase/client/go/libkb" 10 keybase1 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/stretchr/testify/require" 12 context "golang.org/x/net/context" 13 ) 14 15 func TestLoadingUserCachesServiceMap(t *testing.T) { 16 const tTracy = keybase1.UID("eb72f49f2dde6429e5d78003dae0c919") 17 18 tc := setupTest(t, "smap") 19 defer tc.Cleanup() 20 21 getPkgs := func() map[keybase1.UID]libkb.UserServiceSummaryPackage { 22 return tc.G.ServiceMapper.MapUIDsToServiceSummaries( 23 context.Background(), 24 tc.G, 25 []keybase1.UID{tTracy}, 26 time.Duration(0), // never stale 27 uidmap.DisallowNetworkBudget, // no network calls 28 ) 29 } 30 31 pkgs := getPkgs() 32 require.Len(t, pkgs, 0) 33 34 arg := libkb.NewLoadUserArg(tc.G).WithName("t_tracy") 35 user, err := libkb.LoadUser(arg) 36 require.NoError(t, err) 37 require.Equal(t, tTracy, user.GetUID()) 38 39 pkgs = getPkgs() 40 require.Contains(t, pkgs, tTracy) 41 42 // Exact maps depend on remote_identities on the test server. 43 tracyPkg := pkgs[tTracy] 44 require.Equal(t, "tacoplusplus", tracyPkg.ServiceMap["github"]) 45 require.Equal(t, "t_tracy", tracyPkg.ServiceMap["rooter"]) 46 require.Equal(t, "tacovontaco", tracyPkg.ServiceMap["twitter"]) 47 } 48 49 func TestServiceMapRevokedProofs(t *testing.T) { 50 tt := newTeamTester(t) 51 defer tt.cleanup() 52 53 alice := tt.addUser("alice") 54 bob := tt.addUser("bob") 55 56 getPkgs := func() map[keybase1.UID]libkb.UserServiceSummaryPackage { 57 return bob.tc.G.ServiceMapper.MapUIDsToServiceSummaries( 58 context.Background(), 59 bob.tc.G, 60 []keybase1.UID{alice.uid}, 61 time.Duration(0), // never stale 62 uidmap.DisallowNetworkBudget, // no network calls 63 ) 64 } 65 66 // We got nothing on first try because we've never loaded the user and we 67 // disallow network in MapUIDsToServiceSummaries. 68 pkgs := getPkgs() 69 require.Len(t, pkgs, 0) 70 71 loadUser := func() { 72 arg := libkb.NewLoadUserArg(bob.tc.G).WithName(alice.username) 73 user, err := libkb.LoadUser(arg) 74 require.NoError(t, err) 75 require.Equal(t, alice.uid, user.GetUID()) 76 } 77 78 // Try again, after loading user. 79 loadUser() 80 pkgs = getPkgs() 81 require.Contains(t, pkgs, alice.uid) 82 require.Len(t, pkgs[alice.uid].ServiceMap, 0) // no proofs yet 83 84 // Alice proves 85 alice.proveRooter() 86 alice.proveGubbleSocial() 87 88 // Reload user and try again 89 loadUser() 90 pkgs = getPkgs() 91 require.Contains(t, pkgs, alice.uid) 92 alicePkg := pkgs[alice.uid] 93 require.Len(t, alicePkg.ServiceMap, 2) 94 require.Equal(t, alice.username, alicePkg.ServiceMap["gubble.social"]) 95 require.Equal(t, alice.username, alicePkg.ServiceMap["rooter"]) 96 97 // Alice revokes 98 alice.revokeServiceProof("rooter") 99 100 loadUser() 101 pkgs = getPkgs() 102 require.Contains(t, pkgs, alice.uid) 103 alicePkg = pkgs[alice.uid] 104 require.Len(t, alicePkg.ServiceMap, 1) 105 require.Equal(t, alice.username, alicePkg.ServiceMap["gubble.social"]) 106 require.NotContains(t, alicePkg.ServiceMap, "rooter") 107 }