-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from real-digital/INFRA-1006-hide-password-dur…
…ing-init hash sensitive values before logging them
- Loading branch information
Showing
12 changed files
with
387 additions
and
192 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,33 @@ | ||
import hashlib | ||
import re | ||
|
||
from pyconnect.core import hide_sensitive_values | ||
|
||
|
||
def test_hide_sensitive_values_hashes(): | ||
config = {"sasl.password": "unhashed password", "regular_key": "regular value"} | ||
hashed_config = hide_sensitive_values(config) | ||
hash_pattern = r"\$PBKDF2-HMAC-(?P<algo>[^:]+):(?P<salt>[^:]+):(?P<iterations>\d+)\$(?P<hash>\w+)" | ||
groups = re.match(hash_pattern, hashed_config["sasl.password"]).groupdict() | ||
recomputed_hash = hashlib.pbkdf2_hmac( | ||
groups["algo"].lower(), b"unhashed password", bytes.fromhex(groups["salt"]), int(groups["iterations"]) | ||
) | ||
|
||
assert recomputed_hash.hex() == groups["hash"] | ||
assert hashed_config["sasl.password"] != config["sasl.password"] | ||
assert hashed_config["regular_key"] == config["regular_key"] | ||
|
||
|
||
def test_hide_sensitive_values_obfuscates(): | ||
config = {"sasl.password": "unhashed password", "regular_key": "regular value"} | ||
hidden_config = hide_sensitive_values(config, hash_sensitive_values=False) | ||
|
||
assert hidden_config["sasl.password"] == "****" | ||
assert hidden_config["regular_key"] == config["regular_key"] | ||
|
||
|
||
def test_hide_sensitive_values_doesnt_hash_when_it_shouldnt(): | ||
config = {"not_sensitive_key": "not sensitive key", "regular_key": "regular value"} | ||
hashed_config = hide_sensitive_values(config) | ||
|
||
assert hashed_config == config |
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
Oops, something went wrong.