github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/teams/resolve_test.go (about) 1 package teams 2 3 import ( 4 "context" 5 "fmt" 6 "testing" 7 8 "github.com/keybase/client/go/externals" 9 "github.com/keybase/client/go/libkb" 10 "github.com/keybase/client/go/protocol/keybase1" 11 "github.com/stretchr/testify/require" 12 ) 13 14 func TestOurResolve(t *testing.T) { 15 _, nm, g, cleanup := createUserAndRootTeam(t) 16 defer cleanup() 17 require.True(t, nm.IsRootTeam()) 18 id := nm.ToPrivateTeamID() 19 20 ctx := context.TODO() 21 nm2, err := ResolveIDToName(ctx, g, id) 22 require.NoError(t, err) 23 require.True(t, nm.Eq(nm2)) 24 25 id2, err := ResolveNameToID(ctx, g, nm) 26 require.NoError(t, err) 27 require.True(t, id.Eq(id2)) 28 29 r2input := fmt.Sprintf("team:%s", nm.String()) 30 rres := g.Resolver.ResolveFullExpressionNeedUsername(libkb.NewMetaContext(ctx, g), r2input) 31 require.NoError(t, rres.GetError()) 32 require.True(t, rres.GetTeamID().Exists()) 33 require.Equal(t, rres.UserOrTeam().Name, nm.String()) 34 require.Equal(t, rres.UserOrTeam().Id.String(), id2.String()) 35 } 36 37 // Test that verifyResolveResult would catch a bad (unverifiable) resolution. 38 func TestVerifyResolveEvilServer(t *testing.T) { 39 _, tcs, cleanup := setupNTests(t, 1) 40 defer cleanup() 41 42 t.Logf("check good assertion") 43 assertion, err := externals.AssertionParseAndOnly(libkb.NewMetaContext(context.Background(), tcs[0].G), "t_tracy@rooter") 44 require.NoError(t, err) 45 err = verifyResolveResult(context.TODO(), tcs[0].G, libkb.ResolvedAssertion{ 46 Assertion: assertion, 47 UID: keybase1.UID("eb72f49f2dde6429e5d78003dae0c919"), 48 }) 49 require.NoError(t, err) 50 51 t.Logf("check bad assertion") 52 assertion, err = externals.AssertionParseAndOnly(libkb.NewMetaContext(context.Background(), tcs[0].G), "beluga@rooter") 53 require.NoError(t, err) 54 err = verifyResolveResult(context.TODO(), tcs[0].G, libkb.ResolvedAssertion{ 55 Assertion: assertion, 56 UID: keybase1.UID("eb72f49f2dde6429e5d78003dae0c919"), 57 }) 58 require.Error(t, err) 59 require.IsType(t, libkb.UnmetAssertionError{}, err) 60 require.Regexp(t, `Unmet remote assertions`, err) 61 }