secretscreen 0.5.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- secretscreen-0.5.1/.github/scripts/pr_test_gate.py +200 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/workflows/codeql.yml +3 -3
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/workflows/scorecard.yml +1 -1
- secretscreen-0.5.1/.github/workflows/test-gate.yml +61 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/PKG-INFO +2 -2
- {secretscreen-0.5.0 → secretscreen-0.5.1}/pyproject.toml +14 -1
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/__init__.py +1 -1
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_cli.py +15 -1
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_cli.py +49 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_yaml_and_prefixes.py +4 -1
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/FUNDING.yml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/dependabot.yml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/pull_request_template.md +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/workflows/ci.yml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/workflows/dependabot-automerge.yml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.github/workflows/publish.yml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/.gitignore +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/CODE_OF_CONDUCT.md +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/CONTRIBUTING.md +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/LICENSE +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/NOTICE +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/README.md +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/SECURITY.md +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/docs/audits/security-audit-2026-04-05.md +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_config.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_core.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_entropy.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_formats.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_keys.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_parsers.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/_urls.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/gitleaks.toml +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/src/secretscreen/py.typed +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/__init__.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_architecture.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_config.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_core.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_entropy.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_explain.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_formats.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_keys.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_parsers.py +0 -0
- {secretscreen-0.5.0 → secretscreen-0.5.1}/tests/test_urls.py +0 -0
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Require every behaviour change to arrive with a test that proves it.
|
|
3
|
+
|
|
4
|
+
The gate runs the pull request's own tests against the pull request's *base*
|
|
5
|
+
source. At least one newly added test must fail there, and every changed test
|
|
6
|
+
must pass once the patch is applied. A test that passes without the patch does
|
|
7
|
+
not demonstrate anything; it is the failure on base that turns a test into
|
|
8
|
+
evidence.
|
|
9
|
+
|
|
10
|
+
Exit codes: 0 pass, 1 gate failure, 2 harness error.
|
|
11
|
+
|
|
12
|
+
Run it locally the same way CI does:
|
|
13
|
+
|
|
14
|
+
python .github/scripts/pr_test_gate.py --base origin/main --head HEAD
|
|
15
|
+
|
|
16
|
+
Escape hatch: a pull request that genuinely changes no behaviour (a pure
|
|
17
|
+
refactor, a rename, a performance change covered by existing tests) is exempt
|
|
18
|
+
via the `no-test-gate` label. The label is checked by the workflow, not here,
|
|
19
|
+
so that the reason is recorded on the pull request rather than buried in a log.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import argparse
|
|
25
|
+
import re
|
|
26
|
+
import subprocess
|
|
27
|
+
import sys
|
|
28
|
+
from pathlib import Path
|
|
29
|
+
|
|
30
|
+
SRC_DIR = "src"
|
|
31
|
+
TEST_DIR = "tests"
|
|
32
|
+
|
|
33
|
+
# `def test_x`, `async def test_x`, added by the diff.
|
|
34
|
+
ADDED_TEST_RE = re.compile(r"^\+\s*(?:async\s+)?def\s+(test_[A-Za-z0-9_]+)")
|
|
35
|
+
# pytest's short summary lines: "FAILED tests/test_x.py::Cls::test_y - detail"
|
|
36
|
+
OUTCOME_RE = re.compile(r"^(?:FAILED|ERROR)\s+(\S+)")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class GateError(RuntimeError):
|
|
40
|
+
"""The gate could not run. Distinct from the gate deciding to fail."""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def git(*args: str) -> str:
|
|
44
|
+
result = subprocess.run(["git", *args], capture_output=True, text=True, check=False)
|
|
45
|
+
if result.returncode != 0:
|
|
46
|
+
raise GateError(f"git {' '.join(args)} failed: {result.stderr.strip()}")
|
|
47
|
+
return result.stdout
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def changed_files(base: str, head: str, path: str) -> list[str]:
|
|
51
|
+
out = git("diff", "--name-only", "--diff-filter=ACMR", base, head, "--", path)
|
|
52
|
+
return [line for line in out.splitlines() if line.strip()]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def added_test_names(base: str, head: str) -> set[str]:
|
|
56
|
+
diff = git("diff", base, head, "--", TEST_DIR)
|
|
57
|
+
return {match.group(1) for line in diff.splitlines() if (match := ADDED_TEST_RE.match(line))}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def run_pytest(paths: list[str]) -> tuple[int, str, set[str]]:
|
|
61
|
+
"""Run pytest over `paths`; return (exit code, output, failing test names)."""
|
|
62
|
+
result = subprocess.run(
|
|
63
|
+
[
|
|
64
|
+
sys.executable,
|
|
65
|
+
"-m",
|
|
66
|
+
"pytest",
|
|
67
|
+
*paths,
|
|
68
|
+
"-q",
|
|
69
|
+
"--no-header",
|
|
70
|
+
"-p",
|
|
71
|
+
"no:cacheprovider",
|
|
72
|
+
"--tb=no",
|
|
73
|
+
"-rfE",
|
|
74
|
+
],
|
|
75
|
+
capture_output=True,
|
|
76
|
+
text=True,
|
|
77
|
+
check=False,
|
|
78
|
+
)
|
|
79
|
+
output = result.stdout + result.stderr
|
|
80
|
+
failing = set()
|
|
81
|
+
for line in output.splitlines():
|
|
82
|
+
if match := OUTCOME_RE.match(line):
|
|
83
|
+
# tests/test_core.py::TestFoo::test_bar -> test_bar
|
|
84
|
+
failing.add(match.group(1).split("::")[-1].split("[")[0])
|
|
85
|
+
return result.returncode, output, failing
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def fail(reason: str, *, detail: str = "") -> int:
|
|
89
|
+
print(f"\n::error::PR test gate: {reason}")
|
|
90
|
+
print(f"\n FAILED — {reason}\n")
|
|
91
|
+
if detail:
|
|
92
|
+
print(detail)
|
|
93
|
+
print(
|
|
94
|
+
"\n A change to src/ has to arrive with a test that fails without it.\n"
|
|
95
|
+
" If this pull request genuinely changes no behaviour — a pure refactor,\n"
|
|
96
|
+
" a rename, a dependency bump — add the `no-test-gate` label and say why\n"
|
|
97
|
+
" in the pull request body. The exemption is recorded, not silent.\n"
|
|
98
|
+
)
|
|
99
|
+
return 1
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def main() -> int:
|
|
103
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
104
|
+
parser.add_argument("--base", required=True, help="base ref or SHA")
|
|
105
|
+
parser.add_argument("--head", default="HEAD", help="head ref or SHA")
|
|
106
|
+
args = parser.parse_args()
|
|
107
|
+
|
|
108
|
+
if not Path(SRC_DIR).is_dir() or not Path(TEST_DIR).is_dir():
|
|
109
|
+
raise GateError(f"expected {SRC_DIR}/ and {TEST_DIR}/ in {Path.cwd()}")
|
|
110
|
+
|
|
111
|
+
base, head = args.base, args.head
|
|
112
|
+
src_changed = changed_files(base, head, SRC_DIR)
|
|
113
|
+
test_changed = changed_files(base, head, TEST_DIR)
|
|
114
|
+
|
|
115
|
+
print(f" base {git('rev-parse', '--short', base).strip()} head {git('rev-parse', '--short', head).strip()}")
|
|
116
|
+
|
|
117
|
+
if not src_changed:
|
|
118
|
+
print("\n SKIPPED — no changes under src/. Nothing to demonstrate.\n")
|
|
119
|
+
return 0
|
|
120
|
+
|
|
121
|
+
print(f"\n source files changed ({len(src_changed)}):")
|
|
122
|
+
for path in src_changed:
|
|
123
|
+
print(f" {path}")
|
|
124
|
+
|
|
125
|
+
if not test_changed:
|
|
126
|
+
return fail(
|
|
127
|
+
"src/ changed but no test changed",
|
|
128
|
+
detail=" Changed without a test:\n" + "".join(f" {p}\n" for p in src_changed),
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
added = added_test_names(base, head)
|
|
132
|
+
if not added:
|
|
133
|
+
return fail(
|
|
134
|
+
"test files changed but no new test was added",
|
|
135
|
+
detail=f" Changed test files: {', '.join(test_changed)}\n"
|
|
136
|
+
" The gate looks for added `def test_*`. Editing an existing\n"
|
|
137
|
+
" test in place cannot show that the defect was ever present.\n",
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
print(f"\n tests added ({len(added)}):")
|
|
141
|
+
for name in sorted(added):
|
|
142
|
+
print(f" {name}")
|
|
143
|
+
|
|
144
|
+
# --- Half one: the new tests must fail against the base source. ----------
|
|
145
|
+
# Only src/ is reverted. Packaging and test fixtures stay at head so the
|
|
146
|
+
# single variable under test is the source change itself.
|
|
147
|
+
print("\n [1/2] running the PR's tests against base source ...")
|
|
148
|
+
git("checkout", base, "--", SRC_DIR)
|
|
149
|
+
try:
|
|
150
|
+
code, output, failing = run_pytest(test_changed)
|
|
151
|
+
finally:
|
|
152
|
+
git("checkout", head, "--", SRC_DIR)
|
|
153
|
+
|
|
154
|
+
if code == 0:
|
|
155
|
+
return fail(
|
|
156
|
+
"every test passes without the patch",
|
|
157
|
+
detail=" The tests in this pull request pass against the base source,\n"
|
|
158
|
+
" so they do not demonstrate that anything was broken.\n"
|
|
159
|
+
" Write a test that fails first, then make it pass.\n",
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
proving = sorted(added & failing)
|
|
163
|
+
if not proving:
|
|
164
|
+
if not failing:
|
|
165
|
+
# Base could not even collect the tests — they reference API that
|
|
166
|
+
# only exists on head. That is the strongest possible signal.
|
|
167
|
+
print(" base run could not collect the tests (new API referenced).")
|
|
168
|
+
print(" accepted as evidence the tests require the patch.")
|
|
169
|
+
else:
|
|
170
|
+
return fail(
|
|
171
|
+
"no *added* test fails without the patch",
|
|
172
|
+
detail=f" Failing on base: {', '.join(sorted(failing))}\n"
|
|
173
|
+
f" Added by this PR: {', '.join(sorted(added))}\n"
|
|
174
|
+
" Something failed on base, but nothing this pull request\n"
|
|
175
|
+
" added. That is a pre-existing failure, not evidence.\n",
|
|
176
|
+
)
|
|
177
|
+
else:
|
|
178
|
+
print(f" {len(proving)} added test(s) fail without the patch:")
|
|
179
|
+
for name in proving:
|
|
180
|
+
print(f" {name}")
|
|
181
|
+
|
|
182
|
+
# --- Half two: everything must pass with the patch applied. -------------
|
|
183
|
+
print("\n [2/2] running the same tests against the PR ...")
|
|
184
|
+
code, output, failing = run_pytest(test_changed)
|
|
185
|
+
if code != 0:
|
|
186
|
+
return fail(
|
|
187
|
+
"the tests do not pass with the patch applied",
|
|
188
|
+
detail=f" Still failing: {', '.join(sorted(failing))}\n\n{output[-2000:]}",
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
print("\n PASSED — the defect is demonstrated and the patch closes it.\n")
|
|
192
|
+
return 0
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
if __name__ == "__main__":
|
|
196
|
+
try:
|
|
197
|
+
sys.exit(main())
|
|
198
|
+
except GateError as exc:
|
|
199
|
+
print(f"::error::PR test gate could not run: {exc}", file=sys.stderr)
|
|
200
|
+
sys.exit(2)
|
|
@@ -21,12 +21,12 @@ jobs:
|
|
|
21
21
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
22
22
|
|
|
23
23
|
- name: Initialize CodeQL
|
|
24
|
-
uses: github/codeql-action/init@
|
|
24
|
+
uses: github/codeql-action/init@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
|
25
25
|
with:
|
|
26
26
|
languages: python
|
|
27
27
|
|
|
28
28
|
- name: Autobuild
|
|
29
|
-
uses: github/codeql-action/autobuild@
|
|
29
|
+
uses: github/codeql-action/autobuild@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
|
30
30
|
|
|
31
31
|
- name: Perform CodeQL Analysis
|
|
32
|
-
uses: github/codeql-action/analyze@
|
|
32
|
+
uses: github/codeql-action/analyze@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
|
@@ -30,6 +30,6 @@ jobs:
|
|
|
30
30
|
publish_results: true
|
|
31
31
|
|
|
32
32
|
- name: Upload to code-scanning
|
|
33
|
-
uses: github/codeql-action/upload-sarif@
|
|
33
|
+
uses: github/codeql-action/upload-sarif@5595ccaf912efad79be6eef63a5619ff05969be3 # v4.37.6
|
|
34
34
|
with:
|
|
35
35
|
sarif_file: results.sarif
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: Test Gate
|
|
2
|
+
|
|
3
|
+
# Every change to src/ must arrive with a test that fails without it. The gate
|
|
4
|
+
# runs the pull request's own tests against the base source: at least one newly
|
|
5
|
+
# added test has to fail there, and all of them have to pass once the patch is
|
|
6
|
+
# applied. A test that passes either way proves nothing.
|
|
7
|
+
#
|
|
8
|
+
# Exemptions are deliberate and visible: Dependabot is skipped by author, and a
|
|
9
|
+
# genuine no-behaviour-change pull request is skipped by the `no-test-gate`
|
|
10
|
+
# label, which leaves the reason on the pull request instead of in a log.
|
|
11
|
+
|
|
12
|
+
on:
|
|
13
|
+
pull_request:
|
|
14
|
+
|
|
15
|
+
concurrency:
|
|
16
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
17
|
+
cancel-in-progress: true
|
|
18
|
+
|
|
19
|
+
permissions:
|
|
20
|
+
contents: read
|
|
21
|
+
|
|
22
|
+
jobs:
|
|
23
|
+
gate:
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
if: >-
|
|
26
|
+
github.actor != 'dependabot[bot]' &&
|
|
27
|
+
!contains(github.event.pull_request.labels.*.name, 'no-test-gate')
|
|
28
|
+
steps:
|
|
29
|
+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
30
|
+
with:
|
|
31
|
+
# Full history: the gate diffs against the merge base and checks the
|
|
32
|
+
# base revision of src/ out in place.
|
|
33
|
+
fetch-depth: 0
|
|
34
|
+
|
|
35
|
+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
|
|
36
|
+
with:
|
|
37
|
+
python-version: "3.13"
|
|
38
|
+
cache: pip
|
|
39
|
+
|
|
40
|
+
- name: Install dependencies
|
|
41
|
+
run: pip install -e ".[dev]"
|
|
42
|
+
|
|
43
|
+
- name: Resolve merge base
|
|
44
|
+
run: |
|
|
45
|
+
BASE=$(git merge-base "origin/${{ github.base_ref }}" HEAD)
|
|
46
|
+
echo "BASE_SHA=$BASE" >> "$GITHUB_ENV"
|
|
47
|
+
echo "Comparing against $BASE (merge base with ${{ github.base_ref }})"
|
|
48
|
+
|
|
49
|
+
- name: Does the test prove the fix?
|
|
50
|
+
run: python .github/scripts/pr_test_gate.py --base "$BASE_SHA" --head HEAD
|
|
51
|
+
|
|
52
|
+
# Reports the exemption rather than leaving a silent gap in the checks list.
|
|
53
|
+
exempt:
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
if: contains(github.event.pull_request.labels.*.name, 'no-test-gate')
|
|
56
|
+
steps:
|
|
57
|
+
- name: Record the exemption
|
|
58
|
+
run: |
|
|
59
|
+
echo "::notice::Test gate skipped via the no-test-gate label."
|
|
60
|
+
echo "This pull request claims it changes no behaviour."
|
|
61
|
+
echo "That claim is the reviewer's to check."
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: secretscreen
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Detect and redact secrets in key-value pairs, dicts, and environment variables. Library and CLI.
|
|
5
5
|
Project-URL: Homepage, https://github.com/featurecreep-cron/secretscreen
|
|
6
6
|
Project-URL: Repository, https://github.com/featurecreep-cron/secretscreen
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "secretscreen"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.1"
|
|
8
8
|
description = "Detect and redact secrets in key-value pairs, dicts, and environment variables. Library and CLI."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -45,6 +45,19 @@ packages = ["src/secretscreen"]
|
|
|
45
45
|
[tool.pytest.ini_options]
|
|
46
46
|
testpaths = ["tests"]
|
|
47
47
|
|
|
48
|
+
# Measure the package, not the suite. Bare `pytest --cov` measures everything
|
|
49
|
+
# imported, which counts tests/ as covered code and puts patch coverage on the
|
|
50
|
+
# test file itself. That penalises exactly the tests worth writing: a branch
|
|
51
|
+
# that exists to fail the suite if a bug returns never runs while the code is
|
|
52
|
+
# correct, so a passing suite reads as an uncovered line.
|
|
53
|
+
#
|
|
54
|
+
# Omit rather than `source`: setting a source root rewrites every path in
|
|
55
|
+
# coverage.xml relative to it, and codecov matches those paths against the
|
|
56
|
+
# repository. Dropping the suite leaves `src/secretscreen/...` exactly as it
|
|
57
|
+
# has always been reported.
|
|
58
|
+
[tool.coverage.run]
|
|
59
|
+
omit = ["tests/*"]
|
|
60
|
+
|
|
48
61
|
[tool.mypy]
|
|
49
62
|
strict = true
|
|
50
63
|
warn_return_any = true
|
|
@@ -694,7 +694,8 @@ examples:
|
|
|
694
694
|
exit codes:
|
|
695
695
|
0 nothing to report
|
|
696
696
|
1 --audit found something
|
|
697
|
-
2 a line could not be parsed, a file could not be read,
|
|
697
|
+
2 a line could not be parsed, a file could not be read, a config is invalid,
|
|
698
|
+
or no input was given
|
|
698
699
|
|
|
699
700
|
--audit prints key names, layers, and reasons — never a value, in either mode.
|
|
700
701
|
--explain does the same for values that were left alone.
|
|
@@ -761,6 +762,19 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
761
762
|
# flag should override it.
|
|
762
763
|
args.mode = Mode.AGGRESSIVE if args.aggressive else None
|
|
763
764
|
|
|
765
|
+
# No files and a terminal on stdin: nothing was given to read and nothing
|
|
766
|
+
# is coming. Blocking on the terminal there is indistinguishable from a
|
|
767
|
+
# hang, and a cat-replacement that appears to hang on the first bare run is
|
|
768
|
+
# one nobody runs twice. An explicit `-` still reads the terminal — that is
|
|
769
|
+
# someone asking for it on purpose.
|
|
770
|
+
if not args.files and sys.stdin.isatty():
|
|
771
|
+
parser.print_help(sys.stderr)
|
|
772
|
+
print(
|
|
773
|
+
"\nsecretscreen: no input — pass a FILE, pipe something in, or use '-' to read the terminal.",
|
|
774
|
+
file=sys.stderr,
|
|
775
|
+
)
|
|
776
|
+
return EXIT_ERROR
|
|
777
|
+
|
|
764
778
|
report = _Report()
|
|
765
779
|
# One loader for the run: discovery repeats per input, and the files it
|
|
766
780
|
# finds do not change underneath a single invocation.
|
|
@@ -251,6 +251,51 @@ class TestFormats:
|
|
|
251
251
|
assert out.count("[REDACTED]") == 2
|
|
252
252
|
|
|
253
253
|
|
|
254
|
+
class TestNoInput:
|
|
255
|
+
"""A bare `secretscreen` at a terminal must not sit there reading it.
|
|
256
|
+
|
|
257
|
+
Waiting on an interactive terminal is indistinguishable from a hang, and it
|
|
258
|
+
is the first thing anyone types after installing.
|
|
259
|
+
"""
|
|
260
|
+
|
|
261
|
+
def test_bare_invocation_at_a_terminal_exits_instead_of_reading(self, capsys, monkeypatch) -> None:
|
|
262
|
+
monkeypatch.setattr("sys.stdin", _TtyStdin())
|
|
263
|
+
code = main([])
|
|
264
|
+
err = capsys.readouterr().err
|
|
265
|
+
|
|
266
|
+
assert code == EXIT_ERROR
|
|
267
|
+
assert "no input" in err
|
|
268
|
+
assert "usage: secretscreen" in err
|
|
269
|
+
|
|
270
|
+
def test_audit_with_no_files_at_a_terminal_exits_too(self, capsys, monkeypatch) -> None:
|
|
271
|
+
monkeypatch.setattr("sys.stdin", _TtyStdin())
|
|
272
|
+
assert main(["--audit"]) == EXIT_ERROR
|
|
273
|
+
|
|
274
|
+
def test_explicit_dash_still_reads_the_terminal(self, capsys, monkeypatch) -> None:
|
|
275
|
+
"""`-` is someone asking for stdin on purpose; the guard is for the implicit case."""
|
|
276
|
+
monkeypatch.setattr("sys.stdin", _TtyStdin("DB_PASSWORD=hunter2\n"))
|
|
277
|
+
code = main(["-"])
|
|
278
|
+
out = capsys.readouterr().out
|
|
279
|
+
|
|
280
|
+
assert code == EXIT_OK
|
|
281
|
+
assert "DB_PASSWORD=[REDACTED]" in out
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
class _TtyStdin:
|
|
285
|
+
"""An interactive terminal on stdin. read() blocks in reality, so it fails here."""
|
|
286
|
+
|
|
287
|
+
def __init__(self, text: str | None = None) -> None:
|
|
288
|
+
self._text = text
|
|
289
|
+
|
|
290
|
+
def read(self) -> str:
|
|
291
|
+
if self._text is None:
|
|
292
|
+
raise AssertionError("read the terminal instead of bailing out")
|
|
293
|
+
return self._text
|
|
294
|
+
|
|
295
|
+
def isatty(self) -> bool:
|
|
296
|
+
return True
|
|
297
|
+
|
|
298
|
+
|
|
254
299
|
class _FakeStdin:
|
|
255
300
|
"""Minimal stdin stand-in for pipe tests."""
|
|
256
301
|
|
|
@@ -259,3 +304,7 @@ class _FakeStdin:
|
|
|
259
304
|
|
|
260
305
|
def read(self) -> str:
|
|
261
306
|
return self._text
|
|
307
|
+
|
|
308
|
+
def isatty(self) -> bool:
|
|
309
|
+
"""A pipe, not a terminal — the CLI checks before it decides to read."""
|
|
310
|
+
return False
|
|
@@ -239,10 +239,13 @@ class TestPrefixDetectionIsConservative:
|
|
|
239
239
|
|
|
240
240
|
|
|
241
241
|
class _Stdin:
|
|
242
|
-
"""Minimal stdin stand-in; the CLI
|
|
242
|
+
"""Minimal stdin stand-in; the CLI reads it and asks whether it is a terminal."""
|
|
243
243
|
|
|
244
244
|
def __init__(self, text: str) -> None:
|
|
245
245
|
self._text = text
|
|
246
246
|
|
|
247
247
|
def read(self) -> str:
|
|
248
248
|
return self._text
|
|
249
|
+
|
|
250
|
+
def isatty(self) -> bool:
|
|
251
|
+
return False
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|