From d39839cd5c129ec9acd30dfe7b87308d806795fc Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:07:47 -0700 Subject: add spec for invalid secret --- lib/tfa/totp_command.rb | 8 +++----- spec/lib/totp_command_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/tfa/totp_command.rb b/lib/tfa/totp_command.rb index 8dd0125..fe632a2 100644 --- a/lib/tfa/totp_command.rb +++ b/lib/tfa/totp_command.rb @@ -12,11 +12,9 @@ module TFA private def password_for(secret) - begin - ::ROTP::TOTP.new(secret).now - rescue - "???" - end + ::ROTP::TOTP.new(secret).now + rescue ROTP::Base32::Base32Error => error + "INVALID SECRET" end def all_passwords diff --git a/spec/lib/totp_command_spec.rb b/spec/lib/totp_command_spec.rb index 5049adc..ebc18a5 100644 --- a/spec/lib/totp_command_spec.rb +++ b/spec/lib/totp_command_spec.rb @@ -36,6 +36,17 @@ module TFA expect(subject.run(["blah"])).to be_empty end end + + context "when the secret is invalid" do + let(:invalid_secret) { "hello world" } + + it 'returns an error message' do + storage.save('development', invalid_secret) + expect(subject.run(["development"])).to eql([ + { 'development' => "INVALID SECRET" } + ]) + end + end end end end -- cgit v1.2.3 From b20eb1b797ae6d961a763cf66d4182704592767d Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:15:33 -0700 Subject: Add a destroy command to remove a secret. --- lib/tfa/cli.rb | 5 +++++ lib/tfa/storage.rb | 6 ++++++ lib/tfa/totp_command.rb | 2 +- spec/lib/cli_spec.rb | 11 +++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/tfa/cli.rb b/lib/tfa/cli.rb index 107f202..03feeeb 100644 --- a/lib/tfa/cli.rb +++ b/lib/tfa/cli.rb @@ -12,6 +12,11 @@ module TFA "Added #{name}" end + desc "destroy NAME", "remove the secret associated with the name" + def destroy(name) + storage.delete(name) + end + desc "show NAME", "shows the secret for the given key" def show(name = nil) name ? storage.secret_for(name) : storage.all diff --git a/lib/tfa/storage.rb b/lib/tfa/storage.rb index 1424315..5eb0a3a 100644 --- a/lib/tfa/storage.rb +++ b/lib/tfa/storage.rb @@ -30,6 +30,12 @@ module TFA end end + def delete(key) + @storage.transaction do + @storage.delete(key) + end + end + private def open_readonly diff --git a/lib/tfa/totp_command.rb b/lib/tfa/totp_command.rb index fe632a2..14bc064 100644 --- a/lib/tfa/totp_command.rb +++ b/lib/tfa/totp_command.rb @@ -13,7 +13,7 @@ module TFA def password_for(secret) ::ROTP::TOTP.new(secret).now - rescue ROTP::Base32::Base32Error => error + rescue ROTP::Base32::Base32Error "INVALID SECRET" end diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb index 80d1ab8..d1d10f3 100644 --- a/spec/lib/cli_spec.rb +++ b/spec/lib/cli_spec.rb @@ -66,5 +66,16 @@ module TFA end end end + + describe "#destroy" do + let(:name) { "development" } + + it 'removes the secret with the given name' do + subject.add(name, dev_secret) + subject.destroy(name) + + expect(subject.show(name)).to be_nil + end + end end end -- cgit v1.2.3 From e50e52ef391ab1f3a4efe192b43ff9eee7215148 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:15:57 -0700 Subject: bump version --- lib/tfa/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tfa/version.rb b/lib/tfa/version.rb index 411ea83..315a320 100644 --- a/lib/tfa/version.rb +++ b/lib/tfa/version.rb @@ -1,3 +1,3 @@ module TFA - VERSION = "0.0.11" + VERSION = "0.0.12" end -- cgit v1.2.3 From cf229b01155280187062e175dce161dad4d3c896 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:21:34 -0700 Subject: make hound happy. --- spec/lib/cli_spec.rb | 2 +- spec/lib/totp_command_spec.rb | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb index d1d10f3..f1a68d4 100644 --- a/spec/lib/cli_spec.rb +++ b/spec/lib/cli_spec.rb @@ -70,7 +70,7 @@ module TFA describe "#destroy" do let(:name) { "development" } - it 'removes the secret with the given name' do + it "removes the secret with the given name" do subject.add(name, dev_secret) subject.destroy(name) diff --git a/spec/lib/totp_command_spec.rb b/spec/lib/totp_command_spec.rb index ebc18a5..7aff1d9 100644 --- a/spec/lib/totp_command_spec.rb +++ b/spec/lib/totp_command_spec.rb @@ -12,7 +12,7 @@ module TFA let(:secret) { ::ROTP::Base32.random_base32 } it "returns a time based one time password for the authentication secret given" do - storage.save('development', secret) + storage.save("development", secret) expect(subject.run("development")).to eql(code_for(secret)) end end @@ -22,16 +22,16 @@ module TFA 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) + storage.save("development", development_secret) + storage.save("staging", staging_secret) expect(subject.run(nil)).to eql([ - { 'development' => code_for(development_secret) }, - { 'staging' => code_for(staging_secret) } + { "development" => code_for(development_secret) }, + { "staging" => code_for(staging_secret) } ]) end end - context 'when the key is not known' do + context "when the key is not known" do it "returns with nothing" do expect(subject.run(["blah"])).to be_empty end @@ -40,11 +40,13 @@ module TFA context "when the secret is invalid" do let(:invalid_secret) { "hello world" } - it 'returns an error message' do - storage.save('development', invalid_secret) - expect(subject.run(["development"])).to eql([ - { 'development' => "INVALID SECRET" } - ]) + before :each do + storage.save("development", invalid_secret) + end + + it "returns an error message" do + expected = { "development" => "INVALID SECRET" } + expect(subject.run(["development"])).to match_array([expected]) end end end -- cgit v1.2.3 From 528035e8e8d4e5e2703db548176338e98fbeab98 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:23:23 -0700 Subject: update description and ruby build. --- .travis.yml | 1 + tfa.gemspec | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 00cdd53..ced2a3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ language: ruby rvm: - 2.1.1 + - 2.3.1 diff --git a/tfa.gemspec b/tfa.gemspec index 03c5dab..bb7cde3 100644 --- a/tfa.gemspec +++ b/tfa.gemspec @@ -8,9 +8,9 @@ Gem::Specification.new do |spec| spec.version = TFA::VERSION spec.authors = ["mo khan"] spec.email = ["mo@mokhan.ca"] - spec.summary = %q{A CLI to manage your one time passwords.} - spec.description = %q{A CLI to manage your one time passwords.} - spec.homepage = "" + spec.summary = %q{A CLI to manage your time based one time passwords.} + spec.description = %q{A CLI to manage your time based one time passwords.} + spec.homepage = "https://github.com/mokhan/tfa/" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0") -- cgit v1.2.3 From d6f5d1d392f160da21d5191326848e44131ead91 Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:24:59 -0700 Subject: freeze the version --- lib/tfa/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tfa/version.rb b/lib/tfa/version.rb index 315a320..ffd9203 100644 --- a/lib/tfa/version.rb +++ b/lib/tfa/version.rb @@ -1,3 +1,3 @@ module TFA - VERSION = "0.0.12" + VERSION = "0.0.12".freeze end -- cgit v1.2.3 From 32938166ecb1d446101f0b312a3ba4635a010bdc Mon Sep 17 00:00:00 2001 From: mo khan Date: Fri, 18 Nov 2016 10:26:48 -0700 Subject: use match_array --- spec/lib/totp_command_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/lib/totp_command_spec.rb b/spec/lib/totp_command_spec.rb index 7aff1d9..58405e4 100644 --- a/spec/lib/totp_command_spec.rb +++ b/spec/lib/totp_command_spec.rb @@ -24,7 +24,8 @@ module TFA it "returns the one time password for all keys" do storage.save("development", development_secret) storage.save("staging", staging_secret) - expect(subject.run(nil)).to eql([ + + expect(subject.run(nil)).to match_array([ { "development" => code_for(development_secret) }, { "staging" => code_for(staging_secret) } ]) -- cgit v1.2.3