Skip to content

Commit

Permalink
feat: invalid password error message (Postgres) (apache#14038)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Apr 12, 2021
1 parent c563ea0 commit 786dadc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/src/pages/docs/Miscellaneous/issue_codes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,12 @@ The username provided when connecting to a database is not valid.

The user provided a username that doesn't exist in the database. Please check
that the username is typed correctly and exists in the database.

## Issue 1013

```
The password provided when connecting to a database is not valid.
```

The user provided a password that is incorrect. Please check that the
password is typed correctly.
2 changes: 2 additions & 0 deletions superset-frontend/src/components/ErrorMessage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const ErrorTypeEnum = {
TABLE_DOES_NOT_EXIST_ERROR: 'TABLE_DOES_NOT_EXIST_ERROR',
TEST_CONNECTION_INVALID_USERNAME_ERROR:
'TEST_CONNECTION_INVALID_USERNAME_ERROR',
TEST_CONNECTION_INVALID_PASSWORD_ERROR:
'TEST_CONNECTION_INVALID_PASSWORD_ERROR',
TEST_CONNECTION_INVALID_HOSTNAME_ERROR:
'TEST_CONNECTION_INVALID_HOSTNAME_ERROR',
TEST_CONNECTION_PORT_CLOSED_ERROR: 'TEST_CONNECTION_PORT_CLOSED_ERROR',
Expand Down
7 changes: 7 additions & 0 deletions superset/db_engine_specs/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class FixedOffsetTimezone(_FixedOffset):

# Regular expressions to catch custom errors
INVALID_USERNAME_REGEX = re.compile('role "(?P<username>.*?)" does not exist')
INVALID_PASSWORD_REGEX = re.compile(
'password authentication failed for user "(?P<username>.*?)"'
)
INVALID_HOSTNAME_REGEX = re.compile(
'could not translate host name "(?P<hostname>.*?)" to address: '
"nodename nor servname provided, or not known"
Expand Down Expand Up @@ -96,6 +99,10 @@ class PostgresBaseEngineSpec(BaseEngineSpec):
__('The username "%(username)s" does not exist.'),
SupersetErrorType.TEST_CONNECTION_INVALID_USERNAME_ERROR,
),
INVALID_PASSWORD_REGEX: (
__('The password provided for username "%(username)s" is incorrect.'),
SupersetErrorType.TEST_CONNECTION_INVALID_PASSWORD_ERROR,
),
INVALID_HOSTNAME_REGEX: (
__('The hostname "%(hostname)s" cannot be resolved.'),
SupersetErrorType.TEST_CONNECTION_INVALID_HOSTNAME_ERROR,
Expand Down
10 changes: 10 additions & 0 deletions superset/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SupersetErrorType(str, Enum):
COLUMN_DOES_NOT_EXIST_ERROR = "COLUMN_DOES_NOT_EXIST_ERROR"
TABLE_DOES_NOT_EXIST_ERROR = "TABLE_DOES_NOT_EXIST_ERROR"
TEST_CONNECTION_INVALID_USERNAME_ERROR = "TEST_CONNECTION_INVALID_USERNAME_ERROR"
TEST_CONNECTION_INVALID_PASSWORD_ERROR = "TEST_CONNECTION_INVALID_PASSWORD_ERROR"
TEST_CONNECTION_INVALID_HOSTNAME_ERROR = "TEST_CONNECTION_INVALID_HOSTNAME_ERROR"
TEST_CONNECTION_PORT_CLOSED_ERROR = "TEST_CONNECTION_PORT_CLOSED_ERROR"
TEST_CONNECTION_HOST_DOWN_ERROR = "TEST_CONNECTION_HOST_DOWN_ERROR"
Expand Down Expand Up @@ -163,6 +164,15 @@ class SupersetErrorType(str, Enum):
),
},
],
SupersetErrorType.TEST_CONNECTION_INVALID_PASSWORD_ERROR: [
{
"code": 1013,
"message": _(
"Issue 1013 - The password provided when "
"connecting to a database is not valid."
),
},
],
}


Expand Down
11 changes: 11 additions & 0 deletions tests/db_engine_specs/postgres_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,14 @@ def test_extract_errors(self):
extra={"engine_name": "PostgreSQL"},
)
]

msg = 'FATAL: password authentication failed for user "postgres"'
result = PostgresEngineSpec.extract_errors(Exception(msg))
assert result == [
SupersetError(
error_type=SupersetErrorType.TEST_CONNECTION_INVALID_PASSWORD_ERROR,
message=('The password provided for username "postgres" is incorrect.'),
level=ErrorLevel.ERROR,
extra={"engine_name": "PostgreSQL"},
)
]

0 comments on commit 786dadc

Please sign in to comment.