diff options
| author | mo khan <mo@mokhan.ca> | 2014-08-03 09:41:55 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-08-03 09:41:55 -0600 |
| commit | 5a175f53268dc9a8c090fcc68e4b82716062a413 (patch) | |
| tree | ef56cf56978a313ee65069ea07d6d0123e0dba27 | |
| parent | 4a56daba4a9bdf8605664a5fb157bc55e7517d7e (diff) | |
dump all time based one time passwords when the key is not known.
| -rw-r--r-- | lib/tfa/totp_command.rb | 8 | ||||
| -rw-r--r-- | spec/lib/totp_command_spec.rb | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/tfa/totp_command.rb b/lib/tfa/totp_command.rb index b49afde..63ecd13 100644 --- a/lib/tfa/totp_command.rb +++ b/lib/tfa/totp_command.rb @@ -5,7 +5,7 @@ module TFA end def run(arguments) - return password_for(secret_for(arguments.first)) if arguments.any? + return password_for(secret_for(arguments.first)) if valid?(arguments) all_passwords end @@ -24,7 +24,11 @@ module TFA end def secret_for(key) - @storage.secret_for(key) + @storage.secret_for(key) + end + + def valid?(arguments) + arguments.any? && secret_for(arguments.first) end end end diff --git a/spec/lib/totp_command_spec.rb b/spec/lib/totp_command_spec.rb index 44267b2..9c5dd2e 100644 --- a/spec/lib/totp_command_spec.rb +++ b/spec/lib/totp_command_spec.rb @@ -31,6 +31,12 @@ module TFA ]) end end + + context 'when the key is not known' do + it "returns with nothing" do + expect(subject.run(["blah"])).to be_empty + end + end end end end |
