Skip to content

Commit d65ecee

Browse files
committed
Merge pull request #38 from tejaycar/master
Version 0.10.2
2 parents ace9e82 + 7fb5637 commit d65ecee

File tree

10 files changed

+84
-40
lines changed

10 files changed

+84
-40
lines changed

.kitchen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ driver:
33
name: vagrant
44

55
driver_config:
6-
require_chef_omnibus: true
6+
require_chef_omnibus: '11.16.4'
77
box: opscode-ubuntu-12.04
88
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
99

Berksfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
source "https://supermarket.getchef.com"
1+
source 'https://supermarket.getchef.com'
22

33
metadata
44

55
group :test do
6-
cookbook "ssh_test", :path => "./test/cookbooks/ssh_test"
6+
cookbook 'ssh_test', :path => './test/cookbooks/ssh_test'
77
end

Berksfile.lock

Lines changed: 0 additions & 13 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# CHANGELOG for ssh
2+
## 0.10.2
3+
* Update the README
4+
* Fix some spec tests
5+
* Fix bug in `config` that did not allow `HostName` directive
6+
7+
## 0.10.0
8+
* MAJOR rewrite, but no breaking changes known of.
29

310
## 0.6.5
411

Rakefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
require 'rspec/core/rake_task'
2+
require 'rubocop/rake_task'
3+
require 'foodcritic'
4+
require 'kitchen'
5+
6+
# lint tests. Rubocop and Foodcritic
7+
namespace :lint do
8+
desc 'Run Ruby lint checks'
9+
RuboCop::RakeTask.new(:ruby)
10+
11+
desc 'Run Chef lint checks'
12+
FoodCritic::Rake::LintTask.new(:chef) do |t|
13+
t.options = {
14+
:fail_tags => %w(any)
15+
}
16+
end
17+
end
18+
19+
desc 'Run all style checks'
20+
task :lint => %w(lint:chef lint:ruby)
21+
22+
# Rspec and ChefSpec
23+
desc 'Run ChefSpec examples'
24+
RSpec::Core::RakeTask.new(:spec)
25+
26+
# Integration tests. Kitchen.ci
27+
desc 'Run Test Kitchen'
28+
task :integration do
29+
Kitchen.logger = Kitchen.default_file_logger
30+
Kitchen::Config.new.instances.each do |instance|
31+
instance.test(:always)
32+
end
33+
end
34+
35+
# Default
36+
task :default => %w(all)
37+
38+
desc 'Run only the reasonably fast tests (lint, spec, and fast kitchen tests'
39+
task :fast => %w(lint spec)
40+
41+
desc 'Run everything we have'
42+
task :all => %w(lint spec integration)

libraries/ssh_config_helpers.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@ def parse_file(path)
1919
IO.foreach(path) do |line|
2020
next if line.match(/^\s*(#|\r?\n|\s*$)/) # skip lines with only comments or whitespace
2121

22-
matchdata = line.match(/^\s*([h|H]ost\s+)(.*$)/)
23-
if matchdata
24-
name = matchdata.captures[1].strip
25-
entries[name] = {}
26-
next
27-
end
22+
check_name = parse_name(line)
23+
next if check_name && (name = check_name) && (entries[name] = {})
2824

29-
matchdata = line.match(/^\s*(\w+)(.*$)/)
30-
unless matchdata
31-
Chef::Log.error("Line |#{line}| does not parse correctly")
32-
next
33-
end
34-
entries[name][matchdata.captures[0]] = matchdata.captures[1].strip
25+
key, entry = parse_line(line)
26+
next unless entry
27+
entries[name][key] = entry
3528
end
3629
entries
3730
end
@@ -46,6 +39,19 @@ def to_config(existing_entries)
4639
["Host #{name}", body].join("\n")
4740
end.join("\n\n") + "\n"
4841
end
42+
43+
def parse_name(line)
44+
matchdata = line.match(/^\s*([h|H]ost\s+)(.*$)/)
45+
matchdata ? matchdata.captures[1].strip : false
46+
end
47+
48+
def parse_line(line)
49+
matchdata = line.match(/^\s*(\w+)(.*$)/)
50+
return matchdata.captures[0], matchdata.captures[1].strip if matchdata
51+
52+
Chef::Log.error("Line |#{line}| does not parse correctly")
53+
return nil, nil
54+
end
4955
end
5056
end
5157
end

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
license 'Apache 2.0'
55
description 'LWRPs for managing SSH known_hosts and config files'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version '0.10.0'
7+
version '0.10.2'

providers/known_hosts.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def load_key_if_needed
6767
return if new_resource.action.is_a?(Array) ? new_resource.action.include?(:remove) : new_resource.action == :remove
6868

6969
keyscan = Mixlib::ShellOut.new(
70-
"ssh-keyscan #{new_resource.hashed ? '-H ' : ''} -p #{new_resource.port.to_i} #{Shellwords.escape(new_resource.host)}"
70+
"ssh-keyscan #{new_resource.hashed ? '-H ' : ''} "\
71+
"-p #{new_resource.port.to_i} #{Shellwords.escape(new_resource.host)}"
7172
)
7273
keyscan.run_command
7374
keyscan.error! # this will raise an error if the command failed for any reason.

spec/provider_tests/config_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'spec_helper'
22

33
describe 'ssh_config resource' do
4-
54
let(:chef_run) do
65
runner = ChefSpec::SoloRunner.new(:step_into => :ssh_config)
76
runner.converge('ssh_test::config')
@@ -81,7 +80,12 @@
8180
allow(IO).to partial_start.reduce(receive(:foreach).with(default_config), :and_yield)
8281
allow(IO).to partial_start.reduce(receive(:foreach).with(test_config), :and_yield)
8382

84-
allow(Etc).to receive(:getpwnam)
83+
allow(Etc).to receive(:getgrgid).and_raise(Exception.new('This should not happen'))
84+
allow(Etc).to receive(:getgrgid).with(200).and_return(Struct.new(:name).new('vagrant'))
85+
allow(Etc).to receive(:getgrgid).with(100).and_return(Struct.new(:name).new('someone'))
86+
allow(Etc).to receive(:getgrgid).with(0).and_return(Struct.new(:name).new('root'))
87+
88+
allow(Etc).to receive(:getpwnam).and_raise(Exception.new('This should not happen'))
8589
allow(Etc).to receive(:getpwnam).with('vagrant').and_return(
8690
Struct.new(:gid, :dir).new(200, '/home/vagrant')
8791
)
@@ -169,7 +173,7 @@
169173
it 'can create user ssh configs' do
170174
expect(chef_run).to create_file(vagrant_config).with(
171175
:owner => 'vagrant',
172-
:group => 200,
176+
:group => 'vagrant',
173177
:mode => 00600
174178
).with_content(
175179
(common_end + github_and_partial_end).join("\n")
@@ -179,7 +183,7 @@
179183
it 'can create the global ssh config' do
180184
expect(chef_run).to create_file(default_config).with(
181185
:owner => 'root',
182-
:group => 0,
186+
:group => 'root',
183187
:mode => 00644
184188
).with_content(
185189
(common_end + github_and_partial_end).join("\n")
@@ -189,15 +193,15 @@
189193
it 'creates the /etc/ssh directory if it is missing' do
190194
expect(chef_run).to create_directory(::File.dirname(default_config)).with(
191195
:owner => 'root',
192-
:group => 0,
196+
:group => 'root',
193197
:mode => 00755
194198
)
195199
end
196200

197201
it "creates vagrant's ~/.ssh/config file" do
198202
expect(chef_run).to create_directory(::File.dirname(vagrant_config)).with(
199203
:owner => 'vagrant',
200-
:group => 200,
204+
:group => 'vagrant',
201205
:mode => 00700
202206
)
203207
end

spec/provider_tests/known_hosts_spec.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require 'spec_helper'
22

33
describe 'ssh_config resource' do
4-
54
let(:chef_run) do
65
runner = ChefSpec::SoloRunner.new(:step_into => :ssh_config)
76
runner.converge('ssh_test::known_hosts')
@@ -24,7 +23,5 @@
2423
)
2524
end
2625

27-
it 'works' do
28-
pending 'I can not think of any spec tests that make sense'
29-
end
26+
pending 'I can not think of any spec tests that make sense'
3027
end

0 commit comments

Comments
 (0)