vmware-vra 3.1.2 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/linters.yml +9 -0
- data/.markdownlint.yaml +5 -0
- data/.mdlrc +1 -0
- data/CHANGELOG.md +9 -0
- data/README.md +37 -26
- data/Rakefile +2 -2
- data/lib/vra/catalog.rb +6 -7
- data/lib/vra/catalog_base.rb +4 -4
- data/lib/vra/catalog_item.rb +12 -12
- data/lib/vra/catalog_source.rb +13 -13
- data/lib/vra/catalog_type.rb +6 -6
- data/lib/vra/client.rb +13 -13
- data/lib/vra/deployment.rb +21 -21
- data/lib/vra/deployment_request.rb +8 -9
- data/lib/vra/deployments.rb +1 -1
- data/lib/vra/http.rb +6 -6
- data/lib/vra/request.rb +6 -6
- data/lib/vra/request_parameters.rb +9 -9
- data/lib/vra/resource.rb +16 -16
- data/lib/vra/version.rb +1 -1
- data/lib/vra.rb +14 -14
- data/spec/catalog_item_spec.rb +50 -50
- data/spec/catalog_source_spec.rb +53 -53
- data/spec/catalog_spec.rb +45 -45
- data/spec/catalog_type_spec.rb +32 -32
- data/spec/client_spec.rb +202 -202
- data/spec/deployment_request_spec.rb +74 -74
- data/spec/deployment_spec.rb +70 -70
- data/spec/deployments_spec.rb +19 -19
- data/spec/http_spec.rb +59 -59
- data/spec/request_spec.rb +34 -34
- data/spec/resource_spec.rb +55 -55
- data/spec/spec_helper.rb +4 -4
- metadata +6 -6
- data/.github/ISSUE_TEMPLATE.md +0 -23
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- data/.github/workflows/unit.yml +0 -23
data/spec/client_spec.rb
CHANGED
@@ -17,17 +17,17 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
#
|
19
19
|
|
20
|
-
require
|
21
|
-
require
|
20
|
+
require "spec_helper"
|
21
|
+
require "pry"
|
22
22
|
# require 'pry-byebug'
|
23
23
|
|
24
24
|
describe Vra::Client do
|
25
25
|
let(:client_params) do
|
26
26
|
{
|
27
|
-
username:
|
28
|
-
password:
|
29
|
-
tenant:
|
30
|
-
base_url:
|
27
|
+
username: "user@corp.local",
|
28
|
+
password: "password",
|
29
|
+
tenant: "tenant",
|
30
|
+
base_url: "https://vra.corp.local",
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
@@ -39,52 +39,52 @@ describe Vra::Client do
|
|
39
39
|
described_class.new(client_params.merge(verify_ssl: false))
|
40
40
|
end
|
41
41
|
|
42
|
-
describe
|
43
|
-
it
|
42
|
+
describe "#initialize" do
|
43
|
+
it "calls validate_client_options!" do
|
44
44
|
client = described_class.allocate
|
45
45
|
expect(client).to receive(:validate_client_options!)
|
46
46
|
client.send(:initialize, client_params)
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
describe
|
51
|
-
it
|
52
|
-
expect(client.token_params[:password]).to eq(
|
50
|
+
describe "#token_params" do
|
51
|
+
it "gets the correct password from the PasswordMasker object" do
|
52
|
+
expect(client.token_params[:password]).to eq("password")
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
describe
|
57
|
-
context
|
58
|
-
it
|
59
|
-
client.access_token =
|
60
|
-
expect(client.request_headers.key?(
|
56
|
+
describe "#request_headers" do
|
57
|
+
context "when access token exists" do
|
58
|
+
it "has an Authorization header" do
|
59
|
+
client.access_token = "12345"
|
60
|
+
expect(client.request_headers.key?("Authorization")).to be true
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
context
|
65
|
-
it
|
66
|
-
expect(client.request_headers.key?(
|
64
|
+
context "when access token does not exist" do
|
65
|
+
it "does not have an Authorization header" do
|
66
|
+
expect(client.request_headers.key?("Authorization")).to be false
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
describe
|
72
|
-
context
|
73
|
-
it
|
71
|
+
describe "#authorize!" do
|
72
|
+
context "when a token is not authorized or no token exists" do
|
73
|
+
it "generates a token successfully" do
|
74
74
|
allow(client).to receive(:authorized?).twice.and_return(false, true)
|
75
75
|
expect(client).to receive(:generate_access_token)
|
76
76
|
|
77
77
|
client.authorize!
|
78
78
|
end
|
79
79
|
|
80
|
-
it
|
80
|
+
it "raises an exception if token generation fails" do
|
81
81
|
allow(client).to receive(:authorized?).and_return(false)
|
82
82
|
allow(client).to receive(:generate_access_token).and_raise(Vra::Exception::Unauthorized)
|
83
83
|
|
84
84
|
expect { client.authorize! }.to raise_error(Vra::Exception::Unauthorized)
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
87
|
+
it "raises an exception if a generated token is unauthorized" do
|
88
88
|
allow(client).to receive(:authorized).twice.and_return(false, false)
|
89
89
|
allow(client).to receive(:generate_access_token)
|
90
90
|
|
@@ -92,8 +92,8 @@ describe Vra::Client do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
context
|
96
|
-
it
|
95
|
+
context "when a token is authorized" do
|
96
|
+
it "does not generate a new token" do
|
97
97
|
allow(client).to receive(:authorized?).and_return(true)
|
98
98
|
expect(client).to_not receive(:generate_access_token)
|
99
99
|
|
@@ -102,28 +102,28 @@ describe Vra::Client do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
describe
|
106
|
-
context
|
107
|
-
it
|
105
|
+
describe "#authorized?" do
|
106
|
+
context "when token does not exist" do
|
107
|
+
it "returns false" do
|
108
108
|
expect(client.authorized?).to be false
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
context
|
112
|
+
context "when token exists" do
|
113
113
|
before(:each) do
|
114
|
-
client.access_token =
|
115
|
-
client.refresh_token =
|
114
|
+
client.access_token = "12345"
|
115
|
+
client.refresh_token = "54321"
|
116
116
|
end
|
117
117
|
|
118
|
-
it
|
119
|
-
response = double(
|
118
|
+
it "returns true if the token validates successfully" do
|
119
|
+
response = double("response", success_no_content?: true, code: 204, success?: true)
|
120
120
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
121
121
|
|
122
122
|
expect(client.authorized?).to be true
|
123
123
|
end
|
124
124
|
|
125
|
-
it
|
126
|
-
response = double(
|
125
|
+
it "returns false if the token validates unsuccessfully" do
|
126
|
+
response = double("response", success_no_content?: false, code: 401, success?: false)
|
127
127
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
128
128
|
|
129
129
|
expect(client.authorized?).to be false
|
@@ -131,28 +131,28 @@ describe Vra::Client do
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
|
134
|
-
describe
|
134
|
+
describe "#generate_access_token" do
|
135
135
|
let(:payload) do
|
136
136
|
{
|
137
|
-
username:
|
138
|
-
password:
|
139
|
-
|
137
|
+
username: "user@corp.local",
|
138
|
+
password: "password",
|
139
|
+
domain: "tenant",
|
140
140
|
}.to_json
|
141
141
|
end
|
142
142
|
|
143
143
|
let(:success_response) do
|
144
144
|
{
|
145
|
-
access_token:
|
146
|
-
refresh_token:
|
147
|
-
id:
|
145
|
+
access_token: "123456",
|
146
|
+
refresh_token: "654321",
|
147
|
+
id: "123456",
|
148
148
|
}.to_json
|
149
149
|
end
|
150
150
|
|
151
|
-
let(:refresh_response_body) { { token:
|
151
|
+
let(:refresh_response_body) { { token: "123456" }.to_json }
|
152
152
|
|
153
|
-
it
|
154
|
-
response = double(
|
155
|
-
refresh_response = double(
|
153
|
+
it "posts to the tokens API endpoint" do
|
154
|
+
response = double("response", code: 200, body: success_response, success_ok?: true)
|
155
|
+
refresh_response = double("response", code: 200, body: refresh_response_body, success_ok?: true)
|
156
156
|
# First request to generate the refresh token
|
157
157
|
expect(Vra::Http).to receive(:execute)
|
158
158
|
.with(method: :post,
|
@@ -174,22 +174,22 @@ describe Vra::Client do
|
|
174
174
|
client.generate_access_token
|
175
175
|
end
|
176
176
|
|
177
|
-
context
|
178
|
-
it
|
179
|
-
response = double(
|
180
|
-
refresh_response = double(
|
177
|
+
context "when token is generated successfully" do
|
178
|
+
it "sets the token" do
|
179
|
+
response = double("response", code: 200, body: success_response, success_ok?: true)
|
180
|
+
refresh_response = double("response", code: 200, body: refresh_response_body, success_ok?: true)
|
181
181
|
allow(Vra::Http).to receive(:execute).twice.and_return(response, refresh_response)
|
182
182
|
|
183
183
|
client.generate_access_token
|
184
184
|
|
185
|
-
expect(client.access_token).to eq
|
186
|
-
expect(client.refresh_token).to eq
|
185
|
+
expect(client.access_token).to eq "123456"
|
186
|
+
expect(client.refresh_token).to eq "654321"
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
|
-
context
|
191
|
-
it
|
192
|
-
response = double(
|
190
|
+
context "when token is not generated successfully" do
|
191
|
+
it "raises an exception" do
|
192
|
+
response = double("response", code: 400, body: "error string", success_ok?: false)
|
193
193
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
194
194
|
|
195
195
|
expect { client.generate_access_token }.to raise_error(Vra::Exception::Unauthorized)
|
@@ -197,38 +197,38 @@ describe Vra::Client do
|
|
197
197
|
end
|
198
198
|
end
|
199
199
|
|
200
|
-
describe
|
201
|
-
it
|
202
|
-
expect(client.full_url(
|
200
|
+
describe "#full_url" do
|
201
|
+
it "returns a properly formatted url" do
|
202
|
+
expect(client.full_url("/url_path")).to eq "https://vra.corp.local/url_path"
|
203
203
|
end
|
204
204
|
end
|
205
205
|
|
206
|
-
describe
|
207
|
-
context
|
208
|
-
it
|
209
|
-
response = double(
|
206
|
+
describe "#http_head" do
|
207
|
+
context "when skip_auth is nil" do
|
208
|
+
it "authorizes before proceeding" do
|
209
|
+
response = double("response")
|
210
210
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
211
211
|
expect(client).to receive(:authorize!)
|
212
212
|
|
213
|
-
client.http_head(
|
213
|
+
client.http_head("/test")
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
217
|
-
context
|
218
|
-
it
|
219
|
-
response = double(
|
217
|
+
context "when skip_auth is not nil" do
|
218
|
+
it "does not authorize before proceeding" do
|
219
|
+
response = double("response")
|
220
220
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
221
221
|
expect(client).to_not receive(:authorize!)
|
222
222
|
|
223
|
-
client.http_head(
|
223
|
+
client.http_head("/test", :skip_auth)
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
-
it
|
228
|
-
response = double(
|
229
|
-
path =
|
230
|
-
full_url =
|
231
|
-
headers = {
|
227
|
+
it "calls Vra::Http.execute" do
|
228
|
+
response = double("response")
|
229
|
+
path = "/test"
|
230
|
+
full_url = "https://vra.corp.local/test"
|
231
|
+
headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
|
232
232
|
verify_ssl = true
|
233
233
|
|
234
234
|
allow(client).to receive(:authorize!)
|
@@ -243,11 +243,11 @@ describe Vra::Client do
|
|
243
243
|
client.http_head(path)
|
244
244
|
end
|
245
245
|
|
246
|
-
it
|
247
|
-
response = double(
|
248
|
-
path =
|
249
|
-
full_url =
|
250
|
-
headers = {
|
246
|
+
it "calls Vra::Http.execute with verify_ssl false" do
|
247
|
+
response = double("response")
|
248
|
+
path = "/test"
|
249
|
+
full_url = "https://vra.corp.local/test"
|
250
|
+
headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
|
251
251
|
verify_ssl = false
|
252
252
|
|
253
253
|
allow(client_without_ssl).to receive(:authorize!)
|
@@ -261,41 +261,41 @@ describe Vra::Client do
|
|
261
261
|
client_without_ssl.http_head(path)
|
262
262
|
end
|
263
263
|
|
264
|
-
it
|
264
|
+
it "raises an HTTPNotFound on a 404 error" do
|
265
265
|
allow(client).to receive(:authorize!)
|
266
266
|
allow(Vra::Http).to receive(:execute)
|
267
|
-
.and_raise(Vra::Http::Error.new(
|
267
|
+
.and_raise(Vra::Http::Error.new("message", 404, "Not Found"))
|
268
268
|
|
269
|
-
expect { client.http_head(
|
269
|
+
expect { client.http_head("/404") }.to raise_error(Vra::Exception::HTTPNotFound)
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
273
|
-
describe
|
274
|
-
context
|
275
|
-
it
|
276
|
-
response = double(
|
273
|
+
describe "#http_get" do
|
274
|
+
context "when skip_auth is nil" do
|
275
|
+
it "authorizes before proceeding" do
|
276
|
+
response = double("response")
|
277
277
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
278
278
|
expect(client).to receive(:authorize!)
|
279
279
|
|
280
|
-
client.http_get(
|
280
|
+
client.http_get("/test")
|
281
281
|
end
|
282
282
|
end
|
283
283
|
|
284
|
-
context
|
285
|
-
it
|
286
|
-
response = double(
|
284
|
+
context "when skip_auth is not nil" do
|
285
|
+
it "does not authorize before proceeding" do
|
286
|
+
response = double("response")
|
287
287
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
288
288
|
expect(client).to_not receive(:authorize!)
|
289
289
|
|
290
|
-
client.http_get(
|
290
|
+
client.http_get("/test", :skip_auth)
|
291
291
|
end
|
292
292
|
end
|
293
293
|
|
294
|
-
it
|
295
|
-
response = double(
|
296
|
-
path =
|
297
|
-
full_url =
|
298
|
-
headers = {
|
294
|
+
it "calls Vra::Http.execute" do
|
295
|
+
response = double("response")
|
296
|
+
path = "/test"
|
297
|
+
full_url = "https://vra.corp.local/test"
|
298
|
+
headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
|
299
299
|
verify_ssl = true
|
300
300
|
|
301
301
|
allow(client).to receive(:authorize!)
|
@@ -309,93 +309,93 @@ describe Vra::Client do
|
|
309
309
|
client.http_get(path)
|
310
310
|
end
|
311
311
|
|
312
|
-
it
|
312
|
+
it "raises an HTTPNotFound on a 404 error" do
|
313
313
|
allow(client).to receive(:authorize!)
|
314
314
|
allow(Vra::Http).to receive(:execute)
|
315
|
-
.and_raise(Vra::Http::Error.new(
|
315
|
+
.and_raise(Vra::Http::Error.new("message", 404, "Not Found"))
|
316
316
|
|
317
|
-
expect { client.http_get(
|
317
|
+
expect { client.http_get("/404") }.to raise_error(Vra::Exception::HTTPNotFound)
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
321
|
-
describe
|
322
|
-
it
|
321
|
+
describe "#http_get_paginated_array!" do
|
322
|
+
it "allows a limit override" do
|
323
323
|
client.page_size = 10
|
324
324
|
expect(client).to receive(:get_parsed)
|
325
|
-
.with(
|
326
|
-
.and_return(
|
325
|
+
.with("/test?$top=10&$skip=0")
|
326
|
+
.and_return("content" => [], "totalPages" => 1)
|
327
327
|
|
328
|
-
client.http_get_paginated_array!(
|
328
|
+
client.http_get_paginated_array!("/test")
|
329
329
|
end
|
330
330
|
|
331
|
-
it
|
331
|
+
it "only calls get_parsed once when total pages is 0 (no items)" do
|
332
332
|
expect(client).to receive(:get_parsed)
|
333
333
|
.once
|
334
|
-
.with(
|
335
|
-
.and_return(
|
334
|
+
.with("/test?$top=20&$skip=0")
|
335
|
+
.and_return("content" => [], "totalPages" => 0)
|
336
336
|
|
337
|
-
client.http_get_paginated_array!(
|
337
|
+
client.http_get_paginated_array!("/test")
|
338
338
|
end
|
339
339
|
|
340
|
-
it
|
340
|
+
it "only calls get_parsed once when total pages is 1" do
|
341
341
|
expect(client).to receive(:get_parsed)
|
342
342
|
.once
|
343
|
-
.with(
|
344
|
-
.and_return(
|
343
|
+
.with("/test?$top=20&$skip=0")
|
344
|
+
.and_return("content" => [], "totalPages" => 1)
|
345
345
|
|
346
|
-
client.http_get_paginated_array!(
|
346
|
+
client.http_get_paginated_array!("/test")
|
347
347
|
end
|
348
348
|
|
349
|
-
it
|
349
|
+
it "calls get_parsed 3 times if there are 3 pages of response" do
|
350
350
|
expect(client).to receive(:get_parsed)
|
351
|
-
.with(
|
352
|
-
.and_return(
|
351
|
+
.with("/test?$top=20&$skip=0")
|
352
|
+
.and_return("content" => [], "totalPages" => 3)
|
353
353
|
expect(client).to receive(:get_parsed)
|
354
|
-
.with(
|
355
|
-
.and_return(
|
354
|
+
.with("/test?$top=20&$skip=20")
|
355
|
+
.and_return("content" => [], "totalPages" => 3)
|
356
356
|
expect(client).to receive(:get_parsed)
|
357
|
-
.with(
|
358
|
-
.and_return(
|
357
|
+
.with("/test?$top=20&$skip=40")
|
358
|
+
.and_return("content" => [], "totalPages" => 3)
|
359
359
|
|
360
|
-
client.http_get_paginated_array!(
|
360
|
+
client.http_get_paginated_array!("/test")
|
361
361
|
end
|
362
362
|
|
363
|
-
it
|
363
|
+
it "raises an exception if duplicate items are returned by the API" do
|
364
364
|
allow(client).to receive(:get_parsed)
|
365
|
-
.with(
|
366
|
-
.and_return(
|
365
|
+
.with("/test?$top=20&$skip=0")
|
366
|
+
.and_return("content" => [1, 2, 3, 1], "totalPages" => 1)
|
367
367
|
|
368
|
-
expect { client.http_get_paginated_array!(
|
368
|
+
expect { client.http_get_paginated_array!("/test") }.to raise_error(Vra::Exception::DuplicateItemsDetected)
|
369
369
|
end
|
370
370
|
end
|
371
371
|
|
372
|
-
describe
|
373
|
-
context
|
374
|
-
it
|
375
|
-
response = double(
|
372
|
+
describe "#http_post" do
|
373
|
+
context "when skip_auth is nil" do
|
374
|
+
it "authorizes before proceeding" do
|
375
|
+
response = double("response")
|
376
376
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
377
377
|
expect(client).to receive(:authorize!)
|
378
378
|
|
379
|
-
client.http_post(
|
379
|
+
client.http_post("/test", "some payload")
|
380
380
|
end
|
381
381
|
end
|
382
382
|
|
383
|
-
context
|
384
|
-
it
|
385
|
-
response = double(
|
383
|
+
context "when skip_auth is not nil" do
|
384
|
+
it "does not authorize before proceeding" do
|
385
|
+
response = double("response")
|
386
386
|
allow(Vra::Http).to receive(:execute).and_return(response)
|
387
387
|
expect(client).to_not receive(:authorize!)
|
388
388
|
|
389
|
-
client.http_post(
|
389
|
+
client.http_post("/test", "some payload", :skip_auth)
|
390
390
|
end
|
391
391
|
end
|
392
392
|
|
393
|
-
it
|
394
|
-
response = double(
|
395
|
-
path =
|
396
|
-
full_url =
|
397
|
-
headers = {
|
398
|
-
payload =
|
393
|
+
it "calls Vra::Http.execute" do
|
394
|
+
response = double("response")
|
395
|
+
path = "/test"
|
396
|
+
full_url = "https://vra.corp.local/test"
|
397
|
+
headers = { "Accept" => "application/json", "Content-Type" => "application/json" }
|
398
|
+
payload = "some payload"
|
399
399
|
verify_ssl = true
|
400
400
|
|
401
401
|
allow(client).to receive(:authorize!)
|
@@ -410,12 +410,12 @@ describe Vra::Client do
|
|
410
410
|
client.http_post(path, payload)
|
411
411
|
end
|
412
412
|
|
413
|
-
context
|
413
|
+
context "when not verifying ssl" do
|
414
414
|
let(:unverified_client) do
|
415
|
-
Vra::Client.new(username:
|
416
|
-
password:
|
417
|
-
tenant:
|
418
|
-
base_url:
|
415
|
+
Vra::Client.new(username: "user@corp.local",
|
416
|
+
password: "password",
|
417
|
+
tenant: "tenant",
|
418
|
+
base_url: "https://vra.corp.local",
|
419
419
|
verify_ssl: false)
|
420
420
|
end
|
421
421
|
|
@@ -423,158 +423,158 @@ describe Vra::Client do
|
|
423
423
|
allow(unverified_client).to receive(:authorized?).and_return(true)
|
424
424
|
end
|
425
425
|
|
426
|
-
it
|
426
|
+
it "configures Net::HTTP with VERIFY_NONE" do
|
427
427
|
allow(Net::HTTP).to receive(:start).and_wrap_original do |_http, *args|
|
428
428
|
expect(args.last).to include(verify_mode: OpenSSL::SSL::VERIFY_NONE)
|
429
|
-
double(
|
429
|
+
double("response", final?: true, success?: true)
|
430
430
|
end
|
431
431
|
|
432
|
-
unverified_client.http_post(
|
432
|
+
unverified_client.http_post("/path", "payload")
|
433
433
|
|
434
|
-
%i
|
435
|
-
unverified_client.http_fetch(method,
|
434
|
+
%i{head get}.each do |method|
|
435
|
+
unverified_client.http_fetch(method, "/test", true)
|
436
436
|
end
|
437
437
|
end
|
438
438
|
end
|
439
439
|
|
440
|
-
it
|
440
|
+
it "calls raise_http_exception upon error" do
|
441
441
|
allow(client).to receive(:authorize!)
|
442
442
|
allow(Vra::Http).to receive(:execute).and_raise(StandardError)
|
443
443
|
expect(client).to receive(:raise_http_exception)
|
444
444
|
|
445
|
-
client.http_post(
|
445
|
+
client.http_post("/404", "test payload")
|
446
446
|
end
|
447
447
|
end
|
448
448
|
|
449
|
-
describe
|
450
|
-
it
|
451
|
-
response = double(
|
452
|
-
allow(client).to receive(:http_post).with(
|
449
|
+
describe "#http_post!" do
|
450
|
+
it "returns the response body" do
|
451
|
+
response = double("response", body: "body text")
|
452
|
+
allow(client).to receive(:http_post).with("/test", "test payload").and_return(response)
|
453
453
|
|
454
|
-
expect(client.http_post!(
|
454
|
+
expect(client.http_post!("/test", "test payload")).to eq "body text"
|
455
455
|
end
|
456
456
|
end
|
457
457
|
|
458
|
-
describe
|
459
|
-
it
|
458
|
+
describe "#http_delete" do
|
459
|
+
it "should perform the delete method" do
|
460
460
|
allow(client).to receive(:authorized?).and_return(true)
|
461
461
|
expect(Vra::Http).to receive(:execute)
|
462
462
|
|
463
|
-
client.http_delete(
|
463
|
+
client.http_delete("/test")
|
464
464
|
end
|
465
465
|
end
|
466
466
|
|
467
|
-
describe
|
468
|
-
context
|
467
|
+
describe "#raise_http_exception" do
|
468
|
+
context "when a 404 is received" do
|
469
469
|
let(:exception) do
|
470
|
-
double(
|
470
|
+
double("RestClient::ResourceNotFound",
|
471
471
|
http_code: 404,
|
472
|
-
message:
|
473
|
-
response:
|
472
|
+
message: "Not Found",
|
473
|
+
response: "404 Not Found")
|
474
474
|
end
|
475
475
|
|
476
|
-
it
|
477
|
-
expect { client.raise_http_exception(exception,
|
476
|
+
it "raises a Vra::Exception::HTTPNotFound exception" do
|
477
|
+
expect { client.raise_http_exception(exception, "/test") }.to raise_error(Vra::Exception::HTTPNotFound)
|
478
478
|
end
|
479
479
|
end
|
480
480
|
|
481
|
-
context
|
481
|
+
context "when an unspecified http error is received" do
|
482
482
|
let(:exception) do
|
483
|
-
double(
|
483
|
+
double("RestClient::BadRequest",
|
484
484
|
http_code: 400,
|
485
|
-
message:
|
486
|
-
response:
|
485
|
+
message: "Bad Request",
|
486
|
+
response: "400 Bad Request")
|
487
487
|
end
|
488
488
|
|
489
|
-
it
|
490
|
-
expect { client.raise_http_exception(exception,
|
489
|
+
it "raises a Vra::Exception::HTTPError exception" do
|
490
|
+
expect { client.raise_http_exception(exception, "/test") }.to raise_error(Vra::Exception::HTTPError)
|
491
491
|
end
|
492
492
|
end
|
493
493
|
end
|
494
494
|
|
495
|
-
describe
|
496
|
-
context
|
497
|
-
it
|
495
|
+
describe "#validate_client_options!" do
|
496
|
+
context "when all required options are supplied" do
|
497
|
+
it "does not raise an exception" do
|
498
498
|
expect { client.validate_client_options! }.not_to raise_error
|
499
499
|
end
|
500
500
|
end
|
501
501
|
|
502
|
-
context
|
502
|
+
context "when username is missing" do
|
503
503
|
let(:client) do
|
504
504
|
described_class.new(
|
505
|
-
password:
|
506
|
-
tenant:
|
507
|
-
base_url:
|
505
|
+
password: "password",
|
506
|
+
tenant: "tenant",
|
507
|
+
base_url: "https://vra.corp.local"
|
508
508
|
)
|
509
509
|
end
|
510
510
|
|
511
|
-
it
|
511
|
+
it "raises an exception" do
|
512
512
|
expect { client.validate_client_options! }.to raise_error(ArgumentError)
|
513
513
|
end
|
514
514
|
end
|
515
515
|
|
516
|
-
context
|
516
|
+
context "when password is missing" do
|
517
517
|
let(:client) do
|
518
518
|
described_class.new(
|
519
|
-
username:
|
520
|
-
tenant:
|
521
|
-
base_url:
|
519
|
+
username: "username",
|
520
|
+
tenant: "tenant",
|
521
|
+
base_url: "https://vra.corp.local"
|
522
522
|
)
|
523
523
|
end
|
524
524
|
|
525
|
-
it
|
525
|
+
it "raises an exception" do
|
526
526
|
expect { client.validate_client_options! }.to raise_error(ArgumentError)
|
527
527
|
end
|
528
528
|
end
|
529
529
|
|
530
|
-
context
|
530
|
+
context "when tenant is missing" do
|
531
531
|
let(:client) do
|
532
532
|
described_class.new(
|
533
|
-
username:
|
534
|
-
password:
|
535
|
-
base_url:
|
533
|
+
username: "username",
|
534
|
+
password: "password",
|
535
|
+
base_url: "https://vra.corp.local"
|
536
536
|
)
|
537
537
|
end
|
538
538
|
|
539
|
-
it
|
539
|
+
it "raises an exception" do
|
540
540
|
expect { client.validate_client_options! }.to raise_error(ArgumentError)
|
541
541
|
end
|
542
542
|
end
|
543
543
|
|
544
|
-
context
|
544
|
+
context "when base URL is missing" do
|
545
545
|
let(:client) do
|
546
546
|
described_class.new(
|
547
|
-
username:
|
548
|
-
password:
|
549
|
-
tenant:
|
547
|
+
username: "username",
|
548
|
+
password: "password",
|
549
|
+
tenant: "tenant"
|
550
550
|
)
|
551
551
|
end
|
552
552
|
|
553
|
-
it
|
553
|
+
it "raises an exception" do
|
554
554
|
expect { client.validate_client_options! }.to raise_error(ArgumentError)
|
555
555
|
end
|
556
556
|
end
|
557
557
|
|
558
|
-
context
|
558
|
+
context "when base URL is not a valid HTTP URL" do
|
559
559
|
let(:client) do
|
560
560
|
described_class.new(
|
561
|
-
username:
|
562
|
-
password:
|
563
|
-
tenant:
|
564
|
-
base_url:
|
561
|
+
username: "username",
|
562
|
+
password: "password",
|
563
|
+
tenant: "tenant",
|
564
|
+
base_url: "something-that-is-not-a-HTTP-URI"
|
565
565
|
)
|
566
566
|
end
|
567
567
|
|
568
|
-
it
|
568
|
+
it "raises an exception" do
|
569
569
|
expect { client.validate_client_options! }.to raise_error(ArgumentError)
|
570
570
|
end
|
571
571
|
|
572
|
-
it
|
572
|
+
it "should raise an exception when the URI::InvalidURIError is raised" do
|
573
573
|
allow(URI).to receive(:parse).and_raise(URI::InvalidURIError)
|
574
574
|
|
575
575
|
expect { client.validate_client_options! }
|
576
576
|
.to raise_error(ArgumentError)
|
577
|
-
.with_message(
|
577
|
+
.with_message("Base URL something-that-is-not-a-HTTP-URI is not a valid URI.")
|
578
578
|
end
|
579
579
|
end
|
580
580
|
end
|