|
1 | 1 | require 'spec_helper' |
2 | 2 |
|
3 | | -describe "ssh_config resource" do |
| 3 | +describe 'ssh_config resource' do |
4 | 4 |
|
5 | 5 | let(:chef_run) do |
6 | 6 | runner = ChefSpec::SoloRunner.new(:step_into => :ssh_config) |
7 | 7 | runner.converge('ssh_test::config') |
8 | 8 | end |
9 | 9 |
|
10 | 10 | let(:default_config) { '/etc/ssh/ssh_config' } |
11 | | - let(:vagrant_config) { '/home/vagrant' } |
| 11 | + let(:vagrant_config) { '/home/vagrant/.ssh/config' } |
12 | 12 |
|
13 | 13 | let(:test_user) { 'someone' } |
14 | 14 | let(:test_group) { 'other_group' } |
15 | | - let(:test_config) { '/some/random/path' } |
| 15 | + let(:test_config) { '/some/random/path/config' } |
16 | 16 |
|
17 | 17 | let(:partial_start) do |
18 | 18 | content = [] |
|
54 | 54 |
|
55 | 55 | let(:test_end) do |
56 | 56 | content = [] |
57 | | - content << 'Host github.com' |
| 57 | + content << 'Host test.io' |
58 | 58 | content << ' User testuser' |
59 | 59 | content << ' DummyKey I was allowed' |
60 | 60 | content << '' |
|
77 | 77 | allow(IO).to receive(:foreach) |
78 | 78 | allow(IO).to partial_start.reduce(receive(:foreach).with(vagrant_config), :and_yield) |
79 | 79 | allow(IO).to partial_start.reduce(receive(:foreach).with(default_config), :and_yield) |
| 80 | + allow(IO).to partial_start.reduce(receive(:foreach).with(test_config), :and_yield) |
80 | 81 |
|
81 | 82 | allow(Etc).to receive(:getpwnam) |
82 | 83 | allow(Etc).to receive(:getpwnam).with('vagrant').and_return( |
|
162 | 163 | break if found_one |
163 | 164 | end |
164 | 165 | end |
| 166 | + |
| 167 | + it 'can create user ssh configs' do |
| 168 | + expect(chef_run).to create_file(vagrant_config).with( |
| 169 | + :owner => 'vagrant', |
| 170 | + :group => 200, |
| 171 | + :mode => 00600 |
| 172 | + ).with_content( |
| 173 | + (common_end + github_and_partial_end).join("\n") |
| 174 | + ) |
| 175 | + end |
| 176 | + |
| 177 | + it 'can create the global ssh config' do |
| 178 | + expect(chef_run).to create_file(default_config).with( |
| 179 | + :owner => 'root', |
| 180 | + :group => 0, |
| 181 | + :mode => 00644 |
| 182 | + ).with_content( |
| 183 | + (common_end + github_and_partial_end).join("\n") |
| 184 | + ) |
| 185 | + end |
| 186 | + |
| 187 | + it 'creates the /etc/ssh directory if it is missing' do |
| 188 | + expect(chef_run).to create_directory(::File.dirname(default_config)).with( |
| 189 | + :owner => 'root', |
| 190 | + :group => 0, |
| 191 | + :mode => 00755 |
| 192 | + ) |
| 193 | + end |
| 194 | + |
| 195 | + it "creates vagrant's ~/.ssh/config file" do |
| 196 | + expect(chef_run).to create_directory(::File.dirname(vagrant_config)).with( |
| 197 | + :owner => 'vagrant', |
| 198 | + :group => 200, |
| 199 | + :mode => 00700 |
| 200 | + ) |
| 201 | + end |
| 202 | + |
| 203 | + context 'when non-default attributes are used' do |
| 204 | + it 'can handle a custom path' do |
| 205 | + expect(chef_run).to render_file(test_config).with_content( |
| 206 | + (common_end + test_and_partial_end).join("\n") |
| 207 | + ) |
| 208 | + end |
| 209 | + |
| 210 | + it 'can handle a custom owner and group for the config file' do |
| 211 | + expect(chef_run).to create_file(test_config).with( |
| 212 | + :owner => test_user, |
| 213 | + :group => test_group, |
| 214 | + :mode => 00600 |
| 215 | + ) |
| 216 | + end |
| 217 | + end |
165 | 218 | end |
0 commit comments