Commit 5a175f5

mo khan <mo@mokhan.ca>
2014-08-03 15:41:55
dump all time based one time passwords when the key is not known.
1 parent 4a56dab
Changed files (2)
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
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