@@ -1570,32 +1570,34 @@ describe('Poppy middleware', () => {
15701570 extension : { unchanged : true } ,
15711571 } ;
15721572
1573- it . each ( [ '/.well-known/poppy.json' , '/.well-known/oauth-protected-resource' ] ) (
1574- 'serves %s from the Backend API artifact before authentication' ,
1575- async path => {
1576- const __experimental_getPoppyJson = vi . fn ( ) . mockResolvedValue ( metadata ) ;
1577- vi . mocked ( clerkClient ) . mockResolvedValue (
1578- Object . assign ( await clerkClient ( ) , { artifacts : { __experimental_getPoppyJson } } ) ,
1579- ) ;
1580- const middleware = clerkMiddleware ( { __experimental_poppy : true } ) ;
1581- const response = await middleware ( mockRequest ( { url : 'https://company.example' + path } ) , { } as NextFetchEvent ) ;
1582- assert ( response instanceof Response ) ;
1583- expect ( response . status ) . toBe ( 200 ) ;
1584- expect ( await response . json ( ) ) . toEqual (
1585- path === '/.well-known/poppy.json'
1586- ? metadata
1587- : {
1588- resource : 'https://company.example' ,
1589- authorization_servers : [ 'https://clerk.company.example' ] ,
1590- scopes_supported : [ 'poppy:browser-sign-in' , 'profile' ] ,
1591- bearer_methods_supported : [ 'header' ] ,
1592- } ,
1593- ) ;
1594- expect ( response . headers . get ( 'cache-control' ) ) . toBe ( 'no-store' ) ;
1595- expect ( __experimental_getPoppyJson ) . toHaveBeenCalledExactlyOnceWith ( ) ;
1596- expect ( authenticateRequestMock ) . not . toHaveBeenCalled ( ) ;
1597- } ,
1598- ) ;
1573+ it . each ( [
1574+ 'https://company.example/.well-known/poppy.json' ,
1575+ 'https://company.example/.well-known/oauth-protected-resource' ,
1576+ 'https://preview.example/.well-known/poppy.json' ,
1577+ 'https://preview.example/.well-known/oauth-protected-resource' ,
1578+ ] ) ( 'serves %s from the Backend API artifact before authentication' , async url => {
1579+ const __experimental_getPoppyJson = vi . fn ( ) . mockResolvedValue ( metadata ) ;
1580+ vi . mocked ( clerkClient ) . mockResolvedValue (
1581+ Object . assign ( await clerkClient ( ) , { artifacts : { __experimental_getPoppyJson } } ) ,
1582+ ) ;
1583+ const middleware = clerkMiddleware ( { __experimental_poppy : true } ) ;
1584+ const response = await middleware ( mockRequest ( { url } ) , { } as NextFetchEvent ) ;
1585+ assert ( response instanceof Response ) ;
1586+ expect ( response . status ) . toBe ( 200 ) ;
1587+ expect ( await response . json ( ) ) . toEqual (
1588+ url . endsWith ( '/.well-known/poppy.json' )
1589+ ? metadata
1590+ : {
1591+ resource : 'https://company.example' ,
1592+ authorization_servers : [ 'https://clerk.company.example' ] ,
1593+ scopes_supported : [ 'poppy:browser-sign-in' , 'profile' ] ,
1594+ bearer_methods_supported : [ 'header' ] ,
1595+ } ,
1596+ ) ;
1597+ expect ( response . headers . get ( 'cache-control' ) ) . toBe ( 'no-store' ) ;
1598+ expect ( __experimental_getPoppyJson ) . toHaveBeenCalledExactlyOnceWith ( ) ;
1599+ expect ( authenticateRequestMock ) . not . toHaveBeenCalled ( ) ;
1600+ } ) ;
15991601
16001602 it . each ( [
16011603 { path : '/.well-known/poppy.json' , method : 'POST' } ,
@@ -1656,20 +1658,6 @@ describe('Poppy middleware', () => {
16561658 expect ( authenticateRequestMock ) . not . toHaveBeenCalled ( ) ;
16571659 } ) ;
16581660
1659- it ( 'rejects discovery on a different Company origin' , async ( ) => {
1660- const __experimental_getPoppyJson = vi . fn ( ) . mockResolvedValue ( {
1661- ...metadata ,
1662- organization : { ...metadata . organization , domain : 'other.example' } ,
1663- } ) ;
1664- vi . mocked ( clerkClient ) . mockResolvedValue (
1665- Object . assign ( await clerkClient ( ) , { artifacts : { __experimental_getPoppyJson } } ) ,
1666- ) ;
1667- const middleware = clerkMiddleware ( { __experimental_poppy : true } ) ;
1668- await expect (
1669- middleware ( mockRequest ( { url : 'https://company.example/.well-known/poppy.json' } ) , { } as NextFetchEvent ) ,
1670- ) . rejects . toThrow ( 'configured Company origin' ) ;
1671- } ) ;
1672-
16731661 it . each ( [ '/.well-known/poppy.json' , '/.well-known/oauth-protected-resource' ] ) (
16741662 'propagates an artifact failure for %s without fabricated discovery' ,
16751663 async path => {
0 commit comments