spec/lib/totp_command_spec.rb in tfa-0.0.3 vs spec/lib/totp_command_spec.rb in tfa-0.0.4
- old
+ new
@@ -1,20 +1,34 @@
module TFA
describe TotpCommand do
subject { TotpCommand.new(storage) }
let(:secret) { ::ROTP::Base32.random_base32 }
- let(:storage) { PStore.new(Tempfile.new('test').path) }
+ let(:storage) { Storage.new(Tempfile.new('test').path) }
- before :each do
- storage.transaction do
- storage['development'] = secret
- end
+ def code_for(secret)
+ ::ROTP::TOTP.new(secret).now
end
describe "#run" do
- it "returns a time based one time password for the authentication secret given" do
- correct_code = ::ROTP::TOTP.new(secret).now
- expect(subject.run(["development"])).to eql(correct_code)
+ context "when a single key is given" do
+ it "returns a time based one time password for the authentication secret given" do
+ storage.save('development', secret)
+ expect(subject.run(["development"])).to eql(code_for(secret))
+ end
+ end
+
+ context "when no arguments are given" do
+ let(:development_secret) { ::ROTP::Base32.random_base32 }
+ let(:staging_secret) { ::ROTP::Base32.random_base32 }
+
+ it "returns the one time password for all keys" do
+ storage.save('development', development_secret)
+ storage.save('staging', staging_secret)
+ expect(subject.run([])).to eql([
+ { 'development' => code_for(development_secret) },
+ { 'staging' => code_for(staging_secret) }
+ ])
+ end
end
end
end
end