vcloud-edge_gateway 0.0.1

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.
Files changed (58) hide show
  1. data/.gitignore +16 -0
  2. data/Gemfile +9 -0
  3. data/LICENSE.txt +20 -0
  4. data/README.md +160 -0
  5. data/Rakefile +23 -0
  6. data/bin/vcloud-edge +12 -0
  7. data/jenkins.sh +11 -0
  8. data/lib/vcloud/config_loader.rb +27 -0
  9. data/lib/vcloud/config_validator.rb +207 -0
  10. data/lib/vcloud/edge_gateway/configuration_differ.rb +17 -0
  11. data/lib/vcloud/edge_gateway/configuration_generator/firewall_service.rb +63 -0
  12. data/lib/vcloud/edge_gateway/configuration_generator/id_ranges.rb +10 -0
  13. data/lib/vcloud/edge_gateway/configuration_generator/load_balancer_service.rb +243 -0
  14. data/lib/vcloud/edge_gateway/configuration_generator/nat_service.rb +54 -0
  15. data/lib/vcloud/edge_gateway/edge_gateway_configuration.rb +41 -0
  16. data/lib/vcloud/edge_gateway/version.rb +6 -0
  17. data/lib/vcloud/edge_gateway.rb +32 -0
  18. data/lib/vcloud/edge_gateway_services.rb +26 -0
  19. data/lib/vcloud/schema/edge_gateway.rb +15 -0
  20. data/lib/vcloud/schema/firewall_service.rb +39 -0
  21. data/lib/vcloud/schema/load_balancer_service.rb +129 -0
  22. data/lib/vcloud/schema/nat_service.rb +35 -0
  23. data/scripts/generate_fog_conf_file.sh +6 -0
  24. data/spec/erb_helper.rb +11 -0
  25. data/spec/integration/edge_gateway/data/firewall_config.yaml.erb +17 -0
  26. data/spec/integration/edge_gateway/data/firewall_config_updated_rule.yaml.erb +17 -0
  27. data/spec/integration/edge_gateway/data/firewall_rule_order_test.yaml.erb +24 -0
  28. data/spec/integration/edge_gateway/data/hairpin_nat_config.yaml.erb +13 -0
  29. data/spec/integration/edge_gateway/data/incorrect_firewall_config.yaml +14 -0
  30. data/spec/integration/edge_gateway/data/nat_and_firewall_config.yaml.erb +32 -0
  31. data/spec/integration/edge_gateway/data/nat_config.yaml.erb +17 -0
  32. data/spec/integration/edge_gateway/edge_gateway_services_spec.rb +132 -0
  33. data/spec/integration/edge_gateway/firewall_service_spec.rb +201 -0
  34. data/spec/integration/edge_gateway/nat_service_spec.rb +208 -0
  35. data/spec/spec_helper.rb +26 -0
  36. data/spec/vcloud/config_loader_spec.rb +112 -0
  37. data/spec/vcloud/config_validator_spec.rb +570 -0
  38. data/spec/vcloud/data/basic_preamble_test.erb +8 -0
  39. data/spec/vcloud/data/basic_preamble_test.erb.OUT +8 -0
  40. data/spec/vcloud/data/working.json +21 -0
  41. data/spec/vcloud/data/working.yaml +22 -0
  42. data/spec/vcloud/data/working_with_defaults.yaml +25 -0
  43. data/spec/vcloud/edge_gateway/configuration_differ_spec.rb +131 -0
  44. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-input.yaml +41 -0
  45. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-output.yaml +93 -0
  46. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_https-input.yaml +39 -0
  47. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_https-output.yaml +92 -0
  48. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_mixed_complex-input.yaml +65 -0
  49. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_mixed_complex-output.yaml +94 -0
  50. data/spec/vcloud/edge_gateway/configuration_generator/firewall_service_spec.rb +378 -0
  51. data/spec/vcloud/edge_gateway/configuration_generator/load_balancer_service_spec.rb +233 -0
  52. data/spec/vcloud/edge_gateway/configuration_generator/nat_service_spec.rb +360 -0
  53. data/spec/vcloud/edge_gateway/edge_gateway_configuration_spec.rb +182 -0
  54. data/spec/vcloud/edge_gateway/firewall_schema_validation_spec.rb +45 -0
  55. data/spec/vcloud/edge_gateway/load_balancer_schema_validation_spec.rb +153 -0
  56. data/spec/vcloud/edge_gateway/nat_schema_validation_spec.rb +93 -0
  57. data/vcloud-edge_gateway.gemspec +32 -0
  58. metadata +252 -0
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vcloud::ConfigLoader do
4
+
5
+ before(:all) do
6
+ @valid_config = valid_config
7
+ end
8
+
9
+ it "should create a valid hash when input is JSON" do
10
+ input_file = 'spec/vcloud/data/working.json'
11
+ loader = Vcloud::ConfigLoader.new
12
+ actual_config = loader.load_config(input_file)
13
+ valid_config.should eq(actual_config)
14
+ end
15
+
16
+ it "should create a valid hash when input is YAML" do
17
+ input_file = 'spec/vcloud/data/working.yaml'
18
+ loader = Vcloud::ConfigLoader.new
19
+ actual_config = loader.load_config(input_file)
20
+ valid_config.should eq(actual_config)
21
+ end
22
+
23
+ it "should create a valid hash when input is YAML with anchor defaults" do
24
+ input_file = 'spec/vcloud/data/working_with_defaults.yaml'
25
+ loader = Vcloud::ConfigLoader.new
26
+ actual_config = loader.load_config(input_file)
27
+ valid_config['vapps'].should eq(actual_config['vapps'])
28
+ end
29
+
30
+ # it "should validate correctly against a schema" do
31
+ # input_file = 'spec/vcloud/data/working_with_defaults.yaml'
32
+ # loader = Vcloud::ConfigLoader.new
33
+ # schema = Vcloud::Launch.new.config_schema
34
+ # actual_config = loader.load_config(input_file, schema)
35
+ # valid_config['vapps'].should eq(actual_config['vapps'])
36
+ # end
37
+
38
+ # it "should raise an error if checked against an invalid schema" do
39
+ # input_file = 'spec/vcloud/data/working_with_defaults.yaml'
40
+ # loader = Vcloud::ConfigLoader.new
41
+ # Vcloud.logger.should_receive(:fatal).with("vapps: is not a hash")
42
+ # expect { loader.load_config(input_file, invalid_schema) }.
43
+ # to raise_error('Supplied configuration does not match supplied schema')
44
+ # end
45
+ #
46
+ context "loading example vcloud_launch configurations" do
47
+ examples_dir = File.join(
48
+ File.dirname(__FILE__),
49
+ '..', '..', 'examples'
50
+ )
51
+ Dir["#{examples_dir}/vcloud-launch/*.yaml"].each do |input_file|
52
+ it "should load example config #{File.basename(input_file)}" do
53
+ loader = Vcloud::ConfigLoader.new
54
+ actual_config = loader.load_config(input_file, ::Vcloud::Launch::new.config_schema)
55
+ expect(actual_config).to be_true
56
+ end
57
+ end
58
+ end
59
+
60
+ context "loading example vcloud-net-launch configurations" do
61
+ examples_dir = File.join(
62
+ File.dirname(__FILE__),
63
+ '..', '..', 'examples'
64
+ )
65
+ Dir["#{examples_dir}/vcloud-net-launch/*.yaml"].each do |input_file|
66
+ it "should load example config #{File.basename(input_file)}" do
67
+ loader = Vcloud::ConfigLoader.new
68
+ actual_config = loader.load_config(input_file)
69
+ expect(actual_config).to be_true
70
+ end
71
+ end
72
+ end
73
+
74
+ def invalid_schema
75
+ {
76
+ type: Hash,
77
+ permit_unknown_parameters: true,
78
+ internals: {
79
+ vapps: { type: Hash },
80
+ }
81
+ }
82
+ end
83
+
84
+ def valid_config
85
+ {
86
+ :vapps=>[{
87
+ :name=>"vapp-vcloud-tools-tests",
88
+ :vdc_name=>"VDC_NAME",
89
+ :catalog=>"CATALOG_NAME",
90
+ :catalog_item=>"CATALOG_ITEM",
91
+ :vm=>{
92
+ :hardware_config=>{:memory=>"4096", :cpu=>"2"},
93
+ :extra_disks=>[{:size=>"8192"}],
94
+ :network_connections=>[{
95
+ :name=>"Default",
96
+ :ip_address=>"192.168.2.10"
97
+ },
98
+ {
99
+ :name=>"NetworkTest2",
100
+ :ip_address=>"192.168.1.10"
101
+ }],
102
+ :bootstrap=>{
103
+ :script_path=>"spec/data/basic_preamble_test.erb",
104
+ :vars=>{:message=>"hello world"}
105
+ },
106
+ :metadata=>{}
107
+ }
108
+ }]
109
+ }
110
+ end
111
+
112
+ end
@@ -0,0 +1,570 @@
1
+ require 'spec_helper'
2
+
3
+ module Vcloud
4
+ describe ConfigValidator do
5
+
6
+ context "sanitize type" do
7
+
8
+ it "should be ok with type as bare String" do
9
+ data = "hello world"
10
+ schema = { type: String }
11
+ v = ConfigValidator.validate(:base, data, schema)
12
+ expect(v.valid?).to be_true
13
+ end
14
+
15
+ it "should be ok with type as string 'String'" do
16
+ data = "hello world"
17
+ schema = { type: 'String' }
18
+ v = ConfigValidator.validate(:base, data, schema)
19
+ expect(v.valid?).to be_true
20
+ end
21
+
22
+ it "should be ok with type as string 'string'" do
23
+ data = "hello world"
24
+ schema = { type: 'string' }
25
+ v = ConfigValidator.validate(:base, data, schema)
26
+ expect(v.valid?).to be_true
27
+ end
28
+
29
+ end
30
+
31
+ context "string validations" do
32
+
33
+ it "should validate a basic string" do
34
+ data = "hello world"
35
+ schema = { type: 'string' }
36
+ v = ConfigValidator.validate(:base, data, schema)
37
+ expect(v.valid?).to be_true
38
+ end
39
+
40
+ it "should not validate a number as a basic string" do
41
+ data = 42
42
+ schema = { type: 'string' }
43
+ v = ConfigValidator.validate(:base, data, schema)
44
+ expect(v.valid?).to be_false
45
+ end
46
+
47
+ it "should log error with number as a basic string" do
48
+ data = 42
49
+ schema = { type: 'string' }
50
+ v = ConfigValidator.validate(:base, data, schema)
51
+ expect(v.errors).to eq([ 'base: 42 is not a string'] )
52
+ end
53
+
54
+ it "should return error with empty string (by default)" do
55
+ data = ""
56
+ schema = { type: 'string' }
57
+ v = ConfigValidator.validate(:base, data, schema)
58
+ expect(v.errors).to eq([ 'base: cannot be empty string'] )
59
+ end
60
+
61
+ it "should return error with empty string with allowed_empty: false)" do
62
+ data = ""
63
+ schema = { type: 'string', allowed_empty: false }
64
+ v = ConfigValidator.validate(:base, data, schema)
65
+ expect(v.errors).to eq([ 'base: cannot be empty string'] )
66
+ end
67
+
68
+ it "should validate ok with empty string with allowed_empty: true)" do
69
+ data = ""
70
+ schema = { type: 'string', allowed_empty: true }
71
+ v = ConfigValidator.validate(:base, data, schema)
72
+ expect(v.valid?).to be_true
73
+ end
74
+
75
+ it "should validate ok with a :matcher regex specified" do
76
+ data = "name-1234"
77
+ schema = { type: 'string', matcher: /^name-\d+$/ }
78
+ v = ConfigValidator.validate(:base, data, schema)
79
+ expect(v.valid?).to be_true
80
+ end
81
+
82
+ it "should return errror with a :matcher regex not matching" do
83
+ data = "name-123a"
84
+ schema = { type: 'string', matcher: /^name-\d+$/ }
85
+ v = ConfigValidator.validate(:base, data, schema)
86
+ expect(v.errors).to eq(['base: name-123a does not match'])
87
+ end
88
+
89
+ end
90
+
91
+ context "hash validations" do
92
+
93
+ it "should validate a basic hash" do
94
+ data = { name: "santa", address: "north pole" }
95
+ schema = {
96
+ type: "Hash",
97
+ internals: {
98
+ name: { type: 'string' },
99
+ address: { type: 'string' },
100
+ }
101
+ }
102
+ v = ConfigValidator.validate(:base, data, schema)
103
+ expect(v.valid?).to be_true
104
+ end
105
+
106
+ it "should not validate a bogus hash" do
107
+ data = { name: 42, address: 42 }
108
+ schema = {
109
+ type: "Hash",
110
+ internals: {
111
+ name: { type: "string" },
112
+ address: { type: "string" },
113
+ }
114
+ }
115
+ v = ConfigValidator.validate(:base, data, schema)
116
+ expect(v.valid?).to be_false
117
+ end
118
+
119
+ it "should return correct errors validating a bogus hash" do
120
+ data = { name: 42, address: 42 }
121
+ schema = {
122
+ type: "Hash",
123
+ internals: {
124
+ name: { type: "string" },
125
+ address: { type: "string" },
126
+ }
127
+ }
128
+ v = ConfigValidator.validate(:base, data, schema)
129
+ expect(v.errors).to eq([
130
+ "name: 42 is not a string",
131
+ "address: 42 is not a string",
132
+ ])
133
+ end
134
+
135
+ it "should return error with empty hash (by default)" do
136
+ data = {}
137
+ schema = { type: 'hash' }
138
+ v = ConfigValidator.validate(:base, data, schema)
139
+ expect(v.errors).to eq([ 'base: cannot be empty hash'] )
140
+ end
141
+
142
+ it "should return error with empty hash with allowed_empty: false)" do
143
+ data = {}
144
+ schema = { type: 'hash', allowed_empty: false }
145
+ v = ConfigValidator.validate(:base, data, schema)
146
+ expect(v.errors).to eq([ 'base: cannot be empty hash'] )
147
+ end
148
+
149
+ it "should validate ok with empty hash with allowed_empty: true)" do
150
+ data = {}
151
+ schema = { type: 'hash', allowed_empty: true }
152
+ v = ConfigValidator.validate(:base, data, schema)
153
+ expect(v.valid?).to be_true
154
+ end
155
+
156
+ it "should validate ok with a missing parameter, when marked :required => false" do
157
+ data = {
158
+ name: 'hello'
159
+ }
160
+ schema = {
161
+ type: 'hash',
162
+ internals: {
163
+ name: { type: 'string' },
164
+ optional_param: { type: 'string', required: false },
165
+ }
166
+ }
167
+ v = ConfigValidator.validate(:base, data, schema)
168
+ expect(v.valid?).to be_true
169
+ end
170
+
171
+ it "should return error with a missing :required => true param" do
172
+ data = {
173
+ name: 'hello'
174
+ }
175
+ schema = {
176
+ type: 'hash',
177
+ internals: {
178
+ name: { type: 'string' },
179
+ not_optional_param: { type: 'string', required: true },
180
+ }
181
+ }
182
+ v = ConfigValidator.validate(:base, data, schema)
183
+ expect(v.errors).to eq(["base: missing 'not_optional_param' parameter"])
184
+ end
185
+
186
+ it "should return error if a bogus parameter is specified" do
187
+ data = {
188
+ name: 'hello',
189
+ bogus_parameter: [ 'wibble' ],
190
+ bogus_parameter2: 'hello',
191
+ }
192
+ schema = {
193
+ type: 'hash',
194
+ internals: {
195
+ name: { type: 'string' },
196
+ },
197
+ }
198
+ v = ConfigValidator.validate(:base, data, schema)
199
+ expect(v.errors).to eq([
200
+ "base: parameter 'bogus_parameter' is invalid",
201
+ "base: parameter 'bogus_parameter2' is invalid",
202
+ ])
203
+ end
204
+
205
+ it "should validate ok if a bogus parameter is specified, when :permit_unknown_parameters is true" do
206
+ data = {
207
+ name: 'hello',
208
+ bogus_parameter: [ 'wibble' ],
209
+ bogus_parameter2: 'hello',
210
+ }
211
+ schema = {
212
+ type: 'hash',
213
+ permit_unknown_parameters: true,
214
+ internals: {
215
+ name: { type: 'string' },
216
+ },
217
+ }
218
+ v = ConfigValidator.validate(:base, data, schema)
219
+ expect(v.valid?).to be_true
220
+ end
221
+
222
+ end
223
+
224
+ context "array validations" do
225
+
226
+ it "should validate a basic array" do
227
+ data = [ "santa", "north pole" ]
228
+ schema = {
229
+ type: "Array",
230
+ each_element_is: { type: "string" }
231
+ }
232
+ v = ConfigValidator.validate(:base, data, schema)
233
+ expect(v.valid?).to be_true
234
+ end
235
+
236
+ it "should validate a bogus array" do
237
+ data = [ 42, 43 ]
238
+ schema = {
239
+ type: "Array",
240
+ each_element_is: { type: "string" }
241
+ }
242
+ v = ConfigValidator.validate(:base, data, schema)
243
+ expect(v.valid?).to be_false
244
+ end
245
+
246
+ it "should return correct errors validating a bogus array" do
247
+ data = [ 42, 43 ]
248
+ schema = {
249
+ type: "Array",
250
+ each_element_is: { type: "string" }
251
+ }
252
+ v = ConfigValidator.validate(:base, data, schema)
253
+ expect(v.errors).to eq([
254
+ "base: 42 is not a string",
255
+ "base: 43 is not a string",
256
+ ])
257
+ end
258
+
259
+ it "should return error with empty array (by default)" do
260
+ data = []
261
+ schema = { type: 'array' }
262
+ v = ConfigValidator.validate(:base, data, schema)
263
+ expect(v.errors).to eq([ 'base: cannot be empty array'] )
264
+ end
265
+
266
+ it "should return error with empty array with allowed_empty: false)" do
267
+ data = []
268
+ schema = { type: 'array', allowed_empty: false }
269
+ v = ConfigValidator.validate(:base, data, schema)
270
+ expect(v.errors).to eq([ 'base: cannot be empty array'] )
271
+ end
272
+
273
+ it "should validate ok with empty array with allowed_empty: true)" do
274
+ data = []
275
+ schema = { type: 'array', allowed_empty: true }
276
+ v = ConfigValidator.validate(:base, data, schema)
277
+ expect(v.valid?).to be_true
278
+ end
279
+
280
+ end
281
+
282
+ context "array of hashes validations" do
283
+
284
+ it "should validate an array of hashes" do
285
+ data = [
286
+ { name: "santa", address: "north pole" },
287
+ { name: "mole", address: "1 hole street" },
288
+ ]
289
+ schema = {
290
+ type: "array",
291
+ each_element_is: {
292
+ type: "hash",
293
+ internals: {
294
+ name: { type: 'string' },
295
+ address: { type: 'string' },
296
+ }
297
+ }
298
+ }
299
+ v = ConfigValidator.validate(:base, data, schema)
300
+ expect(v.valid?).to be_true
301
+ end
302
+
303
+ it "should correctly error on an invalid an array of hashes" do
304
+ data = [
305
+ { name: "santa", address: [] },
306
+ { name: 43, address: "1 hole street" },
307
+ ]
308
+ schema = {
309
+ type: "array",
310
+ each_element_is: {
311
+ type: "hash",
312
+ internals: {
313
+ name: { type: 'string' },
314
+ address: { type: 'string' },
315
+ }
316
+ }
317
+ }
318
+ v = ConfigValidator.validate(:base, data, schema)
319
+ expect(v.errors).to eq([
320
+ "address: [] is not a string",
321
+ "name: 43 is not a string",
322
+ ])
323
+ end
324
+
325
+ end
326
+
327
+ context "hash of arrays validations" do
328
+
329
+ it "should validate a hash of arrays" do
330
+ data = {
331
+ boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
332
+ girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
333
+ }
334
+ schema = {
335
+ type: "Hash",
336
+ internals: {
337
+ boys_names: {
338
+ type: "Array",
339
+ each_element_is: { type: 'String' }
340
+ },
341
+ girls_names: {
342
+ type: "Array",
343
+ each_element_is: { type: 'String' }
344
+ }
345
+ }
346
+ }
347
+ v = ConfigValidator.validate(:base, data, schema)
348
+ expect(v.valid?).to be_true
349
+ end
350
+
351
+ it "should correctly error on an invalid hash of arrays" do
352
+ data = {
353
+ boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
354
+ girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
355
+ }
356
+ schema = {
357
+ type: "Hash",
358
+ internals: {
359
+ boys_names: {
360
+ type: "Array",
361
+ each_element_is: { type: 'String' },
362
+ },
363
+ girls_names: {
364
+ type: "Array",
365
+ each_element_is: { type: 'String' },
366
+ }
367
+ },
368
+ }
369
+ v = ConfigValidator.validate(:base, data, schema)
370
+ expect(v.valid?).to be_true
371
+ end
372
+
373
+ end
374
+
375
+ context "string_or_number validations" do
376
+
377
+ it "should correctly validate an Integer" do
378
+ data = 2
379
+ schema = { type: 'string_or_number' }
380
+ v = ConfigValidator.validate(:base, data, schema)
381
+ expect(v.valid?).to be_true
382
+ end
383
+
384
+ it "should correctly validate a String" do
385
+ data = '2'
386
+ schema = { type: 'string_or_number' }
387
+ v = ConfigValidator.validate(:base, data, schema)
388
+ expect(v.valid?).to be_true
389
+ end
390
+
391
+ it "should correctly error if not a string or numeric" do
392
+ data = []
393
+ schema = { type: 'string_or_number' }
394
+ v = ConfigValidator.validate(:base, data, schema)
395
+ expect(v.errors).to eq(["base: [] is not a string_or_number"])
396
+ end
397
+
398
+ end
399
+
400
+ context "ip_address validations" do
401
+
402
+ it "should correctly validate an IP address" do
403
+ data = '192.168.100.100'
404
+ schema = { type: 'ip_address' }
405
+ v = ConfigValidator.validate(:base, data, schema)
406
+ expect(v.valid?).to be_true
407
+ end
408
+
409
+ it "should correctly error on an invalid IP address" do
410
+ data = '256.168.100.100'
411
+ schema = { type: 'ip_address' }
412
+ v = ConfigValidator.validate(:base, data, schema)
413
+ expect(v.errors).to eq(['base: 256.168.100.100 is not a valid ip_address'])
414
+ end
415
+
416
+ it "should error if ip address have wrong octets" do
417
+ data = '192.168.100.100/33/33/33'
418
+ schema = { type: 'ip_address' }
419
+ v = ConfigValidator.validate(:base, data, schema)
420
+ expect(v.errors).to eq(['base: 192.168.100.100/33/33/33 is not a valid ip_address'])
421
+ end
422
+
423
+ end
424
+
425
+ context "ip_address_range validations" do
426
+ context "validate CIDR" do
427
+ it "should validate OK if CIDR is correct" do
428
+ data = '192.168.100.100/24'
429
+ schema = { type: 'ip_address_range' }
430
+ v = ConfigValidator.validate(:base, data, schema)
431
+ expect(v.valid?).to be_true
432
+ end
433
+
434
+ it "should return error if network bit value is greater than 32" do
435
+ data = '192.168.100.100/33'
436
+ schema = { type: 'ip_address_range' }
437
+ v = ConfigValidator.validate(:base, data, schema)
438
+ expect(v.valid?).to be_false
439
+ expect(v.errors).to eq(["base: 192.168.100.100/33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
440
+ end
441
+
442
+ it "should return error if network bit value is less than 0" do
443
+ data = '192.168.100.100/33'
444
+ schema = { type: 'ip_address_range' }
445
+ v = ConfigValidator.validate(:base, data, schema)
446
+ expect(v.valid?).to be_false
447
+ expect(v.errors).to eq(["base: 192.168.100.100/33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
448
+ end
449
+
450
+ it "should return error if network IP address is incorrect" do
451
+ data = '192.168.100./33'
452
+ schema = { type: 'ip_address_range' }
453
+ v = ConfigValidator.validate(:base, data, schema)
454
+ expect(v.valid?).to be_false
455
+ expect(v.errors).to eq(["base: 192.168.100./33 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
456
+ end
457
+ end
458
+
459
+ context "validate alphabetical values for IP range" do
460
+ %w(Any internal external).each do |data|
461
+ it "should validate OK if IP range is '#{data}'" do
462
+ schema = { type: 'ip_address_range' }
463
+ v = ConfigValidator.validate(:base, data, schema)
464
+ expect(v.valid?).to be_true
465
+ expect(v.errors).to be_empty
466
+ end
467
+ end
468
+
469
+ it "should error if IP range is a string but not a valid alphabetical value" do
470
+ data = 'invalid_ip_range_string'
471
+ schema = { type: 'ip_address_range' }
472
+ v = ConfigValidator.validate(:base, data, schema)
473
+ expect(v.valid?).to be_false
474
+ expect(v.errors).to eq(["base: invalid_ip_range_string is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
475
+ end
476
+ end
477
+
478
+ context "validate ranges specified using start and end addresses" do
479
+ it "should validate ok if the combination of start IP and end IP is correct" do
480
+ data = '192.168.100.100-192.168.100.110'
481
+ schema = { type: 'ip_address_range' }
482
+ v = ConfigValidator.validate(:base, data, schema)
483
+ expect(v.valid?).to be_true
484
+ expect(v.errors).to be_empty
485
+ end
486
+
487
+ it "should error if start IP address is incorrect" do
488
+ data = '192.168.100-192.168.100.110'
489
+ schema = { type: 'ip_address_range' }
490
+ v = ConfigValidator.validate(:base, data, schema)
491
+ expect(v.valid?).to be_false
492
+ expect(v.errors).to eq(["base: 192.168.100-192.168.100.110 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
493
+ end
494
+
495
+ it "should error if end IP address is incorrect" do
496
+ data = '192.168.100.110-192.168.100'
497
+ schema = { type: 'ip_address_range' }
498
+ v = ConfigValidator.validate(:base, data, schema)
499
+ expect(v.valid?).to be_false
500
+ expect(v.errors).to eq(["base: 192.168.100.110-192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
501
+ end
502
+
503
+ it "should error if the combination of start IP and end IP is incorrect" do
504
+ data = '200.168.100.99-192.168.100'
505
+ schema = { type: 'ip_address_range' }
506
+ v = ConfigValidator.validate(:base, data, schema)
507
+ expect(v.valid?).to be_false
508
+ expect(v.errors).to eq(["base: 200.168.100.99-192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
509
+ end
510
+
511
+ it "should error if the start and end IPS are not separated by -" do
512
+ data = '190.168.100.99:192.168.100'
513
+ schema = { type: 'ip_address_range' }
514
+ v = ConfigValidator.validate(:base, data, schema)
515
+ expect(v.valid?).to be_false
516
+ expect(v.errors).to eq(["base: 190.168.100.99:192.168.100 is not a valid IP address range. Valid values can be IP address, CIDR, IP range, 'Any','internal' and 'external'."])
517
+ end
518
+ end
519
+
520
+ it "should accept single ip address as range" do
521
+ data = '190.168.100.99'
522
+ schema = { type: 'ip_address_range' }
523
+ v = ConfigValidator.validate(:base, data, schema)
524
+ expect(v.valid?).to be_true
525
+ expect(v.errors).to eq([])
526
+ end
527
+ end
528
+
529
+ context "enum validations" do
530
+ it "should error if enum value is not present in list" do
531
+ data = 'blah'
532
+ schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
533
+ v = ConfigValidator.validate(:base, data, schema)
534
+ expect(v.errors).to eq(["base: blah is not a valid value. Acceptable values are 'allow', 'decline', 'none'."])
535
+ end
536
+
537
+ it "should raise error if enum schema does not contain acceptable_values" do
538
+ data = 'blah'
539
+ schema = { type: 'enum', required: false}
540
+ expect{ ConfigValidator.validate(:base, data, schema) }.to raise_error("Must set :acceptable_values for type 'enum'")
541
+ end
542
+
543
+ it "should validate ok if enum is acceptable" do
544
+ data = 'allow'
545
+ schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
546
+ v = ConfigValidator.validate(:base, data, schema)
547
+ expect(v.valid?).to be_true
548
+ end
549
+ end
550
+
551
+ context "boolean validations" do
552
+ it "should error if boolean value is not valid" do
553
+ data = 'blah'
554
+ schema = { type: 'boolean' }
555
+ v = ConfigValidator.validate(:base, data, schema)
556
+ expect(v.errors).to eq(["base: blah is not a valid boolean value."])
557
+ end
558
+
559
+ [true, false].each do |boolean_value|
560
+ it "should validate ok if value is #{boolean_value}" do
561
+ schema = { type: 'boolean' }
562
+ v = ConfigValidator.validate(:base, boolean_value, schema)
563
+ expect(v.valid?).to be_true
564
+ end
565
+ end
566
+
567
+ end
568
+
569
+ end
570
+ end
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ # Default preamble
4
+
5
+ (
6
+ echo "in $*"
7
+ echo "message: <%= vars[:message] -%>"
8
+ ) >> /PREAMBLE_OUTPUT
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ # Default preamble
4
+
5
+ (
6
+ echo "in $*"
7
+ echo "message: hello world"
8
+ ) >> /PREAMBLE_OUTPUT