Commit 1c1770a
Changed files (2)
lib
tfa
spec
lib
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