Skip to content

Commit 6244510

Browse files
committed
rename error message, remove obsolete parts in test setups
1 parent 0613136 commit 6244510

File tree

5 files changed

+9
-35
lines changed

5 files changed

+9
-35
lines changed

app/controllers/v3/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def handle_db_connection_error(_)
221221
end
222222

223223
def handle_key_derivation_error(_)
224-
error = CloudController::Errors::V3::ApiError.new_from_details('InternalServerError', 'Failed to decrypt credentials')
224+
error = CloudController::Errors::V3::ApiError.new_from_details('InternalServerError', 'Error while processing encrypted data')
225225
handle_api_error(error)
226226
end
227227

spec/request/apps_spec.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3401,33 +3401,18 @@
34013401

34023402
context 'when the encryption_key_label is invalid' do
34033403
let(:instance) { VCAP::CloudController::ManagedServiceInstance.make(space:) }
3404-
let(:app_binding) do
3405-
VCAP::CloudController::ServiceBinding.make(
3406-
app: app_model,
3407-
service_instance_guid: instance.guid,
3408-
credentials: { key: 'value' },
3409-
syslog_drain_url: 'syslog-url',
3410-
volume_mounts: %w[volume1 volume2]
3411-
)
3412-
end
34133404

34143405
before do
3415-
VCAP::CloudController::Encryptor.database_encryption_keys = {
3416-
encryption_key_0: 'somevalidkeyvalue',
3417-
foo: 'fooencryptionkey',
3418-
death: 'headbangingdeathmetalkey', 'invalid-key-label': 'fakekey'
3419-
}
34203406
allow_any_instance_of(ErrorPresenter).to receive(:raise_500?).and_return(false)
34213407
end
34223408

34233409
it 'fails to decrypt the environment variables and returns a 500 error' do
3424-
app_binding.class.db[:service_bindings].where(id: app_binding.id).update(encryption_key_label: 'invalid-key-label')
3425-
3410+
app_model # ensure that app model is created before run_cipher is mocked to throw an error
34263411
allow(VCAP::CloudController::Encryptor).to receive(:run_cipher).and_raise(OpenSSL::Cipher::CipherError)
34273412
api_call.call(admin_headers)
34283413

34293414
expect(last_response).to have_status_code(500)
3430-
expect(parsed_response['errors'].first['detail']).to match(/Failed/i)
3415+
expect(parsed_response['errors'].first['detail']).to match(/Error while processing encrypted data/i)
34313416
end
34323417
end
34333418
end

spec/request/service_brokers_spec.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -915,21 +915,16 @@ def expect_empty_list(user_headers)
915915
end
916916

917917
before do
918-
VCAP::CloudController::Encryptor.database_encryption_keys = {
919-
encryption_key_0: 'somevalidkeyvalue',
920-
foo: 'fooencryptionkey',
921-
death: 'headbangingdeathmetalkey', 'invalid-key-label': 'fakekey'
922-
}
923-
broker.class.db[:service_brokers].where(id: broker.id).update(encryption_key_label: 'invalid-key-label')
924-
allow(VCAP::CloudController::Encryptor).to receive(:run_cipher).and_raise(OpenSSL::Cipher::CipherError)
925918
allow_any_instance_of(ErrorPresenter).to receive(:raise_500?).and_return(false)
926919
end
927920

928921
it 'fails to decrypt the broker data and returns a 500 error' do
922+
broker # ensure the broker is created before run_cipher is mocked to throw an error
923+
allow(VCAP::CloudController::Encryptor).to receive(:run_cipher).and_raise(OpenSSL::Cipher::CipherError)
929924
api_call.call(admin_headers)
930925

931926
expect(last_response).to have_status_code(500)
932-
expect(parsed_response['errors'].first['detail']).to match(/Failed/i)
927+
expect(parsed_response['errors'].first['detail']).to match(/Error while processing encrypted data/i)
933928
end
934929
end
935930
end

spec/request/service_credential_bindings_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,22 +626,16 @@ def check_filtered_bindings(*bindings)
626626

627627
context 'when the encryption_key_label is invalid' do
628628
before do
629-
VCAP::CloudController::Encryptor.database_encryption_keys = {
630-
encryption_key_0: 'somevalidkeyvalue',
631-
foo: 'fooencryptionkey',
632-
death: 'headbangingdeathmetalkey', 'invalid-key-label': 'fakekey'
633-
}
634629
allow_any_instance_of(ErrorPresenter).to receive(:raise_500?).and_return(false)
635630
end
636631

637632
it 'fails to decrypt the credentials and returns a 500 error' do
638-
app_binding.class.db[:service_bindings].where(id: app_binding.id).update(encryption_key_label: 'invalid-key-label')
639-
633+
app_binding # ensure that binding is created before run_cipher is mocked to throw an error
640634
allow(VCAP::CloudController::Encryptor).to receive(:run_cipher).and_raise(OpenSSL::Cipher::CipherError)
641635
api_call.call(admin_headers)
642636

643637
expect(last_response).to have_status_code(500)
644-
expect(parsed_response['errors'].first['detail']).to match(/Failed/i)
638+
expect(parsed_response['errors'].first['detail']).to match(/Error while processing encrypted data/i)
645639
end
646640
end
647641

spec/unit/controllers/v3/application_controller_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def warnings_incorrect_type
337337
it 'rescues from OpenSSL::Cipher::CipherError and renders an error presenter' do
338338
get :key_derivation_error
339339
expect(response).to have_http_status(:internal_server_error)
340-
expect(response).to have_error_message(/Failed to decrypt credentials/)
340+
expect(response).to have_error_message(/Error while processing encrypted data/)
341341
end
342342
end
343343

0 commit comments

Comments
 (0)