MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / test_log_redact_file

Function test_log_redact_file

tools-tests/tasks_test.py:212–239  ·  view source on GitHub ↗
(tmp_path)

Source from the content-addressed store, hash-verified

210
211
212def test_log_redact_file(tmp_path):
213 log_file = tmp_path / "foo.log.gz"
214 input_log_lines = [
215 "logline1: foo",
216 "logline2: <ud>password</ud>",
217 "logline3: log-redaction-salt=AAA",
218 "logline4: bar",
219 ]
220 with gzip.open(log_file, "wt") as fh:
221 for line in input_log_lines:
222 fh.write(line + "\n")
223
224 salt = "AA"
225 redactor = tasks.LogRedactor(salt, tmp_path)
226 redacted_file = redactor.redact_file(log_file.name, log_file)
227
228 output_log_lines = [
229 "RedactLevel:partial,HashOfSalt:e2512172abf8cc9f67fdd49eb6cacf2df71bbad3",
230 "logline1: foo",
231 "logline2: <ud>1700bc8ae71605063ae83d80837fa53988c635ef</ud>",
232 "logline3: log-redaction-salt <redacted>",
233 "logline4: bar",
234 "", # file has trailing newline
235 ]
236 updated_text = os.linesep.join(output_log_lines).encode("utf-8")
237
238 redacted_text = gzip.open(redacted_file).read()
239 assert redacted_text == updated_text

Callers

nothing calls this directly

Calls 3

redact_fileMethod · 0.95
readMethod · 0.80
openMethod · 0.45

Tested by

no test coverage detected