1
1
import { describe } from "vitest" ;
2
- import { it , localRedirectUrl } from "../../../../../../helpers" ;
2
+ import { it } from "../../../../../../helpers" ;
3
3
import { Auth , InternalApiKey , Project , niceBackendFetch } from "../../../../../backend-helpers" ;
4
+ import { parseJson , stringifyJson } from "@stackframe/stack-shared/dist/utils/json" ;
4
5
5
6
describe ( "OAuth with wildcard domains" , ( ) => {
6
7
it ( "should work with exact domain configuration" , async ( { expect } ) => {
@@ -19,12 +20,12 @@ describe("OAuth with wildcard domains", () => {
19
20
'x-stack-admin-access-token' : adminAccessToken ,
20
21
} ,
21
22
body : {
22
- config_override_string : JSON . stringify ( {
23
+ config_override_string : stringifyJson ( {
23
24
'domains.trustedDomains.exact' : {
24
25
baseUrl : 'http://localhost:8107' ,
25
26
handlerPath : '/handler' ,
26
27
} ,
27
- 'domains.allowLocalhost' : true ,
28
+ 'domains.allowLocalhost' : false ,
28
29
} ) ,
29
30
} ,
30
31
} ) ;
@@ -51,7 +52,7 @@ describe("OAuth with wildcard domains", () => {
51
52
'x-stack-admin-access-token' : adminAccessToken ,
52
53
} ,
53
54
body : {
54
- config_override_string : JSON . stringify ( {
55
+ config_override_string : stringifyJson ( {
55
56
'domains.trustedDomains.exact' : {
56
57
baseUrl : 'https://app.example.com' ,
57
58
handlerPath : '/handler' ,
@@ -84,7 +85,7 @@ describe("OAuth with wildcard domains", () => {
84
85
'x-stack-admin-access-token' : adminAccessToken ,
85
86
} ,
86
87
body : {
87
- config_override_string : JSON . stringify ( {
88
+ config_override_string : stringifyJson ( {
88
89
'domains.trustedDomains.wildcard' : {
89
90
baseUrl : 'http://*.localhost:8107' ,
90
91
handlerPath : '/handler' ,
@@ -116,7 +117,7 @@ describe("OAuth with wildcard domains", () => {
116
117
'x-stack-admin-access-token' : adminAccessToken ,
117
118
} ,
118
119
body : {
119
- config_override_string : JSON . stringify ( {
120
+ config_override_string : stringifyJson ( {
120
121
'domains.trustedDomains.wildcard' : {
121
122
baseUrl : 'https://*.example.com' ,
122
123
handlerPath : '/handler' ,
@@ -149,7 +150,7 @@ describe("OAuth with wildcard domains", () => {
149
150
'x-stack-admin-access-token' : adminAccessToken ,
150
151
} ,
151
152
body : {
152
- config_override_string : JSON . stringify ( {
153
+ config_override_string : stringifyJson ( {
153
154
'domains.trustedDomains.double' : {
154
155
baseUrl : 'http://**.localhost:8107' ,
155
156
handlerPath : '/handler' ,
@@ -181,7 +182,7 @@ describe("OAuth with wildcard domains", () => {
181
182
'x-stack-admin-access-token' : adminAccessToken ,
182
183
} ,
183
184
body : {
184
- config_override_string : JSON . stringify ( {
185
+ config_override_string : stringifyJson ( {
185
186
'domains.trustedDomains.double' : {
186
187
baseUrl : 'https://**.example.org' , // Different TLD - won't match localhost
187
188
handlerPath : '/handler' ,
@@ -214,7 +215,7 @@ describe("OAuth with wildcard domains", () => {
214
215
'x-stack-admin-access-token' : adminAccessToken ,
215
216
} ,
216
217
body : {
217
- config_override_string : JSON . stringify ( {
218
+ config_override_string : stringifyJson ( {
218
219
'domains.trustedDomains.prefix' : {
219
220
baseUrl : 'http://local*:8107' , // Should match localhost
220
221
handlerPath : '/handler' ,
@@ -246,7 +247,7 @@ describe("OAuth with wildcard domains", () => {
246
247
'x-stack-admin-access-token' : adminAccessToken ,
247
248
} ,
248
249
body : {
249
- config_override_string : JSON . stringify ( {
250
+ config_override_string : stringifyJson ( {
250
251
'domains.trustedDomains.prefix' : {
251
252
baseUrl : 'http://api-*:8107' , // Won't match localhost
252
253
handlerPath : '/handler' ,
@@ -269,7 +270,6 @@ describe("OAuth with wildcard domains", () => {
269
270
oauth_providers : [ { id : "spotify" , type : "shared" } ] ,
270
271
}
271
272
} ) ;
272
- } ) ;
273
273
await InternalApiKey . createAndSetProjectKeys ( ) ;
274
274
// Configure multiple domains, only one matches
275
275
const configResponse = await niceBackendFetch ( "/api/v1/internal/config/override" , {
@@ -279,7 +279,7 @@ describe("OAuth with wildcard domains", () => {
279
279
'x-stack-admin-access-token' : adminAccessToken ,
280
280
} ,
281
281
body : {
282
- config_override_string : JSON . stringify ( {
282
+ config_override_string : stringifyJson ( {
283
283
'domains.trustedDomains.prod' : {
284
284
baseUrl : 'https://app.production.com' ,
285
285
handlerPath : '/handler' ,
@@ -308,7 +308,7 @@ describe("OAuth with wildcard domains", () => {
308
308
} ) ;
309
309
expect ( getResponse . status ) . toBe ( 200 ) ;
310
310
311
- const config = JSON . parse ( getResponse . body . config_string ) ;
311
+ const config = parseJson ( getResponse . body . config_string ) ;
312
312
expect ( Object . keys ( config . domains . trustedDomains ) . length ) . toBe ( 3 ) ;
313
313
} ) ;
314
314
} ) ;
0 commit comments