specinfra 0.0.11 → 0.0.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6118703ee530caa196ace37a17e7bb1d8e3c3eca
4
- data.tar.gz: 59a757a847c01020d1779f615aac634489d267c0
3
+ metadata.gz: 121e7af246fe65b06bd3a329b7cb9ae0033f547e
4
+ data.tar.gz: cbfb56fd735652160824ccc683e695ec255dd82e
5
5
  SHA512:
6
- metadata.gz: e01163f076632e187e9233343f9f2136a2c5b14da639bb4820948faf44b3f5b42681216e7eacfc57bed46f6e94eddae660db0bc69d4677077739d7f03f407ba3
7
- data.tar.gz: a588c2c8a429eb37134b54b3bf5fa810f7aa3e20fc1361f7ea447f05c1e1ac7724f2a921cfb465352a0269680b64ef3b30892b69c4b20d9653eb832dfa6ee6f5
6
+ metadata.gz: 1dd10759511986d426b809a36f4178ec6af45100d6f6c4fc5e7e1071edac2e2eafbe63d72264b7dafc40a25fb02e111d0e3d9149198992778402014232cbda62
7
+ data.tar.gz: 08a596c0c4335f3f565da659c74a75abacefd335eb67f3ea50a3a12039a6b2f47b6c70045929f6d8c1023835cec1465ffbf9d46b7d4a1762a8db0d1b12fa7053
data/Rakefile CHANGED
@@ -4,8 +4,18 @@ require 'rspec/core/rake_task'
4
4
  task :spec => 'spec:all'
5
5
 
6
6
  namespace :spec do
7
- RSpec::Core::RakeTask.new(:all) do |t|
8
- t.pattern = "spec/**/*_spec.rb"
7
+ task :all => [ :helper, :backend, :configuration ]
8
+
9
+ RSpec::Core::RakeTask.new(:helper) do |t|
10
+ t.pattern = "spec/helper/*_spec.rb"
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:backend) do |t|
14
+ t.pattern = "spec/backend/*/*_spec.rb"
15
+ end
16
+
17
+ RSpec::Core::RakeTask.new(:configuration) do |t|
18
+ t.pattern = "spec/configuration_spec.rb"
9
19
  end
10
20
  end
11
21
 
@@ -20,7 +20,9 @@ module SpecInfra
20
20
 
21
21
  def build_command(cmd)
22
22
  cmd = super(cmd)
23
- if SpecInfra.configuration.ssh.options[:user] != 'root'
23
+ user = SpecInfra.configuration.ssh.options[:user]
24
+ disable_sudo = SpecInfra.configuration.disable_sudo
25
+ if user != 'root' && !disable_sudo
24
26
  cmd = "#{sudo} #{cmd}"
25
27
  cmd.gsub!(/(\&\&\s*!?\(?\s*)/, "\\1#{sudo} ")
26
28
  cmd.gsub!(/(\|\|\s*!?\(?\s*)/, "\\1#{sudo} ")
@@ -32,7 +34,8 @@ module SpecInfra
32
34
  cmd = super(cmd)
33
35
  user = SpecInfra.configuration.ssh.options[:user]
34
36
  pre_command = SpecInfra.configuration.pre_command
35
- if pre_command && user != 'root'
37
+ disable_sudo = SpecInfra.configuration.disable_sudo
38
+ if pre_command && user != 'root' && !disable_sudo
36
39
  cmd = "#{sudo} #{cmd}"
37
40
  end
38
41
  cmd
@@ -1,7 +1,7 @@
1
1
  module SpecInfra
2
2
  module Configuration
3
3
  class << self
4
- VALID_OPTIONS_KEYS = [:path, :pre_command, :stdout, :stderr, :sudo_path, :pass_prompt].freeze
4
+ VALID_OPTIONS_KEYS = [:path, :pre_command, :stdout, :stderr, :sudo_path, :sudo_disable, :pass_prompt].freeze
5
5
 
6
6
  def defaults
7
7
  VALID_OPTIONS_KEYS.inject({}) { |o, k| o.merge!(k => send(k)) }
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/lib/specinfra.rb CHANGED
@@ -21,6 +21,7 @@ if defined?(RSpec)
21
21
  c.add_setting :host, :default => nil
22
22
  c.add_setting :ssh, :default => nil
23
23
  c.add_setting :sudo_password, :default => nil
24
+ c.add_setting :disable_sudo, :default => false
24
25
  c.add_setting :winrm, :default => nil
25
26
  SpecInfra.configuration.defaults.each { |k, v| c.add_setting k, :default => v }
26
27
  c.before :each do
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ include SpecInfra::Helper::Ssh
4
+
5
+ ssh = double
6
+
7
+
8
+ describe 'build command with sudo' do
9
+ before :each do
10
+ RSpec.configure do |c|
11
+ ssh.stub(:options) { { :user => 'foo' } }
12
+ c.ssh = ssh
13
+ c.sudo_path = nil
14
+ end
15
+ end
16
+
17
+ context 'command pattern 1' do
18
+ subject { backend.build_command('test -f /etc/passwd') }
19
+ it { should eq 'sudo test -f /etc/passwd' }
20
+ end
21
+
22
+ context 'command pattern 2' do
23
+ subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
24
+ it { should eq 'sudo test ! -f /etc/selinux/config || (sudo getenforce | grep -i -- disabled && sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' }
25
+ end
26
+
27
+ context 'command pattern 3' do
28
+ subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
29
+ it { should eq "sudo dpkg -s apache2 && ! sudo dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
30
+ end
31
+ end
32
+
33
+ # Alternate path for sudo command:
34
+ sudo_path = '/usr/local/bin'
35
+
36
+ describe 'build command with sudo on alternate path' do
37
+ before :each do
38
+ RSpec.configure do |c|
39
+ ssh.stub(:options) { { :user => 'foo' } }
40
+ c.ssh = ssh
41
+ c.sudo_path = "#{sudo_path}"
42
+ end
43
+ end
44
+
45
+
46
+ context 'command pattern 1a' do
47
+ subject { backend.build_command('test -f /etc/passwd') }
48
+ it { should eq "#{sudo_path}/sudo test -f /etc/passwd" }
49
+ end
50
+
51
+ context 'command pattern 2a' do
52
+ subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
53
+ it { should eq "#{sudo_path}/sudo test ! -f /etc/selinux/config || (#{sudo_path}/sudo getenforce | grep -i -- disabled && #{sudo_path}/sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" }
54
+ end
55
+
56
+ context 'command pattern 3a' do
57
+ subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
58
+ it { should eq "#{sudo_path}/sudo dpkg -s apache2 && ! #{sudo_path}/sudo dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
59
+ end
60
+
61
+ after :each do
62
+ RSpec.configure do |c|
63
+ c.sudo_path = nil
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ describe 'build command without sudo' do
70
+ before :each do
71
+ RSpec.configure do |c|
72
+ ssh.stub(:options) { { :user => 'foo' } }
73
+ c.ssh = ssh
74
+ c.disable_sudo = true
75
+ end
76
+ end
77
+
78
+ context 'command pattern 1b' do
79
+ subject { backend.build_command('test -f /etc/passwd') }
80
+ it { should eq 'test -f /etc/passwd' }
81
+ end
82
+
83
+ context 'command pattern 2b' do
84
+ subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
85
+ it { should eq 'test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' }
86
+ end
87
+
88
+ context 'command pattern 3b' do
89
+ subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
90
+ it { should eq "dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
91
+ end
92
+
93
+ after :each do
94
+ RSpec.configure do |c|
95
+ c.disable_sudo = false
96
+ end
97
+ end
98
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'specinfra'
2
+ require 'rspec/mocks/standalone'
2
3
 
3
4
  include SpecInfra::Helper::Exec
4
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-13 00:00:00.000000000 Z
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -109,7 +109,8 @@ files:
109
109
  - lib/specinfra/helper/properties.rb
110
110
  - lib/specinfra/properties.rb
111
111
  - lib/specinfra/version.rb
112
- - spec/configurtaion_spec.rb
112
+ - spec/backend/ssh/build_command_spec.rb
113
+ - spec/configuration_spec.rb
113
114
  - spec/helper/backend_spec.rb
114
115
  - spec/helper/properties_spec.rb
115
116
  - spec/spec_helper.rb
@@ -139,7 +140,8 @@ signing_key:
139
140
  specification_version: 4
140
141
  summary: Common layer for serverspec and configspec
141
142
  test_files:
142
- - spec/configurtaion_spec.rb
143
+ - spec/backend/ssh/build_command_spec.rb
144
+ - spec/configuration_spec.rb
143
145
  - spec/helper/backend_spec.rb
144
146
  - spec/helper/properties_spec.rb
145
147
  - spec/spec_helper.rb