Skip to content

Commit

Permalink
Fix issue that prevented logging of non-string objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcmxgti committed Sep 8, 2023
1 parent 45703a5 commit 0c36963
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pydocstyle
pylint
pyotp
pyroma
pytest>=7.0.0,<=7.3.1
pytest>=7.0.0,<8.0.0
pytest-cov
pytest-env
pytest-mock
Expand Down
8 changes: 5 additions & 3 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ functional (end-to-end) testing.
To run end-to-end tests, use `py.test -v -rA -k 'functional' -s tests`
instead. Several other arguments can be provided so that the tool can
run in non-interactive mode. Currently, the config file, arguments, and
environment variables (mix and match) are supported. The syntax is the
same as for `tokendito`.
environment variables (mix and match) are supported. The syntax is as close as
possible as for `tokendito`, with the exception of `--tool-config-file`. Pytest
version 7.4.0 introduced a similarly named variable, and options defined in
`conftest.py` cannot collide with command-line arguments to `pytest`.

If all of the username, password, MFA, tile URL, and role ARN are passed to
`py.test`, then two other tests are kicked off. The first will execute
Expand All @@ -20,7 +22,7 @@ credentials.
# Example 1

``` txt
py.test -v -rA -s tests --config-file=/tmp/my-tokendito-config.ini
py.test -v -rA -s tests --tool-config-file=/tmp/my-tokendito-config.ini
```

Where the config file has valid configuration items for the tool.
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def pytest_addoption(parser):
)
parser.addoption("--aws-role-arn", default=None, help="Sets the IAM role")
parser.addoption(
"--config-file",
"--tool-config-file",
default="/dev/null",
help="Sets an optional config file to read from",
)
Expand Down
24 changes: 14 additions & 10 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1694,16 +1694,20 @@ def test_authenticate(mocker):
mocker.patch("tokendito.user.request_cookies", return_value=sid)
mocker.patch("tokendito.okta.local_auth", return_value="foobar")
mocker.patch("tokendito.okta.saml2_auth", return_value=sid)
with mocker.patch("tokendito.okta.get_auth_properties", return_value={"type": "OKTA"}):
assert okta.authenticate(pytest_config) == sid
with mocker.patch("tokendito.okta.get_auth_properties", return_value={"type": "SAML2"}):
assert okta.authenticate(pytest_config) == sid
with mocker.patch("tokendito.okta.get_auth_properties", return_value={"type": "UNKNOWN"}):
with pytest.raises(SystemExit) as error:
assert okta.authenticate(pytest_config) == error
with mocker.patch("tokendito.okta.get_auth_properties", return_value={}):
with pytest.raises(SystemExit) as error:
assert okta.authenticate(pytest_config) == error

mocker.patch("tokendito.okta.get_auth_properties", return_value={"type": "OKTA"})
assert okta.authenticate(pytest_config) == sid

mocker.patch("tokendito.okta.get_auth_properties", return_value={"type": "SAML2"})
assert okta.authenticate(pytest_config) == sid

mocker.patch("tokendito.okta.get_auth_properties", return_value={"type": "UNKNOWN"})
with pytest.raises(SystemExit) as error:
assert okta.authenticate(pytest_config) == error

mocker.patch("tokendito.okta.get_auth_properties", return_value={})
with pytest.raises(SystemExit) as error:
assert okta.authenticate(pytest_config) == error


def test_local_auth(mocker):
Expand Down
2 changes: 2 additions & 0 deletions tokendito/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def filter(self, record):
for secret in mask_items:
if not isinstance(secret, str):
secret = str(secret)
if not isinstance(record.msg, str):
record.msg = str(record.msg)
record.msg = record.msg.replace(secret, "*****")
return True

Expand Down

0 comments on commit 0c36963

Please sign in to comment.