github-auth 0.5.0 → 0.6.0
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 +4 -4
- data/lib/github/auth/keys_file.rb +10 -7
- data/lib/github/auth/version.rb +1 -1
- data/spec/unit/github/auth/keys_file_spec.rb +37 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13910bb7a77151c5be95f4fda4fcd3dde4e2bd67
|
4
|
+
data.tar.gz: 3ad56d064832e34b9510745ca8f3514e59e3a0ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4a4de892ab9447007bf7ea946502d5f61393676585bb0b03876d25684ac89fe849bd206a80d08345a01f94a62a8027e287377ac3dea77e300e4f4f6f47ab922
|
7
|
+
data.tar.gz: b7fe980cc445036dc62c743dd778794f4647fd13432d3912be7ac68ce8a961185c4d41f80515be4e1162b7ceea44609337dad8d043d451c92602b8ec639fabc2
|
@@ -13,9 +13,12 @@ module Github::Auth
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def write!(keys)
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
Array(keys).each do |key|
|
17
|
+
unless keys_file_content.include? key
|
18
|
+
append_keys_file do |keys_file|
|
19
|
+
keys_file.write "\n" unless keys_file_content.empty?
|
20
|
+
keys_file.write key
|
21
|
+
end
|
19
22
|
end
|
20
23
|
end
|
21
24
|
end
|
@@ -36,6 +39,10 @@ module Github::Auth
|
|
36
39
|
with_keys_file 'w', block
|
37
40
|
end
|
38
41
|
|
42
|
+
def keys_file_content
|
43
|
+
with_keys_file 'r', Proc.new { |keys_file| keys_file.read }
|
44
|
+
end
|
45
|
+
|
39
46
|
def with_keys_file(mode, block)
|
40
47
|
File.open(path, mode) { |keys_file| block.call keys_file }
|
41
48
|
rescue Errno::EACCES => e
|
@@ -44,10 +51,6 @@ module Github::Auth
|
|
44
51
|
raise FileDoesNotExistError.new e
|
45
52
|
end
|
46
53
|
|
47
|
-
def keys_file_content
|
48
|
-
File.read path
|
49
|
-
end
|
50
|
-
|
51
54
|
def keys_file_content_without(keys)
|
52
55
|
keys_file_content.tap do |content|
|
53
56
|
Array(keys).each {|k| content.gsub! /#{Regexp.escape k}( .*)?$\n?/, '' }
|
data/lib/github/auth/version.rb
CHANGED
@@ -5,7 +5,6 @@ require 'github/auth/keys_file'
|
|
5
5
|
describe Github::Auth::KeysFile do
|
6
6
|
subject { described_class.new path: path }
|
7
7
|
|
8
|
-
let(:keys) { %w(abc123 def456 ghi789) }
|
9
8
|
let(:keys_file) { Tempfile.new 'authorized_keys' }
|
10
9
|
let(:path) { keys_file.path }
|
11
10
|
|
@@ -38,39 +37,60 @@ describe Github::Auth::KeysFile do
|
|
38
37
|
end
|
39
38
|
|
40
39
|
describe '#write!' do
|
41
|
-
|
42
|
-
|
40
|
+
shared_examples_for 'a successful key addition' do
|
41
|
+
it 'writes the key to the keys file' do
|
42
|
+
subject.write! keys
|
43
|
+
|
44
|
+
keys_file.read.tap do |keys_file_content|
|
45
|
+
keys.each { |key| expect(keys_file_content).to include key }
|
46
|
+
end
|
47
|
+
end
|
43
48
|
|
44
|
-
|
45
|
-
|
49
|
+
it 'does not leave a blank line' do
|
50
|
+
subject.write! keys
|
51
|
+
|
52
|
+
expect(
|
53
|
+
keys_file.readlines.select { |line| line =~ /^$\n/ }
|
54
|
+
).to be_empty
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
58
|
+
context 'with many keys' do
|
59
|
+
let(:keys) { %w(abc123 def456 ghi789) }
|
60
|
+
|
61
|
+
it_should_behave_like 'a successful key addition'
|
62
|
+
end
|
63
|
+
|
49
64
|
context 'with a single key' do
|
50
|
-
let(:
|
65
|
+
let(:keys) { %w(abc123) }
|
51
66
|
|
52
|
-
|
53
|
-
subject.write! key
|
54
|
-
expect(keys_file.read).to include key
|
55
|
-
end
|
67
|
+
it_should_behave_like 'a successful key addition'
|
56
68
|
end
|
57
69
|
|
58
70
|
context 'with existing keys in the keys file' do
|
59
|
-
let(:existing_keys) { %w(ghi789
|
71
|
+
let(:existing_keys) { %w(abc123 def456 ghi789) }
|
72
|
+
let(:keys) { %w(jkl012) }
|
60
73
|
|
61
74
|
before do
|
62
75
|
keys_file.write existing_keys.join("\n")
|
63
76
|
keys_file.rewind
|
64
77
|
end
|
65
78
|
|
79
|
+
it_should_behave_like 'a successful key addition'
|
80
|
+
|
66
81
|
it 'preserves the existing keys' do
|
67
82
|
subject.write! keys
|
68
|
-
|
69
|
-
|
83
|
+
|
84
|
+
keys_file.read.tap do |keys_file_content|
|
85
|
+
existing_keys.each do |key|
|
86
|
+
expect(keys_file_content).to include "#{key}\n"
|
87
|
+
end
|
88
|
+
end
|
70
89
|
end
|
71
90
|
|
72
91
|
it 'does not write duplicate keys into the keys file' do
|
73
92
|
subject.write! existing_keys.first
|
93
|
+
|
74
94
|
expect(keys_file.readlines.count).to eq existing_keys.count
|
75
95
|
end
|
76
96
|
end
|
@@ -80,7 +100,7 @@ describe Github::Auth::KeysFile do
|
|
80
100
|
|
81
101
|
it 'raises PermissionDeniedError' do
|
82
102
|
expect {
|
83
|
-
subject.write!
|
103
|
+
subject.write! %w(abc123 def456)
|
84
104
|
}.to raise_error Github::Auth::KeysFile::PermissionDeniedError
|
85
105
|
end
|
86
106
|
end
|
@@ -90,13 +110,15 @@ describe Github::Auth::KeysFile do
|
|
90
110
|
|
91
111
|
it 'raises FileDoesNotExistError' do
|
92
112
|
expect {
|
93
|
-
subject.write!
|
113
|
+
subject.write! %w(abc123 def456)
|
94
114
|
}.to raise_error Github::Auth::KeysFile::FileDoesNotExistError
|
95
115
|
end
|
96
116
|
end
|
97
117
|
end
|
98
118
|
|
99
119
|
describe '#delete!' do
|
120
|
+
let(:keys) { %w(abc123 def456 ghi789) }
|
121
|
+
|
100
122
|
before do
|
101
123
|
keys_file.write keys.join("\n")
|
102
124
|
keys_file.rewind
|