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

     1  package externals
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	libkb "github.com/keybase/client/go/libkb"
     8  	"github.com/keybase/client/go/protocol/keybase1"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestLoadParamServices(t *testing.T) {
    13  	tc := setupTest(t, "TestLoadParamServices", 1)
    14  	defer tc.Cleanup()
    15  
    16  	m := libkb.NewMetaContextForTest(tc)
    17  
    18  	proofServices := newProofServices(tc.G)
    19  	entry, err := tc.G.GetParamProofStore().GetLatestEntry(m)
    20  	require.NoError(t, err)
    21  
    22  	config, err := proofServices.parseServerConfig(m, entry)
    23  	require.NoError(t, err)
    24  	require.NotNil(t, config.ProofConfigs)
    25  	require.NotNil(t, config.DisplayConfigs)
    26  	require.NotZero(t, len(config.ProofConfigs))
    27  	require.NotZero(t, len(config.DisplayConfigs))
    28  
    29  	// assert that we parse the dev gubble configuration correctly
    30  	var gubbleConf *GenericSocialProofConfig
    31  	for _, config := range config.ProofConfigs {
    32  		if config.Domain == "gubble.social" {
    33  			gubbleConf = config
    34  			break
    35  		}
    36  	}
    37  	t.Logf("Found config %+v", gubbleConf)
    38  	require.NotNil(t, gubbleConf)
    39  	require.True(t, gubbleConf.Version >= 1)
    40  	require.Equal(t, "gubble.social", gubbleConf.Domain)
    41  	require.Equal(t, keybase1.ParamProofUsernameConfig{
    42  		Re:  "^([a-zA-Z0-9_])+$",
    43  		Min: 2,
    44  		Max: 20,
    45  	}, gubbleConf.UsernameConfig)
    46  	require.NotZero(t, len(gubbleConf.BrandColor))
    47  	require.NotZero(t, len(gubbleConf.DisplayName))
    48  	require.NotZero(t, len(gubbleConf.Description))
    49  
    50  	serverURI, err := tc.G.Env.GetServerURI()
    51  	require.NoError(t, err)
    52  
    53  	gubbleRoot := fmt.Sprintf("%s/_/gubble_universe/gubble_social", serverURI)
    54  	gubbleAPIRoot := fmt.Sprintf("%s/_/api/1.0/gubble_universe/gubble_social", serverURI)
    55  	require.Equal(t, fmt.Sprintf("%s%s", gubbleRoot, "/%{username}"), gubbleConf.ProfileUrl)
    56  	require.Equal(t, fmt.Sprintf("%s%s", gubbleRoot, "?kb_username=%{kb_username}&username=%{username}&sig_hash=%{sig_hash}&kb_ua=%{kb_ua}"), gubbleConf.PrefillUrl)
    57  	require.Equal(t, fmt.Sprintf("%s%s", gubbleAPIRoot, "/%{username}/proofs.json"), gubbleConf.CheckUrl)
    58  
    59  	require.Equal(t, []keybase1.SelectorEntry{
    60  		{
    61  			IsKey: true,
    62  			Key:   "res",
    63  		},
    64  		{
    65  			IsKey: true,
    66  			Key:   "keybase_proofs",
    67  		},
    68  	}, gubbleConf.CheckPath)
    69  
    70  	require.Equal(t, []keybase1.SelectorEntry{
    71  		{
    72  			IsKey: true,
    73  			Key:   "res",
    74  		},
    75  		{
    76  			IsKey: true,
    77  			Key:   "avatar",
    78  		},
    79  	}, gubbleConf.AvatarPath)
    80  
    81  	foundGubble := false
    82  	foundFacebook := false
    83  	for _, config := range config.DisplayConfigs {
    84  		if config.Key == "gubble.social" {
    85  			group := "Gubble instance"
    86  			require.NotNil(t, config.Group)
    87  			require.EqualValues(t, group, *config.Group)
    88  			require.False(t, config.CreationDisabled)
    89  			foundGubble = true
    90  			if foundFacebook {
    91  				break
    92  			}
    93  		}
    94  		if config.Key == "facebook" {
    95  			require.True(t, config.CreationDisabled)
    96  			foundFacebook = true
    97  			if foundGubble {
    98  				break
    99  			}
   100  		}
   101  	}
   102  	require.True(t, foundGubble && foundFacebook)
   103  }