Skip to content

Commit acdeaf6

Browse files
committed
1680: add generic error message to avoid leaking potential sensitive information
1 parent 3568eb0 commit acdeaf6

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

app/services/task_service/push_external.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ def initialize(zip:, account_link:)
1010

1111
def execute
1212
response = self.class.connection.post(@account_link.push_url) {|request| request_parameters(request, @zip.string) }
13-
return nil if response.success?
14-
return I18n.t('tasks.export_external_confirm.not_authorized', account_link: @account_link.name) if response.status == 401
15-
16-
handle_error(message: response.body)
13+
handle_response(response)
1714
rescue Faraday::ServerError => e
1815
handle_error(error: e, message: I18n.t('tasks.export_external_confirm.server_error', account_link: @account_link.name))
1916
rescue StandardError => e
20-
handle_error(error: e)
17+
handle_error(error: e, message: I18n.t('tasks.export_external_confirm.generic_error'))
2118
end
2219

2320
private
2421

25-
def handle_error(message: nil, error: nil)
22+
def handle_response(response)
23+
return nil if response.success?
24+
return I18n.t('tasks.export_external_confirm.not_authorized', account_link: @account_link.name) if response.status == 401
25+
26+
handle_error(message: response.body)
27+
end
28+
29+
def handle_error(message:, error: nil)
2630
Sentry.capture_exception(error) if error.present?
27-
ERB::Util.html_escape(message || error.to_s)
31+
ERB::Util.html_escape(message)
2832
end
2933

3034
def request_parameters(request, body)

config/locales/de/controllers/tasks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ de:
88
error_alert: Die Aufgabe konnte nicht dupliziert werden.
99
export_external_confirm:
1010
error: 'Der Export der Aufgabe (%{title}) ist fehlgeschlagen. <br><br> Fehler: %{error}'
11+
generic_error: Ein unbekannter Fehler ist beim exportieren der Aufgabe aufgetreten.
1112
not_authorized: Die Autorisierung mit "%{account_link}" konnte nicht hergestellt werden. Ist der API-Schlüssel korrekt?
1213
server_error: Verbindung zu %{account_link} fehlgeschlagen. Gegenseite nicht erreichbar.
1314
success: Aufgabe (%{title}) erfolgreich exportiert.

config/locales/en/controllers/tasks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ en:
88
error_alert: Task could not be duplicated
99
export_external_confirm:
1010
error: 'Export of task (%{title}) failed. <br><br> Error: %{error}'
11+
generic_error: An unknown error has occurred while exporting the task.
1112
not_authorized: Authorization with could not be established with "%{account_link}". Is the API Key correct?
1213
server_error: Connection to %{account_link} failed. Remote host unreachable.
1314
success: Task (%{title}) successfully exported.

spec/services/task_service/push_external_spec.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,22 @@
7272
let(:error) { Faraday::ServerError }
7373

7474
before do
75-
allow(Faraday).to receive(:new).and_return(connection)
75+
allow(TaskService).to receive(:connection).and_return(connection)
7676
allow(connection).to receive(:post).and_raise(error)
7777
end
7878

7979
it { is_expected.to eql I18n.t('tasks.export_external_confirm.server_error', account_link: account_link.name) }
80-
81-
context 'when another error occurs' do
82-
let(:error) { 'another error' }
83-
84-
it { is_expected.to eql 'another error' }
85-
end
8680
end
8781
end
8882

8983
context 'when an error occurs' do
84+
let(:error) { StandardError.new('Standard error occurred') }
85+
9086
before do
91-
# Un-memoize the connection to force a reconnection
92-
described_class.instance_variable_set(:@connection, nil)
93-
allow(Faraday).to receive(:new).and_raise(StandardError)
87+
allow(TaskService).to receive(:connection).and_raise(error)
9488
end
9589

96-
it { is_expected.not_to be_nil }
90+
it { is_expected.to eql I18n.t('tasks.export_external_confirm.generic_error') }
9791
end
9892
end
9993
end

0 commit comments

Comments
 (0)