push-claim-audit 0.1.0__py3-none-any.whl
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.
- push_claim_audit/__init__.py +2 -0
- push_claim_audit/__main__.py +41 -0
- push_claim_audit/audit.py +138 -0
- push_claim_audit-0.1.0.dist-info/METADATA +35 -0
- push_claim_audit-0.1.0.dist-info/RECORD +9 -0
- push_claim_audit-0.1.0.dist-info/WHEEL +5 -0
- push_claim_audit-0.1.0.dist-info/entry_points.txt +2 -0
- push_claim_audit-0.1.0.dist-info/licenses/LICENSE +21 -0
- push_claim_audit-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import sys
|
|
4
|
+
from . import __version__
|
|
5
|
+
from .audit import audit
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Parser(argparse.ArgumentParser):
|
|
9
|
+
def error(self, message):
|
|
10
|
+
self.print_usage(sys.stderr)
|
|
11
|
+
self.exit(1, 'error: ' + message + '\n')
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def main(argv=None):
|
|
15
|
+
parser = Parser(description='Audit documented device-delivery capabilities statically.')
|
|
16
|
+
parser.add_argument('root')
|
|
17
|
+
parser.add_argument('--json', action='store_true')
|
|
18
|
+
parser.add_argument('--verbose', action='store_true')
|
|
19
|
+
parser.add_argument('--ignore', action='append', default=[])
|
|
20
|
+
parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
|
|
21
|
+
parser.add_argument('--version', action='version', version=__version__)
|
|
22
|
+
args = parser.parse_args(argv)
|
|
23
|
+
try:
|
|
24
|
+
result = audit(args.root, args.ignore, args.fail_on)
|
|
25
|
+
except (OSError, ValueError, UnicodeError) as exc:
|
|
26
|
+
print('error: ' + str(exc), file=sys.stderr)
|
|
27
|
+
return 1
|
|
28
|
+
if args.json:
|
|
29
|
+
print(json.dumps(result))
|
|
30
|
+
else:
|
|
31
|
+
print(result['verdict'])
|
|
32
|
+
for item in result['findings']:
|
|
33
|
+
print('{severity} {rule}: {message}'.format(**item))
|
|
34
|
+
if args.verbose:
|
|
35
|
+
print('Evidence: ' + (', '.join(result['evidence']) or 'none'))
|
|
36
|
+
print('Claim files: ' + (', '.join(result['claims']) or 'none'))
|
|
37
|
+
return 2 if result['verdict'] == 'FAIL' else 0
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == '__main__':
|
|
41
|
+
sys.exit(main())
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Read documentation and Python ASTs without executing project code."""
|
|
2
|
+
import ast
|
|
3
|
+
import fnmatch
|
|
4
|
+
import re
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
PUSH = ('support for push notifications', 'support for push', 'push notification support', 'push notifications', 'push notification', 'push alerts', 'push alert', 'push messages', 'push message', 'sends push notifications', 'send push notifications', 'sends push', 'send push', 'push support', 'push enabled', 'push powered', 'push based', 'supports push notifications', 'supports push', 'uses push', 'using push', 'over push', 'via push', 'with push')
|
|
8
|
+
NOPUSH = ('no push notifications', 'no push notification', 'no push support', 'does not support push', 'does not send push', 'does not use push', 'push notifications not supported', 'push not supported', 'without push', 'no push')
|
|
9
|
+
CLIENTS = {'APNsClient', 'APNSClient', 'OneSignalClient', 'Client'}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def normalize(text):
|
|
13
|
+
return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' ')).strip()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def pattern(phrases):
|
|
17
|
+
return re.compile(r'\b(?:' + '|'.join(re.escape(p) for p in sorted(phrases, key=len, reverse=True)) + r')\b')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def claims(text):
|
|
21
|
+
lines, fence = [], None
|
|
22
|
+
for line in text.splitlines():
|
|
23
|
+
mark = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
|
|
24
|
+
if mark:
|
|
25
|
+
token = mark.group(1)
|
|
26
|
+
if fence is None:
|
|
27
|
+
fence = token
|
|
28
|
+
elif token[0] == fence[0] and len(token) >= len(fence) and not line.strip()[len(token):].strip():
|
|
29
|
+
fence = None
|
|
30
|
+
lines.append('')
|
|
31
|
+
elif fence is None:
|
|
32
|
+
lines.append(line)
|
|
33
|
+
positive = negative = False
|
|
34
|
+
for paragraph in re.split(r'\n\s*\n', '\n'.join(lines)):
|
|
35
|
+
text = normalize(paragraph)
|
|
36
|
+
negative |= bool(pattern(NOPUSH).search(text))
|
|
37
|
+
positive |= bool(pattern(PUSH).search(pattern(NOPUSH).sub(' ', text)))
|
|
38
|
+
return positive, negative
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def dotted(node):
|
|
42
|
+
if isinstance(node, ast.Name):
|
|
43
|
+
return node.id
|
|
44
|
+
if isinstance(node, ast.Attribute):
|
|
45
|
+
base = dotted(node.value)
|
|
46
|
+
return base + '.' + node.attr if base else ''
|
|
47
|
+
return ''
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def push_module(name):
|
|
51
|
+
return bool(set(name.split('.')) & {'apns', 'apns2', 'aioapns', 'onesignal'})
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def evidence(text):
|
|
55
|
+
try:
|
|
56
|
+
tree = ast.parse(text)
|
|
57
|
+
except (SyntaxError, ValueError):
|
|
58
|
+
return False
|
|
59
|
+
aliases = {}
|
|
60
|
+
for node in ast.walk(tree):
|
|
61
|
+
if isinstance(node, ast.Import):
|
|
62
|
+
for item in node.names:
|
|
63
|
+
aliases[item.asname or item.name.split('.')[0]] = item.name if item.asname else item.name.split('.')[0]
|
|
64
|
+
elif isinstance(node, ast.ImportFrom) and node.module:
|
|
65
|
+
for item in node.names:
|
|
66
|
+
aliases[item.asname or item.name] = node.module + '.' + item.name
|
|
67
|
+
|
|
68
|
+
def resolve(node):
|
|
69
|
+
name = dotted(node)
|
|
70
|
+
first, sep, rest = name.partition('.')
|
|
71
|
+
return aliases.get(first, '') + (sep + rest if sep else '') if first in aliases else ''
|
|
72
|
+
|
|
73
|
+
def provider_call(node, provider, names):
|
|
74
|
+
if not isinstance(node, ast.Call):
|
|
75
|
+
return False
|
|
76
|
+
path = resolve(node.func)
|
|
77
|
+
module, _, symbol = path.rpartition('.')
|
|
78
|
+
return symbol in names and (module == provider or module.startswith(provider + '.'))
|
|
79
|
+
|
|
80
|
+
def creation(node):
|
|
81
|
+
if not isinstance(node, ast.Call):
|
|
82
|
+
return False
|
|
83
|
+
module, _, symbol = resolve(node.func).rpartition('.')
|
|
84
|
+
return symbol in CLIENTS and push_module(module)
|
|
85
|
+
|
|
86
|
+
nodes = list(ast.walk(tree))
|
|
87
|
+
bindings = set()
|
|
88
|
+
for node in nodes:
|
|
89
|
+
if isinstance(node, (ast.Assign, ast.AnnAssign)) and creation(node.value):
|
|
90
|
+
targets = node.targets if isinstance(node, ast.Assign) else [node.target]
|
|
91
|
+
bindings.update(dotted(t) for t in targets if dotted(t))
|
|
92
|
+
message = send = usage = False
|
|
93
|
+
for node in nodes:
|
|
94
|
+
message |= provider_call(node, 'firebase_admin.messaging', {'Message'})
|
|
95
|
+
send |= provider_call(node, 'firebase_admin.messaging', {'send', 'send_multicast', 'send_all'})
|
|
96
|
+
if provider_call(node, 'pywebpush', {'webpush'}):
|
|
97
|
+
return True
|
|
98
|
+
if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr in {'send_notification', 'create_notification'}:
|
|
99
|
+
usage |= dotted(node.func.value) in bindings or creation(node.func.value)
|
|
100
|
+
return bool((message and send) or usage)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def audit(root, ignores=(), fail_on='HIGH'):
|
|
104
|
+
root = Path(root)
|
|
105
|
+
if not root.is_dir() or root.stat().st_mode & 0o444 == 0:
|
|
106
|
+
raise ValueError('root must be a readable directory')
|
|
107
|
+
positive = negative = prod = test = False
|
|
108
|
+
sources, claim_files = [], []
|
|
109
|
+
for path in sorted(root.rglob('*')):
|
|
110
|
+
rel = path.relative_to(root)
|
|
111
|
+
if path.is_symlink() or any(parent.is_symlink() for parent in path.parents if parent != root) or not path.is_file():
|
|
112
|
+
continue
|
|
113
|
+
if any(fnmatch.fnmatch(rel.as_posix(), glob) for glob in ignores):
|
|
114
|
+
continue
|
|
115
|
+
parts = rel.parts
|
|
116
|
+
if (rel.as_posix() == 'README.md' or 'docs' in parts) and path.suffix.lower() == '.md':
|
|
117
|
+
p, n = claims(path.read_text(encoding='utf-8'))
|
|
118
|
+
if not ('tests' in parts or 'fixtures' in parts):
|
|
119
|
+
positive |= p
|
|
120
|
+
negative |= n
|
|
121
|
+
if p or n:
|
|
122
|
+
claim_files.append(rel.as_posix())
|
|
123
|
+
if path.suffix != '.py' or any(p in {'fixtures', 'docs', 'examples'} for p in parts):
|
|
124
|
+
continue
|
|
125
|
+
is_test = 'tests' in parts or path.name.startswith('test_') or path.name.endswith('_test.py')
|
|
126
|
+
if evidence(path.read_text(encoding='utf-8')):
|
|
127
|
+
sources.append(rel.as_posix())
|
|
128
|
+
if is_test:
|
|
129
|
+
test = True
|
|
130
|
+
else:
|
|
131
|
+
prod = True
|
|
132
|
+
findings = []
|
|
133
|
+
if positive and not prod:
|
|
134
|
+
findings.append(dict(rule='documented-push-claim-false', severity='MEDIUM' if test else 'HIGH', message='Documented device delivery lacks production send evidence.'))
|
|
135
|
+
if negative and prod:
|
|
136
|
+
findings.append(dict(rule='documented-no-push-claim-false', severity='HIGH', message='Documented absence conflicts with production send evidence.'))
|
|
137
|
+
failed = any(f['severity'] == 'HIGH' or fail_on == 'MEDIUM' for f in findings)
|
|
138
|
+
return dict(verdict='FAIL' if failed else 'PASS', findings=findings, claims=claim_files, evidence=sources)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: push-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline static audit of documented device-notification delivery
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Requires-Python: >=3.9
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# push-claim-audit
|
|
12
|
+
|
|
13
|
+
Offline static auditing of documented device-notification delivery against Python source. Version 0.1.0; standard library only at runtime. Audited code is never executed. Environment files are never opened.
|
|
14
|
+
|
|
15
|
+
Install and run:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python3 -m pip install .
|
|
19
|
+
push-claim-audit /path/to/project --json
|
|
20
|
+
python3 -m push_claim_audit /path/to/project --verbose
|
|
21
|
+
python3 -m unittest discover
|
|
22
|
+
python3 -m build
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The positional directory is required. Options: `--json`, `--verbose`, repeatable `--ignore <glob>` relative to the directory, `--fail-on {HIGH,MEDIUM}` (default HIGH), and `--version`. Exit 0 means PASS, 2 means a finding meets the threshold, and 1 means a usage or filesystem error. MEDIUM findings remain visible at the default threshold.
|
|
26
|
+
|
|
27
|
+
Root README.md and Markdown files below any docs path component supply claims. Fenced blocks are excluded; inline code counts. Matching is case insensitive, expands contractions, replaces hyphens, and joins lines within paragraphs. Negative spans are removed before affirmative matching. One finding per family is emitted, at most two.
|
|
28
|
+
|
|
29
|
+
## Limitations
|
|
30
|
+
|
|
31
|
+
Only the fixed affirmative and negative templates defined in `push_claim_audit/audit.py` count as claims; arbitrary paraphrases do not. The bare word “push”, titles, dependency names, and git commands do not qualify. SMS, email, inbound hooks, framed sockets, browser event streams, GraphQL, gRPC, and MQTT are separate channels.
|
|
32
|
+
|
|
33
|
+
Evidence requires a same-module Firebase message construction and send, a pywebpush call, or an imported APNs/OneSignal client construction followed by a direct send on the bound receiver or chained constructor. Imports resolve aliases. Attribute bindings such as self.client count. Intermediate method aliases and cross-module pairs do not count. This is a syntactic check, without control-flow, runtime reachability, credential validity, or delivery guarantees. Parse-invalid modules supply no evidence. Scope shadowing and reassignment are not modeled.
|
|
34
|
+
|
|
35
|
+
Production scanning excludes tests, test-named modules, fixtures, docs, examples, and symlinks. Evidence confined to tests yields MEDIUM for an affirmative production claim. A contradictory negative claim yields HIGH only when production evidence exists, including a negative claim in test documentation. An affirmative claim without source yields HIGH; an absence claim without source is consistent. JSON includes verdict, findings, claim paths, and evidence paths.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
push_claim_audit/__init__.py,sha256=EaFsNuXjJflc6x1Z9MK1JxgbrTvHaKqmanL2neo-kRA,87
|
|
2
|
+
push_claim_audit/__main__.py,sha256=N_BSWL76u5TtWdK2lCB-DxuIVcD8TFeVFv1b0A0ef5k,1439
|
|
3
|
+
push_claim_audit/audit.py,sha256=n_xDMStEn5cy0XhB9Fw4k9pgoqBEYRDN6fCLzqtWejg,6384
|
|
4
|
+
push_claim_audit-0.1.0.dist-info/licenses/LICENSE,sha256=OXpC5Z6A2Zv093qwBmVYR1APEXi_9ZsdX5RnU4e_Q0A,1086
|
|
5
|
+
push_claim_audit-0.1.0.dist-info/METADATA,sha256=yiHbHBM2Lp8eD95dFqdyDun_ZWoYX1RRW0NTlil-vtg,2743
|
|
6
|
+
push_claim_audit-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
push_claim_audit-0.1.0.dist-info/entry_points.txt,sha256=xSOG8F0RyRV2Vu_IbHLX641DVk4LnNmgO-ESjcpjH6U,68
|
|
8
|
+
push_claim_audit-0.1.0.dist-info/top_level.txt,sha256=qimeRaEDKqNLHmiDiXI4D9g5L0zq1Nt-UoRpxA15I60,17
|
|
9
|
+
push_claim_audit-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 push-claim-audit contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
push_claim_audit
|