github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/systests/standalone_test.go (about) 1 package systests 2 3 import ( 4 "testing" 5 6 "golang.org/x/net/context" 7 8 "github.com/keybase/client/go/client" 9 "github.com/keybase/client/go/libkb" 10 keybase1 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/keybase/client/go/service" 12 "github.com/keybase/client/go/teams" 13 "github.com/stretchr/testify/require" 14 ) 15 16 type standaloneUserArgs struct { 17 disableGregor bool 18 suppressTeamChatAnnounce bool 19 } 20 21 func makeUserStandalone(t *testing.T, tt *teamTester, pre string, opts standaloneUserArgs) *userPlusDevice { 22 tctx := setupTest(t, pre) 23 var u userPlusDevice 24 25 g := tctx.G 26 27 if opts.suppressTeamChatAnnounce { 28 u.suppressTeamChatAnnounce = opts.suppressTeamChatAnnounce 29 g.Env.Test.SkipSendingSystemChatMessages = true 30 } 31 32 if opts.disableGregor { 33 // Some tests may want to disable gregor loop completely to 34 // simulate user that stays offline when not doing anything. 35 // Useful for teams tests to have a user that can post sigs 36 // but will not respond to any rekeyd messages. 37 err := g.Env.GetConfigWriter().SetBoolAtPath("push.disabled", true) 38 require.NoError(t, err) 39 } 40 41 u.device = &deviceWrapper{tctx: tctx} 42 43 // Mimic what keybase/main.go does for Standalone. 44 var err error 45 svc := service.NewService(tctx.G, false) 46 err = svc.SetupCriticalSubServices() 47 require.NoError(t, err) 48 err = svc.StartLoopbackServer(libkb.LoginAttemptOffline) 49 require.NoError(t, err) 50 51 g.StandaloneChatConnector = svc 52 g.Standalone = true 53 54 userInfo := randomUser(pre) 55 56 signupUI := signupUI{ 57 info: userInfo, 58 Contextified: libkb.NewContextified(g), 59 } 60 g.SetUI(&signupUI) 61 signup := client.NewCmdSignupRunner(g) 62 signup.SetTest() 63 if err := signup.Run(); err != nil { 64 t.Fatal(err) 65 } 66 t.Logf("signed up %s", userInfo.username) 67 68 u.tc = tctx 69 u.userInfo = userInfo 70 u.username = userInfo.username 71 u.passphrase = userInfo.passphrase 72 u.uid = libkb.UsernameToUID(u.username) 73 74 cli, _, err := client.GetRPCClientWithContext(g) 75 require.NoError(t, err) 76 77 u.deviceClient = keybase1.DeviceClient{Cli: cli} 78 u.teamsClient = keybase1.TeamsClient{Cli: cli} 79 80 u.device.userClient = keybase1.UserClient{Cli: cli} 81 u.device.accountClient = keybase1.AccountClient{Cli: cli} 82 83 tt.users = append(tt.users, &u) 84 85 return &u 86 } 87 88 func TestStandaloneTeamMemberOps(t *testing.T) { 89 tt := newTeamTester(t) 90 defer tt.cleanup() 91 92 makeUserStandalone(t, tt, "user1", standaloneUserArgs{}) 93 tt.addUser("user2") 94 95 team := tt.users[0].createTeam() 96 97 g := tt.users[0].tc.G 98 99 add := client.NewCmdTeamAddMemberRunner(g) 100 add.Team = team 101 add.Username = tt.users[1].username 102 add.Role = keybase1.TeamRole_WRITER 103 add.SkipChatNotification = false 104 err := add.Run() 105 require.NoError(t, err) 106 107 // Check if adding worked 108 t0, err := teams.GetTeamByNameForTest(context.TODO(), g, team, false, true) 109 require.NoError(t, err) 110 writers, err := t0.UsersWithRole(keybase1.TeamRole_WRITER) 111 require.NoError(t, err) 112 require.Equal(t, len(writers), 1, "expected 1 writer") 113 require.True(t, writers[0].Uid.Equal(tt.users[1].uid), "unexpected writer uid") 114 115 // Do not care about result (printed to UI), just be sure that it 116 // doesn't crash or fail. 117 listmem := client.NewCmdTeamListMembershipsRunner(g) 118 listmem.SetJSON(true) 119 err = listmem.Run() 120 require.NoError(t, err) 121 122 listmem = client.NewCmdTeamListMembershipsRunner(g) 123 listmem.SetJSON(true) 124 listmem.SetTeam(team) 125 err = listmem.Run() 126 require.NoError(t, err) 127 128 remove := client.NewCmdTeamRemoveMemberRunner(g) 129 remove.Team = team 130 remove.Assertion = tt.users[1].username 131 remove.Force = true // avoid Yes/No prompt 132 err = remove.Run() 133 require.NoError(t, err) 134 135 // Check if removal worked 136 t0, err = teams.GetTeamByNameForTest(context.TODO(), g, team, false, true) 137 require.NoError(t, err) 138 writers, err = t0.UsersWithRole(keybase1.TeamRole_WRITER) 139 require.NoError(t, err) 140 require.Equal(t, len(writers), 0, "expected 0 writers") 141 }