serverspec-extra-types 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.travis.yml +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +657 -4
- data/Rakefile +0 -0
- data/bin/consul_gen.rb +115 -0
- data/bin/http_doc_gem.rb +67 -0
- data/http_matchers.md +1771 -0
- data/lib/serverspec_extra_types.rb +0 -0
- data/lib/serverspec_extra_types/helpers/properties.rb +0 -0
- data/lib/serverspec_extra_types/matchers.rb +4 -0
- data/lib/serverspec_extra_types/matchers/allowed_to_run_anything.rb +38 -0
- data/lib/serverspec_extra_types/matchers/allowed_to_run_command.rb +40 -0
- data/lib/serverspec_extra_types/matchers/be_a_manager_node.rb +0 -0
- data/lib/serverspec_extra_types/matchers/be_a_worker_node.rb +0 -0
- data/lib/serverspec_extra_types/matchers/be_active.rb +0 -0
- data/lib/serverspec_extra_types/matchers/configure_queue.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_count.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_domain_name.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_engine_version.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_environment_variable.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_ha_mode.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_ha_nodes.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_ha_sync_mode.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_host.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_hostname.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_image.rb +4 -0
- data/lib/serverspec_extra_types/matchers/have_image_sha.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_label.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_mount.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_network.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_placement_constraint.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_replica_count.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_restart_limit.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_restart_policy.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_user.rb +0 -0
- data/lib/serverspec_extra_types/matchers/have_vhost.rb +0 -0
- data/lib/serverspec_extra_types/matchers/http_1xx.rb +0 -0
- data/lib/serverspec_extra_types/matchers/http_2xx.rb +0 -0
- data/lib/serverspec_extra_types/matchers/http_3xx.rb +0 -0
- data/lib/serverspec_extra_types/matchers/http_4xx.rb +0 -0
- data/lib/serverspec_extra_types/matchers/http_5xx.rb +0 -0
- data/lib/serverspec_extra_types/matchers/include_regex.rb +0 -0
- data/lib/serverspec_extra_types/matchers/map_port.rb +0 -0
- data/lib/serverspec_extra_types/matchers/mirror_all.rb +0 -0
- data/lib/serverspec_extra_types/matchers/publish_all_ports.rb +0 -0
- data/lib/serverspec_extra_types/matchers/read_from_queue.rb +0 -0
- data/lib/serverspec_extra_types/matchers/url_matchers.rb +0 -0
- data/lib/serverspec_extra_types/matchers/write_to_queue.rb +0 -0
- data/lib/serverspec_extra_types/types.rb +2 -1
- data/lib/serverspec_extra_types/types/api_base.rb +10 -1
- data/lib/serverspec_extra_types/types/consul_base.rb +6 -2
- data/lib/serverspec_extra_types/types/consul_node.rb +21 -1
- data/lib/serverspec_extra_types/types/consul_node_list.rb +1 -1
- data/lib/serverspec_extra_types/types/consul_service.rb +188 -1
- data/lib/serverspec_extra_types/types/consul_service_list.rb +0 -0
- data/lib/serverspec_extra_types/types/curl.rb +5 -1
- data/lib/serverspec_extra_types/types/docker_config.rb +55 -0
- data/lib/serverspec_extra_types/types/docker_container.rb +0 -0
- data/lib/serverspec_extra_types/types/docker_network.rb +74 -1
- data/lib/serverspec_extra_types/types/docker_node.rb +12 -0
- data/lib/serverspec_extra_types/types/docker_secret.rb +56 -0
- data/lib/serverspec_extra_types/types/docker_service.rb +0 -0
- data/lib/serverspec_extra_types/types/rabbitmq_base.rb +7 -1
- data/lib/serverspec_extra_types/types/rabbitmq_node_list.rb +5 -1
- data/lib/serverspec_extra_types/types/rabbitmq_user_permission.rb +0 -0
- data/lib/serverspec_extra_types/types/rabbitmq_vhost_list.rb +4 -0
- data/lib/serverspec_extra_types/types/rabbitmq_vhost_policy.rb +0 -0
- data/lib/serverspec_extra_types/types/sudo_user.rb +90 -0
- data/lib/serverspec_extra_types/version.rb +1 -1
- data/properties.yml +45 -7
- data/serverspec-extra-types.gemspec +4 -1
- metadata +55 -5
File without changes
|
File without changes
|
@@ -36,3 +36,7 @@ require 'serverspec_extra_types/matchers/configure_queue'
|
|
36
36
|
require 'serverspec_extra_types/matchers/have_count'
|
37
37
|
|
38
38
|
require 'serverspec_extra_types/matchers/url_matchers'
|
39
|
+
|
40
|
+
#--- sudo matchers
|
41
|
+
require 'serverspec_extra_types/matchers/allowed_to_run_command'
|
42
|
+
require 'serverspec_extra_types/matchers/allowed_to_run_anything'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
RSpec::Matchers.define :be_allowed_to_run_anything do
|
2
|
+
chain :as do |user|
|
3
|
+
@user = user
|
4
|
+
end
|
5
|
+
chain :as_anybody do
|
6
|
+
@user = 'ALL'
|
7
|
+
end
|
8
|
+
chain :without_password do
|
9
|
+
@checkpw = true
|
10
|
+
end
|
11
|
+
chain :without_a_password do
|
12
|
+
@checkpw = true
|
13
|
+
end
|
14
|
+
match do |actual|
|
15
|
+
if @user
|
16
|
+
actual.allowed_to_run_command?('ALL', @user, @checkpw)
|
17
|
+
else
|
18
|
+
actual.allowed_to_run_command?('ALL', @checkpw)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
failure_message do |actual|
|
23
|
+
msg = if @user
|
24
|
+
"expected to be able to run anything as #{@user} got #{actual.permission('ALL')[:user]}"
|
25
|
+
else
|
26
|
+
"expected anything} to be in #{actual.permissions.map{|x| x[:command]}}"
|
27
|
+
end
|
28
|
+
msg << %( without a password ) if @checkpw
|
29
|
+
msg
|
30
|
+
end
|
31
|
+
|
32
|
+
description do
|
33
|
+
msg = "be allowed to run anything"
|
34
|
+
msg << %( as #{@user}) if @user
|
35
|
+
msg << %( without a password ) if @checkpw
|
36
|
+
msg
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
RSpec::Matchers.define :be_allowed_to_run_command do |command|
|
2
|
+
chain :as do |user|
|
3
|
+
@user = user
|
4
|
+
end
|
5
|
+
chain :as_anybody do
|
6
|
+
@anybody = true
|
7
|
+
end
|
8
|
+
chain :without_password do
|
9
|
+
@checkpw = true
|
10
|
+
end
|
11
|
+
chain :without_a_password do
|
12
|
+
@checkpw = true
|
13
|
+
end
|
14
|
+
match do |actual|
|
15
|
+
if @user
|
16
|
+
actual.allowed_to_run_command?(command, @user, @checkpw)
|
17
|
+
elsif @anybody
|
18
|
+
(actual.allowed_to_run_command?(command, 'ALL', @checkpw) || actual.allowed_to_run_command?(command, 'ALL:ALL' ,@checkpw))
|
19
|
+
else
|
20
|
+
actual.allowed_to_run_command?(command, @checkpw)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
failure_message do |actual|
|
25
|
+
msg = if @user
|
26
|
+
"expected to be able to run #{command} as #{@user} got #{actual.permission(command)[:user]}"
|
27
|
+
else
|
28
|
+
"expected #{command} to be in #{actual.permissions.map{|x| x[:command]}}"
|
29
|
+
end
|
30
|
+
msg << %( without a password ) if @checkpw
|
31
|
+
msg
|
32
|
+
end
|
33
|
+
|
34
|
+
description do
|
35
|
+
msg = "be allowed to run #{command}"
|
36
|
+
msg << %( as #{@user}) if @user
|
37
|
+
msg << %( without a password ) if @checkpw
|
38
|
+
msg
|
39
|
+
end
|
40
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'rspec/expectations'
|
2
3
|
|
3
4
|
RSpec::Matchers.define :have_image do |image|
|
4
5
|
match do |actual|
|
5
6
|
actual.has_image?(image)
|
6
7
|
end
|
8
|
+
description do
|
9
|
+
"have image #{image}"
|
10
|
+
end
|
7
11
|
failure_message do |actual|
|
8
12
|
"expected image to be #{image} was #{actual.image}"
|
9
13
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -8,7 +8,8 @@ module Serverspec
|
|
8
8
|
module Type
|
9
9
|
types = %w[docker_service docker_node rabbitmq_vhost_policy rabbitmq_node_list rabbitmq_vhost_list
|
10
10
|
rabbitmq_user_permission consul_service consul_service_list consul_node consul_node_list
|
11
|
-
curl nfs_export jenkins_credential jenkins_job jenkins_plugin
|
11
|
+
curl nfs_export jenkins_credential jenkins_job jenkins_plugin sudo_user docker_network
|
12
|
+
docker_config docker_secret]
|
12
13
|
|
13
14
|
types.each do |type|
|
14
15
|
require "serverspec_extra_types/types/#{type}"
|
@@ -26,14 +26,23 @@ module Serverspec::Type
|
|
26
26
|
@url_base
|
27
27
|
end
|
28
28
|
|
29
|
+
|
29
30
|
def inspection
|
30
31
|
@inspection ||= ::MultiJson.load(get_inspection.stdout)
|
31
32
|
end
|
32
33
|
|
33
34
|
private
|
34
35
|
|
36
|
+
def extra_args
|
37
|
+
""
|
38
|
+
end
|
39
|
+
|
40
|
+
def curl_command
|
41
|
+
"curl #{extra_args} -s #{url} #{@insecure ? '-k' : ''} #{@redirects ? '-L' : ''}"
|
42
|
+
end
|
43
|
+
|
35
44
|
def get_inspection
|
36
|
-
command =
|
45
|
+
command = curl_command
|
37
46
|
@get_inspection ||= @runner.run_command(command)
|
38
47
|
end
|
39
48
|
end
|
@@ -33,9 +33,13 @@ module Serverspec::Type
|
|
33
33
|
|
34
34
|
private
|
35
35
|
|
36
|
+
def extra_args
|
37
|
+
@token ? "--header 'X-Consul-Token: #{@token}'" : ''
|
38
|
+
end
|
39
|
+
|
36
40
|
def get_inspection
|
37
|
-
|
38
|
-
command =
|
41
|
+
|
42
|
+
command = curl_command
|
39
43
|
@get_inspection ||= @runner.run_command(command)
|
40
44
|
end
|
41
45
|
end
|
@@ -9,8 +9,28 @@ module Serverspec::Type
|
|
9
9
|
"#{@url_base}/v1/catalog/node/#{@name}"
|
10
10
|
end
|
11
11
|
|
12
|
+
def has_datacenter?(dc)
|
13
|
+
datacenter == dc
|
14
|
+
end
|
15
|
+
|
16
|
+
def datacenter
|
17
|
+
inspection['Node']['Datacenter']
|
18
|
+
end
|
19
|
+
|
20
|
+
def has_service?(service_name)
|
21
|
+
service(service_name) != nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def service(service_name)
|
25
|
+
services.find service_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def services
|
29
|
+
inspection['Services']
|
30
|
+
end
|
31
|
+
|
12
32
|
def inspection
|
13
|
-
@inspection ||= ::MultiJson.load(get_inspection.stdout)
|
33
|
+
@inspection ||= ::MultiJson.load(get_inspection.stdout)
|
14
34
|
end
|
15
35
|
end
|
16
36
|
end
|
@@ -16,7 +16,194 @@ module Serverspec::Type
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def inspection
|
19
|
-
@inspection ||= ::MultiJson.load(get_inspection.stdout)
|
19
|
+
@inspection ||= ::MultiJson.load(get_inspection.stdout)[0]
|
20
20
|
end
|
21
|
+
|
22
|
+
|
23
|
+
##= Generated Code Start =##
|
24
|
+
# TODO: Make these better
|
25
|
+
# Key Type: String
|
26
|
+
def id
|
27
|
+
inspection['ID']
|
28
|
+
end
|
29
|
+
|
30
|
+
def has_id?(id)
|
31
|
+
self.id == id
|
32
|
+
end
|
33
|
+
|
34
|
+
# Key Type: String
|
35
|
+
def node
|
36
|
+
inspection['Node']
|
37
|
+
end
|
38
|
+
|
39
|
+
def has_node?(node)
|
40
|
+
self.node == node
|
41
|
+
end
|
42
|
+
|
43
|
+
# Key Type: String
|
44
|
+
def address
|
45
|
+
inspection['Address']
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_address?(address)
|
49
|
+
self.address == address
|
50
|
+
end
|
51
|
+
|
52
|
+
# Key Type: String
|
53
|
+
def datacenter
|
54
|
+
inspection['Datacenter']
|
55
|
+
end
|
56
|
+
|
57
|
+
def has_datacenter?(datacenter)
|
58
|
+
self.datacenter == datacenter
|
59
|
+
end
|
60
|
+
|
61
|
+
# Key Type: Hash
|
62
|
+
def tagged_addresses
|
63
|
+
inspection['TaggedAddresses']
|
64
|
+
end
|
65
|
+
|
66
|
+
# Todo: do method for indiviual tagged addresses
|
67
|
+
def has_tagged_addresses?(tagged_addresses)
|
68
|
+
self.tagged_addresses == tagged_addresses
|
69
|
+
end
|
70
|
+
|
71
|
+
# Key Type: Hash
|
72
|
+
def node_meta
|
73
|
+
inspection['NodeMeta']
|
74
|
+
end
|
75
|
+
|
76
|
+
def has_node_meta?(node_meta)
|
77
|
+
self.node_meta == node_meta
|
78
|
+
end
|
79
|
+
|
80
|
+
# Key Type: String
|
81
|
+
def service_kind
|
82
|
+
inspection['ServiceKind']
|
83
|
+
end
|
84
|
+
|
85
|
+
def has_service_kind?(service_kind)
|
86
|
+
self.service_kind == service_kind
|
87
|
+
end
|
88
|
+
|
89
|
+
# Key Type: String
|
90
|
+
def service_id
|
91
|
+
inspection['ServiceID']
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_service_id?(service_id)
|
95
|
+
self.service_id == service_id
|
96
|
+
end
|
97
|
+
|
98
|
+
# Key Type: String
|
99
|
+
def service_name
|
100
|
+
inspection['ServiceName']
|
101
|
+
end
|
102
|
+
|
103
|
+
def has_service_name?(service_name)
|
104
|
+
self.service_name == service_name
|
105
|
+
end
|
106
|
+
|
107
|
+
# Key Type: Array
|
108
|
+
def service_tags
|
109
|
+
inspection['ServiceTags']
|
110
|
+
end
|
111
|
+
|
112
|
+
def has_service_tags?(service_tags)
|
113
|
+
self.service_tags == service_tags
|
114
|
+
end
|
115
|
+
|
116
|
+
# Key Type: String
|
117
|
+
def service_address
|
118
|
+
inspection['ServiceAddress']
|
119
|
+
end
|
120
|
+
|
121
|
+
def has_service_address?(service_address)
|
122
|
+
self.service_address == service_address
|
123
|
+
end
|
124
|
+
|
125
|
+
# Key Type: Hash
|
126
|
+
def service_weights
|
127
|
+
inspection['ServiceWeights']
|
128
|
+
end
|
129
|
+
|
130
|
+
# Todo: do method for indiviual service weight are well as passing/warning
|
131
|
+
def has_service_weights?(service_weights)
|
132
|
+
self.service_weights == service_weights
|
133
|
+
end
|
134
|
+
|
135
|
+
# Key Type: Hash
|
136
|
+
def service_meta
|
137
|
+
inspection['ServiceMeta']
|
138
|
+
end
|
139
|
+
|
140
|
+
def has_service_meta?(service_meta)
|
141
|
+
self.service_meta == service_meta
|
142
|
+
end
|
143
|
+
|
144
|
+
# Key Type: Integer
|
145
|
+
def service_port
|
146
|
+
inspection['ServicePort']
|
147
|
+
end
|
148
|
+
|
149
|
+
def has_service_port?(service_port)
|
150
|
+
self.service_port == service_port
|
151
|
+
end
|
152
|
+
|
153
|
+
# Key Type: FalseClass
|
154
|
+
def service_enable_tag_override
|
155
|
+
inspection['ServiceEnableTagOverride']
|
156
|
+
end
|
157
|
+
|
158
|
+
def has_service_enable_tag_override?(service_enable_tag_override)
|
159
|
+
self.service_enable_tag_override == service_enable_tag_override
|
160
|
+
end
|
161
|
+
|
162
|
+
# Key Type: String
|
163
|
+
def service_proxy_destination
|
164
|
+
inspection['ServiceProxyDestination']
|
165
|
+
end
|
166
|
+
|
167
|
+
def has_service_proxy_destination?(service_proxy_destination)
|
168
|
+
self.service_proxy_destination == service_proxy_destination
|
169
|
+
end
|
170
|
+
|
171
|
+
# Key Type: Hash
|
172
|
+
def service_proxy
|
173
|
+
inspection['ServiceProxy']
|
174
|
+
end
|
175
|
+
|
176
|
+
def has_service_proxy?(service_proxy)
|
177
|
+
self.service_proxy == service_proxy
|
178
|
+
end
|
179
|
+
|
180
|
+
# Key Type: Hash
|
181
|
+
def service_connect
|
182
|
+
inspection['ServiceConnect']
|
183
|
+
end
|
184
|
+
|
185
|
+
def has_service_connect?(service_connect)
|
186
|
+
self.service_connect == service_connect
|
187
|
+
end
|
188
|
+
|
189
|
+
# Key Type: Integer
|
190
|
+
def create_index
|
191
|
+
inspection['CreateIndex']
|
192
|
+
end
|
193
|
+
|
194
|
+
def has_create_index?(create_index)
|
195
|
+
self.create_index == create_index
|
196
|
+
end
|
197
|
+
|
198
|
+
# Key Type: Integer
|
199
|
+
def modify_index
|
200
|
+
inspection['ModifyIndex']
|
201
|
+
end
|
202
|
+
|
203
|
+
def has_modify_index?(modify_index)
|
204
|
+
self.modify_index == modify_index
|
205
|
+
end
|
206
|
+
##= Generated Code End =##
|
207
|
+
|
21
208
|
end
|
22
209
|
end
|