github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/engine/passphrase_check_test.go (about) 1 // Copyright 2019 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 "testing" 8 9 "github.com/stretchr/testify/require" 10 11 "github.com/keybase/client/go/libkb" 12 "github.com/keybase/client/go/protocol/keybase1" 13 ) 14 15 func TestPassphraseChange(t *testing.T) { 16 tc := SetupEngineTest(t, "PassphraseChange") 17 defer tc.Cleanup() 18 19 u := CreateAndSignupFakeUser(tc, "login") 20 21 arg := &keybase1.PassphraseCheckArg{} 22 secretUI := u.NewSecretUI() 23 uis := libkb.UIs{ 24 SecretUI: secretUI, 25 } 26 eng := NewPassphraseCheck(tc.G, arg) 27 m := NewMetaContextForTest(tc).WithUIs(uis) 28 err := eng.Run(m) 29 require.NoError(t, err) 30 require.True(t, eng.GetResult()) 31 32 secretUI.Passphrase += " " 33 err = eng.Run(m) 34 require.NoError(t, err) 35 require.False(t, eng.GetResult()) 36 37 // Without SecretUI and without passphrase argument. 38 m = NewMetaContextForTest(tc) 39 err = eng.Run(m) 40 require.Error(t, err) 41 42 // Pass passphrase in arg 43 arg.Passphrase = u.Passphrase 44 eng = NewPassphraseCheck(tc.G, arg) 45 err = eng.Run(m) 46 require.NoError(t, err) 47 require.True(t, eng.GetResult()) 48 49 arg.Passphrase = u.Passphrase + " " 50 eng = NewPassphraseCheck(tc.G, arg) 51 err = eng.Run(m) 52 require.NoError(t, err) 53 require.False(t, eng.GetResult()) 54 }