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