github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/externals/social_assertion_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package externals
     5  
     6  import (
     7  	"testing"
     8  
     9  	libkb "github.com/keybase/client/go/libkb"
    10  	"github.com/keybase/client/go/protocol/keybase1"
    11  	"github.com/stretchr/testify/require"
    12  )
    13  
    14  type nsatest struct {
    15  	in  string
    16  	out keybase1.SocialAssertion
    17  	ok  bool
    18  }
    19  
    20  var nsatests = []nsatest{
    21  	{in: "keybase", out: keybase1.SocialAssertion{}, ok: false},
    22  	{in: "alice@twitter", out: keybase1.SocialAssertion{User: "alice", Service: "twitter"}, ok: true},
    23  	{in: "alice@twitter+bob@twitter", out: keybase1.SocialAssertion{}, ok: false},
    24  	{in: "alice+bob@twitter", out: keybase1.SocialAssertion{}, ok: false},
    25  	{in: "twitter:alice", out: keybase1.SocialAssertion{User: "alice", Service: "twitter"}, ok: true},
    26  	{in: "Twitter:alice", out: keybase1.SocialAssertion{User: "alice", Service: "twitter"}, ok: true},
    27  	{in: "twitter:Alice", out: keybase1.SocialAssertion{User: "alice", Service: "twitter"}, ok: true},
    28  	{in: "AlicE@twitter", out: keybase1.SocialAssertion{User: "alice", Service: "twitter"}, ok: true},
    29  	{in: "012345678901234567891@twitter", out: keybase1.SocialAssertion{}, ok: false},
    30  	{in: "bob@foo@bar", out: keybase1.SocialAssertion{}, ok: false},
    31  	{in: "foo:bar:bob", out: keybase1.SocialAssertion{}, ok: false},
    32  	{in: "foo:bob@bar", out: keybase1.SocialAssertion{}, ok: false},
    33  	{in: "BOB@github", out: keybase1.SocialAssertion{User: "bob", Service: "github"}, ok: true},
    34  	{in: "BOB@hackernews", out: keybase1.SocialAssertion{User: "BOB", Service: "hackernews"}, ok: true},
    35  	{in: "BOB@reddit", out: keybase1.SocialAssertion{User: "bob", Service: "reddit"}, ok: true},
    36  	{in: "BOB@rooter", out: keybase1.SocialAssertion{User: "bob", Service: "rooter"}, ok: true},
    37  	{in: "BOB@facebook", out: keybase1.SocialAssertion{User: "bob", Service: "facebook"}, ok: true},
    38  	{in: "Akalin.Com@web", out: keybase1.SocialAssertion{User: "akalin.com", Service: "web"}, ok: true},
    39  	{in: "alice@gubble.SoCiAl", out: keybase1.SocialAssertion{User: "alice", Service: "gubble.social"}, ok: true},
    40  	{in: "a@gubble.SoCiAl", out: keybase1.SocialAssertion{}, ok: false},            // username check fails
    41  	{in: "alice@gubble", out: keybase1.SocialAssertion{}, ok: false},               // invalid service
    42  	{in: "sadtimes@nousers.notsocial", out: keybase1.SocialAssertion{}, ok: false}, // invalid service
    43  }
    44  
    45  func TestNormalizeSocialAssertion(t *testing.T) {
    46  	tc := setupTest(t, "NormalizeSocialAssertion", 1)
    47  	defer tc.Cleanup()
    48  	for _, test := range nsatests {
    49  		out, ok := NormalizeSocialAssertion(libkb.NewMetaContextForTest(tc), test.in)
    50  
    51  		require.Equal(t, test.out, out)
    52  		require.Equal(t, test.ok, ok)
    53  	}
    54  }