-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathapp_features_spec.rb
More file actions
371 lines (313 loc) · 13.5 KB
/
app_features_spec.rb
File metadata and controls
371 lines (313 loc) · 13.5 KB
1
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
require 'spec_helper'
require 'request_spec_shared_examples'
RSpec.describe 'App Features' do
let(:user) { VCAP::CloudController::User.make }
let(:user_header) { headers_for(user, email: Sham.email, user_name: 'some-username') }
let(:admin_header) { admin_headers_for(user) }
let(:org) { VCAP::CloudController::Organization.make(created_at: 3.days.ago) }
let(:space) { VCAP::CloudController::Space.make(organization: org) }
let(:service_binding_k8s_enabled) { true }
let(:file_based_vcap_services_enabled) { false }
let(:request_body_enabled) { { body: { enabled: true } } }
let(:app_model) do
VCAP::CloudController::AppModel.make(
space: space,
enable_ssh: true,
service_binding_k8s_enabled: service_binding_k8s_enabled,
file_based_vcap_services_enabled: file_based_vcap_services_enabled
)
end
describe 'GET /v3/apps/:guid/features' do
context 'getting a list of available features for the app' do
let(:api_call) { ->(user_headers) { get "/v3/apps/#{app_model.guid}/features", nil, user_headers } }
let(:features_response_object) do
{
'resources' => [
{
'name' => 'ssh',
'description' => 'Enable SSHing into the app.',
'enabled' => true
},
{
'name' => 'revisions',
'description' => 'Enable versioning of an application',
'enabled' => true
},
{
'name' => 'service-binding-k8s',
'description' => 'Enable k8s service bindings for the app',
'enabled' => true
},
{
'name' => 'file-based-vcap-services',
'description' => 'Enable file-based VCAP service bindings for the app',
'enabled' => false
}
],
'pagination' =>
{
'total_results' => 4,
'total_pages' => 1,
'first' => { 'href' => "/v3/apps/#{app_model.guid}/features" },
'last' => { 'href' => "/v3/apps/#{app_model.guid}/features" },
'next' => nil,
'previous' => nil
}
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 404 }.freeze)
%w[admin admin_read_only global_auditor space_developer space_manager space_auditor org_manager
space_supporter].each do |r|
h[r] = { code: 200, response_object: features_response_object }
end
h
end
before do
space.organization.add_user(user)
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
describe 'GET /v3/apps/:guid/features/:name' do
let(:expected_codes_and_responses) do
h = Hash.new({ code: 404 }.freeze)
%w[admin admin_read_only global_auditor space_developer space_manager space_auditor org_manager
space_supporter].each do |r|
h[r] = { code: 200, response_object: feature_response_object }
end
h
end
before do
space.organization.add_user(user)
end
context 'ssh app feature' do
let(:api_call) { ->(user_headers) { get "/v3/apps/#{app_model.guid}/features/ssh", nil, user_headers } }
let(:feature_response_object) do
{
'name' => 'ssh',
'description' => 'Enable SSHing into the app.',
'enabled' => true
}
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
context 'revisions app feature' do
let(:api_call) { ->(user_headers) { get "/v3/apps/#{app_model.guid}/features/revisions", nil, user_headers } }
let(:feature_response_object) do
{
'name' => 'revisions',
'description' => 'Enable versioning of an application',
'enabled' => true
}
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
context 'service-binding-k8s app feature' do
let(:api_call) { ->(user_headers) { get "/v3/apps/#{app_model.guid}/features/service-binding-k8s", nil, user_headers } }
let(:feature_response_object) do
{
'name' => 'service-binding-k8s',
'description' => 'Enable k8s service bindings for the app',
'enabled' => true
}
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
context 'file-based-vcap-services app feature' do
let(:api_call) { ->(user_headers) { get "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", nil, user_headers } }
let(:feature_response_object) do
{
'name' => 'file-based-vcap-services',
'description' => 'Enable file-based VCAP service bindings for the app',
'enabled' => false
}
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
describe 'PATCH /v3/apps/:guid/features/:name' do
let(:request_body) { { body: { enabled: false } } }
before do
space.organization.add_user(user)
end
context 'ssh app feature' do
let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/ssh", request_body.to_json, user_headers } }
let(:feature_response_object) do
{
'name' => 'ssh',
'description' => 'Enable SSHing into the app.',
'enabled' => false
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze)
%w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } }
%w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } }
h
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
context 'when organization is suspended' do
let(:expected_codes_and_responses) do
h = super()
h['space_developer'] = { code: 403, errors: CF_ORG_SUSPENDED }
h
end
before do
org.update(status: VCAP::CloudController::Organization::SUSPENDED)
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
context 'revisions app feature' do
let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/revisions", request_body.to_json, user_headers } }
let(:feature_response_object) do
{
'name' => 'revisions',
'description' => 'Enable versioning of an application',
'enabled' => false
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze)
%w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } }
%w[admin space_developer space_supporter].each do |r|
h[r] = { code: 200, response_object: feature_response_object }
end
h
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
context 'when organization is suspended' do
let(:expected_codes_and_responses) do
h = super()
%w[space_developer space_supporter].each { |r| h[r] = { code: 403, errors: CF_ORG_SUSPENDED } }
h
end
before do
org.update(status: VCAP::CloudController::Organization::SUSPENDED)
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
context 'service-binding-k8s app feature' do
context 'when feature is enabled' do
let(:service_binding_k8s_enabled) { true }
let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body.to_json, user_headers } }
let(:feature_response_object) do
{
'name' => 'service-binding-k8s',
'description' => 'Enable k8s service bindings for the app',
'enabled' => false
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze)
%w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } }
%w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } }
h
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
context 'when organization is suspended' do
let(:expected_codes_and_responses) do
h = super()
h['space_developer'] = { code: 403, errors: CF_ORG_SUSPENDED }
h
end
before do
org.update(status: VCAP::CloudController::Organization::SUSPENDED)
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
context 'when feature is disabled' do
let(:service_binding_k8s_enabled) { false }
let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body_enabled.to_json, user_headers } }
let(:feature_response_object) do
{
'name' => 'service-binding-k8s',
'description' => 'Enable k8s service bindings for the app',
'enabled' => true
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze)
%w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } }
%w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } }
h
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
context 'when file-based-vcap-services is enabled' do
before do
patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body_enabled.to_json, admin_header
end
it 'returns an error which states that both features cannot be enabled at the same time' do
patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body_enabled.to_json, admin_header
expect(last_response.status).to eq(422)
expect(parsed_response['errors'][0]['detail']).to eq("'file-based-vcap-services' and 'service-binding-k8s' features cannot be enabled at the same time.")
end
end
end
end
context 'file-based-vcap-services app feature' do
context 'when feature is enabled' do
let(:service_binding_k8s_enabled) { false }
let(:file_based_vcap_services_enabled) { true }
let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body.to_json, user_headers } }
let(:feature_response_object) do
{
'name' => 'file-based-vcap-services',
'description' => 'Enable file-based VCAP service bindings for the app',
'enabled' => false
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze)
%w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } }
%w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } }
h
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
context 'when organization is suspended' do
let(:expected_codes_and_responses) do
h = super()
h['space_developer'] = { code: 403, errors: CF_ORG_SUSPENDED }
h
end
before do
org.update(status: VCAP::CloudController::Organization::SUSPENDED)
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
end
end
context 'when feature is disabled' do
let(:service_binding_k8s_enabled) { false }
let(:file_based_vcap_services_enabled) { false }
let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body_enabled.to_json, user_headers } }
let(:feature_response_object) do
{
'name' => 'file-based-vcap-services',
'description' => 'Enable file-based VCAP service bindings for the app',
'enabled' => true
}
end
let(:expected_codes_and_responses) do
h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze)
%w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } }
%w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } }
h
end
it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS
context 'when service-binding-k8s is enabled' do
before do
patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body_enabled.to_json, admin_header
end
it 'returns an error which states that both features cannot be enabled at the same time' do
patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body_enabled.to_json, admin_header
expect(last_response.status).to eq(422)
expect(parsed_response['errors'][0]['detail']).to eq("'file-based-vcap-services' and 'service-binding-k8s' features cannot be enabled at the same time.")
end
end
end
end
end
end