diff --git a/cmd/authenticator.go b/cmd/authenticator.go index c08906b0079..d7265bdf883 100644 --- a/cmd/authenticator.go +++ b/cmd/authenticator.go @@ -13,9 +13,9 @@ type KeyStoreAuthenticator interface { Authenticate(*store.Store, string) error } -// TerminalAuthenticator contains fields for prompting the user and an +// TerminalKeyStoreAuthenticator contains fields for prompting the user and an // exit code. -type TerminalAuthenticator struct { +type TerminalKeyStoreAuthenticator struct { Prompter Prompter } @@ -23,7 +23,7 @@ type TerminalAuthenticator struct { // the KeyStore, and if there are none, a new account will be created // by prompting for a password. If there are accounts present, the // account which is unlocked by the given password will be used. -func (auth TerminalAuthenticator) Authenticate(store *store.Store, pwd string) error { +func (auth TerminalKeyStoreAuthenticator) Authenticate(store *store.Store, pwd string) error { if len(pwd) != 0 { return auth.authenticateWithPwd(store, pwd) } else if auth.Prompter.IsTerminal() { @@ -33,14 +33,14 @@ func (auth TerminalAuthenticator) Authenticate(store *store.Store, pwd string) e } } -func (auth TerminalAuthenticator) authenticationPrompt(store *store.Store) error { +func (auth TerminalKeyStoreAuthenticator) authenticationPrompt(store *store.Store) error { if store.KeyStore.HasAccounts() { return auth.promptAndCheckPasswordLoop(store) } return auth.promptAndCreateAccount(store) } -func (auth TerminalAuthenticator) authenticateWithPwd(store *store.Store, pwd string) error { +func (auth TerminalKeyStoreAuthenticator) authenticateWithPwd(store *store.Store, pwd string) error { if !store.KeyStore.HasAccounts() { fmt.Println("There are no accounts, creating a new account with the specified password") return createAccount(store, pwd) @@ -56,7 +56,7 @@ func checkPassword(store *store.Store, phrase string) error { return nil } -func (auth TerminalAuthenticator) promptAndCheckPasswordLoop(store *store.Store) error { +func (auth TerminalKeyStoreAuthenticator) promptAndCheckPasswordLoop(store *store.Store) error { for { phrase := auth.Prompter.PasswordPrompt("Enter Password:") if checkPassword(store, phrase) == nil { @@ -67,7 +67,7 @@ func (auth TerminalAuthenticator) promptAndCheckPasswordLoop(store *store.Store) return nil } -func (auth TerminalAuthenticator) promptAndCreateAccount(store *store.Store) error { +func (auth TerminalKeyStoreAuthenticator) promptAndCreateAccount(store *store.Store) error { for { phrase := auth.Prompter.PasswordPrompt("New Password: ") clearLine() diff --git a/cmd/authenticator_test.go b/cmd/authenticator_test.go index 262ea70d7e4..9e1276bf266 100644 --- a/cmd/authenticator_test.go +++ b/cmd/authenticator_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestTerminalAuthenticatorWithNoAcctNoPwdCreatesAccount(t *testing.T) { +func TestTerminalKeyStoreAuthenticator_WithNoAcctNoPwdCreatesAccount(t *testing.T) { t.Parallel() app, cleanup := cltest.NewApplication() @@ -18,20 +18,20 @@ func TestTerminalAuthenticatorWithNoAcctNoPwdCreatesAccount(t *testing.T) { cltest.Password, "wrongconfirmation", cltest.Password, cltest.Password, }} - auth := cmd.TerminalAuthenticator{Prompter: prompt} + auth := cmd.TerminalKeyStoreAuthenticator{Prompter: prompt} assert.False(t, app.Store.KeyStore.HasAccounts()) assert.NoError(t, auth.Authenticate(app.Store, "")) assert.Equal(t, 4, prompt.Count) assert.Equal(t, 1, len(app.Store.KeyStore.Accounts())) } -func TestTerminalAuthenticatorWithNoAcctWithInitialPwdCreatesAcct(t *testing.T) { +func TestTerminalKeyStoreAuthenticator_WithNoAcctWithInitialPwdCreatesAcct(t *testing.T) { t.Parallel() app, cleanup := cltest.NewApplication() defer cleanup() - auth := cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}} + auth := cmd.TerminalKeyStoreAuthenticator{Prompter: &cltest.MockCountingPrompter{}} assert.Equal(t, 0, len(app.Store.KeyStore.Accounts())) assert.NoError(t, auth.Authenticate(app.Store, "somepassword")) @@ -39,7 +39,7 @@ func TestTerminalAuthenticatorWithNoAcctWithInitialPwdCreatesAcct(t *testing.T) assert.Equal(t, 1, len(app.Store.KeyStore.Accounts())) } -func TestTerminalAuthenticatorWithAcctNoInitialPwdPromptLoop(t *testing.T) { +func TestTerminalKeyStoreAuthenticator_WithAcctNoInitialPwdPromptLoop(t *testing.T) { t.Parallel() app, cleanup := cltest.NewApplicationWithKeyStore() @@ -50,12 +50,12 @@ func TestTerminalAuthenticatorWithAcctNoInitialPwdPromptLoop(t *testing.T) { EnteredStrings: []string{"wrongpassword", cltest.Password}, } - auth := cmd.TerminalAuthenticator{Prompter: prompt} + auth := cmd.TerminalKeyStoreAuthenticator{Prompter: prompt} assert.NoError(t, auth.Authenticate(app.Store, "")) assert.Equal(t, 2, prompt.Count) } -func TestTerminalAuthenticatorWithAcctAndPwd(t *testing.T) { +func TestTerminalKeyStoreAuthenticator_WithAcctAndPwd(t *testing.T) { t.Parallel() app, cleanup := cltest.NewApplicationWithKeyStore() @@ -71,7 +71,7 @@ func TestTerminalAuthenticatorWithAcctAndPwd(t *testing.T) { for _, test := range tests { t.Run(test.password, func(t *testing.T) { - auth := cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}} + auth := cmd.TerminalKeyStoreAuthenticator{Prompter: &cltest.MockCountingPrompter{}} err := auth.Authenticate(app.Store, test.password) assert.Equal(t, test.wantError, err != nil) }) diff --git a/main.go b/main.go index 445426eecd9..eef52d94bfd 100644 --- a/main.go +++ b/main.go @@ -168,7 +168,7 @@ func NewProductionClient() *cmd.Client { Renderer: cmd.RendererTable{Writer: os.Stdout}, Config: cfg, AppFactory: cmd.ChainlinkAppFactory{}, - KeyStoreAuthenticator: cmd.TerminalAuthenticator{Prompter: prompter}, + KeyStoreAuthenticator: cmd.TerminalKeyStoreAuthenticator{Prompter: prompter}, FallbackAPIInitializer: cmd.NewPromptingAPIInitializer(prompter), Runner: cmd.ChainlinkRunner{}, HTTP: cmd.NewAuthenticatedHTTPClient(cfg, cookieAuth), diff --git a/main_test.go b/main_test.go index e6d750a116b..bf84d545f32 100644 --- a/main_test.go +++ b/main_test.go @@ -16,7 +16,7 @@ func ExampleRun() { Renderer: cmd.RendererTable{Writer: ioutil.Discard}, Config: tc.Config, AppFactory: cmd.ChainlinkAppFactory{}, - KeyStoreAuthenticator: cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}}, + KeyStoreAuthenticator: cmd.TerminalKeyStoreAuthenticator{Prompter: &cltest.MockCountingPrompter{}}, FallbackAPIInitializer: &cltest.MockAPIInitializer{}, Runner: cmd.ChainlinkRunner{}, HTTP: cltest.NewMockAuthenticatedHTTPClient(tc.Config), @@ -64,7 +64,7 @@ func ExampleVersion() { Renderer: cmd.RendererTable{Writer: ioutil.Discard}, Config: tc.Config, AppFactory: cmd.ChainlinkAppFactory{}, - KeyStoreAuthenticator: cmd.TerminalAuthenticator{Prompter: &cltest.MockCountingPrompter{}}, + KeyStoreAuthenticator: cmd.TerminalKeyStoreAuthenticator{Prompter: &cltest.MockCountingPrompter{}}, FallbackAPIInitializer: &cltest.MockAPIInitializer{}, Runner: cmd.ChainlinkRunner{}, HTTP: cltest.NewMockAuthenticatedHTTPClient(tc.Config),