@@ -174,6 +174,73 @@ describe("auth plugin - actions", () => {
174
174
expect ( system . fn . fetch . mock . calls [ 0 ] [ 0 ] . url )
175
175
. toEqual ( "http://google.com/authorize?q=1&myCustomParam=abc123" )
176
176
} )
177
+
178
+ it ( "should make a simple request that doesn't trigger CORS preflight" , ( ) => {
179
+
180
+ // Given
181
+ const data = {
182
+ url : "/authorize?q=1"
183
+ }
184
+ const system = {
185
+ fn : {
186
+ fetch : jest . fn ( ) . mockImplementation ( ( ) => Promise . resolve ( ) )
187
+ } ,
188
+ errActions : {
189
+ newAuthErr : ( ) => ( { } )
190
+ } ,
191
+ getConfigs : ( ) => ( { } ) ,
192
+ authSelectors : {
193
+ getConfigs : ( ) => ( {
194
+ additionalQueryStringParams : {
195
+ myCustomParam : "abc123"
196
+ }
197
+ } )
198
+ } ,
199
+ oas3Selectors : {
200
+ selectedServer : ( ) => "http://google.com" ,
201
+ serverEffectiveValue : ( ) => "http://google.com"
202
+ } ,
203
+ specSelectors : {
204
+ isOAS3 : ( ) => true ,
205
+ }
206
+ }
207
+
208
+ // When
209
+ authorizeRequest ( data ) ( system )
210
+
211
+ // Then
212
+ // source: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
213
+ const allowed_methods = [ "get" , "head" , "post" ]
214
+ const allowed_headers = [
215
+ "accept" ,
216
+ "accept-language" ,
217
+ "content-language" ,
218
+ "content-type" ,
219
+ "dpr" ,
220
+ "downlink" ,
221
+ "save-data" ,
222
+ "viewport-width" ,
223
+ "width"
224
+ ]
225
+ const allowed_types = [
226
+ "application/x-www-form-urlencoded" ,
227
+ "multipart/form-data" ,
228
+ "text/plain"
229
+ ]
230
+
231
+ expect ( system . fn . fetch . mock . calls . length ) . toEqual ( 1 )
232
+
233
+ expect ( allowed_methods )
234
+ . toContain ( system . fn . fetch . mock . calls [ 0 ] [ 0 ] . method . toLowerCase ( ) )
235
+ const reqHeaders = system . fn . fetch . mock . calls [ 0 ] [ 0 ] . headers
236
+ Object . keys ( reqHeaders ) . forEach ( header => {
237
+ expect ( allowed_headers ) . toContain ( header . toLowerCase ( ) )
238
+
239
+ if ( header . toLowerCase ( ) == "content-type" ) {
240
+ expect ( allowed_types ) . toContain ( reqHeaders [ header ] )
241
+ }
242
+ } )
243
+ } )
177
244
} )
178
245
179
246
describe ( "tokenRequest" , function ( ) {
0 commit comments