Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3afce45e69 |
No files matched your search
@@ -18,13 +18,6 @@ def runs():
|
||||
|
||||
|
||||
class EnforcementTests(unittest.TestCase):
|
||||
def test_check_comparison_ignores_only_order(self):
|
||||
checks = [*enforcement.DESIRED, {'context': 'scanner', 'app_id': 15368}]
|
||||
self.assertTrue(enforcement.same_checks(checks, list(reversed(checks))))
|
||||
self.assertFalse(enforcement.same_checks(checks, checks[:-1]))
|
||||
self.assertFalse(enforcement.same_checks(checks, checks + checks[:1]))
|
||||
self.assertFalse(enforcement.same_checks(checks, [*enforcement.DESIRED, {'context': 'scanner', 'app_id': 999}]))
|
||||
|
||||
def test_preserves_security_gate_and_binds_orb_checks(self):
|
||||
before = {'required_status_checks': {'strict': False, 'contexts': ['security', 'setup'],
|
||||
'checks': [{'context': 'security', 'app_id': 15368}, {'context': 'setup', 'app_id': -1}]}}
|
||||
@@ -89,22 +82,6 @@ class EnforcementTests(unittest.TestCase):
|
||||
enforcement.enforce(plan, request)
|
||||
self.assertEqual([], state['writes'])
|
||||
|
||||
def test_github_may_reorder_required_checks_on_readback(self):
|
||||
before = {'required_status_checks': {'strict': True, 'checks': [
|
||||
*enforcement.DESIRED, {'context': 'scanner', 'app_id': 15368}]},
|
||||
'enforce_admins': {'enabled': False}, 'required_signatures': {'enabled': True}}
|
||||
plan, request, state = self.fixture(before)
|
||||
|
||||
def reordered(path, method='GET', payload=None):
|
||||
value = request(path, method, payload)
|
||||
if method == 'PATCH':
|
||||
state['before']['required_status_checks']['checks'].reverse()
|
||||
return value
|
||||
|
||||
enforcement.enforce(plan, reordered)
|
||||
self.assertTrue(state['before']['enforce_admins']['enabled'])
|
||||
self.assertEqual(before['required_signatures'], state['before']['required_signatures'])
|
||||
|
||||
def test_head_or_protection_drift_never_mutates(self):
|
||||
for field, value in [('head', 'b' * 40), ('before', {'unexpected': True})]:
|
||||
plan, request, state = self.fixture(None)
|
||||
|
||||
@@ -17,12 +17,6 @@ DESIRED = [{'context': name, 'app_id': 18001} for name in ('setup', 'verify')]
|
||||
PROFILES = {'qbit', 'core', 'frontend-core', 'frontend-material', 'repository-policy'}
|
||||
|
||||
|
||||
def same_checks(left, right):
|
||||
"""GitHub may reorder checks; retain exact bindings and duplicate counts."""
|
||||
return sorted(json.dumps(check, sort_keys=True) for check in left) == sorted(
|
||||
json.dumps(check, sort_keys=True) for check in right)
|
||||
|
||||
|
||||
def api(path, method='GET', payload=None):
|
||||
"""Use existing gh authentication; never expose response bodies on failure."""
|
||||
args = ['gh', 'api', '--method', method, path]
|
||||
@@ -130,7 +124,7 @@ def inspect(repo, branch, version, request=api):
|
||||
'required_status_checks': desired, 'changed': False, 'protection_mode': 'rulesets',
|
||||
'effective_rules': rules, 'rulesets': rulesets}
|
||||
current = (before or {}).get('required_status_checks') or {}
|
||||
ready = (current.get('strict') is True and same_checks(current.get('checks', []), desired['checks'])
|
||||
ready = (current.get('strict') is True and current.get('checks') == desired['checks']
|
||||
and (before or {}).get('enforce_admins', {}).get('enabled') is True)
|
||||
return {'repository': repo, 'branch': branch, 'head': head, 'before': before,
|
||||
'required_status_checks': desired, 'changed': not ready}
|
||||
@@ -184,7 +178,7 @@ def enforce(plan, request=api):
|
||||
request(prefix + '/protection/enforce_admins', 'POST')
|
||||
after = request(prefix + '/protection')
|
||||
actual = after['required_status_checks']
|
||||
if not actual['strict'] or not same_checks(actual['checks'], plan['required_status_checks']['checks']) or not after['enforce_admins']['enabled']:
|
||||
if not actual['strict'] or actual['checks'] != plan['required_status_checks']['checks'] or not after['enforce_admins']['enabled']:
|
||||
raise ValueError('Protection readback did not match requested gates')
|
||||
if before:
|
||||
for key, value in before.items():
|
||||
|
||||
Reference in new issue
Block a user