diff options
| -rw-r--r-- | .travis.yml | 1 | ||||
| -rw-r--r-- | lib/tfa/cli.rb | 5 | ||||
| -rw-r--r-- | lib/tfa/storage.rb | 6 | ||||
| -rw-r--r-- | lib/tfa/totp_command.rb | 8 | ||||
| -rw-r--r-- | lib/tfa/version.rb | 2 | ||||
| -rw-r--r-- | spec/lib/cli_spec.rb | 11 | ||||
| -rw-r--r-- | spec/lib/totp_command_spec.rb | 28 | ||||
| -rw-r--r-- | tfa.gemspec | 6 |
8 files changed, 51 insertions, 16 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/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 8dd0125..14bc064 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 + "INVALID SECRET" end def all_passwords diff --git a/lib/tfa/version.rb b/lib/tfa/version.rb index 411ea83..ffd9203 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".freeze end diff --git a/spec/lib/cli_spec.rb b/spec/lib/cli_spec.rb index 80d1ab8..f1a68d4 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 diff --git a/spec/lib/totp_command_spec.rb b/spec/lib/totp_command_spec.rb index 5049adc..58405e4 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,20 +22,34 @@ 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) - expect(subject.run(nil)).to eql([ - { 'development' => code_for(development_secret) }, - { 'staging' => code_for(staging_secret) } + storage.save("development", development_secret) + storage.save("staging", staging_secret) + + expect(subject.run(nil)).to match_array([ + { "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 end + + context "when the secret is invalid" do + let(:invalid_secret) { "hello world" } + + 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 end end 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") |
