serverspec-extended-types 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGES.md +4 -0
- data/README.md +3 -1
- data/lib/serverspec_extended_types/http_get.rb +13 -4
- data/lib/serverspec_extended_types/version.rb +1 -1
- data/spec/types/http_get_spec.rb +29 -1
- metadata +21 -21
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OGRiMjQ5NWZhNGMxZjg4MzQ2ZmM0MDA1MTllM2M4NDUzZWE5ZWU4Yw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7323a24b2db29288fb1c5b48d10444b3febf582d
|
4
|
+
data.tar.gz: 8c6cc0312da2d38b244a933cba6b930c6f67d779
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZjA0NmVjNTkzYmQ5OTI3ZjA4ZDFkYjIxZTQwM2NjNzE0ZjNiNjJhMDAzNjBm
|
11
|
-
NzkzYjY3NDE4NDcwZGNkNmQzMmQ0ZGFjY2EzZTcxYWQ4OTQ5YzY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
OWFhMTJmOTE5YzU3NDI3ODZmNTZkZjQyNGFhMTk4NzQ4MjZmMDQ3Yzc0ODRi
|
14
|
-
ZTUzMTJkMmM5YjFjYzllNjZhMWQ2ZWY1MmQwNjQ0YzU3ZGIwMWVlNTgyNjc0
|
15
|
-
YzM1ODRkYTRjYzZhOWVmMmRjMGJmZjY4NTJlNzEwMDM0NTY1NmQ=
|
6
|
+
metadata.gz: de53147b38a00edfd945ed14569e0713fc2045b11ab798cfb1a0431e9fafa4df904f0fcce1256204ed64fcd3d23340ff9d3fe5e3772c9d3347b02bf9fcb4f57d
|
7
|
+
data.tar.gz: 64026f353890298a85bb60b59e0fb2dfe288e042166936002c4fe7938862a72f1f454130398dc19c2c9eeb7f6c64233376b2eba7e90e0d04aafd6af519daea58
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# serverspec-extended-types, changelog
|
2
2
|
|
3
|
+
## 0.1.0 2017-05-15 Jason Antman <jason@jasonantman.com>
|
4
|
+
|
5
|
+
* Add `protocol` (http|https) and `bypass_ssl_verify` parameters for http_get.
|
6
|
+
|
3
7
|
## 0.0.3 2015-03-23 Jason Antman <jason@jasonantman.com>
|
4
8
|
|
5
9
|
* Add ``json`` matcher for http_get type.
|
data/README.md
CHANGED
@@ -109,7 +109,7 @@ The http_get type performs an HTTP GET from the local (rspec runner) system, aga
|
|
109
109
|
the IP address that serverspec is running against (``ENV[TARGET_HOST]``), with a
|
110
110
|
specified ``Host`` header value. The request is wrapped in a configurable-length timeout.
|
111
111
|
|
112
|
-
describe http_get(port, host_header, path, timeout_sec=10)
|
112
|
+
describe http_get(port, host_header, path, timeout_sec=10, protocol='http', bypass_ssl_verify=false)
|
113
113
|
# matchers here
|
114
114
|
end
|
115
115
|
|
@@ -123,6 +123,8 @@ state variables for later use by the various matchers.
|
|
123
123
|
* __host_header__ - the ``Host`` header value to provide in the request
|
124
124
|
* __path__ - the path to request from the server
|
125
125
|
* __timeout_sec__ - timeout in seconds before canceling the request (Int; default 10)
|
126
|
+
* __protocol__ - protocol to be used (default to `http`, can be `http`)
|
127
|
+
* __bypass_ssl_verify__ - bypass SSL verification (default to `false` to keep good security. Set it to `true` for self-signed certificates only!)
|
126
128
|
|
127
129
|
#### Matchers
|
128
130
|
|
@@ -30,6 +30,8 @@ module Serverspec
|
|
30
30
|
# @param host_header [String] the value to set in the 'Host' HTTP request header
|
31
31
|
# @param path [String] the URI/path to request from the server
|
32
32
|
# @param timeout_sec [Int] how many seconds to allow request to run before timing out and setting @timed_out_status to True
|
33
|
+
# @param protocol [String] the protocol to connect to the server (e.g. 'http', 'https')
|
34
|
+
# @param bypass_ssl_verify [Boolean] if true, SSL verification will be bypassed (useful for self-signed certificates)
|
33
35
|
#
|
34
36
|
# @example
|
35
37
|
# describe http_get(80, 'myhostname', '/') do
|
@@ -38,7 +40,7 @@ module Serverspec
|
|
38
40
|
#
|
39
41
|
# @api public
|
40
42
|
# @return [nil]
|
41
|
-
def initialize(port, host_header, path, timeout_sec=10)
|
43
|
+
def initialize(port, host_header, path, timeout_sec=10, protocol='http', bypass_ssl_verify=false)
|
42
44
|
@ip = ENV['TARGET_HOST']
|
43
45
|
@port = port
|
44
46
|
@host = host_header
|
@@ -48,6 +50,8 @@ module Serverspec
|
|
48
50
|
@headers_hash = nil
|
49
51
|
@response_code_int = nil
|
50
52
|
@response_json = nil
|
53
|
+
@protocol = protocol
|
54
|
+
@bypass_ssl_verify = bypass_ssl_verify
|
51
55
|
begin
|
52
56
|
Timeout::timeout(timeout_sec) do
|
53
57
|
getpage
|
@@ -66,7 +70,10 @@ module Serverspec
|
|
66
70
|
def getpage
|
67
71
|
ip = @ip
|
68
72
|
port = @port
|
69
|
-
|
73
|
+
protocol = @protocol
|
74
|
+
options = []
|
75
|
+
options << { ssl: { verify: false } } if @bypass_ssl_verify
|
76
|
+
conn = Faraday.new("#{protocol}://#{ip}:#{port}/", *options)
|
70
77
|
version = ServerspecExtendedTypes::VERSION
|
71
78
|
conn.headers[:user_agent] = "Serverspec::Type::Http_Get/#{version} (https://github.com/jantman/serverspec-extended-types)"
|
72
79
|
conn.headers[:Host] = @host
|
@@ -168,11 +175,13 @@ module Serverspec
|
|
168
175
|
# @param host_header [String] the value to set in the 'Host' HTTP request header
|
169
176
|
# @param path [String] the URI/path to request from the server
|
170
177
|
# @param timeout_sec [Int] how many seconds to allow request to run before timing out and setting @timed_out_status to True
|
178
|
+
# @param protocol [String] the protocol to connect to the server (default 'http', can be 'https')
|
179
|
+
# @param bypass_ssl_verify [Boolean] if true, SSL verification will be bypassed (useful for self-signed certificates)
|
171
180
|
#
|
172
181
|
# @api public
|
173
182
|
# @return [Serverspec::Type::Http_Get]
|
174
|
-
def http_get(port, host_header, path, timeout_sec=10)
|
175
|
-
Http_Get.new(port, host_header, path, timeout_sec
|
183
|
+
def http_get(port, host_header, path, timeout_sec=10, protocol='http', bypass_ssl_verify=false)
|
184
|
+
Http_Get.new(port, host_header, path, timeout_sec, protocol, bypass_ssl_verify)
|
176
185
|
end
|
177
186
|
end
|
178
187
|
end
|
data/spec/types/http_get_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require 'serverspec_extended_types/http_get'
|
|
4
4
|
describe 'http_get()' do
|
5
5
|
context 'Serverspec::Type method' do
|
6
6
|
it 'instantiates the class with the correct parameters' do
|
7
|
-
expect(Serverspec::Type::Http_Get).to receive(:new).with(1, 'hostheader', 'mypath', timeout_sec=20)
|
7
|
+
expect(Serverspec::Type::Http_Get).to receive(:new).with(1, 'hostheader', 'mypath', timeout_sec=20, 'http', false)
|
8
8
|
http_get(1, 'hostheader', 'mypath', timeout_sec=20)
|
9
9
|
end
|
10
10
|
it 'returns the new object' do
|
@@ -26,6 +26,8 @@ describe 'http_get()' do
|
|
26
26
|
expect(x.instance_variable_get(:@headers_hash)).to be nil
|
27
27
|
expect(x.instance_variable_get(:@response_code_int)).to be nil
|
28
28
|
expect(x.instance_variable_get(:@response_json)).to be nil
|
29
|
+
expect(x.instance_variable_get(:@protocol)).to eq 'http'
|
30
|
+
expect(x.instance_variable_get(:@bypass_ssl_verify)).to eq false
|
29
31
|
end
|
30
32
|
it 'calls getpage' do
|
31
33
|
expect_any_instance_of(Serverspec::Type::Http_Get).to receive(:getpage).once
|
@@ -74,6 +76,32 @@ describe 'http_get()' do
|
|
74
76
|
expect(x.json).to be_empty
|
75
77
|
expect(x.json).to be_a_kind_of(Hash)
|
76
78
|
end
|
79
|
+
it 'supports https' do
|
80
|
+
# boilerplate
|
81
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'myhost'))
|
82
|
+
headers = double
|
83
|
+
expect(headers).to receive(:[]=).with(:user_agent, %r"Serverspec::Type::Http_Get/\d+\.\d+\.\d+ \(https://github.com/jantman/serverspec-extended-types\)")
|
84
|
+
expect(headers).to receive(:[]=).with(:Host, 'hostheader')
|
85
|
+
conn = double(headers: headers)
|
86
|
+
response = double(status: 200, body: "OK", headers: [])
|
87
|
+
expect(conn).to receive(:get).with('mypath').and_return(response)
|
88
|
+
# most importantly, we want https here
|
89
|
+
expect(Faraday).to receive(:new).with("https://myhost:1/").and_return(conn)
|
90
|
+
x = http_get(1, 'hostheader', 'mypath', 30, 'https')
|
91
|
+
end
|
92
|
+
it 'supports ssl verify bypass for self-signed certificates' do
|
93
|
+
# boilerplate
|
94
|
+
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'myhost'))
|
95
|
+
headers = double
|
96
|
+
expect(headers).to receive(:[]=).with(:user_agent, %r"Serverspec::Type::Http_Get/\d+\.\d+\.\d+ \(https://github.com/jantman/serverspec-extended-types\)")
|
97
|
+
expect(headers).to receive(:[]=).with(:Host, 'hostheader')
|
98
|
+
conn = double(headers: headers)
|
99
|
+
response = double(status: 200, body: "OK", headers: [])
|
100
|
+
expect(conn).to receive(:get).with('mypath').and_return(response)
|
101
|
+
# most importantly, we want https here
|
102
|
+
expect(Faraday).to receive(:new).with("https://myhost:1/", {ssl: {verify: false}}).and_return(conn)
|
103
|
+
x = http_get(1, 'hostheader', 'mypath', 30, 'https', true)
|
104
|
+
end
|
77
105
|
it 'sets JSON if parsable' do
|
78
106
|
stub_const('ENV', ENV.to_hash.merge('TARGET_HOST' => 'myhost'))
|
79
107
|
conn = double
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverspec-extended-types
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Antman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: serverspec
|
@@ -42,28 +42,28 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: faraday
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
@@ -84,84 +84,84 @@ dependencies:
|
|
84
84
|
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: codecov
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: yard
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: yardstick
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: redcarpet
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - '>='
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - '>='
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
description: This gem provides some purpose-specific types for ServerSpec 2.x beyond
|
@@ -201,17 +201,17 @@ require_paths:
|
|
201
201
|
- lib
|
202
202
|
required_ruby_version: !ruby/object:Gem::Requirement
|
203
203
|
requirements:
|
204
|
-
- -
|
204
|
+
- - '>='
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '0'
|
207
207
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
208
208
|
requirements:
|
209
|
-
- -
|
209
|
+
- - '>='
|
210
210
|
- !ruby/object:Gem::Version
|
211
211
|
version: '0'
|
212
212
|
requirements: []
|
213
213
|
rubyforge_project:
|
214
|
-
rubygems_version: 2.
|
214
|
+
rubygems_version: 2.4.8
|
215
215
|
signing_key:
|
216
216
|
specification_version: 4
|
217
217
|
summary: A set of extended types for ServerSpec 2.x
|