Skip to content

Commit ad04ad7

Browse files
committed
change error name
1 parent 7e061a2 commit ad04ad7

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

app/controllers/v3/application_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class ApplicationController < ActionController::Base
9393
rescue_from CloudController::Errors::CompoundError, with: :handle_compound_error
9494
rescue_from ActionDispatch::Http::Parameters::ParseError, with: :handle_invalid_request_body
9595
rescue_from Sequel::DatabaseConnectionError, Sequel::DatabaseDisconnectError, with: :handle_db_connection_error
96-
rescue_from OpenSSL::Cipher::CipherError, with: :handle_decryption_error
96+
rescue_from OpenSSL::Cipher::CipherError, with: :handle_key_derivation_error
9797

9898
def configuration
9999
Config.config
@@ -220,8 +220,8 @@ def handle_db_connection_error(_)
220220
handle_api_error(error)
221221
end
222222

223-
def handle_decryption_error(_)
224-
error = CloudController::Errors::ApiError.new_from_details('InternalServerError', 'Failed to decrypt credentials')
223+
def handle_key_derivation_error(_)
224+
error = CloudController::Errors::V3::ApiError.new_from_details('InternalServerError', 'Failed to decrypt credentials')
225225
handle_api_error(error)
226226
end
227227

app/controllers/v3/service_credential_bindings_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def details
135135
else
136136
begin
137137
service_credential_binding.credentials
138-
rescue VCAP::CloudController::Encryptor::EncryptorError => e
138+
rescue VCAP::CloudController::Encryptor::KeyDerivationError => e
139139
logger.error("Failed to decrypt credentials: #{e.message}")
140140
raise CloudController::Errors::V3::ApiError.new_from_details('InternalServerError', 'Failed to decrypt credentials')
141141
end

lib/cloud_controller/encryptor.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
module VCAP::CloudController
99
module Encryptor
1010
ENCRYPTION_ITERATIONS = 2048
11-
class EncryptorError < StandardError; end
11+
class KeyDerivationError < StandardError; end
1212
class << self
1313
ALGORITHM = 'AES-128-CBC'.freeze
1414

@@ -87,7 +87,7 @@ def run_cipher(cipher, input, salt, key, iterations:)
8787
cipher.key = OpenSSL::PKCS5.pbkdf2_hmac(key, salt, iterations, 16, OpenSSL::Digest.new('SHA256'))
8888
rescue OpenSSL::Cipher::CipherError => e
8989
logger.error("Failed to derive cipher key due to missing key for encryption_key_label=#{current_encryption_key_label}: #{e.class}: #{e.message}") if key.nil?
90-
raise EncryptorError
90+
raise KeyDerivationError
9191
end
9292
cipher.iv = salt
9393
end

spec/request/service_credential_bindings_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def check_filtered_bindings(*bindings)
637637
it 'fails to decrypt the credentials and returns a 500 error' do
638638
app_binding.class.db[:service_bindings].where(id: app_binding.id).update(encryption_key_label: 'invalid-key-label')
639639

640-
allow(VCAP::CloudController::Encryptor).to receive(:run_cipher).and_raise(VCAP::CloudController::Encryptor::EncryptorError)
640+
allow(VCAP::CloudController::Encryptor).to receive(:run_cipher).and_raise(VCAP::CloudController::Encryptor::KeyDerivationError)
641641
api_call.call(admin_headers)
642642

643643
expect(last_response).to have_status_code(500)

spec/unit/controllers/v3/application_controller_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def not_found
3838
raise CloudController::Errors::NotFound.new_from_details('NotFound')
3939
end
4040

41-
def decryption_error
41+
def key_derivation_error
4242
raise OpenSSL::Cipher::CipherError.new
4343
end
4444

@@ -324,18 +324,18 @@ def warnings_incorrect_type
324324
end
325325
end
326326

327-
describe '#handle_decryption_error' do
327+
describe '#handle_key_derivation_error' do
328328
let!(:user) { set_current_user(VCAP::CloudController::User.make) }
329329

330330
before do
331331
allow_any_instance_of(ErrorPresenter).to receive(:raise_500?).and_return(false)
332332
routes.draw do
333-
get 'decryption_error' => 'anonymous#decryption_error'
333+
get 'key_derivation_error' => 'anonymous#key_derivation_error'
334334
end
335335
end
336336

337337
it 'rescues from OpenSSL::Cipher::CipherError and renders an error presenter1' do
338-
get :decryption_error
338+
get :key_derivation_error
339339
expect(response).to have_http_status(:internal_server_error)
340340
expect(response).to have_error_message(/Failed to decrypt credentials/)
341341
end

0 commit comments

Comments
 (0)