vcloud-core 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +13 -1
- data/README.md +13 -8
- data/lib/vcloud/core/version.rb +1 -1
- data/spec/vcloud/core/config_loader_spec.rb +155 -159
- data/spec/vcloud/core/config_validator_spec.rb +615 -619
- data/spec/vcloud/core/edge_gateway_interface_spec.rb +65 -70
- data/spec/vcloud/core/edge_gateway_spec.rb +138 -144
- data/spec/vcloud/core/independent_disk_spec.rb +15 -15
- data/spec/vcloud/core/metadata_helper_spec.rb +73 -77
- data/spec/vcloud/core/org_vdc_network_spec.rb +226 -230
- data/spec/vcloud/core/query_runner_spec.rb +31 -31
- data/spec/vcloud/core/query_spec.rb +1 -1
- data/spec/vcloud/core/vapp_spec.rb +175 -179
- data/spec/vcloud/core/vapp_template_spec.rb +82 -86
- data/spec/vcloud/core/vdc_spec.rb +47 -53
- data/spec/vcloud/core/vm_spec.rb +354 -358
- data/vcloud-core.gemspec +4 -4
- metadata +28 -30
- data/spec/integration/README.md +0 -36
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## 1.0.1 (2015-01-29)
|
2
|
+
|
3
|
+
Documentation:
|
4
|
+
|
5
|
+
- Update integration test details in README
|
6
|
+
- Update Gem ownership details
|
7
|
+
|
8
|
+
Fixes:
|
9
|
+
|
10
|
+
- Tighten dependency on vcloud-tools-tester
|
11
|
+
- Refactored test namespacing
|
12
|
+
|
1
13
|
## 1.0.0 (2015-01-22)
|
2
14
|
|
3
15
|
- Release 1.0.0 since the public API is now stable
|
@@ -12,7 +24,7 @@ Bugfixes:
|
|
12
24
|
|
13
25
|
Features:
|
14
26
|
|
15
|
-
- New `
|
27
|
+
- New `vcloud-logout` command line utility to revoke session tokens.
|
16
28
|
- New `Vcloud::Core::Fog.logout` method to revoke session tokens.
|
17
29
|
|
18
30
|
## 0.15.0 (2014-11-26)
|
data/README.md
CHANGED
@@ -137,14 +137,19 @@ Run the default suite of tests (e.g. lint, unit, features):
|
|
137
137
|
|
138
138
|
bundle exec rake
|
139
139
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
140
|
+
There are also integration tests. These are slower and require a real environment.
|
141
|
+
See the [vCloud Tools website](http://gds-operations.github.io/vcloud-tools/testing/) for details of how to set up and run the integration tests.
|
142
|
+
|
143
|
+
The parameters required to run the vCloud Core integration tests are:
|
144
|
+
|
145
|
+
````
|
146
|
+
default: # This is the fog credential that refers to your testing environment, e.g. `test_credential`
|
147
|
+
vdc_1_name: # The name of a VDC
|
148
|
+
catalog: # A catalog
|
149
|
+
vapp_template: # A vApp Template within that catalog
|
150
|
+
network_1: # The name of the primary network
|
151
|
+
network_1_ip: # The IP address of the primary network
|
152
|
+
````
|
148
153
|
## Contributing
|
149
154
|
|
150
155
|
1. Fork it
|
data/lib/vcloud/core/version.rb
CHANGED
@@ -1,164 +1,160 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
expect(Vcloud::Core.logger).not_to receive(:warn)
|
66
|
-
loader.load_config(input_file, vapp_config_schema)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should log warnings if checked against a deprecated schema" do
|
70
|
-
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
71
|
-
loader = ConfigLoader.new
|
72
|
-
|
73
|
-
expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
|
74
|
-
loader.load_config(input_file, deprecated_schema)
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should log warning before raising error against an invalid and deprecated schema" do
|
78
|
-
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
79
|
-
loader = ConfigLoader.new
|
80
|
-
|
81
|
-
expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
|
82
|
-
expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
|
83
|
-
expect { loader.load_config(input_file, invalid_and_deprecated_schema) }.
|
84
|
-
to raise_error('Supplied configuration does not match supplied schema')
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def vapp_config_schema
|
89
|
-
{
|
90
|
-
type: 'hash',
|
91
|
-
allowed_empty: false,
|
92
|
-
permit_unknown_parameters: true,
|
93
|
-
internals: {
|
94
|
-
vapps: {
|
95
|
-
type: 'array',
|
96
|
-
required: false,
|
97
|
-
allowed_empty: true,
|
98
|
-
},
|
99
|
-
}
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
def invalid_schema
|
104
|
-
{
|
105
|
-
type: Hash,
|
106
|
-
permit_unknown_parameters: true,
|
107
|
-
internals: {
|
108
|
-
vapps: { type: Hash },
|
109
|
-
}
|
110
|
-
}
|
111
|
-
end
|
112
|
-
|
113
|
-
def invalid_and_deprecated_schema
|
114
|
-
{
|
115
|
-
type: 'hash',
|
116
|
-
permit_unknown_parameters: true,
|
117
|
-
internals: {
|
118
|
-
vapps: { type: Hash, deprecated_by: 'vapps_new' },
|
119
|
-
vapps_new: { type: 'array' },
|
120
|
-
}
|
121
|
-
}
|
122
|
-
end
|
123
|
-
|
124
|
-
def deprecated_schema
|
125
|
-
{
|
126
|
-
type: 'hash',
|
127
|
-
permit_unknown_parameters: true,
|
128
|
-
internals: {
|
129
|
-
vapps: { type: 'array', deprecated_by: 'vapps_new' },
|
130
|
-
vapps_new: { type: 'array' },
|
131
|
-
}
|
132
|
-
}
|
133
|
-
end
|
134
|
-
|
135
|
-
def valid_config
|
136
|
-
{
|
137
|
-
:vapps=>[{
|
138
|
-
:name=>"vapp-vcloud-tools-tests",
|
139
|
-
:vdc_name=>"VDC_NAME",
|
140
|
-
:catalog=>"CATALOG_NAME",
|
141
|
-
:vapp_template=>"VAPP_TEMPLATE",
|
142
|
-
:vm=>{
|
143
|
-
:hardware_config=>{:memory=>"4096", :cpu=>"2"},
|
144
|
-
:extra_disks=>[{:size=>"8192"}],
|
145
|
-
:network_connections=>[{
|
146
|
-
:name=>"Default",
|
147
|
-
:ip_address=>"192.168.2.10"
|
148
|
-
},
|
149
|
-
{
|
150
|
-
:name=>"NetworkTest2",
|
151
|
-
:ip_address=>"192.168.1.10"
|
152
|
-
}],
|
153
|
-
:bootstrap=>{
|
154
|
-
:script_path=>"spec/data/basic_preamble_test.erb",
|
155
|
-
:vars=>{:message=>"hello world"}
|
156
|
-
},
|
157
|
-
:metadata=>{}
|
158
|
-
}
|
159
|
-
}]
|
160
|
-
}
|
161
|
-
end
|
3
|
+
describe Vcloud::Core::ConfigLoader do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@data_dir = File.join(File.dirname(__FILE__), "/data")
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'basic config loading' do
|
10
|
+
it "should create a valid hash when input is JSON" do
|
11
|
+
input_file = "#{@data_dir}/working.json"
|
12
|
+
loader = Vcloud::Core::ConfigLoader.new
|
13
|
+
actual_config = loader.load_config(input_file)
|
14
|
+
expect(valid_config).to eq(actual_config)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create a valid hash when input is YAML" do
|
18
|
+
input_file = "#{@data_dir}/working.yaml"
|
19
|
+
loader = Vcloud::Core::ConfigLoader.new
|
20
|
+
actual_config = loader.load_config(input_file)
|
21
|
+
expect(valid_config).to eq(actual_config)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should create a valid hash when input is YAML with anchor defaults" do
|
25
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
26
|
+
loader = Vcloud::Core::ConfigLoader.new
|
27
|
+
actual_config = loader.load_config(input_file)
|
28
|
+
expect(valid_config['vapps']).to eq(actual_config['vapps'])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'config loading with variable interpolation' do
|
33
|
+
it "should create a valid hash when input is YAML with variable file" do
|
34
|
+
input_file = "#{@data_dir}/working_template.yaml"
|
35
|
+
vars_file = "#{@data_dir}/working_variables.yaml"
|
36
|
+
loader = Vcloud::Core::ConfigLoader.new
|
37
|
+
actual_config = loader.load_config(input_file, nil, vars_file)
|
38
|
+
expect(valid_config).to eq(actual_config)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'config loading with schema validation' do
|
43
|
+
it "should validate correctly against a schema" do
|
44
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
45
|
+
loader = Vcloud::Core::ConfigLoader.new
|
46
|
+
schema = vapp_config_schema
|
47
|
+
actual_config = loader.load_config(input_file, schema)
|
48
|
+
expect(valid_config['vapps']).to eq(actual_config['vapps'])
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise an error if checked against an invalid schema" do
|
52
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
53
|
+
loader = Vcloud::Core::ConfigLoader.new
|
54
|
+
expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
|
55
|
+
expect { loader.load_config(input_file, invalid_schema) }.
|
56
|
+
to raise_error('Supplied configuration does not match supplied schema')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should not log warnings if there are none" do
|
60
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
61
|
+
loader = Vcloud::Core::ConfigLoader.new
|
62
|
+
|
63
|
+
expect(Vcloud::Core.logger).not_to receive(:warn)
|
64
|
+
loader.load_config(input_file, vapp_config_schema)
|
162
65
|
end
|
66
|
+
|
67
|
+
it "should log warnings if checked against a deprecated schema" do
|
68
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
69
|
+
loader = Vcloud::Core::ConfigLoader.new
|
70
|
+
|
71
|
+
expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
|
72
|
+
loader.load_config(input_file, deprecated_schema)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should log warning before raising error against an invalid and deprecated schema" do
|
76
|
+
input_file = "#{@data_dir}/working_with_defaults.yaml"
|
77
|
+
loader = Vcloud::Core::ConfigLoader.new
|
78
|
+
|
79
|
+
expect(Vcloud::Core.logger).to receive(:warn).with("vapps: is deprecated by 'vapps_new'")
|
80
|
+
expect(Vcloud::Core.logger).to receive(:fatal).with("vapps: is not a hash")
|
81
|
+
expect { loader.load_config(input_file, invalid_and_deprecated_schema) }.
|
82
|
+
to raise_error('Supplied configuration does not match supplied schema')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def vapp_config_schema
|
87
|
+
{
|
88
|
+
type: 'hash',
|
89
|
+
allowed_empty: false,
|
90
|
+
permit_unknown_parameters: true,
|
91
|
+
internals: {
|
92
|
+
vapps: {
|
93
|
+
type: 'array',
|
94
|
+
required: false,
|
95
|
+
allowed_empty: true,
|
96
|
+
},
|
97
|
+
}
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
def invalid_schema
|
102
|
+
{
|
103
|
+
type: Hash,
|
104
|
+
permit_unknown_parameters: true,
|
105
|
+
internals: {
|
106
|
+
vapps: { type: Hash },
|
107
|
+
}
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
def invalid_and_deprecated_schema
|
112
|
+
{
|
113
|
+
type: 'hash',
|
114
|
+
permit_unknown_parameters: true,
|
115
|
+
internals: {
|
116
|
+
vapps: { type: Hash, deprecated_by: 'vapps_new' },
|
117
|
+
vapps_new: { type: 'array' },
|
118
|
+
}
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def deprecated_schema
|
123
|
+
{
|
124
|
+
type: 'hash',
|
125
|
+
permit_unknown_parameters: true,
|
126
|
+
internals: {
|
127
|
+
vapps: { type: 'array', deprecated_by: 'vapps_new' },
|
128
|
+
vapps_new: { type: 'array' },
|
129
|
+
}
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def valid_config
|
134
|
+
{
|
135
|
+
:vapps=>[{
|
136
|
+
:name=>"vapp-vcloud-tools-tests",
|
137
|
+
:vdc_name=>"VDC_NAME",
|
138
|
+
:catalog=>"CATALOG_NAME",
|
139
|
+
:vapp_template=>"VAPP_TEMPLATE",
|
140
|
+
:vm=>{
|
141
|
+
:hardware_config=>{:memory=>"4096", :cpu=>"2"},
|
142
|
+
:extra_disks=>[{:size=>"8192"}],
|
143
|
+
:network_connections=>[{
|
144
|
+
:name=>"Default",
|
145
|
+
:ip_address=>"192.168.2.10"
|
146
|
+
},
|
147
|
+
{
|
148
|
+
:name=>"NetworkTest2",
|
149
|
+
:ip_address=>"192.168.1.10"
|
150
|
+
}],
|
151
|
+
:bootstrap=>{
|
152
|
+
:script_path=>"spec/data/basic_preamble_test.erb",
|
153
|
+
:vars=>{:message=>"hello world"}
|
154
|
+
},
|
155
|
+
:metadata=>{}
|
156
|
+
}
|
157
|
+
}]
|
158
|
+
}
|
163
159
|
end
|
164
160
|
end
|
@@ -1,697 +1,693 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
module Core
|
5
|
-
describe ConfigValidator do
|
3
|
+
describe Vcloud::Core::ConfigValidator do
|
6
4
|
|
7
|
-
|
5
|
+
context "sanitize type" do
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
it "should be ok with type as bare String" do
|
8
|
+
data = "hello world"
|
9
|
+
schema = { type: String }
|
10
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
11
|
+
expect(v.valid?).to be_true
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
it "should be ok with type as string 'String'" do
|
15
|
+
data = "hello world"
|
16
|
+
schema = { type: 'String' }
|
17
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
18
|
+
expect(v.valid?).to be_true
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
21
|
+
it "should be ok with type as string 'string'" do
|
22
|
+
data = "hello world"
|
23
|
+
schema = { type: 'string' }
|
24
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
25
|
+
expect(v.valid?).to be_true
|
26
|
+
end
|
29
27
|
|
30
|
-
|
28
|
+
end
|
31
29
|
|
32
|
-
|
30
|
+
context "string validations" do
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
it "should validate a basic string" do
|
33
|
+
data = "hello world"
|
34
|
+
schema = { type: 'string' }
|
35
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
36
|
+
expect(v.valid?).to be_true
|
37
|
+
end
|
40
38
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
it "should not validate a number as a basic string" do
|
40
|
+
data = 42
|
41
|
+
schema = { type: 'string' }
|
42
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
43
|
+
expect(v.valid?).to be_false
|
44
|
+
end
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
it "should log error with number as a basic string" do
|
47
|
+
data = 42
|
48
|
+
schema = { type: 'string' }
|
49
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
50
|
+
expect(v.errors).to eq([ 'base: 42 is not a string'] )
|
51
|
+
end
|
54
52
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
it "should return error with empty string (by default)" do
|
54
|
+
data = ""
|
55
|
+
schema = { type: 'string' }
|
56
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
57
|
+
expect(v.errors).to eq([ 'base: cannot be empty string'] )
|
58
|
+
end
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
it "should return error with empty string with allowed_empty: false)" do
|
61
|
+
data = ""
|
62
|
+
schema = { type: 'string', allowed_empty: false }
|
63
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
64
|
+
expect(v.errors).to eq([ 'base: cannot be empty string'] )
|
65
|
+
end
|
68
66
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
67
|
+
it "should validate ok with empty string with allowed_empty: true)" do
|
68
|
+
data = ""
|
69
|
+
schema = { type: 'string', allowed_empty: true }
|
70
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
71
|
+
expect(v.valid?).to be_true
|
72
|
+
end
|
75
73
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
it "should return error for nil value with allowed_empty: true)" do
|
75
|
+
data = nil
|
76
|
+
schema = { type: 'string', allowed_empty: true }
|
77
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
78
|
+
expect(v.errors).to eq([ 'base: is not a string'] )
|
79
|
+
end
|
82
80
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
81
|
+
it "should validate ok with a :matcher regex specified" do
|
82
|
+
data = "name-1234"
|
83
|
+
schema = { type: 'string', matcher: /^name-\d+$/ }
|
84
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
85
|
+
expect(v.valid?).to be_true
|
86
|
+
end
|
89
87
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
88
|
+
it "should return errror with a :matcher regex not matching" do
|
89
|
+
data = "name-123a"
|
90
|
+
schema = { type: 'string', matcher: /^name-\d+$/ }
|
91
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
92
|
+
expect(v.errors).to eq(['base: name-123a does not match'])
|
93
|
+
end
|
96
94
|
|
97
|
-
|
95
|
+
end
|
98
96
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
97
|
+
context "hash validations" do
|
98
|
+
|
99
|
+
it "should validate a basic hash" do
|
100
|
+
data = { name: "santa", address: "north pole" }
|
101
|
+
schema = {
|
102
|
+
type: "Hash",
|
103
|
+
internals: {
|
104
|
+
name: { type: 'string' },
|
105
|
+
address: { type: 'string' },
|
106
|
+
}
|
107
|
+
}
|
108
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
109
|
+
expect(v.valid?).to be_true
|
110
|
+
end
|
113
111
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
112
|
+
it "should not validate a bogus hash" do
|
113
|
+
data = { name: 42, address: 42 }
|
114
|
+
schema = {
|
115
|
+
type: "Hash",
|
116
|
+
internals: {
|
117
|
+
name: { type: "string" },
|
118
|
+
address: { type: "string" },
|
119
|
+
}
|
120
|
+
}
|
121
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
122
|
+
expect(v.valid?).to be_false
|
123
|
+
end
|
126
124
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
125
|
+
it "should return correct errors validating a bogus hash" do
|
126
|
+
data = { name: 42, address: 42 }
|
127
|
+
schema = {
|
128
|
+
type: "Hash",
|
129
|
+
internals: {
|
130
|
+
name: { type: "string" },
|
131
|
+
address: { type: "string" },
|
132
|
+
}
|
133
|
+
}
|
134
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
135
|
+
expect(v.errors).to eq([
|
136
|
+
"name: 42 is not a string",
|
137
|
+
"address: 42 is not a string",
|
138
|
+
])
|
139
|
+
end
|
142
140
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
141
|
+
it "should return error with empty hash (by default)" do
|
142
|
+
data = {}
|
143
|
+
schema = { type: 'hash' }
|
144
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
145
|
+
expect(v.errors).to eq([ 'base: cannot be empty hash'] )
|
146
|
+
end
|
149
147
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
148
|
+
it "should return error with empty hash with allowed_empty: false)" do
|
149
|
+
data = {}
|
150
|
+
schema = { type: 'hash', allowed_empty: false }
|
151
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
152
|
+
expect(v.errors).to eq([ 'base: cannot be empty hash'] )
|
153
|
+
end
|
156
154
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
155
|
+
it "should validate ok with empty hash with allowed_empty: true)" do
|
156
|
+
data = {}
|
157
|
+
schema = { type: 'hash', allowed_empty: true }
|
158
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
159
|
+
expect(v.valid?).to be_true
|
160
|
+
end
|
163
161
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
162
|
+
it "should validate ok with a missing parameter, when marked :required => false" do
|
163
|
+
data = {
|
164
|
+
name: 'hello'
|
165
|
+
}
|
166
|
+
schema = {
|
167
|
+
type: 'hash',
|
168
|
+
internals: {
|
169
|
+
name: { type: 'string' },
|
170
|
+
optional_param: { type: 'string', required: false },
|
171
|
+
}
|
172
|
+
}
|
173
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
174
|
+
expect(v.valid?).to be_true
|
175
|
+
end
|
178
176
|
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
177
|
+
it "should return error with a missing :required => true param" do
|
178
|
+
data = {
|
179
|
+
name: 'hello'
|
180
|
+
}
|
181
|
+
schema = {
|
182
|
+
type: 'hash',
|
183
|
+
internals: {
|
184
|
+
name: { type: 'string' },
|
185
|
+
not_optional_param: { type: 'string', required: true },
|
186
|
+
}
|
187
|
+
}
|
188
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
189
|
+
expect(v.errors).to eq(["base: missing 'not_optional_param' parameter"])
|
190
|
+
end
|
193
191
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
192
|
+
it "should return error if a bogus parameter is specified" do
|
193
|
+
data = {
|
194
|
+
name: 'hello',
|
195
|
+
bogus_parameter: [ 'wibble' ],
|
196
|
+
bogus_parameter2: 'hello',
|
197
|
+
}
|
198
|
+
schema = {
|
199
|
+
type: 'hash',
|
200
|
+
internals: {
|
201
|
+
name: { type: 'string' },
|
202
|
+
},
|
203
|
+
}
|
204
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
205
|
+
expect(v.errors).to eq([
|
206
|
+
"base: parameter 'bogus_parameter' is invalid",
|
207
|
+
"base: parameter 'bogus_parameter2' is invalid",
|
208
|
+
])
|
209
|
+
end
|
212
210
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
211
|
+
it "should validate ok if a bogus parameter is specified, when :permit_unknown_parameters is true" do
|
212
|
+
data = {
|
213
|
+
name: 'hello',
|
214
|
+
bogus_parameter: [ 'wibble' ],
|
215
|
+
bogus_parameter2: 'hello',
|
216
|
+
}
|
217
|
+
schema = {
|
218
|
+
type: 'hash',
|
219
|
+
permit_unknown_parameters: true,
|
220
|
+
internals: {
|
221
|
+
name: { type: 'string' },
|
222
|
+
},
|
223
|
+
}
|
224
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
225
|
+
expect(v.valid?).to be_true
|
226
|
+
end
|
229
227
|
|
230
|
-
|
228
|
+
end
|
231
229
|
|
232
|
-
|
230
|
+
context "array validations" do
|
233
231
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
232
|
+
it "should validate a basic array" do
|
233
|
+
data = [ "santa", "north pole" ]
|
234
|
+
schema = {
|
235
|
+
type: "Array",
|
236
|
+
each_element_is: { type: "string" }
|
237
|
+
}
|
238
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
239
|
+
expect(v.valid?).to be_true
|
240
|
+
end
|
243
241
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
242
|
+
it "should validate a bogus array" do
|
243
|
+
data = [ 42, 43 ]
|
244
|
+
schema = {
|
245
|
+
type: "Array",
|
246
|
+
each_element_is: { type: "string" }
|
247
|
+
}
|
248
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
249
|
+
expect(v.valid?).to be_false
|
250
|
+
end
|
253
251
|
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
252
|
+
it "should return correct errors validating a bogus array" do
|
253
|
+
data = [ 42, 43 ]
|
254
|
+
schema = {
|
255
|
+
type: "Array",
|
256
|
+
each_element_is: { type: "string" }
|
257
|
+
}
|
258
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
259
|
+
expect(v.errors).to eq([
|
260
|
+
"base: 42 is not a string",
|
261
|
+
"base: 43 is not a string",
|
262
|
+
])
|
263
|
+
end
|
266
264
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
265
|
+
it "should return error with empty array (by default)" do
|
266
|
+
data = []
|
267
|
+
schema = { type: 'array' }
|
268
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
269
|
+
expect(v.errors).to eq([ 'base: cannot be empty array'] )
|
270
|
+
end
|
273
271
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
272
|
+
it "should return error with empty array with allowed_empty: false)" do
|
273
|
+
data = []
|
274
|
+
schema = { type: 'array', allowed_empty: false }
|
275
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
276
|
+
expect(v.errors).to eq([ 'base: cannot be empty array'] )
|
277
|
+
end
|
280
278
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
279
|
+
it "should validate ok with empty array with allowed_empty: true)" do
|
280
|
+
data = []
|
281
|
+
schema = { type: 'array', allowed_empty: true }
|
282
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
283
|
+
expect(v.valid?).to be_true
|
284
|
+
end
|
287
285
|
|
288
|
-
|
286
|
+
end
|
289
287
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
288
|
+
context "array of hashes validations" do
|
289
|
+
|
290
|
+
it "should validate an array of hashes" do
|
291
|
+
data = [
|
292
|
+
{ name: "santa", address: "north pole" },
|
293
|
+
{ name: "mole", address: "1 hole street" },
|
294
|
+
]
|
295
|
+
schema = {
|
296
|
+
type: "array",
|
297
|
+
each_element_is: {
|
298
|
+
type: "hash",
|
299
|
+
internals: {
|
300
|
+
name: { type: 'string' },
|
301
|
+
address: { type: 'string' },
|
302
|
+
}
|
303
|
+
}
|
304
|
+
}
|
305
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
306
|
+
expect(v.valid?).to be_true
|
307
|
+
end
|
310
308
|
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
309
|
+
it "should correctly error on an invalid an array of hashes" do
|
310
|
+
data = [
|
311
|
+
{ name: "santa", address: [] },
|
312
|
+
{ name: 43, address: "1 hole street" },
|
313
|
+
]
|
314
|
+
schema = {
|
315
|
+
type: "array",
|
316
|
+
each_element_is: {
|
317
|
+
type: "hash",
|
318
|
+
internals: {
|
319
|
+
name: { type: 'string' },
|
320
|
+
address: { type: 'string' },
|
321
|
+
}
|
322
|
+
}
|
323
|
+
}
|
324
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
325
|
+
expect(v.errors).to eq([
|
326
|
+
"address: [] is not a string",
|
327
|
+
"name: 43 is not a string",
|
328
|
+
])
|
329
|
+
end
|
332
330
|
|
333
|
-
|
331
|
+
end
|
334
332
|
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
333
|
+
context "hash of arrays validations" do
|
334
|
+
|
335
|
+
it "should validate a hash of arrays" do
|
336
|
+
data = {
|
337
|
+
boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
|
338
|
+
girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
|
339
|
+
}
|
340
|
+
schema = {
|
341
|
+
type: "Hash",
|
342
|
+
internals: {
|
343
|
+
boys_names: {
|
344
|
+
type: "Array",
|
345
|
+
each_element_is: { type: 'String' }
|
346
|
+
},
|
347
|
+
girls_names: {
|
348
|
+
type: "Array",
|
349
|
+
each_element_is: { type: 'String' }
|
350
|
+
}
|
351
|
+
}
|
352
|
+
}
|
353
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
354
|
+
expect(v.valid?).to be_true
|
355
|
+
end
|
358
356
|
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
357
|
+
it "should correctly error on an invalid hash of arrays" do
|
358
|
+
data = {
|
359
|
+
boys_names: [ 'bob', 'andrew', 'charlie', 'dave' ],
|
360
|
+
girls_names: [ 'alice', 'beth', 'carol', 'davina' ],
|
361
|
+
}
|
362
|
+
schema = {
|
363
|
+
type: "Hash",
|
364
|
+
internals: {
|
365
|
+
boys_names: {
|
366
|
+
type: "Array",
|
367
|
+
each_element_is: { type: 'String' },
|
368
|
+
},
|
369
|
+
girls_names: {
|
370
|
+
type: "Array",
|
371
|
+
each_element_is: { type: 'String' },
|
372
|
+
}
|
373
|
+
},
|
374
|
+
}
|
375
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
376
|
+
expect(v.valid?).to be_true
|
377
|
+
end
|
380
378
|
|
381
|
-
|
379
|
+
end
|
382
380
|
|
383
|
-
|
381
|
+
context "string_or_number validations" do
|
384
382
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
383
|
+
it "should correctly validate an Integer" do
|
384
|
+
data = 2
|
385
|
+
schema = { type: 'string_or_number' }
|
386
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
387
|
+
expect(v.valid?).to be_true
|
388
|
+
end
|
391
389
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
390
|
+
it "should correctly validate a String" do
|
391
|
+
data = '2'
|
392
|
+
schema = { type: 'string_or_number' }
|
393
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
394
|
+
expect(v.valid?).to be_true
|
395
|
+
end
|
398
396
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
397
|
+
it "should correctly error if not a string or numeric" do
|
398
|
+
data = []
|
399
|
+
schema = { type: 'string_or_number' }
|
400
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
401
|
+
expect(v.errors).to eq(["base: [] is not a string_or_number"])
|
402
|
+
end
|
405
403
|
|
406
|
-
|
404
|
+
end
|
407
405
|
|
408
|
-
|
406
|
+
context "ip_address validations" do
|
409
407
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
408
|
+
it "should correctly validate an IP address" do
|
409
|
+
data = '192.168.100.100'
|
410
|
+
schema = { type: 'ip_address' }
|
411
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
412
|
+
expect(v.valid?).to be_true
|
413
|
+
end
|
416
414
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
415
|
+
it "should correctly error on an invalid IP address" do
|
416
|
+
data = '256.168.100.100'
|
417
|
+
schema = { type: 'ip_address' }
|
418
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
419
|
+
expect(v.errors).to eq(['base: 256.168.100.100 is not a valid ip_address'])
|
420
|
+
end
|
423
421
|
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
422
|
+
it "should error if ip address have wrong octets" do
|
423
|
+
data = '192.168.100.100/33/33/33'
|
424
|
+
schema = { type: 'ip_address' }
|
425
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
426
|
+
expect(v.errors).to eq(['base: 192.168.100.100/33/33/33 is not a valid ip_address'])
|
427
|
+
end
|
430
428
|
|
429
|
+
end
|
430
|
+
|
431
|
+
context "ip_address_range validations" do
|
432
|
+
context "validate CIDR" do
|
433
|
+
it "should validate OK if CIDR is correct" do
|
434
|
+
data = '192.168.100.100/24'
|
435
|
+
schema = { type: 'ip_address_range' }
|
436
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
437
|
+
expect(v.valid?).to be_true
|
431
438
|
end
|
432
439
|
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
end
|
441
|
-
|
442
|
-
it "should return error if network bit value is greater than 32" 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 bit value is less than 0" do
|
451
|
-
data = '192.168.100.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.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
|
-
|
458
|
-
it "should return error if network IP address is incorrect" do
|
459
|
-
data = '192.168.100./33'
|
460
|
-
schema = { type: 'ip_address_range' }
|
461
|
-
v = ConfigValidator.validate(:base, data, schema)
|
462
|
-
expect(v.valid?).to be_false
|
463
|
-
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'."])
|
464
|
-
end
|
465
|
-
end
|
440
|
+
it "should return error if network bit value is greater than 32" do
|
441
|
+
data = '192.168.100.100/33'
|
442
|
+
schema = { type: 'ip_address_range' }
|
443
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
444
|
+
expect(v.valid?).to be_false
|
445
|
+
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'."])
|
446
|
+
end
|
466
447
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
end
|
475
|
-
end
|
476
|
-
|
477
|
-
it "should error if IP range is a string but not a valid alphabetical value" do
|
478
|
-
data = 'invalid_ip_range_string'
|
479
|
-
schema = { type: 'ip_address_range' }
|
480
|
-
v = ConfigValidator.validate(:base, data, schema)
|
481
|
-
expect(v.valid?).to be_false
|
482
|
-
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'."])
|
483
|
-
end
|
484
|
-
end
|
448
|
+
it "should return error if network bit value is less than 0" do
|
449
|
+
data = '192.168.100.100/33'
|
450
|
+
schema = { type: 'ip_address_range' }
|
451
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
452
|
+
expect(v.valid?).to be_false
|
453
|
+
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'."])
|
454
|
+
end
|
485
455
|
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
it "should error if start IP address is incorrect" do
|
496
|
-
data = '192.168.100-192.168.100.110'
|
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-192.168.100.110 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 end IP address is incorrect" do
|
504
|
-
data = '192.168.100.110-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: 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'."])
|
509
|
-
end
|
510
|
-
|
511
|
-
it "should error if the combination of start IP and end IP is incorrect" do
|
512
|
-
data = '200.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: 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'."])
|
517
|
-
end
|
518
|
-
|
519
|
-
it "should error if the start and end IPS are not separated by -" do
|
520
|
-
data = '190.168.100.99:192.168.100'
|
521
|
-
schema = { type: 'ip_address_range' }
|
522
|
-
v = ConfigValidator.validate(:base, data, schema)
|
523
|
-
expect(v.valid?).to be_false
|
524
|
-
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'."])
|
525
|
-
end
|
526
|
-
end
|
456
|
+
it "should return error if network IP address is incorrect" do
|
457
|
+
data = '192.168.100./33'
|
458
|
+
schema = { type: 'ip_address_range' }
|
459
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
460
|
+
expect(v.valid?).to be_false
|
461
|
+
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'."])
|
462
|
+
end
|
463
|
+
end
|
527
464
|
|
528
|
-
|
529
|
-
|
465
|
+
context "validate alphabetical values for IP range" do
|
466
|
+
%w(Any internal external).each do |data|
|
467
|
+
it "should validate OK if IP range is '#{data}'" do
|
530
468
|
schema = { type: 'ip_address_range' }
|
531
|
-
v = ConfigValidator.validate(:base, data, schema)
|
469
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
532
470
|
expect(v.valid?).to be_true
|
533
|
-
expect(v.errors).to
|
471
|
+
expect(v.errors).to be_empty
|
534
472
|
end
|
535
473
|
end
|
536
474
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
475
|
+
it "should error if IP range is a string but not a valid alphabetical value" do
|
476
|
+
data = 'invalid_ip_range_string'
|
477
|
+
schema = { type: 'ip_address_range' }
|
478
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
479
|
+
expect(v.valid?).to be_false
|
480
|
+
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'."])
|
481
|
+
end
|
482
|
+
end
|
544
483
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
484
|
+
context "validate ranges specified using start and end addresses" do
|
485
|
+
it "should validate ok if the combination of start IP and end IP is correct" do
|
486
|
+
data = '192.168.100.100-192.168.100.110'
|
487
|
+
schema = { type: 'ip_address_range' }
|
488
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
489
|
+
expect(v.valid?).to be_true
|
490
|
+
expect(v.errors).to be_empty
|
491
|
+
end
|
550
492
|
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
493
|
+
it "should error if start IP address is incorrect" do
|
494
|
+
data = '192.168.100-192.168.100.110'
|
495
|
+
schema = { type: 'ip_address_range' }
|
496
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
497
|
+
expect(v.valid?).to be_false
|
498
|
+
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'."])
|
557
499
|
end
|
558
500
|
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
501
|
+
it "should error if end IP address is incorrect" do
|
502
|
+
data = '192.168.100.110-192.168.100'
|
503
|
+
schema = { type: 'ip_address_range' }
|
504
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
505
|
+
expect(v.valid?).to be_false
|
506
|
+
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'."])
|
507
|
+
end
|
566
508
|
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
end
|
509
|
+
it "should error if the combination of start IP and end IP is incorrect" do
|
510
|
+
data = '200.168.100.99-192.168.100'
|
511
|
+
schema = { type: 'ip_address_range' }
|
512
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
513
|
+
expect(v.valid?).to be_false
|
514
|
+
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'."])
|
574
515
|
end
|
575
516
|
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
it "should validate and warn when deprecator is required" do
|
586
|
-
schema = {
|
587
|
-
type: "Hash",
|
588
|
-
internals: {
|
589
|
-
name: { type: 'string', deprecated_by: 'full_name' },
|
590
|
-
full_name: { type: 'string', required: true },
|
591
|
-
}
|
592
|
-
}
|
593
|
-
v = ConfigValidator.validate(:base, data, schema)
|
594
|
-
expect(v.valid?).to be_true
|
595
|
-
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
596
|
-
end
|
597
|
-
|
598
|
-
it "should validate and warn when deprecator appears before deprecatee in schema" do
|
599
|
-
schema = {
|
600
|
-
type: "Hash",
|
601
|
-
internals: {
|
602
|
-
full_name: { type: 'string', required: true },
|
603
|
-
name: { type: 'string', deprecated_by: 'full_name' },
|
604
|
-
}
|
605
|
-
}
|
606
|
-
v = ConfigValidator.validate(:base, data, schema)
|
607
|
-
expect(v.valid?).to be_true
|
608
|
-
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
609
|
-
end
|
610
|
-
|
611
|
-
it "should warn about deprecatee even when both are not required" do
|
612
|
-
schema = {
|
613
|
-
type: "Hash",
|
614
|
-
internals: {
|
615
|
-
name: { type: 'string', required: false, deprecated_by: 'full_name' },
|
616
|
-
full_name: { type: 'string', required: false },
|
617
|
-
}
|
618
|
-
}
|
619
|
-
v = ConfigValidator.validate(:base, data, schema)
|
620
|
-
expect(v.valid?).to be_true
|
621
|
-
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
622
|
-
end
|
623
|
-
end
|
517
|
+
it "should error if the start and end IPS are not separated by -" do
|
518
|
+
data = '190.168.100.99:192.168.100'
|
519
|
+
schema = { type: 'ip_address_range' }
|
520
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
521
|
+
expect(v.valid?).to be_false
|
522
|
+
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'."])
|
523
|
+
end
|
524
|
+
end
|
624
525
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
full_name: { type: 'string', required: true },
|
634
|
-
bogus: { type: 'string' },
|
635
|
-
}
|
636
|
-
}
|
637
|
-
v = ConfigValidator.validate(:base, data, schema)
|
638
|
-
expect(v.valid?).to be_false
|
639
|
-
expect(v.errors).to eq(["base: missing 'full_name' parameter"])
|
640
|
-
end
|
641
|
-
|
642
|
-
it "should raise exception if deprecator does not exist in schema" do
|
643
|
-
schema = {
|
644
|
-
type: "Hash",
|
645
|
-
internals: {
|
646
|
-
name: { type: 'string', deprecated_by: 'does_not_exist' },
|
647
|
-
bogus: { type: 'string' },
|
648
|
-
}
|
649
|
-
}
|
650
|
-
expect {
|
651
|
-
ConfigValidator.validate(:base, data, schema)
|
652
|
-
}.to raise_error("name: deprecated_by target 'does_not_exist' not found in schema")
|
653
|
-
end
|
654
|
-
end
|
526
|
+
it "should accept single ip address as range" do
|
527
|
+
data = '190.168.100.99'
|
528
|
+
schema = { type: 'ip_address_range' }
|
529
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
530
|
+
expect(v.valid?).to be_true
|
531
|
+
expect(v.errors).to eq([])
|
532
|
+
end
|
533
|
+
end
|
655
534
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
name: { type: 'string', deprecated_by: 'full_name' },
|
664
|
-
full_name: { type: 'string', required: true },
|
665
|
-
}
|
666
|
-
}
|
667
|
-
v = ConfigValidator.validate(:base, data, schema)
|
668
|
-
expect(v.valid?).to be_false
|
669
|
-
expect(v.errors).to eq([
|
670
|
-
"name: 123 is not a string",
|
671
|
-
"full_name: 123 is not a string",
|
672
|
-
])
|
673
|
-
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
674
|
-
end
|
675
|
-
end
|
535
|
+
context "enum validations" do
|
536
|
+
it "should error if enum value is not present in list" do
|
537
|
+
data = 'blah'
|
538
|
+
schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
|
539
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
540
|
+
expect(v.errors).to eq(["base: blah is not a valid value. Acceptable values are 'allow', 'decline', 'none'."])
|
541
|
+
end
|
676
542
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
543
|
+
it "should raise error if enum schema does not contain acceptable_values" do
|
544
|
+
data = 'blah'
|
545
|
+
schema = { type: 'enum', required: false}
|
546
|
+
expect{ Vcloud::Core::ConfigValidator.validate(:base, data, schema) }.to raise_error("Must set :acceptable_values for type 'enum'")
|
547
|
+
end
|
548
|
+
|
549
|
+
it "should validate ok if enum is acceptable" do
|
550
|
+
data = 'allow'
|
551
|
+
schema = { type: 'enum', required: false, acceptable_values: ['allow', 'decline', 'none']}
|
552
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
553
|
+
expect(v.valid?).to be_true
|
554
|
+
end
|
555
|
+
end
|
556
|
+
|
557
|
+
context "boolean validations" do
|
558
|
+
it "should error if boolean value is not valid" do
|
559
|
+
data = 'blah'
|
560
|
+
schema = { type: 'boolean' }
|
561
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
562
|
+
expect(v.errors).to eq(["base: blah is not a valid boolean value."])
|
563
|
+
end
|
564
|
+
|
565
|
+
[true, false].each do |boolean_value|
|
566
|
+
it "should validate ok if value is #{boolean_value}" do
|
567
|
+
schema = { type: 'boolean' }
|
568
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, boolean_value, schema)
|
569
|
+
expect(v.valid?).to be_true
|
570
|
+
end
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
context "deprecated_by" do
|
575
|
+
# For clarification:
|
576
|
+
#
|
577
|
+
# - deprecatee: is the old param with a `deprecated_by` field.
|
578
|
+
# - deprecator: is the new param listed in the `deprecated_by` field.
|
579
|
+
#
|
580
|
+
context "deprecatee is provided and deprecator is not" do
|
581
|
+
let(:data) {{ name: "santa" }}
|
582
|
+
|
583
|
+
it "should validate and warn when deprecator is required" do
|
584
|
+
schema = {
|
585
|
+
type: "Hash",
|
586
|
+
internals: {
|
587
|
+
name: { type: 'string', deprecated_by: 'full_name' },
|
588
|
+
full_name: { type: 'string', required: true },
|
589
|
+
}
|
590
|
+
}
|
591
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
592
|
+
expect(v.valid?).to be_true
|
593
|
+
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
594
|
+
end
|
595
|
+
|
596
|
+
it "should validate and warn when deprecator appears before deprecatee in schema" do
|
597
|
+
schema = {
|
598
|
+
type: "Hash",
|
599
|
+
internals: {
|
600
|
+
full_name: { type: 'string', required: true },
|
601
|
+
name: { type: 'string', deprecated_by: 'full_name' },
|
602
|
+
}
|
603
|
+
}
|
604
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
605
|
+
expect(v.valid?).to be_true
|
606
|
+
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
607
|
+
end
|
608
|
+
|
609
|
+
it "should warn about deprecatee even when both are not required" do
|
610
|
+
schema = {
|
611
|
+
type: "Hash",
|
612
|
+
internals: {
|
613
|
+
name: { type: 'string', required: false, deprecated_by: 'full_name' },
|
614
|
+
full_name: { type: 'string', required: false },
|
615
|
+
}
|
616
|
+
}
|
617
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
618
|
+
expect(v.valid?).to be_true
|
619
|
+
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
693
620
|
end
|
621
|
+
end
|
622
|
+
|
623
|
+
context "neither deprecatee or deprecator are provided" do
|
624
|
+
let(:data) {{ bogus: "blah" }}
|
625
|
+
|
626
|
+
it "should return error for deprecator but not deprecatee if neither are set" do
|
627
|
+
schema = {
|
628
|
+
type: "Hash",
|
629
|
+
internals: {
|
630
|
+
name: { type: 'string', deprecated_by: 'full_name' },
|
631
|
+
full_name: { type: 'string', required: true },
|
632
|
+
bogus: { type: 'string' },
|
633
|
+
}
|
634
|
+
}
|
635
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
636
|
+
expect(v.valid?).to be_false
|
637
|
+
expect(v.errors).to eq(["base: missing 'full_name' parameter"])
|
638
|
+
end
|
639
|
+
|
640
|
+
it "should raise exception if deprecator does not exist in schema" do
|
641
|
+
schema = {
|
642
|
+
type: "Hash",
|
643
|
+
internals: {
|
644
|
+
name: { type: 'string', deprecated_by: 'does_not_exist' },
|
645
|
+
bogus: { type: 'string' },
|
646
|
+
}
|
647
|
+
}
|
648
|
+
expect {
|
649
|
+
Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
650
|
+
}.to raise_error("name: deprecated_by target 'does_not_exist' not found in schema")
|
651
|
+
end
|
652
|
+
end
|
694
653
|
|
654
|
+
context "deprecatee and deprecator are provided and of the wrong type" do
|
655
|
+
let(:data) {{ name: 123, full_name: 123 }}
|
656
|
+
|
657
|
+
it "should return an error for each and a warning for deprecatee" do
|
658
|
+
schema = {
|
659
|
+
type: "Hash",
|
660
|
+
internals: {
|
661
|
+
name: { type: 'string', deprecated_by: 'full_name' },
|
662
|
+
full_name: { type: 'string', required: true },
|
663
|
+
}
|
664
|
+
}
|
665
|
+
v = Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
666
|
+
expect(v.valid?).to be_false
|
667
|
+
expect(v.errors).to eq([
|
668
|
+
"name: 123 is not a string",
|
669
|
+
"full_name: 123 is not a string",
|
670
|
+
])
|
671
|
+
expect(v.warnings).to eq(["name: is deprecated by 'full_name'"])
|
672
|
+
end
|
673
|
+
end
|
674
|
+
|
675
|
+
it "should not honour deprecation across nested structures" do
|
676
|
+
data = { bogus: "blah" }
|
677
|
+
schema = {
|
678
|
+
type: "Hash",
|
679
|
+
internals: {
|
680
|
+
name: { type: 'string', deprecated_by: 'full_name' },
|
681
|
+
nested: { type: 'hash', internals: {
|
682
|
+
full_name: { type: 'string', required: true },
|
683
|
+
}},
|
684
|
+
bogus: { type: 'string' },
|
685
|
+
}
|
686
|
+
}
|
687
|
+
expect {
|
688
|
+
Vcloud::Core::ConfigValidator.validate(:base, data, schema)
|
689
|
+
}.to raise_error("name: deprecated_by target 'full_name' not found in schema")
|
695
690
|
end
|
696
691
|
end
|
692
|
+
|
697
693
|
end
|