Commit 1c1770a

Gavin Miller <gavmille@cisco.com>
2015-08-06 19:36:59
Added failing spec & fix for array passing of [name] to TotpCommand.new.run()
1 parent 5f859a7
Changed files (2)
lib
spec
lib/tfa/cli.rb
@@ -18,7 +18,7 @@ module TFA
 
     desc "totp NAME", "generate a Time based One Time Password"
     def totp(name = nil)
-      TotpCommand.new(storage).run([name])
+      TotpCommand.new(storage).run(name)
     end
 
     private
spec/lib/cli_spec.rb
@@ -0,0 +1,20 @@
+module TFA
+  describe CLI do
+    subject { CLI.new }
+
+    def code_for(secret)
+      ::ROTP::TOTP.new(secret).now
+    end
+
+    describe "#totp" do
+      context "when a single key is given" do
+        let(:secret) { ::ROTP::Base32.random_base32 }
+
+        it "returns a time based one time password for the authentication secret given" do
+          subject.add('development', secret)
+          expect(subject.totp("development")).to eql(code_for(secret))
+        end
+      end
+    end
+  end
+end