fix(mobile): count every relay clock-window refusal, not only one wording

The diagnostic spec counts relay timestamp-window refusals instead of
reporting them, but isInvalidRequestRejection only excluded "timestamp too
far from server time". The relay words the same refusal several ways
(canvas events, event admission, leave requests, observer frames), so those
were reported as invalid requests. Match the full set of phrases and keep
unrelated "invalid:" reasons, such as the feedback timestamp conversion
overflow, reported.

Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
Signed-off-by: Tom Brow <tomb@block.xyz>
This commit is contained in:
Tom Brow
2026-11-20 10:33:40 -08:00
parent 7b216969e8
commit 9cdb33b831
2 changed files with 31 additions and 23 deletions

View File

@@ -55,6 +55,23 @@ class RelayInvalidRequest implements Exception {
String toString() => 'RelayInvalidRequest';
}
/// How the relay words a refusal for a timestamp outside its clock window,
/// after `invalid:`. It has one wording per kind of event: ordinary events
/// ("event timestamp too far from server time"), canvas events ("canvas event
/// timestamp too far in the future"), relay-admin, moderation and identity
/// archive commands ("event timestamp out of range: ..."), leave requests
/// ("leave request timestamp out of range (...)") and observer frames
/// ("observer frame timestamp outside ±5 minute freshness window"). Matched on
/// "timestamp" and the phrase after it, so a reason about something else that
/// merely mentions a timestamp ("feedback timestamp is out of range") is still
/// reported.
const _clockWindowRefusals = [
'timestamp too far from server time',
'timestamp too far in the future',
'timestamp out of range',
'timestamp outside',
];
/// Whether [message], a relay `OK` or `CLOSED` reason, says the app sent
/// something invalid. Refusals the app handles as expected outcomes, an
/// archived channel, an Unarchive of a channel that is no longer archived, an
@@ -75,7 +92,7 @@ bool isInvalidRequestRejection(String message) {
'invalid: only members can add people in this channel',
) &&
!normalized.startsWith('invalid: cannot remove the last owner') &&
!normalized.contains('timestamp too far from server time');
!_clockWindowRefusals.any(normalized.contains);
}
/// Explicit access refusal; cached private history must not mask this error.

View File

@@ -19,6 +19,8 @@ void main() {
// The relay's reasons for a request it refuses as invalid.
const reported = [
'invalid: bad signature',
// Mentions a timestamp, but is not about the relay's clock window.
'invalid: feedback timestamp is out of range',
// Limits.
'invalid: a DM may hold at most 9 people; agents do not count',
'invalid: content exceeds maximum size of 262144 bytes (got 262145)',
@@ -30,7 +32,13 @@ void main() {
];
// Refusals the app handles as expected outcomes, and every other reason.
const counted = [
// A timestamp outside the relay's window, in each wording the relay uses.
'invalid: event timestamp too far from server time',
'invalid: canvas event timestamp too far in the future',
'invalid: event timestamp out of range: created_at=1, now=500, '
'delta=-499s (max ±120s)',
'invalid: leave request timestamp out of range (delta=300s, max ±120s)',
'invalid: observer frame timestamp outside ±5 minute freshness window',
'rate-limited: quota exceeded; retry in 7s',
'rate-limited: too many concurrent requests',
'restricted: only members can post in this channel',
@@ -41,28 +49,12 @@ void main() {
'something the relay says in no known form',
'',
];
// The spec counts every refusal for a timestamp outside the relay's window.
// The code reports these three, whose wording differs from the one it
// recognizes, so each is skipped until the two agree.
const clockWindow = [
'invalid: canvas event timestamp too far in the future',
'invalid: event timestamp out of range: created_at=1, now=500, '
'delta=-499s (max ±120s)',
'invalid: leave request timestamp out of range (delta=300s, max ±120s)',
final rows = <(String, bool)>[
for (final reason in reported) (reason, true),
for (final reason in counted) (reason, false),
];
final rows = <(String, bool, String?)>[
for (final reason in reported) (reason, true, null),
for (final reason in counted) (reason, false, null),
for (final reason in clockWindow)
(
reason,
false,
'the code reports it; the spec says a clock-window refusal is counted',
),
];
for (final (reason, isReported, skip) in rows) {
for (final (reason, isReported) in rows) {
final expected = isReported ? 1 : 0;
test('an OK refusal "$reason" is ${isReported ? '' : 'not '}reported', () {
final harness = _session();
@@ -76,7 +68,7 @@ void main() {
expect(harness.reporter.errors.map((e) => e.$2), [
if (isReported) DiagnosticOperation.relayRejection,
]);
}, skip: skip);
});
test(
'a CLOSED refusal "$reason" is ${isReported ? '' : 'not '}reported',
@@ -89,7 +81,6 @@ void main() {
if (isReported) DiagnosticOperation.relayRejection,
]);
},
skip: skip,
);
}