Skip to content

Commit 73d2013

Browse files
committed
fix: address 5 valid CodeRabbit round-9 findings
1 parent af3a140 commit 73d2013

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/synthorg/persistence/sqlite/schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,4 @@ CREATE TABLE IF NOT EXISTS ssrf_violations (
579579
CREATE INDEX IF NOT EXISTS idx_sv_status_timestamp
580580
ON ssrf_violations(status, timestamp DESC);
581581
CREATE INDEX IF NOT EXISTS idx_sv_timestamp ON ssrf_violations(timestamp);
582+
CREATE INDEX IF NOT EXISTS idx_sv_hostname ON ssrf_violations(hostname, port);

tests/unit/persistence/sqlite/test_migrations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"idx_ro_active",
112112
"idx_sv_status_timestamp",
113113
"idx_sv_timestamp",
114+
"idx_sv_hostname",
114115
}
115116

116117

tests/unit/security/test_ssrf_violation.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_allowed_violation(self) -> None:
5252
)
5353
assert v.status == SsrfViolationStatus.ALLOWED
5454
assert v.resolved_by == "user-1"
55+
assert v.resolved_at == _NOW + timedelta(minutes=5)
5556

5657
def test_denied_violation(self) -> None:
5758
v = SsrfViolation(
@@ -65,6 +66,8 @@ def test_denied_violation(self) -> None:
6566
resolved_at=_NOW + timedelta(minutes=5),
6667
)
6768
assert v.status == SsrfViolationStatus.DENIED
69+
assert v.resolved_by == "admin-1"
70+
assert v.resolved_at == _NOW + timedelta(minutes=5)
6871

6972
def test_frozen(self) -> None:
7073
v = SsrfViolation(
@@ -89,6 +92,18 @@ def test_pending_with_resolved_by_rejected(self) -> None:
8992
resolved_by="user-1",
9093
)
9194

95+
def test_pending_with_resolved_at_rejected(self) -> None:
96+
with pytest.raises(ValidationError, match="resolved_at"):
97+
SsrfViolation(
98+
id="v-bad",
99+
timestamp=_NOW,
100+
url="http://example.com:80",
101+
hostname="example.com",
102+
port=80,
103+
status=SsrfViolationStatus.PENDING,
104+
resolved_at=_NOW + timedelta(minutes=5),
105+
)
106+
92107
def test_allowed_without_resolved_by_rejected(self) -> None:
93108
with pytest.raises(ValidationError, match="resolved_by"):
94109
SsrfViolation(
@@ -100,6 +115,17 @@ def test_allowed_without_resolved_by_rejected(self) -> None:
100115
status=SsrfViolationStatus.ALLOWED,
101116
)
102117

118+
def test_denied_without_resolved_by_rejected(self) -> None:
119+
with pytest.raises(ValidationError, match="resolved_by"):
120+
SsrfViolation(
121+
id="v-bad",
122+
timestamp=_NOW,
123+
url="http://example.com:80",
124+
hostname="example.com",
125+
port=80,
126+
status=SsrfViolationStatus.DENIED,
127+
)
128+
103129
def test_port_bounds(self) -> None:
104130
with pytest.raises(ValidationError, match="port"):
105131
SsrfViolation(

0 commit comments

Comments
 (0)