@@ -27,6 +27,45 @@ describe("createNodeMiddleware(app)", () => {
27
27
server . close ( ) ;
28
28
29
29
expect ( response . status ) . toEqual ( 200 ) ;
30
+ expect ( response . headers . get ( "access-control-allow-origin" ) ) . toEqual ( "*" ) ;
31
+ expect ( response . headers . get ( "access-control-allow-methods" ) ) . toEqual ( "*" ) ;
32
+ expect ( response . headers . get ( "access-control-allow-headers" ) ) . toEqual (
33
+ "Content-Type, User-Agent, Authorization" ,
34
+ ) ;
35
+ } ) ;
36
+
37
+ it ( "doesn't overwrite pre-flight requests unrelated to github oauth" , async ( ) => {
38
+ const app = new OAuthApp ( {
39
+ clientId : "0123" ,
40
+ clientSecret : "0123secret" ,
41
+ } ) ;
42
+
43
+ const server = createServer ( ( req , res ) => {
44
+ if ( req . url === "/health" ) {
45
+ res . writeHead ( 200 , {
46
+ "Content-Type" : "text/plain" ,
47
+ "Access-Control-Allow-Origin" : "http://localhost:8080" ,
48
+ } ) ;
49
+ res . end ( "OK" ) ;
50
+ return ;
51
+ }
52
+ createNodeMiddleware ( app ) ;
53
+ } ) . listen ( ) ;
54
+ // @ts -expect-error complains about { port } although it's included in returned AddressInfo interface
55
+ const { port } = server . address ( ) ;
56
+
57
+ const response = await fetch ( `http://localhost:${ port } /health` , {
58
+ method : "OPTIONS" ,
59
+ } ) ;
60
+
61
+ server . close ( ) ;
62
+
63
+ expect ( response . status ) . toEqual ( 200 ) ;
64
+ expect ( response . headers . get ( "access-control-allow-origin" ) ) . toEqual (
65
+ "http://localhost:8080" ,
66
+ ) ;
67
+ expect ( response . headers . get ( "access-control-allow-methods" ) ) . toEqual ( null ) ;
68
+ expect ( response . headers . get ( "access-control-allow-headers" ) ) . toEqual ( null ) ;
30
69
} ) ;
31
70
32
71
it ( "GET /api/github/oauth/login" , async ( ) => {
0 commit comments