Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 18e857d

Browse files
Urse SearleBrian Butz
authored andcommitted
Introduce responses_for_space_restricted_single_endpoint test helper
Signed-off-by: Brian Butz <bbutz@pivotal.io>
1 parent 99c02e4 commit 18e857d

13 files changed

Lines changed: 107 additions & 201 deletions

spec/request/events_spec.rb

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,17 @@
240240
end
241241

242242
let(:expected_codes_and_responses) do
243-
h = Hash.new(
244-
code: 200,
245-
response_object: event_json
243+
responses_for_space_restricted_single_endpoint(
244+
event_json,
245+
permitted_roles: %w(
246+
admin
247+
admin_read_only
248+
global_auditor
249+
org_auditor
250+
space_auditor
251+
space_developer
252+
)
246253
)
247-
h['space_manager'] = {
248-
code: 404,
249-
response_object: []
250-
}
251-
h['org_manager'] = {
252-
code: 404,
253-
response_object: []
254-
}
255-
h['org_billing_manager'] = {
256-
code: 404,
257-
response_object: []
258-
}
259-
h['no_role'] = {
260-
code: 404,
261-
response_object: []
262-
}
263-
h.freeze
264254
end
265255

266256
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS

spec/request/roles_spec.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,11 +1330,7 @@ def make_space_role_for_current_user(type)
13301330
end
13311331

13321332
let(:expected_codes_and_responses) do
1333-
h = Hash.new(code: 200, response_object: expected_response)
1334-
h['org_auditor'] = { code: 404 }
1335-
h['org_billing_manager'] = { code: 404 }
1336-
h['no_role'] = { code: 404 }
1337-
h
1333+
responses_for_space_restricted_single_endpoint(expected_response)
13381334
end
13391335

13401336
before do

spec/request/service_credential_bindings_spec.rb

Lines changed: 7 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -363,42 +363,12 @@ def check_filtered_bindings(*bindings)
363363
let(:api_call) { ->(user_headers) { get "/v3/service_credential_bindings/#{key.guid}", nil, user_headers } }
364364
let(:expected_object) { expected_json(key) }
365365

366-
context 'global roles' do
366+
describe 'permissions' do
367367
let(:expected_codes_and_responses) do
368-
Hash.new({ code: 200, response_object: expected_object })
368+
responses_for_space_restricted_single_endpoint(expected_object)
369369
end
370370

371-
it_behaves_like 'permissions for single object endpoint', GLOBAL_SCOPES
372-
end
373-
374-
context 'local roles' do
375-
context 'user is in the original space of the service instance' do
376-
let(:expected_codes_and_responses) do
377-
Hash.new({ code: 200, response_object: expected_object }).tap do |h|
378-
h['org_auditor'] = { code: 404 }
379-
h['org_billing_manager'] = { code: 404 }
380-
h['no_role'] = { code: 404 }
381-
end
382-
end
383-
384-
it_behaves_like 'permissions for single object endpoint', LOCAL_ROLES
385-
end
386-
387-
context 'user is in a space that the service instance is shared to' do
388-
let(:instance) { VCAP::CloudController::ManagedServiceInstance.make(space: other_space) }
389-
390-
before do
391-
instance.add_shared_space(space)
392-
end
393-
394-
let(:api_call) { ->(user_headers) { get "/v3/service_credential_bindings/#{key.guid}", nil, user_headers } }
395-
396-
let(:expected_codes_and_responses) do
397-
Hash.new(code: 404)
398-
end
399-
400-
it_behaves_like 'permissions for single object endpoint', LOCAL_ROLES
401-
end
371+
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
402372
end
403373

404374
describe 'query params' do
@@ -432,48 +402,12 @@ def check_filtered_bindings(*bindings)
432402
let(:api_call) { ->(user_headers) { get "/v3/service_credential_bindings/#{app_binding.guid}", nil, user_headers } }
433403
let(:expected_object) { expected_json(app_binding) }
434404

435-
context 'global roles' do
405+
describe 'permissions' do
436406
let(:expected_codes_and_responses) do
437-
Hash.new({ code: 200, response_object: expected_object })
407+
responses_for_space_restricted_single_endpoint(expected_object)
438408
end
439409

440-
it_behaves_like 'permissions for single object endpoint', GLOBAL_SCOPES
441-
end
442-
443-
context 'local roles' do
444-
let(:expected_codes_and_responses) do
445-
Hash.new({ code: 200, response_object: expected_object }).tap do |h|
446-
h['org_auditor'] = { code: 404 }
447-
h['org_billing_manager'] = { code: 404 }
448-
h['no_role'] = { code: 404 }
449-
end
450-
end
451-
452-
context 'user is in the original space of the service instance' do
453-
it_behaves_like 'permissions for single object endpoint', LOCAL_ROLES
454-
end
455-
456-
context 'user is in a space that the service instance is shared to' do
457-
let(:instance) { VCAP::CloudController::ManagedServiceInstance.make(space: other_space) }
458-
459-
before do
460-
instance.add_shared_space(space)
461-
end
462-
463-
context 'the app is in the users space' do
464-
it_behaves_like 'permissions for single object endpoint', LOCAL_ROLES
465-
end
466-
467-
context 'the app is not in the users space' do
468-
let(:app_to_bind_to) { VCAP::CloudController::AppModel.make(space: other_space) }
469-
470-
let(:expected_codes_and_responses) do
471-
Hash.new(code: 404)
472-
end
473-
474-
it_behaves_like 'permissions for single object endpoint', LOCAL_ROLES
475-
end
476-
end
410+
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
477411
end
478412

479413
describe 'include' do
@@ -725,11 +659,7 @@ def check_filtered_bindings(*bindings)
725659

726660
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS do
727661
let(:expected_codes_and_responses) do
728-
Hash.new(code: 200, response_object: binding_params).tap do |h|
729-
h['org_auditor'] = { code: 404 }
730-
h['org_billing_manager'] = { code: 404 }
731-
h['no_role'] = { code: 404 }
732-
end
662+
responses_for_space_restricted_single_endpoint(binding_params)
733663
end
734664
end
735665

spec/request/service_instances_spec.rb

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525
let(:guid) { instance.guid }
2626

2727
let(:expected_codes_and_responses) do
28-
Hash.new(
29-
code: 200,
30-
response_object: create_managed_json(instance),
31-
).tap do |h|
32-
h['org_auditor'] = { code: 404 }
33-
h['org_billing_manager'] = { code: 404 }
34-
h['no_role'] = { code: 404 }
35-
end
28+
responses_for_space_restricted_single_endpoint(
29+
create_managed_json(instance)
30+
)
3631
end
3732

3833
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
@@ -43,14 +38,9 @@
4338
let(:guid) { instance.guid }
4439

4540
let(:expected_codes_and_responses) do
46-
h = Hash.new(
47-
code: 200,
48-
response_object: create_user_provided_json(instance),
41+
responses_for_space_restricted_single_endpoint(
42+
create_user_provided_json(instance)
4943
)
50-
h['org_auditor'] = { code: 404 }
51-
h['org_billing_manager'] = { code: 404 }
52-
h['no_role'] = { code: 404 }
53-
h
5444
end
5545

5646
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
@@ -66,15 +56,9 @@
6656
end
6757

6858
let(:expected_codes_and_responses) do
69-
h = Hash.new(
70-
code: 200,
71-
response_object: create_managed_json(instance),
59+
responses_for_space_restricted_single_endpoint(
60+
create_managed_json(instance)
7261
)
73-
74-
h['org_auditor'] = { code: 404 }
75-
h['org_billing_manager'] = { code: 404 }
76-
h['no_role'] = { code: 404 }
77-
h
7862
end
7963

8064
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
@@ -3600,14 +3584,7 @@ def check_filtered_instances(*instances)
36003584
end
36013585

36023586
let(:expected_codes_and_responses) do
3603-
Hash.new(
3604-
code: 200,
3605-
response_object: expected_response,
3606-
).tap do |h|
3607-
h['org_auditor'] = { code: 404 }
3608-
h['org_billing_manager'] = { code: 404 }
3609-
h['no_role'] = { code: 404 }
3610-
end
3587+
responses_for_space_restricted_single_endpoint(expected_response)
36113588
end
36123589
end
36133590
end
@@ -3725,14 +3702,9 @@ def create_bindings(instance, space:, count:)
37253702
}
37263703
}
37273704
}
3728-
let(:usage_summary_response) { { code: 200, response_object: response_object } }
37293705

37303706
let(:expected_codes_and_responses) do
3731-
Hash.new(usage_summary_response).tap do |h|
3732-
h['org_auditor'] = { code: 404 }
3733-
h['org_billing_manager'] = { code: 404 }
3734-
h['no_role'] = { code: 404 }
3735-
end
3707+
responses_for_space_restricted_single_endpoint(response_object)
37363708
end
37373709

37383710
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS

spec/request/service_offerings_spec.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,17 @@
106106
let(:space) { broker_space }
107107

108108
let(:expected_codes_and_responses) do
109-
h = Hash.new(code: 404)
110-
h['admin'] = successful_response
111-
h['admin_read_only'] = successful_response
112-
h['global_auditor'] = successful_response
113-
h['space_developer'] = successful_response
114-
h['space_manager'] = successful_response
115-
h['space_auditor'] = successful_response
116-
h
109+
responses_for_space_restricted_single_endpoint(
110+
create_offering_json(service_offering),
111+
permitted_roles: %w(
112+
admin
113+
admin_read_only
114+
global_auditor
115+
space_developer
116+
space_manager
117+
space_auditor
118+
)
119+
)
117120
end
118121

119122
it_behaves_like 'permissions for single object endpoint', COMPLETE_PERMISSIONS

spec/request/service_plan_visibility_spec.rb

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,36 @@
6060
VCAP::CloudController::ServicePlan.make(public: false, service: offering)
6161
end
6262

63-
let(:space_response) {
63+
let(:response_object) do
6464
{
65-
code: 200,
66-
response_object: {
67-
'type' => 'space',
68-
'space' => {
69-
'guid' => space.guid,
70-
'name' => space.name
71-
}
65+
'type' => 'space',
66+
'space' => {
67+
'guid' => space.guid,
68+
'name' => space.name
7269
}
7370
}
74-
}
75-
let(:expected_codes_and_responses) {
76-
Hash.new(code: 404).tap do |h|
77-
h['admin'] = space_response
78-
h['admin_read_only'] = space_response
79-
h['global_auditor'] = space_response
80-
h['space_developer'] = space_response
81-
h['space_manager'] = space_response
82-
h['space_auditor'] = space_response
83-
end
84-
}
71+
end
72+
73+
let(:space_response) do
74+
{
75+
code: 200,
76+
response_object: response_object
77+
}
78+
end
79+
80+
let(:expected_codes_and_responses) do
81+
responses_for_space_restricted_single_endpoint(
82+
response_object,
83+
permitted_roles: %w(
84+
admin
85+
admin_read_only
86+
global_auditor
87+
space_developer
88+
space_manager
89+
space_auditor
90+
)
91+
)
92+
end
8593

8694
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
8795
end

spec/request/service_plans_spec.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,17 @@
7979
let(:guid) { service_plan.guid }
8080

8181
let(:expected_codes_and_responses) do
82-
Hash.new(code: 200, response_objects: create_plan_json(service_plan)).tap do |r|
83-
r['unauthenticated'] = { code: 404 }
84-
r['no_role'] = { code: 404 }
85-
r['org_billing_manager'] = { code: 404 }
86-
r['org_auditor'] = { code: 404 }
87-
r['org_manager'] = { code: 404 }
88-
end
82+
responses_for_space_restricted_single_endpoint(
83+
create_plan_json(service_plan),
84+
permitted_roles: %w(
85+
admin
86+
admin_read_only
87+
global_auditor
88+
space_developer
89+
space_manager
90+
space_auditor
91+
)
92+
)
8993
end
9094

9195
it_behaves_like 'permissions for single object endpoint', COMPLETE_PERMISSIONS

spec/request/service_route_bindings_spec.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -724,15 +724,7 @@
724724
end
725725

726726
let(:expected_codes_and_responses) do
727-
Hash.new(code: 404).tap do |h|
728-
h['admin'] = { code: 200, response_object: expected_body }
729-
h['admin_read_only'] = { code: 200, response_object: expected_body }
730-
h['global_auditor'] = { code: 200, response_object: expected_body }
731-
h['space_developer'] = { code: 200, response_object: expected_body }
732-
h['space_manager'] = { code: 200, response_object: expected_body }
733-
h['space_auditor'] = { code: 200, response_object: expected_body }
734-
h['org_manager'] = { code: 200, response_object: expected_body }
735-
end
727+
responses_for_space_restricted_single_endpoint(expected_body)
736728
end
737729

738730
context 'user-provided service instance' do

spec/request/space_features_spec.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@
2626
end
2727

2828
let(:expected_codes_and_responses) do
29-
h = Hash.new(code: 200, response_object: space_features_json)
30-
h['org_auditor'] = { code: 404 }
31-
h['org_billing_manager'] = { code: 404 }
32-
h['no_role'] = { code: 404 }
33-
h
29+
responses_for_space_restricted_single_endpoint(space_features_json)
3430
end
3531

3632
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
@@ -50,11 +46,7 @@
5046
end
5147

5248
let(:expected_codes_and_responses) do
53-
h = Hash.new(code: 200, response_object: space_ssh_feature_json)
54-
h['org_auditor'] = { code: 404 }
55-
h['org_billing_manager'] = { code: 404 }
56-
h['no_role'] = { code: 404 }
57-
h
49+
responses_for_space_restricted_single_endpoint(space_ssh_feature_json)
5850
end
5951

6052
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS

0 commit comments

Comments
 (0)