@@ -115,3 +115,64 @@ describe('isStaticTrustedOrigin', () => {
115115 expect ( mainTs ) . toContain ( "import { isTrustedOrigin } from './auth/auth.server'" ) ;
116116 } ) ;
117117} ) ;
118+
119+ describe ( 'getCustomDomains (structural)' , ( ) => {
120+ it ( 'auth.server.ts should NOT filter by domainVerified in CORS domain query' , ( ) => {
121+ // Custom domains should be allowed for CORS as soon as they are configured
122+ // by an admin, not only after DNS verification completes. Vercel can serve
123+ // the trust portal before our domainVerified flag is set, causing CORS
124+ // failures on client-side API calls.
125+ const fs = require ( 'fs' ) ;
126+ const path = require ( 'path' ) ;
127+ const authServer = fs . readFileSync (
128+ path . join ( __dirname , 'auth.server.ts' ) ,
129+ 'utf-8' ,
130+ ) as string ;
131+
132+ // Extract the getCustomDomains function body
133+ const fnMatch = authServer . match (
134+ / a s y n c f u n c t i o n g e t C u s t o m D o m a i n s [ \s \S ] * ?^ } / m,
135+ ) ;
136+ expect ( fnMatch ) . toBeTruthy ( ) ;
137+ const fnBody = fnMatch ! [ 0 ] ;
138+
139+ // Must NOT require domainVerified — that flag lags behind Vercel's own verification
140+ expect ( fnBody ) . not . toContain ( 'domainVerified' ) ;
141+
142+ // Must still filter by published status
143+ expect ( fnBody ) . toContain ( "status: 'published'" ) ;
144+ } ) ;
145+
146+ it ( 'auth.server.ts getCustomDomains should have independent error handling for Redis and DB' , ( ) => {
147+ const fs = require ( 'fs' ) ;
148+ const path = require ( 'path' ) ;
149+ const authServer = fs . readFileSync (
150+ path . join ( __dirname , 'auth.server.ts' ) ,
151+ 'utf-8' ,
152+ ) as string ;
153+
154+ const fnMatch = authServer . match (
155+ / a s y n c f u n c t i o n g e t C u s t o m D o m a i n s [ \s \S ] * ?^ } / m,
156+ ) ;
157+ expect ( fnMatch ) . toBeTruthy ( ) ;
158+ const fnBody = fnMatch ! [ 0 ] ;
159+
160+ // Should have multiple try/catch blocks (Redis read, DB query, Redis write)
161+ const tryCatchCount = ( fnBody . match ( / \b t r y \s * \{ / g) || [ ] ) . length ;
162+ expect ( tryCatchCount ) . toBeGreaterThanOrEqual ( 3 ) ;
163+ } ) ;
164+ } ) ;
165+
166+ describe ( 'originCheckMiddleware (structural)' , ( ) => {
167+ it ( 'should exempt trust-access paths from origin validation' , ( ) => {
168+ const fs = require ( 'fs' ) ;
169+ const path = require ( 'path' ) ;
170+ const middleware = fs . readFileSync (
171+ path . join ( __dirname , 'origin-check.middleware.ts' ) ,
172+ 'utf-8' ,
173+ ) as string ;
174+
175+ // Trust-access endpoints are public (no auth, no cookies) — no CSRF risk
176+ expect ( middleware ) . toContain ( '/v1/trust-access' ) ;
177+ } ) ;
178+ } ) ;
0 commit comments