github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libpages/config/config_test.go (about) 1 // Copyright 2017 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 5 package config 6 7 import ( 8 "bytes" 9 "encoding/json" 10 "testing" 11 12 "github.com/stretchr/testify/require" 13 ) 14 15 func TestParseConfigV1(t *testing.T) { 16 config := &V1{ 17 Common: Common{ 18 Version: Version1Str, 19 }, 20 Users: map[string]string{ 21 "alice": generateBcryptPasswordHashForTestOrBust(t, "12345"), 22 "bob": generateSHA256PasswordHashForTestOrBust(t, "54321"), 23 }, 24 PerPathConfigs: map[string]PerPathConfigV1{ 25 "/alice-and-bob": { 26 WhitelistAdditionalPermissions: map[string]string{ 27 "alice": PermReadAndList, 28 "bob": PermRead, 29 }, 30 }, 31 }, 32 } 33 buf := &bytes.Buffer{} 34 err := json.NewEncoder(buf).Encode(config) 35 require.NoError(t, err) 36 parsed, err := ParseConfig(buf) 37 require.NoError(t, err) 38 parsedV1, ok := parsed.(*V1) 39 require.True(t, ok) 40 require.Equal(t, config.PerPathConfigs, parsedV1.PerPathConfigs) 41 require.Equal(t, config.Common, parsedV1.Common) 42 require.Equal(t, config.Users, parsedV1.Users) 43 }