Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ All notable changes to this project are documented here. The format follows
retried meanwhile, was still executed afterwards: the resource was created behind Terraform's back and the retry
failed with "already exists" (`BucketAlreadyExists`, `ResourceInUseException`). keepstack now checks that the client
is still connected before running a request that waited.
- Route 53 zone IDs that came out without digits (`ZSOVGDZPSPRJKSM`) were not recognized as generated, so they were
not translated after a restart and Terraform saw the zone as deleted (intermittent).

### Added
- `scripts/chaos.py` and a nightly workflow: kill the emulator, keepstack, or everything at once in the middle of
Expand Down
9 changes: 8 additions & 1 deletion src/keepstack/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ def same_name_new_suffix(a, b):
return bool(pa) and pa == pb and ta != tb and len(ta) == len(tb) >= 6 and ta.isalnum() and tb.isalnum()


def same_shape_new_id(a, b):
"""ZSOVGDZPSPRJKSM vs Z3LV898WM8KOB1A: a random uppercase ID that came out without digits, which id_like() cannot
tell from a word. Both responses answer the same request, so a long code that changed is generated."""
return a != b and len(a) == len(b) >= 12 and a.isalnum() and b.isalnum() and a.isupper() and b.isupper()


def b64_blobs(data):
return [m for m in B64_RE.findall(data) if b"+" in m or m.endswith(b"=")]

Expand Down Expand Up @@ -154,7 +160,8 @@ def learn(self, orig_resp, new_resp):
pairs = []
for i, j in pairs:
if not (i and a[i - 1].lower() in REQUEST_ID_KEYS) and (
(id_like(a[i]) and id_like(b[j])) or same_name_new_suffix(a[i], b[j])):
(id_like(a[i]) and id_like(b[j])) or same_name_new_suffix(a[i], b[j])
or same_shape_new_id(a[i], b[j])):
learned += self._learn_pair(a[i], b[j])
return learned

Expand Down
15 changes: 15 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ def test_secret_suffix_in_a_single_case(self): # regression #24: SGAEFE was not
self.assertEqual(m.to_emulator(b"SecretId=demo-db-password-" + old), b"SecretId=demo-db-password-" + new)
self.assertEqual(m.to_client(b"secret:demo-db-password-" + new), b"secret:demo-db-password-" + old)

def test_route53_zone_id_without_digits(self): # regression #36: ZSOVGDZPSPRJKSM was not translated
for old, new in ((b"ZSOVGDZPSPRJKSM", b"Z3LV898WM8KOB1A"), (b"Z3LV898WM8KOB1A", b"ZQWERTYUIOPASDF")):
m = IdMap()
m.learn(b"<HostedZone><Id>/hostedzone/%s</Id><Name>demo.internal.</Name></HostedZone>" % old,
b"<HostedZone><Id>/hostedzone/%s</Id><Name>demo.internal.</Name></HostedZone>" % new)
self.assertEqual(m.to_emulator(b"/2013-04-01/hostedzone/" + old), b"/2013-04-01/hostedzone/" + new)
self.assertEqual(m.to_client(b"/hostedzone/" + new), b"/hostedzone/" + old)

def test_short_or_numeric_codes_are_not_ids(self):
m = IdMap()
# Long AWS enums use underscores; shorter codes and plain numbers are not IDs either.
m.learn(b'{"State":"CREATE_IN_PROGRESS","Alarm":"INSUFFICIENT_DATA","Code":"ABCDEFGHIJK","N":"123456789012"}',
b'{"State":"CREATE_COMPLETE_OK","Alarm":"OK_STATE_REACHED_","Code":"ZYXWVUTSRQP","N":"999999999999"}')
self.assertEqual(m.to_new, {})

def test_status_changes_are_not_suffixes(self):
# Recorded and replayed responses answer the same request, so names match; what changes between them is
# generated values and statuses. Statuses use underscores or have a different length.
Expand Down
Loading