summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2014-08-03 09:41:55 -0600
committermo khan <mo@mokhan.ca>2014-08-03 09:41:55 -0600
commit5a175f53268dc9a8c090fcc68e4b82716062a413 (patch)
treeef56cf56978a313ee65069ea07d6d0123e0dba27
parent4a56daba4a9bdf8605664a5fb157bc55e7517d7e (diff)
dump all time based one time passwords when the key is not known.
-rw-r--r--lib/tfa/totp_command.rb8
-rw-r--r--spec/lib/totp_command_spec.rb6
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