sms-claim-audit 0.1.0__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.
- sms_claim_audit-0.1.0/LICENSE +21 -0
- sms_claim_audit-0.1.0/MANIFEST.in +2 -0
- sms_claim_audit-0.1.0/PKG-INFO +41 -0
- sms_claim_audit-0.1.0/README.md +31 -0
- sms_claim_audit-0.1.0/pyproject.toml +17 -0
- sms_claim_audit-0.1.0/setup.cfg +4 -0
- sms_claim_audit-0.1.0/sms_claim_audit/__init__.py +2 -0
- sms_claim_audit-0.1.0/sms_claim_audit/__main__.py +3 -0
- sms_claim_audit-0.1.0/sms_claim_audit/audit.py +172 -0
- sms_claim_audit-0.1.0/sms_claim_audit.egg-info/PKG-INFO +41 -0
- sms_claim_audit-0.1.0/sms_claim_audit.egg-info/SOURCES.txt +18 -0
- sms_claim_audit-0.1.0/sms_claim_audit.egg-info/dependency_links.txt +1 -0
- sms_claim_audit-0.1.0/sms_claim_audit.egg-info/entry_points.txt +2 -0
- sms_claim_audit-0.1.0/sms_claim_audit.egg-info/top_level.txt +1 -0
- sms_claim_audit-0.1.0/tests/fixtures/.env +1 -0
- sms_claim_audit-0.1.0/tests/fixtures/bad/README.md +1 -0
- sms_claim_audit-0.1.0/tests/fixtures/bad/app.py +1 -0
- sms_claim_audit-0.1.0/tests/fixtures/good/README.md +1 -0
- sms_claim_audit-0.1.0/tests/fixtures/good/app.py +3 -0
- sms_claim_audit-0.1.0/tests/test_audit.py +210 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sms-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,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sms-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline static audit of documented outbound text 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
|
+
# sms-claim-audit
|
|
12
|
+
|
|
13
|
+
Version 0.1.0 audits documented text-message delivery claims against Python AST evidence. It runs offline, requires Python 3.9 or later, has no runtime dependencies, and never executes audited code or reads environment files.
|
|
14
|
+
|
|
15
|
+
Install and run:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python3 -m pip install .
|
|
19
|
+
sms-claim-audit .
|
|
20
|
+
python3 -m sms_claim_audit . --json
|
|
21
|
+
python3 -m sms_claim_audit --version
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The positional root defaults to the current directory. Options are `--json`, `--verbose` (lists evidence files), repeatable `--ignore <glob>` (relative paths), and `--fail-on {HIGH,MEDIUM}` (default HIGH). Exit codes are 0 for PASS, 2 for findings meeting the threshold, and 1 for usage or filesystem errors. JSON includes verdict, findings with rule/severity/message, production evidence, and test evidence.
|
|
25
|
+
|
|
26
|
+
## Scope and limitations
|
|
27
|
+
|
|
28
|
+
Only the fixed positive and negative phrase templates in `sms_claim_audit/audit.py` count as claims; a bare channel noun does not. Email, webhook, websocket, server-sent events, GraphQL, gRPC, MQTT, and push claims are outside scope. Root README.md and Markdown files beneath any docs path component are scanned. Inline code counts; fenced blocks do not. Matching lowercases, expands contracted negation, replaces hyphens, joins paragraph lines, and uses word boundaries. Negative spans are removed before positive matching; phrases cannot span blank paragraphs.
|
|
29
|
+
|
|
30
|
+
Evidence requires a Twilio Client creation and direct messages.create call in the same module. Imported aliases, attribute bindings, and chained calls count. An intermediate messages alias does not. Imports alone, idle clients, inbound handlers, other channels, strings, validation, and unrelated clients do not establish delivery. This static structural check does not verify credentials, reachability, runtime success, control flow, reassignment, or network delivery. Invalid Python syntax supplies no evidence.
|
|
31
|
+
|
|
32
|
+
Production scanning excludes tests, test filename patterns, fixtures, docs, examples, and symbolic links. Test evidence alone produces MEDIUM; absent production and test evidence produces HIGH for a positive claim. A negative claim contradicted by production evidence produces HIGH even in a docs page. There is at most one finding per family. Absent claims always pass. A positive claim without source fails; a negative claim without source passes.
|
|
33
|
+
|
|
34
|
+
## Development
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
python3 -m unittest discover -s tests -v
|
|
38
|
+
python3 -m build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Tests and fixtures ship in the source distribution. MIT licensed.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# sms-claim-audit
|
|
2
|
+
|
|
3
|
+
Version 0.1.0 audits documented text-message delivery claims against Python AST evidence. It runs offline, requires Python 3.9 or later, has no runtime dependencies, and never executes audited code or reads environment files.
|
|
4
|
+
|
|
5
|
+
Install and run:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
python3 -m pip install .
|
|
9
|
+
sms-claim-audit .
|
|
10
|
+
python3 -m sms_claim_audit . --json
|
|
11
|
+
python3 -m sms_claim_audit --version
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The positional root defaults to the current directory. Options are `--json`, `--verbose` (lists evidence files), repeatable `--ignore <glob>` (relative paths), and `--fail-on {HIGH,MEDIUM}` (default HIGH). Exit codes are 0 for PASS, 2 for findings meeting the threshold, and 1 for usage or filesystem errors. JSON includes verdict, findings with rule/severity/message, production evidence, and test evidence.
|
|
15
|
+
|
|
16
|
+
## Scope and limitations
|
|
17
|
+
|
|
18
|
+
Only the fixed positive and negative phrase templates in `sms_claim_audit/audit.py` count as claims; a bare channel noun does not. Email, webhook, websocket, server-sent events, GraphQL, gRPC, MQTT, and push claims are outside scope. Root README.md and Markdown files beneath any docs path component are scanned. Inline code counts; fenced blocks do not. Matching lowercases, expands contracted negation, replaces hyphens, joins paragraph lines, and uses word boundaries. Negative spans are removed before positive matching; phrases cannot span blank paragraphs.
|
|
19
|
+
|
|
20
|
+
Evidence requires a Twilio Client creation and direct messages.create call in the same module. Imported aliases, attribute bindings, and chained calls count. An intermediate messages alias does not. Imports alone, idle clients, inbound handlers, other channels, strings, validation, and unrelated clients do not establish delivery. This static structural check does not verify credentials, reachability, runtime success, control flow, reassignment, or network delivery. Invalid Python syntax supplies no evidence.
|
|
21
|
+
|
|
22
|
+
Production scanning excludes tests, test filename patterns, fixtures, docs, examples, and symbolic links. Test evidence alone produces MEDIUM; absent production and test evidence produces HIGH for a positive claim. A negative claim contradicted by production evidence produces HIGH even in a docs page. There is at most one finding per family. Absent claims always pass. A positive claim without source fails; a negative claim without source passes.
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
python3 -m unittest discover -s tests -v
|
|
28
|
+
python3 -m build
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Tests and fixtures ship in the source distribution. MIT licensed.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "sms-claim-audit"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Offline static audit of documented outbound text delivery"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
|
|
13
|
+
[project.scripts]
|
|
14
|
+
sms-claim-audit = "sms_claim_audit.audit:main"
|
|
15
|
+
|
|
16
|
+
[tool.setuptools.packages.find]
|
|
17
|
+
include = ["sms_claim_audit*"]
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"""Offline AST audit. Audited source is never imported or executed."""
|
|
2
|
+
import argparse
|
|
3
|
+
import ast
|
|
4
|
+
import fnmatch
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from . import __version__
|
|
10
|
+
|
|
11
|
+
SMS = ('support for sms', 'sms notifications', 'sms notification', 'sms messaging',
|
|
12
|
+
'sms messages', 'sms message', 'sms alerts', 'sms alert', 'sends sms',
|
|
13
|
+
'send sms', 'sms support', 'sms enabled', 'sms powered', 'sms based',
|
|
14
|
+
'supports sms', 'uses sms', 'using sms', 'over sms', 'via sms', 'with sms')
|
|
15
|
+
NOSMS = ('no sms support', 'does not support sms', 'does not send sms',
|
|
16
|
+
'does not use sms', 'sms not supported', 'no sms notifications',
|
|
17
|
+
'without sms', 'no sms')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def pattern(phrases):
|
|
21
|
+
return re.compile(r'\b(?:' + '|'.join(re.escape(p) for p in
|
|
22
|
+
sorted(phrases, key=len, reverse=True)) + r')\b')
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def normalize(text):
|
|
26
|
+
return re.sub(r'\s+', ' ', text.lower().replace("n't", ' not').replace('-', ' '))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def claims(text):
|
|
30
|
+
lines = []
|
|
31
|
+
fence = None
|
|
32
|
+
for line in text.splitlines():
|
|
33
|
+
match = re.match(r'^\s{0,3}(`{3,}|~{3,})', line)
|
|
34
|
+
if fence:
|
|
35
|
+
if match and match[1][0] == fence[0] and len(match[1]) >= len(fence):
|
|
36
|
+
fence = None
|
|
37
|
+
lines.append('')
|
|
38
|
+
elif match:
|
|
39
|
+
fence = match[1]
|
|
40
|
+
lines.append('')
|
|
41
|
+
else:
|
|
42
|
+
lines.append(line)
|
|
43
|
+
positive = negative = False
|
|
44
|
+
for paragraph in re.split(r'\n\s*\n', '\n'.join(lines)):
|
|
45
|
+
text = normalize(paragraph)
|
|
46
|
+
negative |= bool(pattern(NOSMS).search(text))
|
|
47
|
+
text = pattern(NOSMS).sub(' ', text)
|
|
48
|
+
positive |= bool(pattern(SMS).search(text))
|
|
49
|
+
return positive, negative
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def dotted(node):
|
|
53
|
+
if isinstance(node, ast.Name):
|
|
54
|
+
return node.id
|
|
55
|
+
if isinstance(node, ast.Attribute):
|
|
56
|
+
base = dotted(node.value)
|
|
57
|
+
return base + '.' + node.attr if base else None
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def evidence(text):
|
|
62
|
+
tree = ast.parse(text)
|
|
63
|
+
constructors, modules = set(), {}
|
|
64
|
+
for node in ast.walk(tree):
|
|
65
|
+
if isinstance(node, ast.ImportFrom) and node.module and 'twilio' in node.module.split('.'):
|
|
66
|
+
constructors.update(a.asname or a.name for a in node.names if a.name == 'Client')
|
|
67
|
+
elif isinstance(node, ast.Import):
|
|
68
|
+
for alias in node.names:
|
|
69
|
+
if 'twilio' in alias.name.split('.'):
|
|
70
|
+
modules[alias.asname or alias.name.split('.')[0]] = alias.name if alias.asname else alias.name.split('.')[0]
|
|
71
|
+
|
|
72
|
+
def creation(node):
|
|
73
|
+
if not isinstance(node, ast.Call):
|
|
74
|
+
return False
|
|
75
|
+
if isinstance(node.func, ast.Name):
|
|
76
|
+
return node.func.id in constructors
|
|
77
|
+
path = dotted(node.func)
|
|
78
|
+
if not path or not path.endswith('.Client'):
|
|
79
|
+
return False
|
|
80
|
+
first, *rest = path.split('.')
|
|
81
|
+
resolved = modules.get(first, '').split('.') + rest[:-1]
|
|
82
|
+
return first in modules and 'twilio' in resolved
|
|
83
|
+
|
|
84
|
+
bindings = set()
|
|
85
|
+
for node in ast.walk(tree):
|
|
86
|
+
if isinstance(node, (ast.Assign, ast.AnnAssign)) and creation(node.value):
|
|
87
|
+
targets = node.targets if isinstance(node, ast.Assign) else [node.target]
|
|
88
|
+
bindings.update(filter(None, (dotted(t) for t in targets)))
|
|
89
|
+
for node in ast.walk(tree):
|
|
90
|
+
if isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute) and node.func.attr == 'create':
|
|
91
|
+
receiver = node.func.value
|
|
92
|
+
if isinstance(receiver, ast.Attribute) and receiver.attr == 'messages':
|
|
93
|
+
if creation(receiver.value) or dotted(receiver.value) in bindings:
|
|
94
|
+
return True
|
|
95
|
+
return False
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def audit(root, ignores=()):
|
|
99
|
+
root = Path(root)
|
|
100
|
+
if not root.is_dir():
|
|
101
|
+
raise ValueError('root must be a readable directory')
|
|
102
|
+
# Force a directory read: recursive globbing can suppress permission errors.
|
|
103
|
+
list(root.iterdir())
|
|
104
|
+
positive = negative = False
|
|
105
|
+
prod, tests = [], []
|
|
106
|
+
excluded = {'fixtures', 'docs', 'examples'}
|
|
107
|
+
for path in sorted(root.rglob('*')):
|
|
108
|
+
relative = path.relative_to(root)
|
|
109
|
+
name = relative.as_posix()
|
|
110
|
+
if path.is_symlink() or any((root / Path(*relative.parts[:i])).is_symlink()
|
|
111
|
+
for i in range(1, len(relative.parts))):
|
|
112
|
+
continue
|
|
113
|
+
if any(fnmatch.fnmatchcase(name, glob) for glob in ignores):
|
|
114
|
+
continue
|
|
115
|
+
if not path.is_file():
|
|
116
|
+
continue
|
|
117
|
+
if name == 'README.md' or ('docs' in relative.parts[:-1] and path.suffix.lower() == '.md'):
|
|
118
|
+
yes, no = claims(path.read_text(encoding='utf-8'))
|
|
119
|
+
positive |= yes
|
|
120
|
+
negative |= no
|
|
121
|
+
if path.suffix != '.py' or excluded.intersection(relative.parts[:-1]):
|
|
122
|
+
continue
|
|
123
|
+
try:
|
|
124
|
+
found = evidence(path.read_text(encoding='utf-8'))
|
|
125
|
+
except (SyntaxError, UnicodeError):
|
|
126
|
+
found = False
|
|
127
|
+
if found:
|
|
128
|
+
is_test = 'tests' in relative.parts[:-1] or path.name.startswith('test_') or path.name.endswith('_test.py')
|
|
129
|
+
(tests if is_test else prod).append(name)
|
|
130
|
+
findings = []
|
|
131
|
+
if positive and not prod:
|
|
132
|
+
findings.append({'rule': 'documented-sms-claim-false',
|
|
133
|
+
'severity': 'MEDIUM' if tests else 'HIGH',
|
|
134
|
+
'message': 'Documented outbound text delivery lacks production creation and direct send evidence.'})
|
|
135
|
+
if negative and prod:
|
|
136
|
+
findings.append({'rule': 'documented-no-sms-claim-false', 'severity': 'HIGH',
|
|
137
|
+
'message': 'Documented absence of outbound text delivery contradicts production evidence.'})
|
|
138
|
+
return {'findings': findings, 'evidence': prod, 'test_evidence': tests}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def main(argv=None):
|
|
142
|
+
parser = argparse.ArgumentParser(description=__doc__)
|
|
143
|
+
parser.add_argument('root', nargs='?', default='.')
|
|
144
|
+
parser.add_argument('--json', action='store_true')
|
|
145
|
+
parser.add_argument('--verbose', action='store_true')
|
|
146
|
+
parser.add_argument('--ignore', action='append', default=[])
|
|
147
|
+
parser.add_argument('--fail-on', choices=['HIGH', 'MEDIUM'], default='HIGH')
|
|
148
|
+
parser.add_argument('--version', action='version', version=__version__)
|
|
149
|
+
try:
|
|
150
|
+
args = parser.parse_args(argv)
|
|
151
|
+
except SystemExit as exc:
|
|
152
|
+
return 0 if exc.code == 0 else 1
|
|
153
|
+
try:
|
|
154
|
+
result = audit(args.root, args.ignore)
|
|
155
|
+
except (OSError, ValueError) as exc:
|
|
156
|
+
if args.json:
|
|
157
|
+
print(json.dumps({'error': str(exc)}))
|
|
158
|
+
else:
|
|
159
|
+
print('Error: ' + str(exc))
|
|
160
|
+
return 1
|
|
161
|
+
failed = any(f['severity'] == 'HIGH' or args.fail_on == 'MEDIUM' for f in result['findings'])
|
|
162
|
+
result['verdict'] = 'FAIL' if failed else 'PASS'
|
|
163
|
+
if args.json:
|
|
164
|
+
print(json.dumps(result))
|
|
165
|
+
else:
|
|
166
|
+
print(result['verdict'])
|
|
167
|
+
for finding in result['findings']:
|
|
168
|
+
print('{severity} {rule}: {message}'.format(**finding))
|
|
169
|
+
if args.verbose:
|
|
170
|
+
print('Production evidence: ' + ', '.join(result['evidence']))
|
|
171
|
+
print('Test evidence: ' + ', '.join(result['test_evidence']))
|
|
172
|
+
return 2 if failed else 0
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sms-claim-audit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Offline static audit of documented outbound text 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
|
+
# sms-claim-audit
|
|
12
|
+
|
|
13
|
+
Version 0.1.0 audits documented text-message delivery claims against Python AST evidence. It runs offline, requires Python 3.9 or later, has no runtime dependencies, and never executes audited code or reads environment files.
|
|
14
|
+
|
|
15
|
+
Install and run:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
python3 -m pip install .
|
|
19
|
+
sms-claim-audit .
|
|
20
|
+
python3 -m sms_claim_audit . --json
|
|
21
|
+
python3 -m sms_claim_audit --version
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The positional root defaults to the current directory. Options are `--json`, `--verbose` (lists evidence files), repeatable `--ignore <glob>` (relative paths), and `--fail-on {HIGH,MEDIUM}` (default HIGH). Exit codes are 0 for PASS, 2 for findings meeting the threshold, and 1 for usage or filesystem errors. JSON includes verdict, findings with rule/severity/message, production evidence, and test evidence.
|
|
25
|
+
|
|
26
|
+
## Scope and limitations
|
|
27
|
+
|
|
28
|
+
Only the fixed positive and negative phrase templates in `sms_claim_audit/audit.py` count as claims; a bare channel noun does not. Email, webhook, websocket, server-sent events, GraphQL, gRPC, MQTT, and push claims are outside scope. Root README.md and Markdown files beneath any docs path component are scanned. Inline code counts; fenced blocks do not. Matching lowercases, expands contracted negation, replaces hyphens, joins paragraph lines, and uses word boundaries. Negative spans are removed before positive matching; phrases cannot span blank paragraphs.
|
|
29
|
+
|
|
30
|
+
Evidence requires a Twilio Client creation and direct messages.create call in the same module. Imported aliases, attribute bindings, and chained calls count. An intermediate messages alias does not. Imports alone, idle clients, inbound handlers, other channels, strings, validation, and unrelated clients do not establish delivery. This static structural check does not verify credentials, reachability, runtime success, control flow, reassignment, or network delivery. Invalid Python syntax supplies no evidence.
|
|
31
|
+
|
|
32
|
+
Production scanning excludes tests, test filename patterns, fixtures, docs, examples, and symbolic links. Test evidence alone produces MEDIUM; absent production and test evidence produces HIGH for a positive claim. A negative claim contradicted by production evidence produces HIGH even in a docs page. There is at most one finding per family. Absent claims always pass. A positive claim without source fails; a negative claim without source passes.
|
|
33
|
+
|
|
34
|
+
## Development
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
python3 -m unittest discover -s tests -v
|
|
38
|
+
python3 -m build
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Tests and fixtures ship in the source distribution. MIT licensed.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
sms_claim_audit/__init__.py
|
|
6
|
+
sms_claim_audit/__main__.py
|
|
7
|
+
sms_claim_audit/audit.py
|
|
8
|
+
sms_claim_audit.egg-info/PKG-INFO
|
|
9
|
+
sms_claim_audit.egg-info/SOURCES.txt
|
|
10
|
+
sms_claim_audit.egg-info/dependency_links.txt
|
|
11
|
+
sms_claim_audit.egg-info/entry_points.txt
|
|
12
|
+
sms_claim_audit.egg-info/top_level.txt
|
|
13
|
+
tests/test_audit.py
|
|
14
|
+
tests/fixtures/.env
|
|
15
|
+
tests/fixtures/bad/README.md
|
|
16
|
+
tests/fixtures/bad/app.py
|
|
17
|
+
tests/fixtures/good/README.md
|
|
18
|
+
tests/fixtures/good/app.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sms_claim_audit
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
MARKER_ONLY
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sms notifications
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import twilio.rest
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sms notifications
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import contextlib
|
|
2
|
+
import io
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import re
|
|
6
|
+
import tempfile
|
|
7
|
+
import unittest
|
|
8
|
+
from unittest.mock import patch
|
|
9
|
+
|
|
10
|
+
from sms_claim_audit.audit import SMS, NOSMS, audit, claims, main, normalize, pattern
|
|
11
|
+
|
|
12
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
13
|
+
GOOD = 'from twilio.rest import Client\nc = Client()\nc.messages.create(body="hello")\n'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AuditTests(unittest.TestCase):
|
|
17
|
+
def setUp(self):
|
|
18
|
+
self.temp = tempfile.TemporaryDirectory()
|
|
19
|
+
self.addCleanup(self.temp.cleanup)
|
|
20
|
+
self.root = Path(self.temp.name)
|
|
21
|
+
|
|
22
|
+
def write(self, name, text):
|
|
23
|
+
path = self.root / name
|
|
24
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
25
|
+
path.write_text(text)
|
|
26
|
+
|
|
27
|
+
def cli(self, *args):
|
|
28
|
+
output = io.StringIO()
|
|
29
|
+
with contextlib.redirect_stdout(output), contextlib.redirect_stderr(io.StringIO()):
|
|
30
|
+
code = main([str(self.root), *args])
|
|
31
|
+
return code, output.getvalue()
|
|
32
|
+
|
|
33
|
+
def case(self, claim='sms notifications', source=GOOD, severity=None, rule='documented-sms-claim-false'):
|
|
34
|
+
self.write('README.md', claim)
|
|
35
|
+
if source is not None:
|
|
36
|
+
self.write('app.py', source)
|
|
37
|
+
code, output = self.cli('--json')
|
|
38
|
+
result = json.loads(output)
|
|
39
|
+
self.assertEqual(code, 2 if severity == 'HIGH' else 0)
|
|
40
|
+
self.assertEqual(result['verdict'], 'FAIL' if severity == 'HIGH' else 'PASS')
|
|
41
|
+
self.assertEqual([(f['rule'], f['severity']) for f in result['findings']],
|
|
42
|
+
[(rule, severity)] if severity else [])
|
|
43
|
+
|
|
44
|
+
def test_01_plain(self):
|
|
45
|
+
self.case()
|
|
46
|
+
|
|
47
|
+
def test_02_module_alias(self):
|
|
48
|
+
self.case('sms support', 'import twilio.rest as tr\nc=tr.Client()\nc.messages.create()')
|
|
49
|
+
|
|
50
|
+
def test_03_attribute_path(self):
|
|
51
|
+
self.case('uses sms', 'import twilio\nc=twilio.rest.Client()\nc.messages.create()')
|
|
52
|
+
|
|
53
|
+
def test_04_chained(self):
|
|
54
|
+
self.case('sends sms', 'from twilio.rest import Client\nClient().messages.create()')
|
|
55
|
+
|
|
56
|
+
def test_05_self(self):
|
|
57
|
+
self.case('sms alerts', 'from twilio.rest import Client\nclass Sender:\n def go(self):\n self.client=Client()\n self.client.messages.create()')
|
|
58
|
+
|
|
59
|
+
def test_06_from_alias(self):
|
|
60
|
+
self.case('supports sms', 'from twilio.rest import Client as TwilioClient\nc=TwilioClient()\nc.messages.create()')
|
|
61
|
+
|
|
62
|
+
def test_07_import_only(self):
|
|
63
|
+
self.case(source='import twilio.rest', severity='HIGH')
|
|
64
|
+
|
|
65
|
+
def test_08_creation_only(self):
|
|
66
|
+
self.case(source='from twilio.rest import Client\nc=Client()', severity='HIGH')
|
|
67
|
+
|
|
68
|
+
def test_09_unbound(self):
|
|
69
|
+
self.case(source='client.messages.create()', severity='HIGH')
|
|
70
|
+
|
|
71
|
+
def test_10_other_create(self):
|
|
72
|
+
self.case(source='from twilio.rest import Client\nc=Client()\nc.create()', severity='HIGH')
|
|
73
|
+
|
|
74
|
+
def test_11_intermediate(self):
|
|
75
|
+
self.case(source='from twilio.rest import Client\nc=Client()\nmsgs=c.messages\nmsgs.create()', severity='HIGH')
|
|
76
|
+
|
|
77
|
+
def test_12_inbound(self):
|
|
78
|
+
self.case(source='@app.post("/incoming")\ndef receive():\n return request.form["Body"]', severity='HIGH')
|
|
79
|
+
|
|
80
|
+
def test_13_email(self):
|
|
81
|
+
self.case(source='import smtplib\nsmtplib.SMTP().sendmail("a", "b", "c")', severity='HIGH')
|
|
82
|
+
|
|
83
|
+
def test_14_strings(self):
|
|
84
|
+
self.case(source='channel="sms"\nsid="AC_MARKER"\nphone="+15550000000"', severity='HIGH')
|
|
85
|
+
|
|
86
|
+
def test_15_boundary(self):
|
|
87
|
+
self.write('other.py', 'c.messages.create()')
|
|
88
|
+
self.case(source='from twilio.rest import Client\nc=Client()', severity='HIGH')
|
|
89
|
+
|
|
90
|
+
def test_16_negative(self):
|
|
91
|
+
self.case('no sms support', severity='HIGH', rule='documented-no-sms-claim-false')
|
|
92
|
+
|
|
93
|
+
def test_17_no_claim(self):
|
|
94
|
+
self.case('Delivery utilities')
|
|
95
|
+
|
|
96
|
+
def test_18_bare(self):
|
|
97
|
+
self.case('the sms chapter explains messaging', 'import twilio.rest')
|
|
98
|
+
|
|
99
|
+
def test_19_email_claim(self):
|
|
100
|
+
self.case('email notifications', 'smtp.sendmail()')
|
|
101
|
+
|
|
102
|
+
def test_20_webhook_claim(self):
|
|
103
|
+
self.case('webhook', '@app.post("/")\ndef receive():\n return "ok"')
|
|
104
|
+
|
|
105
|
+
def test_21_push_claim(self):
|
|
106
|
+
self.case('push notifications', 'push.send()')
|
|
107
|
+
|
|
108
|
+
def test_22_no_source(self):
|
|
109
|
+
self.case(source=None, severity='HIGH')
|
|
110
|
+
self.case('no sms support', None)
|
|
111
|
+
|
|
112
|
+
def test_23_tests_only(self):
|
|
113
|
+
for name in ('tests/sender.py', 'test_sender.py', 'sender_test.py'):
|
|
114
|
+
with self.subTest(name=name):
|
|
115
|
+
self.write(name, GOOD)
|
|
116
|
+
self.case(source=None, severity='MEDIUM')
|
|
117
|
+
self.assertEqual(self.cli('--fail-on', 'MEDIUM')[0], 2)
|
|
118
|
+
(self.root / name).unlink()
|
|
119
|
+
|
|
120
|
+
def test_24_fences_inline(self):
|
|
121
|
+
self.case('```text\nsms notifications\n```', None)
|
|
122
|
+
self.case('`sms notifications`', None, 'HIGH')
|
|
123
|
+
self.case('~~~\nsms notifications\n~~~', None)
|
|
124
|
+
|
|
125
|
+
def test_25_negation(self):
|
|
126
|
+
self.assertEqual(claims('does not send sms'), (False, True))
|
|
127
|
+
self.case('does not send sms', severity='HIGH', rule='documented-no-sms-claim-false')
|
|
128
|
+
|
|
129
|
+
def test_26_self(self):
|
|
130
|
+
result = audit(ROOT)
|
|
131
|
+
self.assertEqual(result['findings'], [])
|
|
132
|
+
self.assertEqual(claims((ROOT / 'README.md').read_text()), (False, False))
|
|
133
|
+
for path in ROOT.rglob('*.md'):
|
|
134
|
+
if path == ROOT / 'README.md' or 'docs' in path.relative_to(ROOT).parts[:-1]:
|
|
135
|
+
text = normalize(path.read_text())
|
|
136
|
+
self.assertIsNone(pattern(SMS + NOSMS).search(text), str(path))
|
|
137
|
+
|
|
138
|
+
def test_27_cli(self):
|
|
139
|
+
self.case()
|
|
140
|
+
self.assertEqual(self.cli('--version'), (0, '0.1.0\n'))
|
|
141
|
+
self.assertIn('app.py', self.cli('--verbose')[1])
|
|
142
|
+
self.write('docs/claim.md', 'no sms support')
|
|
143
|
+
self.assertEqual(self.cli()[0], 2)
|
|
144
|
+
self.assertEqual(self.cli('--ignore', 'docs/*')[0], 0)
|
|
145
|
+
with contextlib.redirect_stdout(io.StringIO()):
|
|
146
|
+
self.assertEqual(main([str(self.root / 'missing')]), 1)
|
|
147
|
+
self.assertEqual(self.cli('--unknown')[0], 1)
|
|
148
|
+
|
|
149
|
+
def test_28_env_guard(self):
|
|
150
|
+
self.write('.env', 'MARKER_ONLY')
|
|
151
|
+
original = Path.open
|
|
152
|
+
def guarded(path, *args, **kwargs):
|
|
153
|
+
self.assertNotEqual(path.name, '.env')
|
|
154
|
+
return original(path, *args, **kwargs)
|
|
155
|
+
with patch.object(Path, 'open', guarded):
|
|
156
|
+
self.case()
|
|
157
|
+
|
|
158
|
+
def test_29_packaging(self):
|
|
159
|
+
for path in list((ROOT / 'sms_claim_audit').glob('*.py')) + list((ROOT / 'tests').rglob('*.py')) + [ROOT / 'README.md']:
|
|
160
|
+
self.assertIsNone(re.search(r'\b' + 'py' + r'thon\b', path.read_text()), str(path))
|
|
161
|
+
metadata = (ROOT / 'pyproject.toml').read_text()
|
|
162
|
+
self.assertIn('setuptools>=77', metadata)
|
|
163
|
+
self.assertIn('license = "MIT"', metadata)
|
|
164
|
+
self.assertIn('requires-' + 'py' + 'thon = ">=3.9"', metadata)
|
|
165
|
+
self.assertIn('recursive-include tests', (ROOT / 'MANIFEST.in').read_text())
|
|
166
|
+
|
|
167
|
+
def test_30_all_phrases(self):
|
|
168
|
+
for phrase in SMS:
|
|
169
|
+
self.assertEqual(claims(phrase), (True, False), phrase)
|
|
170
|
+
for phrase in NOSMS:
|
|
171
|
+
self.assertEqual(claims(phrase), (False, True), phrase)
|
|
172
|
+
self.assertEqual(claims("doesn't send sms"), (False, True))
|
|
173
|
+
self.assertEqual(claims('SMS-\nnotifications'), (True, False))
|
|
174
|
+
self.assertEqual(claims('send\n\nsms'), (False, False))
|
|
175
|
+
self.assertEqual(claims('resend smsx'), (False, False))
|
|
176
|
+
|
|
177
|
+
def test_31_exclusions(self):
|
|
178
|
+
for name in ('fixtures/a.py', 'docs/a.py', 'examples/a.py'):
|
|
179
|
+
self.write(name, GOOD)
|
|
180
|
+
self.case(source=None, severity='HIGH')
|
|
181
|
+
self.write('outside.txt', GOOD)
|
|
182
|
+
(self.root / 'linked.py').symlink_to(self.root / 'outside.txt')
|
|
183
|
+
self.case(source=None, severity='HIGH')
|
|
184
|
+
|
|
185
|
+
def test_32_non_evidence(self):
|
|
186
|
+
for source in ('from database import Client\nc=Client()\nc.messages.create()',
|
|
187
|
+
'class Client: pass\nc=Client()\nc.messages.create()',
|
|
188
|
+
'push.send()', 'ses.send_email()', 'import re\nre.match("phone", "123")',
|
|
189
|
+
'def sms():\n print("sent")', repr(GOOD)):
|
|
190
|
+
self.case(source=source, severity='HIGH')
|
|
191
|
+
|
|
192
|
+
def test_33_both_families(self):
|
|
193
|
+
self.write('README.md', 'sms notifications.\n\nno sms support')
|
|
194
|
+
result = audit(self.root)
|
|
195
|
+
self.assertEqual(len(result['findings']), 1)
|
|
196
|
+
self.assertEqual(result['findings'][0]['rule'], 'documented-sms-claim-false')
|
|
197
|
+
|
|
198
|
+
def test_35_unreadable_root(self):
|
|
199
|
+
with patch.object(Path, 'iterdir', side_effect=PermissionError('unreadable')):
|
|
200
|
+
self.assertEqual(self.cli('--json')[0], 1)
|
|
201
|
+
|
|
202
|
+
def test_34_module_forms(self):
|
|
203
|
+
for source in ('import twilio.rest\napp.client=twilio.rest.Client()\napp.client.messages.create()',
|
|
204
|
+
'import twilio as tw\nc=tw.rest.Client()\nc.messages.create()',
|
|
205
|
+
'from vendor.twilio.rest import Client\nc: object=Client()\nc.messages.create()'):
|
|
206
|
+
self.case(source=source)
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
if __name__ == '__main__':
|
|
210
|
+
unittest.main()
|