github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/engine/scankeys_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 engine 5 6 import ( 7 "github.com/keybase/client/go/libkb" 8 keybase1 "github.com/keybase/client/go/protocol/keybase1" 9 "github.com/stretchr/testify/require" 10 "testing" 11 ) 12 13 func TestScanKeys(t *testing.T) { 14 tc := SetupEngineTest(t, "ScanKeys") 15 defer tc.Cleanup() 16 17 fu := CreateAndSignupFakeUser(tc, "login") 18 m := NewMetaContextForTest(tc).WithSecretUI(fu.NewSecretUI()) 19 20 sk, err := NewScanKeys(m) 21 if err != nil { 22 t.Fatal(err) 23 } 24 25 if sk.Count() != 0 { 26 t.Errorf("scankey count: %d, expected 0", sk.Count()) 27 } 28 } 29 30 // TestScanKeysSync checks a user with a synced PGP key 31 func TestScanKeysSync(t *testing.T) { 32 tc := SetupEngineTest(t, "PGPDecrypt") 33 defer tc.Cleanup() 34 35 // First setup a user with a synced PGP private key 36 fu := createFakeUserWithPGPOnly(t, tc) 37 uis := libkb.UIs{ 38 ProvisionUI: newTestProvisionUIPassphrase(), 39 LoginUI: &libkb.TestLoginUI{Username: fu.Username}, 40 LogUI: tc.G.UI.GetLogUI(), 41 SecretUI: fu.NewSecretUI(), 42 GPGUI: &gpgtestui{}, 43 } 44 45 // Now provision a full device. 46 m := NewMetaContextForTest(tc).WithUIs(uis) 47 eng := NewLogin(tc.G, keybase1.DeviceTypeV2_DESKTOP, "", keybase1.ClientType_CLI) 48 err := RunEngine2(m, eng) 49 require.NoError(t, err, "provisioning worked") 50 51 // Now scankeys should work without any additional secrets. 52 m = m.WithUIs(libkb.UIs{}) 53 sk, err := NewScanKeys(m) 54 require.NoError(t, err, "scanning keys worked") 55 56 if sk.Count() != 1 { 57 t.Errorf("scankey count: %d, expected 1", sk.Count()) 58 } 59 }