github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/systests/team_seitan_invite_v2_test.go (about) 1 package systests 2 3 import ( 4 "testing" 5 6 "golang.org/x/net/context" 7 8 keybase1 "github.com/keybase/client/go/protocol/keybase1" 9 "github.com/keybase/client/go/teams" 10 "github.com/stretchr/testify/require" 11 ) 12 13 // Parameterized high-level tests (using team service API and gregor handler) 14 // for Seitan V1 and Seitan V2. 15 16 func TestTeamInviteSeitanHappy(t *testing.T) { 17 testTeamInviteSeitanHappy(t, false /* implicitAdmin */, teams.SeitanVersion1) 18 testTeamInviteSeitanHappy(t, false /* implicitAdmin */, teams.SeitanVersion2) 19 } 20 21 func TestTeamInviteSeitanHappyImplicitAdmin(t *testing.T) { 22 testTeamInviteSeitanHappy(t, true /* implicitAdmin */, teams.SeitanVersion1) 23 testTeamInviteSeitanHappy(t, true /* implicitAdmin */, teams.SeitanVersion2) 24 } 25 26 func testTeamInviteSeitanHappy(t *testing.T, implicitAdmin bool, seitanVersion teams.SeitanVersion) { 27 tt := newTeamTester(t) 28 defer tt.cleanup() 29 30 own := tt.addUser("own") 31 roo := tt.addUser("roo") 32 33 teamIDParent, teamNameParent := own.createTeam2() 34 teamID := teamIDParent 35 teamName := teamNameParent 36 t.Logf("Created team %v %v", teamIDParent, teamNameParent) 37 if implicitAdmin { 38 subteamID, err := teams.CreateSubteam(context.TODO(), tt.users[0].tc.G, "sub1", teamNameParent, keybase1.TeamRole_NONE /* addSelfAs */) 39 require.NoError(t, err) 40 teamID = *subteamID 41 subteamName, err := teamNameParent.Append("sub1") 42 require.NoError(t, err) 43 teamName = subteamName 44 t.Logf("Created subteam %v %v", teamID, teamName) 45 } 46 47 label := keybase1.NewSeitanKeyLabelWithSms(keybase1.SeitanKeyLabelSms{ 48 F: "bugs", 49 N: "0000", 50 }) 51 var token string 52 switch seitanVersion { 53 case teams.SeitanVersion1: 54 ikey, err := own.teamsClient.TeamCreateSeitanToken(context.TODO(), keybase1.TeamCreateSeitanTokenArg{ 55 Teamname: teamName.String(), 56 Role: keybase1.TeamRole_WRITER, 57 Label: label, 58 }) 59 token = string(ikey) 60 require.NoError(t, err) 61 case teams.SeitanVersion2: 62 ikey, err := own.teamsClient.TeamCreateSeitanTokenV2(context.TODO(), keybase1.TeamCreateSeitanTokenV2Arg{ 63 Teamname: teamName.String(), 64 Role: keybase1.TeamRole_WRITER, 65 Label: label, 66 }) 67 token = string(ikey) 68 require.NoError(t, err) 69 default: 70 t.Fatalf("Invalid seitan version %v", seitanVersion) 71 } 72 73 t.Logf("Created token %q", token) 74 75 details := own.teamGetDetails(teamName.String()) 76 require.Len(t, details.AnnotatedActiveInvites, 1) 77 for _, invite := range details.AnnotatedActiveInvites { 78 require.Equal(t, keybase1.TeamRole_WRITER, invite.InviteMetadata.Invite.Role) 79 tic, err := invite.InviteMetadata.Invite.Type.C() 80 require.NoError(t, err) 81 require.Equal(t, keybase1.TeamInviteCategory_SEITAN, tic) 82 require.Equal(t, keybase1.TeamInviteDisplayName("bugs (0000)"), invite.DisplayName) 83 } 84 85 roo.kickTeamRekeyd() 86 err := roo.teamsClient.TeamAcceptInvite(context.TODO(), keybase1.TeamAcceptInviteArg{ 87 Token: token, 88 }) 89 require.NoError(t, err) 90 91 t.Logf("User used token, waiting for rekeyd") 92 93 own.waitForTeamChangedGregor(teamID, keybase1.Seqno(3)) 94 95 t0, err := teams.GetTeamByNameForTest(context.TODO(), own.tc.G, teamName.String(), false /* public */, true /* needAdmin */) 96 require.NoError(t, err) 97 98 role, err := t0.MemberRole(context.TODO(), teams.NewUserVersion(roo.uid, 1)) 99 require.NoError(t, err) 100 require.Equal(t, role, keybase1.TeamRole_WRITER) 101 102 details = own.teamGetDetails(teamName.String()) 103 require.Len(t, details.AnnotatedActiveInvites, 0) 104 }