From 0b3348bce288bb479db1e4564583540f7df9ff20 Mon Sep 17 00:00:00 2001 From: Chris van der Loo Date: Sat, 22 Aug 2026 19:59:36 -0400 Subject: [PATCH] test: pin official AT identifier syntax vectors --- src/syntax.rs | 22 ++++++++++++++- tests/fixtures/README.md | 9 ++++++ .../atproto-atidentifier-syntax-invalid.txt | 28 +++++++++++++++++++ .../atproto-atidentifier-syntax-valid.txt | 15 ++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/atproto-atidentifier-syntax-invalid.txt create mode 100644 tests/fixtures/atproto-atidentifier-syntax-valid.txt diff --git a/src/syntax.rs b/src/syntax.rs index f8478fa..4cb6189 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -104,7 +104,7 @@ pub fn record_key(value: &str) -> Result<&str> { #[cfg(test)] mod tests { - use atrium_api::types::string::Handle; + use atrium_api::types::string::{AtIdentifier, Handle}; use super::{SpaceRef, collection, did, record_key, space_ref, tid}; @@ -171,6 +171,26 @@ mod tests { } } + #[test] + fn atrium_at_identifier_validation_matches_official_syntax_fixtures() { + for value in fixture_cases(include_str!( + "../tests/fixtures/atproto-atidentifier-syntax-valid.txt" + )) { + assert!( + value.parse::().is_ok(), + "rejected valid AT identifier `{value}`" + ); + } + for value in fixture_cases(include_str!( + "../tests/fixtures/atproto-atidentifier-syntax-invalid.txt" + )) { + assert!( + value.parse::().is_err(), + "accepted invalid AT identifier `{value}`" + ); + } + } + #[test] fn atrium_nsid_validation_matches_official_syntax_fixtures() { for value in fixture_cases(include_str!( diff --git a/tests/fixtures/README.md b/tests/fixtures/README.md index 7a65942..3fde301 100644 --- a/tests/fixtures/README.md +++ b/tests/fixtures/README.md @@ -43,6 +43,15 @@ Source: The fixtures are CC0-1.0 licensed. +`atproto-atidentifier-syntax-{valid,invalid}.txt` are copied without +modification from the matching files under `syntax/` in the same official +fixture repository and commit. + +Source: + + +The fixtures are CC0-1.0 licensed. + `atproto-tid-syntax-{valid,invalid}.txt` are copied without modification from the matching files under `syntax/` in the official, implementation-neutral `bluesky-social/atproto-interop-tests` repository at diff --git a/tests/fixtures/atproto-atidentifier-syntax-invalid.txt b/tests/fixtures/atproto-atidentifier-syntax-invalid.txt new file mode 100644 index 0000000..f0f8430 --- /dev/null +++ b/tests/fixtures/atproto-atidentifier-syntax-invalid.txt @@ -0,0 +1,28 @@ + +# invalid handles +did:thing.test +did:thing +john-.test +john.0 +john.- +xn--bcher-.tld +john..test +jo_hn.test + +# invalid DIDs +did +didmethodval +method:did:val +did:method: +didmethod:val +did:methodval) +:did:method:val +did:method:val: +did:method:val% +DID:method:val + +# other invalid stuff +email@example.com +@handle@example.com +@handle +blah diff --git a/tests/fixtures/atproto-atidentifier-syntax-valid.txt b/tests/fixtures/atproto-atidentifier-syntax-valid.txt new file mode 100644 index 0000000..cc4a42b --- /dev/null +++ b/tests/fixtures/atproto-atidentifier-syntax-valid.txt @@ -0,0 +1,15 @@ + +# allows valid handles +XX.LCS.MIT.EDU +john.test +jan.test +a234567890123456789.test +john2.test +john-john.test + +# allows valid DIDs +did:method:val +did:method:VAL +did:method:val123 +did:method:123 +did:method:val-two -- knotmirror 0.0.1