Skip to content

Commit 5a6d838

Browse files
author
Chris Hunt
committed
Merge branch 'pr/9'
* pr/9: Adds a newline at the very end of the authorized_keys file
2 parents 8565538 + d07c8e2 commit 5a6d838

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

lib/github/auth/keys_file.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def write!(keys)
1616
Array(keys).each do |key|
1717
unless keys_file_content.include? key.key
1818
append_keys_file do |keys_file|
19-
keys_file.write "\n" unless keys_file_content.empty?
20-
keys_file.write key
19+
keys_file.write "\n" unless keys_file_content.empty? || keys_file_content.end_with?("\n")
20+
keys_file.write "#{key}\n"
2121
end
2222
end
2323
end
@@ -57,7 +57,7 @@ def keys_file_content_without(keys)
5757
content.gsub! /#{Regexp.escape key.key}( .*)?$\n?/, ''
5858
end
5959

60-
content.strip!
60+
content << "\n" unless content.empty? || content.end_with?("\n")
6161
end
6262
end
6363
end

spec/unit/github/auth/keys_file_spec.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,10 @@
4949
end
5050
end
5151

52-
it 'does not leave a blank line' do
52+
it 'includes a newline after the last key' do
5353
subject.write! keys
5454

55-
expect(
56-
keys_file.readlines.select { |line| line =~ /^$\n/ }
57-
).to be_empty
55+
expect(keys_file.read).to end_with("\n")
5856
end
5957
end
6058

@@ -80,6 +78,7 @@
8078

8179
before do
8280
keys_file.write existing_keys.join("\n")
81+
keys_file.write "\n"
8382
keys_file.rewind
8483
end
8584

@@ -132,6 +131,7 @@
132131

133132
before do
134133
keys_file.write keys.join("\n")
134+
keys_file.write "\n"
135135
keys_file.rewind
136136
end
137137

@@ -152,12 +152,10 @@
152152
end
153153
end
154154

155-
it 'does not leave a blank line' do
156-
subject.delete! key
155+
it 'includes a newline after the last key' do
156+
subject.write! keys
157157

158-
expect(
159-
keys_file.readlines.select { |line| line =~ /^$\n/ }
160-
).to be_empty
158+
expect(keys_file.read).to end_with("\n")
161159
end
162160
end
163161

0 commit comments

Comments
 (0)