tfa 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fb7180ac2ccb7c877e05e1927763d9bdb0d4e6c
4
- data.tar.gz: f7d18a024879662a22404c42b1a3ef01975b027e
3
+ metadata.gz: e9f7fbb44a573c867d8a50eba076c43886e7badc
4
+ data.tar.gz: 9d6e750cd8c636b7fdd243848e80a335062c48cf
5
5
  SHA512:
6
- metadata.gz: 79e854463b20f67ec678ac3c0e0e08e3c00df4ce9fc27df0a0b7b320647d65de78d938fa38f9a3074f3050dd6789fa4f2166c6e24b173c7e540eb33d40fd6efd
7
- data.tar.gz: 0741cd7c80b47730893ad23fc962d0448a2e8ae3be72a4c98c5ddefab31fe423d8bd6ec4fbefeaa3a2c2b9b2d17c902a37642f73e360a2dfc3cbb725cc79ca23
6
+ metadata.gz: 1999844fac258b7908d306d7d01fd428d2f8ae2918c39826a14a07825fd1e8131aabea4d2cec247b5111e7435ae542dbc92592f6775d318ebd6e4dc1ff66eb02
7
+ data.tar.gz: 214f69224f8a41a12703c980dbb357e54d01ee9c5d05abc714cd113f4b242da19a4ddb2d8627699dfc6fb43ea9c7998e5c0247f4da307b34dcb03ff8278b1261
data/.travis.yml CHANGED
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.1
4
+ - 2.3.1
data/lib/tfa/cli.rb CHANGED
@@ -12,6 +12,11 @@ module TFA
12
12
  "Added #{name}"
13
13
  end
14
14
 
15
+ desc "destroy NAME", "remove the secret associated with the name"
16
+ def destroy(name)
17
+ storage.delete(name)
18
+ end
19
+
15
20
  desc "show NAME", "shows the secret for the given key"
16
21
  def show(name = nil)
17
22
  name ? storage.secret_for(name) : storage.all
data/lib/tfa/storage.rb CHANGED
@@ -30,6 +30,12 @@ module TFA
30
30
  end
31
31
  end
32
32
 
33
+ def delete(key)
34
+ @storage.transaction do
35
+ @storage.delete(key)
36
+ end
37
+ end
38
+
33
39
  private
34
40
 
35
41
  def open_readonly
@@ -13,6 +13,8 @@ module TFA
13
13
 
14
14
  def password_for(secret)
15
15
  ::ROTP::TOTP.new(secret).now
16
+ rescue ROTP::Base32::Base32Error
17
+ "INVALID SECRET"
16
18
  end
17
19
 
18
20
  def all_passwords
data/lib/tfa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TFA
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12".freeze
3
3
  end
data/spec/lib/cli_spec.rb CHANGED
@@ -6,22 +6,43 @@ module TFA
6
6
  ::ROTP::TOTP.new(secret).now
7
7
  end
8
8
 
9
- let(:secret) { ::ROTP::Base32.random_base32 }
9
+ let(:dev_secret) { ::ROTP::Base32.random_base32 }
10
+ let(:prod_secret) { ::ROTP::Base32.random_base32 }
10
11
 
11
12
  describe "#add" do
12
13
  context "when a secret is added" do
13
14
  it "adds the secret" do
14
- subject.add("development", secret)
15
- expect(subject.show("development")).to eql(secret)
15
+ subject.add("development", dev_secret)
16
+ expect(subject.show("development")).to eql(dev_secret)
16
17
  end
17
18
  end
18
19
 
19
20
  context "when a full otpauth string is added" do
20
21
  it "strips out the url for just the secret" do
21
- url = "otpauth://totp/email@email.com?secret=#{secret}&issuer="
22
+ url = "otpauth://totp/email@email.com?secret=#{dev_secret}&issuer="
22
23
 
23
24
  subject.add("development", url)
24
- expect(subject.show("development")).to eql(secret)
25
+ expect(subject.show("development")).to eql(dev_secret)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe "#show" do
31
+ context "when a single key is given" do
32
+ it "returns the secret" do
33
+ subject.add("development", dev_secret)
34
+ expect(subject.show("development")).to eql(dev_secret)
35
+ end
36
+ end
37
+
38
+ context "when no key is given" do
39
+ it "returns the secret for all keys" do
40
+ subject.add("development", dev_secret)
41
+ subject.add("production", prod_secret)
42
+
43
+ result = subject.show.to_s
44
+ expect(result).to include(dev_secret)
45
+ expect(result).to include(prod_secret)
25
46
  end
26
47
  end
27
48
  end
@@ -29,10 +50,32 @@ module TFA
29
50
  describe "#totp" do
30
51
  context "when a single key is given" do
31
52
  it "returns a time based one time password" do
32
- subject.add("development", secret)
33
- expect(subject.totp("development")).to eql(code_for(secret))
53
+ subject.add("development", dev_secret)
54
+ expect(subject.totp("development")).to eql(code_for(dev_secret))
34
55
  end
35
56
  end
57
+
58
+ context "when no key is given" do
59
+ it "returns a time based one time password for all keys" do
60
+ subject.add("development", dev_secret)
61
+ subject.add("production", prod_secret)
62
+
63
+ result = subject.totp.to_s
64
+ expect(result).to include(code_for(dev_secret))
65
+ expect(result).to include(code_for(prod_secret))
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "#destroy" do
71
+ let(:name) { "development" }
72
+
73
+ it "removes the secret with the given name" do
74
+ subject.add(name, dev_secret)
75
+ subject.destroy(name)
76
+
77
+ expect(subject.show(name)).to be_nil
78
+ end
36
79
  end
37
80
  end
38
81
  end
@@ -12,7 +12,7 @@ module TFA
12
12
  let(:secret) { ::ROTP::Base32.random_base32 }
13
13
 
14
14
  it "returns a time based one time password for the authentication secret given" do
15
- storage.save('development', secret)
15
+ storage.save("development", secret)
16
16
  expect(subject.run("development")).to eql(code_for(secret))
17
17
  end
18
18
  end
@@ -22,20 +22,34 @@ module TFA
22
22
  let(:staging_secret) { ::ROTP::Base32.random_base32 }
23
23
 
24
24
  it "returns the one time password for all keys" do
25
- storage.save('development', development_secret)
26
- storage.save('staging', staging_secret)
27
- expect(subject.run(nil)).to eql([
28
- { 'development' => code_for(development_secret) },
29
- { 'staging' => code_for(staging_secret) }
25
+ storage.save("development", development_secret)
26
+ storage.save("staging", staging_secret)
27
+
28
+ expect(subject.run(nil)).to match_array([
29
+ { "development" => code_for(development_secret) },
30
+ { "staging" => code_for(staging_secret) }
30
31
  ])
31
32
  end
32
33
  end
33
34
 
34
- context 'when the key is not known' do
35
+ context "when the key is not known" do
35
36
  it "returns with nothing" do
36
37
  expect(subject.run(["blah"])).to be_empty
37
38
  end
38
39
  end
40
+
41
+ context "when the secret is invalid" do
42
+ let(:invalid_secret) { "hello world" }
43
+
44
+ before :each do
45
+ storage.save("development", invalid_secret)
46
+ end
47
+
48
+ it "returns an error message" do
49
+ expected = { "development" => "INVALID SECRET" }
50
+ expect(subject.run(["development"])).to match_array([expected])
51
+ end
52
+ end
39
53
  end
40
54
  end
41
55
  end
data/tfa.gemspec CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = TFA::VERSION
9
9
  spec.authors = ["mo khan"]
10
10
  spec.email = ["mo@mokhan.ca"]
11
- spec.summary = %q{A CLI to manage your one time passwords.}
12
- spec.description = %q{A CLI to manage your one time passwords.}
13
- spec.homepage = ""
11
+ spec.summary = %q{A CLI to manage your time based one time passwords.}
12
+ spec.description = %q{A CLI to manage your time based one time passwords.}
13
+ spec.homepage = "https://github.com/mokhan/tfa/"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tfa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - mo khan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-09 00:00:00.000000000 Z
11
+ date: 2016-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rotp
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: A CLI to manage your one time passwords.
83
+ description: A CLI to manage your time based one time passwords.
84
84
  email:
85
85
  - mo@mokhan.ca
86
86
  executables:
@@ -106,7 +106,7 @@ files:
106
106
  - spec/lib/totp_command_spec.rb
107
107
  - spec/spec_helper.rb
108
108
  - tfa.gemspec
109
- homepage: ''
109
+ homepage: https://github.com/mokhan/tfa/
110
110
  licenses:
111
111
  - MIT
112
112
  metadata: {}
@@ -126,10 +126,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.4.5
129
+ rubygems_version: 2.5.2
130
130
  signing_key:
131
131
  specification_version: 4
132
- summary: A CLI to manage your one time passwords.
132
+ summary: A CLI to manage your time based one time passwords.
133
133
  test_files:
134
134
  - spec/lib/cli_spec.rb
135
135
  - spec/lib/console_spec.rb