|
7 | 7 | let(:admin_header) { admin_headers_for(user) } |
8 | 8 | let(:org) { VCAP::CloudController::Organization.make(created_at: 3.days.ago) } |
9 | 9 | let(:space) { VCAP::CloudController::Space.make(organization: org) } |
10 | | - let(:app_model) { VCAP::CloudController::AppModel.make(space: space, enable_ssh: true, service_binding_k8s_enabled: true) } |
| 10 | + let(:service_binding_k8s_enabled) { true } |
| 11 | + let(:file_based_vcap_services_enabled) { false } |
| 12 | + let(:request_body_enabled) { { body: { enabled: true } } } |
| 13 | + let(:app_model) { VCAP::CloudController::AppModel.make( |
| 14 | + space: space, |
| 15 | + enable_ssh: true, |
| 16 | + service_binding_k8s_enabled: service_binding_k8s_enabled, |
| 17 | + file_based_vcap_services_enabled: file_based_vcap_services_enabled) } |
11 | 18 |
|
12 | 19 | describe 'GET /v3/apps/:guid/features' do |
13 | 20 | context 'getting a list of available features for the app' do |
|
29 | 36 | 'name' => 'service-binding-k8s', |
30 | 37 | 'description' => 'Enable k8s service bindings for the app', |
31 | 38 | 'enabled' => true |
| 39 | + }, |
| 40 | + { |
| 41 | + 'name' => 'file-based-vcap-services', |
| 42 | + 'description' => 'Enable file-based VCAP service bindings for the app', |
| 43 | + 'enabled' => false |
32 | 44 | } |
33 | 45 | ], |
34 | 46 | 'pagination' => |
35 | 47 | { |
36 | | - 'total_results' => 3, |
| 48 | + 'total_results' => 4, |
37 | 49 | 'total_pages' => 1, |
38 | 50 | 'first' => { 'href' => "/v3/apps/#{app_model.guid}/features" }, |
39 | 51 | 'last' => { 'href' => "/v3/apps/#{app_model.guid}/features" }, |
|
112 | 124 |
|
113 | 125 | it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
114 | 126 | end |
| 127 | + |
| 128 | + context 'file-based-vcap-services app feature' do |
| 129 | + let(:api_call) { ->(user_headers) { get "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", nil, user_headers } } |
| 130 | + let(:feature_response_object) do |
| 131 | + { |
| 132 | + 'name' => 'file-based-vcap-services', |
| 133 | + 'description' => 'Enable file-based VCAP service bindings for the app', |
| 134 | + 'enabled' => false |
| 135 | + } |
| 136 | + end |
| 137 | + |
| 138 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 139 | + end |
115 | 140 | end |
116 | 141 |
|
117 | 142 | describe 'PATCH /v3/apps/:guid/features/:name' do |
|
192 | 217 | end |
193 | 218 |
|
194 | 219 | context 'service-binding-k8s app feature' do |
195 | | - let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body.to_json, user_headers } } |
196 | | - let(:feature_response_object) do |
197 | | - { |
198 | | - 'name' => 'service-binding-k8s', |
199 | | - 'description' => 'Enable k8s service bindings for the app', |
200 | | - 'enabled' => false |
201 | | - } |
| 220 | + context 'when feature is enabled' do |
| 221 | + let(:service_binding_k8s_enabled) { true } |
| 222 | + let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body.to_json, user_headers } } |
| 223 | + let(:feature_response_object) do |
| 224 | + { |
| 225 | + 'name' => 'service-binding-k8s', |
| 226 | + 'description' => 'Enable k8s service bindings for the app', |
| 227 | + 'enabled' => false |
| 228 | + } |
| 229 | + end |
| 230 | + |
| 231 | + let(:expected_codes_and_responses) do |
| 232 | + h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze) |
| 233 | + %w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } } |
| 234 | + %w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } } |
| 235 | + h |
| 236 | + end |
| 237 | + |
| 238 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 239 | + |
| 240 | + context 'when organization is suspended' do |
| 241 | + let(:expected_codes_and_responses) do |
| 242 | + h = super() |
| 243 | + h['space_developer'] = { code: 403, errors: CF_ORG_SUSPENDED } |
| 244 | + h |
| 245 | + end |
| 246 | + |
| 247 | + before do |
| 248 | + org.update(status: VCAP::CloudController::Organization::SUSPENDED) |
| 249 | + end |
| 250 | + |
| 251 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 252 | + end |
202 | 253 | end |
203 | 254 |
|
204 | | - let(:expected_codes_and_responses) do |
205 | | - h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze) |
206 | | - %w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } } |
207 | | - %w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } } |
208 | | - h |
| 255 | + context 'when feature is disabled' do |
| 256 | + let(:service_binding_k8s_enabled) { false } |
| 257 | + let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body_enabled.to_json, user_headers } } |
| 258 | + |
| 259 | + let(:feature_response_object) do |
| 260 | + { |
| 261 | + 'name' => 'service-binding-k8s', |
| 262 | + 'description' => 'Enable k8s service bindings for the app', |
| 263 | + 'enabled' => true |
| 264 | + } |
| 265 | + end |
| 266 | + |
| 267 | + let(:expected_codes_and_responses) do |
| 268 | + h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze) |
| 269 | + %w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } } |
| 270 | + %w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } } |
| 271 | + h |
| 272 | + end |
| 273 | + |
| 274 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 275 | + |
| 276 | + context 'when file-based-vcap-services is enabled' do |
| 277 | + before do |
| 278 | + patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body_enabled.to_json, admin_header |
| 279 | + end |
| 280 | + |
| 281 | + it 'returns an error which states that both features cannot be enabled at the same time' do |
| 282 | + patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body_enabled.to_json, admin_header |
| 283 | + |
| 284 | + expect(last_response.status).to eq(422) |
| 285 | + expect(parsed_response['errors'][0]['detail']).to eq("'file-based-vcap-services' and 'service-binding-k8s' features cannot be enabled at the same time.") |
| 286 | + end |
| 287 | + end |
209 | 288 | end |
| 289 | + end |
210 | 290 |
|
211 | | - it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 291 | + context 'file-based-vcap-services app feature' do |
| 292 | + context 'when feature is enabled' do |
| 293 | + let(:service_binding_k8s_enabled) { false } |
| 294 | + let(:file_based_vcap_services_enabled) { true } |
| 295 | + let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body.to_json, user_headers } } |
| 296 | + let(:feature_response_object) do |
| 297 | + { |
| 298 | + 'name' => 'file-based-vcap-services', |
| 299 | + 'description' => 'Enable file-based VCAP service bindings for the app', |
| 300 | + 'enabled' => false |
| 301 | + } |
| 302 | + end |
212 | 303 |
|
213 | | - context 'when organization is suspended' do |
214 | 304 | let(:expected_codes_and_responses) do |
215 | | - h = super() |
216 | | - h['space_developer'] = { code: 403, errors: CF_ORG_SUSPENDED } |
| 305 | + h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze) |
| 306 | + %w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } } |
| 307 | + %w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } } |
217 | 308 | h |
218 | 309 | end |
219 | 310 |
|
220 | | - before do |
221 | | - org.update(status: VCAP::CloudController::Organization::SUSPENDED) |
| 311 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 312 | + |
| 313 | + context 'when organization is suspended' do |
| 314 | + let(:expected_codes_and_responses) do |
| 315 | + h = super() |
| 316 | + h['space_developer'] = { code: 403, errors: CF_ORG_SUSPENDED } |
| 317 | + h |
| 318 | + end |
| 319 | + |
| 320 | + before do |
| 321 | + org.update(status: VCAP::CloudController::Organization::SUSPENDED) |
| 322 | + end |
| 323 | + |
| 324 | + it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 325 | + end |
| 326 | + end |
| 327 | + |
| 328 | + context 'when feature is disabled' do |
| 329 | + let(:service_binding_k8s_enabled) { false } |
| 330 | + let(:file_based_vcap_services_enabled) { false } |
| 331 | + let(:api_call) { ->(user_headers) { patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body_enabled.to_json, user_headers } } |
| 332 | + |
| 333 | + let(:feature_response_object) do |
| 334 | + { |
| 335 | + 'name' => 'file-based-vcap-services', |
| 336 | + 'description' => 'Enable file-based VCAP service bindings for the app', |
| 337 | + 'enabled' => true |
| 338 | + } |
| 339 | + end |
| 340 | + |
| 341 | + let(:expected_codes_and_responses) do |
| 342 | + h = Hash.new({ code: 403, errors: CF_NOT_AUTHORIZED }.freeze) |
| 343 | + %w[no_role org_auditor org_billing_manager].each { |r| h[r] = { code: 404 } } |
| 344 | + %w[admin space_developer].each { |r| h[r] = { code: 200, response_object: feature_response_object } } |
| 345 | + h |
222 | 346 | end |
223 | 347 |
|
224 | 348 | it_behaves_like 'permissions for single object endpoint', ALL_PERMISSIONS |
| 349 | + |
| 350 | + context 'when service-binding-k8s is enabled' do |
| 351 | + before do |
| 352 | + patch "/v3/apps/#{app_model.guid}/features/service-binding-k8s", request_body_enabled.to_json, admin_header |
| 353 | + end |
| 354 | + |
| 355 | + it 'returns an error which states that both features cannot be enabled at the same time' do |
| 356 | + patch "/v3/apps/#{app_model.guid}/features/file-based-vcap-services", request_body_enabled.to_json, admin_header |
| 357 | + |
| 358 | + expect(last_response.status).to eq(422) |
| 359 | + expect(parsed_response['errors'][0]['detail']).to eq("'file-based-vcap-services' and 'service-binding-k8s' features cannot be enabled at the same time.") |
| 360 | + end |
| 361 | + end |
225 | 362 | end |
226 | 363 | end |
227 | 364 | end |
|
0 commit comments