-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: invalid hostname and password error messages (Redshift) (#14111)
* custom errors for redshift * added unit tests and custom errors
- Loading branch information
Showing
2 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
from textwrap import dedent | ||
from unittest import mock | ||
|
||
from superset.db_engine_specs.redshift import RedshiftEngineSpec | ||
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType | ||
from tests.db_engine_specs.base_tests import TestDbEngineSpec | ||
|
||
|
||
class TestRedshiftDbEngineSpec(TestDbEngineSpec): | ||
def test_extract_errors(self): | ||
""" | ||
Test that custom error messages are extracted correctly. | ||
""" | ||
msg = 'FATAL: password authentication failed for user "wronguser"' | ||
result = RedshiftEngineSpec.extract_errors(Exception(msg)) | ||
assert result == [ | ||
SupersetError( | ||
error_type=SupersetErrorType.TEST_CONNECTION_ACCESS_DENIED_ERROR, | ||
message='Either the username "wronguser" or the password is incorrect.', | ||
level=ErrorLevel.ERROR, | ||
extra={ | ||
"engine_name": "Amazon Redshift", | ||
"issue_codes": [ | ||
{ | ||
"code": 1014, | ||
"message": "Issue 1014 - Either the username or the password is wrong", | ||
} | ||
], | ||
}, | ||
) | ||
] | ||
|
||
msg = 'redshift: error: could not translate host name "badhost" to address: nodename nor servname provided, or not known' | ||
result = RedshiftEngineSpec.extract_errors(Exception(msg)) | ||
assert result == [ | ||
SupersetError( | ||
error_type=SupersetErrorType.TEST_CONNECTION_INVALID_HOSTNAME_ERROR, | ||
message='The hostname "badhost" cannot be resolved.', | ||
level=ErrorLevel.ERROR, | ||
extra={ | ||
"engine_name": "Amazon Redshift", | ||
"issue_codes": [ | ||
{ | ||
"code": 1007, | ||
"message": "Issue 1007 - The hostname provided can't be resolved.", | ||
} | ||
], | ||
}, | ||
) | ||
] | ||
msg = dedent( | ||
""" | ||
psql: error: could not connect to server: Connection refused | ||
Is the server running on host "localhost" (::1) and accepting | ||
TCP/IP connections on port 12345? | ||
could not connect to server: Connection refused | ||
Is the server running on host "localhost" (127.0.0.1) and accepting | ||
TCP/IP connections on port 12345? | ||
""" | ||
) | ||
result = RedshiftEngineSpec.extract_errors(Exception(msg)) | ||
assert result == [ | ||
SupersetError( | ||
error_type=SupersetErrorType.TEST_CONNECTION_PORT_CLOSED_ERROR, | ||
message='Port 12345 on hostname "localhost" refused the connection.', | ||
level=ErrorLevel.ERROR, | ||
extra={ | ||
"engine_name": "Amazon Redshift", | ||
"issue_codes": [ | ||
{"code": 1008, "message": "Issue 1008 - The port is closed."} | ||
], | ||
}, | ||
) | ||
] | ||
|
||
msg = dedent( | ||
""" | ||
psql: error: could not connect to server: Operation timed out | ||
Is the server running on host "example.com" (93.184.216.34) and accepting | ||
TCP/IP connections on port 12345? | ||
""" | ||
) | ||
result = RedshiftEngineSpec.extract_errors(Exception(msg)) | ||
assert result == [ | ||
SupersetError( | ||
error_type=SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR, | ||
message=( | ||
'The host "example.com" might be down, ' | ||
"and can't be reached on port 12345." | ||
), | ||
level=ErrorLevel.ERROR, | ||
extra={ | ||
"engine_name": "Amazon Redshift", | ||
"issue_codes": [ | ||
{ | ||
"code": 1009, | ||
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", | ||
} | ||
], | ||
}, | ||
) | ||
] | ||
|
||
# response with IP only | ||
msg = dedent( | ||
""" | ||
psql: error: could not connect to server: Operation timed out | ||
Is the server running on host "93.184.216.34" and accepting | ||
TCP/IP connections on port 12345? | ||
""" | ||
) | ||
result = RedshiftEngineSpec.extract_errors(Exception(msg)) | ||
assert result == [ | ||
SupersetError( | ||
error_type=SupersetErrorType.TEST_CONNECTION_HOST_DOWN_ERROR, | ||
message=( | ||
'The host "93.184.216.34" might be down, ' | ||
"and can't be reached on port 12345." | ||
), | ||
level=ErrorLevel.ERROR, | ||
extra={ | ||
"engine_name": "Amazon Redshift", | ||
"issue_codes": [ | ||
{ | ||
"code": 1009, | ||
"message": "Issue 1009 - The host might be down, and can't be reached on the provided port.", | ||
} | ||
], | ||
}, | ||
) | ||
] |