/
key_file_writer_spec.rb
61 lines (53 loc) · 1.83 KB
/
key_file_writer_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
module SSHMuggle
describe KeyfileWriter do
context "dumping keys to files" do
before :each do
@writer = KeyfileWriter.new
end
context "#write" do
before :each do
sorted_keys = [
key_fixtures[:pascal],
key_fixtures[:pascal_private],
key_fixtures[:pascal_laptop],
key_fixtures[:bob],
key_fixtures[:upcase]
]
sorted_keys.each do |key|
@writer.write key
end
end
it "should replace special characters with underscores in filename" do
it_should_generate_keyfile 'bob_schneider.pub'
it_should_generate_keyfile 'pascal_friederich.pub'
end
it "should write the ssh key in the appropriate keyfile" do
File.read('keys/bob_schneider.pub').chomp.should == key_fixtures[:bob]
File.read('keys/pascal_friederich.pub').chomp.should == key_fixtures[:pascal]
end
it "should turn the filenames to underscores" do
it_should_generate_keyfile 'upcase_van.pub'
end
it "should number dublicate keynames" do
it_should_generate_keyfile 'pascal_friederich_2.pub'
it_should_generate_keyfile 'pascal_friederich_3.pub'
end
end
context "#write_keys" do
it "should write every key" do
@writer.should_receive(:write).exactly(3).times
keys = [
key_fixtures[:pascal],
key_fixtures[:pascal_private],
key_fixtures[:pascal_laptop]
]
@writer.write_keys(keys)
end
end
end
end
end
def it_should_generate_keyfile(keyfile)
Dir['keys/*.pub'].map {|path| path.split('/').last }.should include keyfile
end