-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-130771 / 24.10-RC.1 / Add RedactedFileMetric and use to redact iS…
…CSI CHAP secrets (by bmeagherix) (#212) * Add RedactedFileMetric and use to redact iSCSI CHAP secrets * Add test_redacted_file_metric (cherry picked from commit 98828e4) --------- Co-authored-by: Brian M <[email protected]>
- Loading branch information
1 parent
0df5782
commit 9fa7a9c
Showing
7 changed files
with
174 additions
and
4 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
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
38 changes: 38 additions & 0 deletions
38
ixdiagnose/test/pytest/unit/metrics/assets/redacted_file_metric_scst_input.txt
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,38 @@ | ||
HANDLER vdisk_fileio { | ||
} | ||
HANDLER vdisk_blockio { | ||
DEVICE test1 { | ||
filename /dev/zvol/tank/test1 | ||
blocksize 512 | ||
read_only 0 | ||
usn cce1fa1b063f9d3 | ||
naa_id 0x6589cfc0000007ddc48032452639e00e | ||
prod_id "iSCSI Disk" | ||
rotational 0 | ||
t10_vend_id TrueNAS | ||
t10_dev_id cce1fa1b063f9d3 | ||
threads_num 32 | ||
} | ||
|
||
} | ||
|
||
TARGET_DRIVER iscsi { | ||
IncomingUser "User1 secpassword123" | ||
enabled 1 | ||
link_local 0 | ||
|
||
TARGET iqn.2005-10.org.freenas.ctl:test1 { | ||
rel_tgt_id 1 | ||
enabled 1 | ||
per_portal_acl 1 | ||
IncomingUser "User1 secpassword123" | ||
OutgoingUser "User2 hellothere12" | ||
|
||
GROUP security_group { | ||
INITIATOR *\#1.2.3.4 | ||
|
||
LUN 0 test1 | ||
} | ||
} | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
ixdiagnose/test/pytest/unit/metrics/assets/redacted_file_metric_scst_output.txt
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,38 @@ | ||
HANDLER vdisk_fileio { | ||
} | ||
HANDLER vdisk_blockio { | ||
DEVICE test1 { | ||
filename /dev/zvol/tank/test1 | ||
blocksize 512 | ||
read_only 0 | ||
usn cce1fa1b063f9d3 | ||
naa_id 0x6589cfc0000007ddc48032452639e00e | ||
prod_id "iSCSI Disk" | ||
rotational 0 | ||
t10_vend_id TrueNAS | ||
t10_dev_id cce1fa1b063f9d3 | ||
threads_num 32 | ||
} | ||
|
||
} | ||
|
||
TARGET_DRIVER iscsi { | ||
IncomingUser "User1 **REDACTED**" | ||
enabled 1 | ||
link_local 0 | ||
|
||
TARGET iqn.2005-10.org.freenas.ctl:test1 { | ||
rel_tgt_id 1 | ||
enabled 1 | ||
per_portal_acl 1 | ||
IncomingUser "User1 **REDACTED**" | ||
OutgoingUser "User2 **REDACTED**" | ||
|
||
GROUP security_group { | ||
INITIATOR *\#1.2.3.4 | ||
|
||
LUN 0 test1 | ||
} | ||
} | ||
} | ||
|
46 changes: 46 additions & 0 deletions
46
ixdiagnose/test/pytest/unit/metrics/test_redacted_file_metric.py
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,46 @@ | ||
import contextlib | ||
import filecmp | ||
import os | ||
import pytest | ||
|
||
from ixdiagnose.plugins.metrics.file import RedactedFileMetric | ||
from ixdiagnose.plugins.iscsi import redact_chap_passwords | ||
|
||
from ixdiagnose.test.pytest.unit.utils import get_asset_path | ||
|
||
|
||
TEST_FILE_DIR = '/tmp' | ||
|
||
|
||
@pytest.mark.parametrize('name,raw_asset_filename,cooked_asset_filename,extension,callback', [ | ||
( | ||
'scst.conf', | ||
'redacted_file_metric_scst_input.txt', | ||
'redacted_file_metric_scst_output.txt', | ||
'.conf', | ||
redact_chap_passwords | ||
), | ||
]) | ||
def test_redacted_file_metric(mocker, | ||
monkeypatch, | ||
name, | ||
raw_asset_filename, | ||
cooked_asset_filename, | ||
extension, | ||
callback): | ||
raw_file_path = get_asset_path(raw_asset_filename) | ||
cooked_file_path = get_asset_path(cooked_asset_filename) | ||
output_file_path = os.path.join(TEST_FILE_DIR, name) | ||
|
||
file_metric = RedactedFileMetric('scst', raw_file_path, extension=extension, redact_callback=callback) | ||
file_metric.execution_context = {'output_dir': TEST_FILE_DIR} | ||
assert file_metric.output_file_path(TEST_FILE_DIR) == output_file_path | ||
|
||
try: | ||
report = file_metric.execute_impl()[0] | ||
assert os.path.exists(output_file_path) is True | ||
assert report['error'] is None | ||
assert filecmp.cmp(cooked_file_path, output_file_path, False) is True | ||
finally: | ||
with contextlib.suppress(FileNotFoundError): | ||
os.unlink(output_file_path) |
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