github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/teams/seitan_common_test.go (about)

     1  package teams
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"testing"
     7  
     8  	"github.com/keybase/client/go/kbtest"
     9  	"github.com/keybase/client/go/protocol/keybase1"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func testTeamCreateSeitanAndCancel(t *testing.T, seitanVersion SeitanVersion) {
    14  	tc := SetupTest(t, "team", 1)
    15  	defer tc.Cleanup()
    16  
    17  	user, err := kbtest.CreateAndSignupFakeUser("team", tc.G)
    18  	require.NoError(t, err)
    19  
    20  	teamName, teamID := createTeam2(tc)
    21  
    22  	t.Logf("Created team %q", teamName.String())
    23  
    24  	var labelSms keybase1.SeitanKeyLabelSms
    25  	labelSms.F = "Patricia S. Goldman-Rakic"
    26  	labelSms.N = "+481II222333"
    27  	label := keybase1.NewSeitanKeyLabelWithSms(labelSms)
    28  
    29  	switch seitanVersion {
    30  	case SeitanVersion1:
    31  		_, err = CreateSeitanToken(context.TODO(), tc.G, teamName.String(), keybase1.TeamRole_WRITER, label)
    32  	case SeitanVersion2:
    33  		_, err = CreateSeitanTokenV2(context.TODO(), tc.G, teamName.String(), keybase1.TeamRole_WRITER, label)
    34  	default:
    35  		t.Logf("Invalid seitan version %v", seitanVersion)
    36  		t.FailNow()
    37  	}
    38  	require.NoError(t, err)
    39  
    40  	t.Logf("Created Seitan token")
    41  
    42  	details, err := Details(context.TODO(), tc.G, teamName.String())
    43  	require.NoError(t, err)
    44  
    45  	var inviteID keybase1.TeamInviteID
    46  
    47  	require.Equal(t, 1, len(details.AnnotatedActiveInvites))
    48  	for key, aInvite := range details.AnnotatedActiveInvites {
    49  		invite := aInvite.InviteMetadata.Invite
    50  		require.Equal(t, keybase1.TeamRole_WRITER, invite.Role)
    51  		require.EqualValues(t, fmt.Sprintf("%s (%s)", labelSms.F, labelSms.N), aInvite.DisplayName)
    52  
    53  		category, err := invite.Type.C()
    54  		require.NoError(t, err)
    55  		require.Equal(t, keybase1.TeamInviteCategory_SEITAN, category)
    56  
    57  		// Test rest of the params, unrelated to Seitan.
    58  		require.Equal(t, key, invite.Id)
    59  		require.Equal(t, user.GetUserVersion(), invite.Inviter)
    60  		require.Equal(t, user.Username, aInvite.InviterUsername)
    61  		require.Equal(t, teamName.String(), aInvite.TeamName)
    62  
    63  		inviteID = invite.Id
    64  	}
    65  
    66  	t.Logf("Checked that invite was added correctly, removing invite by id")
    67  
    68  	err = CancelInviteByID(context.TODO(), tc.G, teamID, inviteID)
    69  	require.NoError(t, err)
    70  
    71  	t.Logf("Removed, checking if there are no active invites")
    72  
    73  	t0, err := GetTeamByNameForTest(context.TODO(), tc.G, teamName.String(), false /* public */, true /* needAdmin */)
    74  	require.NoError(t, err)
    75  	require.Equal(t, 0, t0.NumActiveInvites())
    76  }
    77  
    78  func TestTeamCreateSeitanAndCancel(t *testing.T) {
    79  	testTeamCreateSeitanAndCancel(t, SeitanVersion1)
    80  	testTeamCreateSeitanAndCancel(t, SeitanVersion2)
    81  }