33 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44
55import http from 'http' ;
6- import { createTestServer , TestServerInstance } from '../support/helpers/test-server' ;
6+ import {
7+ createTestServer ,
8+ TestServerInstance ,
9+ } from '../support/helpers/test-server' ;
710
811const Client = require ( '../client' ) ( ) ;
912const packageJson = require ( '../../package.json' ) ;
1013
1114let server : TestServerInstance ;
1215
1316beforeAll ( async ( ) => {
14- server = await createTestServer ( ) ;
17+ server = await createTestServer ( {
18+ configOverrides : {
19+ corsOrigin : [ 'http://foo' , 'http://bar' ] ,
20+ } ,
21+ } ) ;
1522} , 120000 ) ;
1623
1724afterAll ( async ( ) => {
@@ -29,7 +36,12 @@ const testVersions = [
2936function httpGet (
3037 url : string ,
3138 options ?: { headers ?: Record < string , string > }
32- ) : Promise < { statusCode : number ; headers : http . IncomingHttpHeaders ; body : string ; json : ( ) => any } > {
39+ ) : Promise < {
40+ statusCode : number ;
41+ headers : http . IncomingHttpHeaders ;
42+ body : string ;
43+ json : ( ) => any ;
44+ } > {
3345 return new Promise ( ( resolve , reject ) => {
3446 const parsed = new URL ( url ) ;
3547 const req = http . get (
@@ -41,7 +53,9 @@ function httpGet(
4153 } ,
4254 ( res ) => {
4355 let data = '' ;
44- res . on ( 'data' , ( chunk ) => { data += chunk ; } ) ;
56+ res . on ( 'data' , ( chunk ) => {
57+ data += chunk ;
58+ } ) ;
4559 res . on ( 'end' , ( ) => {
4660 resolve ( {
4761 statusCode : res . statusCode ?? 0 ,
@@ -60,7 +74,11 @@ function httpPost(
6074 url : string ,
6175 payload : any ,
6276 headers ?: Record < string , string >
63- ) : Promise < { statusCode : number ; headers : http . IncomingHttpHeaders ; body : string } > {
77+ ) : Promise < {
78+ statusCode : number ;
79+ headers : http . IncomingHttpHeaders ;
80+ body : string ;
81+ } > {
6482 return new Promise ( ( resolve , reject ) => {
6583 const parsed = new URL ( url ) ;
6684 const body = JSON . stringify ( payload ) ;
@@ -78,7 +96,9 @@ function httpPost(
7896 } ,
7997 ( res ) => {
8098 let data = '' ;
81- res . on ( 'data' , ( chunk ) => { data += chunk ; } ) ;
99+ res . on ( 'data' , ( chunk ) => {
100+ data += chunk ;
101+ } ) ;
82102 res . on ( 'end' , ( ) => {
83103 resolve ( {
84104 statusCode : res . statusCode ?? 0 ,
@@ -144,7 +164,9 @@ describe.each(testVersions)(
144164 const res = await httpGet ( `${ server . publicUrl } /` , {
145165 headers : { Origin : randomAllowedOrigin } ,
146166 } ) ;
147- expect ( res . headers [ 'access-control-allow-origin' ] ) . toBe ( randomAllowedOrigin ) ;
167+ expect ( res . headers [ 'access-control-allow-origin' ] ) . toBe (
168+ randomAllowedOrigin
169+ ) ;
148170 } ) ;
149171
150172 it ( 'returns no Access-Control-Allow-Origin with not whitelisted Origin' , async ( ) => {
@@ -171,7 +193,11 @@ describe.each(testVersions)(
171193 const email = server . uniqueEmail ( ) ;
172194 const password = 'allyourbasearebelongtous' ;
173195 const client = await Client . createAndVerify (
174- server . publicUrl , email , password , server . mailbox , testOptions
196+ server . publicUrl ,
197+ email ,
198+ password ,
199+ server . mailbox ,
200+ testOptions
175201 ) ;
176202
177203 await client . login ( ) ;
@@ -181,7 +207,7 @@ describe.each(testVersions)(
181207 ) ;
182208
183209 const res = await httpGet ( url , {
184- headers : { ' Authorization' : `Hawk id="${ token . id } "` } ,
210+ headers : { Authorization : `Hawk id="${ token . id } "` } ,
185211 } ) ;
186212 const now = + new Date ( ) / 1000 ;
187213 expect ( Number ( res . headers . timestamp ) ) . toBeGreaterThan ( now - 60 ) ;
@@ -226,22 +252,34 @@ describe.each(testVersions)(
226252 'GET' ,
227253 server . publicUrl + '/.well-known/browserid'
228254 ) ;
229- expect ( Object . prototype . hasOwnProperty . call ( doc , 'public-key' ) ) . toBe ( true ) ;
255+ expect ( Object . prototype . hasOwnProperty . call ( doc , 'public-key' ) ) . toBe (
256+ true
257+ ) ;
230258 expect ( / ^ [ 0 - 9 ] + $ / . test ( doc [ 'public-key' ] . n ) ) . toBe ( true ) ;
231259 expect ( / ^ [ 0 - 9 ] + $ / . test ( doc [ 'public-key' ] . e ) ) . toBe ( true ) ;
232- expect ( Object . prototype . hasOwnProperty . call ( doc , 'authentication' ) ) . toBe ( true ) ;
233- expect ( Object . prototype . hasOwnProperty . call ( doc , 'provisioning' ) ) . toBe ( true ) ;
260+ expect ( Object . prototype . hasOwnProperty . call ( doc , 'authentication' ) ) . toBe (
261+ true
262+ ) ;
263+ expect ( Object . prototype . hasOwnProperty . call ( doc , 'provisioning' ) ) . toBe (
264+ true
265+ ) ;
234266 expect ( doc . keys . length ) . toBe ( 1 ) ;
235267 } ) ;
236268
237269 it ( 'ignores fail on hawk payload mismatch' , async ( ) => {
238270 const email = server . uniqueEmail ( ) ;
239271 const password = 'allyourbasearebelongtous' ;
240272 const client = await Client . createAndVerify (
241- server . publicUrl , email , password , server . mailbox , testOptions
273+ server . publicUrl ,
274+ email ,
275+ password ,
276+ server . mailbox ,
277+ testOptions
242278 ) ;
243279
244- const token = await client . api . Token . SessionToken . fromHex ( client . sessionToken ) ;
280+ const token = await client . api . Token . SessionToken . fromHex (
281+ client . sessionToken
282+ ) ;
245283 const url = `${ client . api . baseURL } /account/device` ;
246284 const payload : any = {
247285 name : 'my cool device' ,
@@ -250,7 +288,7 @@ describe.each(testVersions)(
250288
251289 payload . name = 'my stealthily-changed device name' ;
252290 const res = await httpPost ( url , payload , {
253- ' Authorization' : `Hawk id="${ token . id } "` ,
291+ Authorization : `Hawk id="${ token . id } "` ,
254292 } ) ;
255293 expect ( res . statusCode ) . toBe ( 200 ) ;
256294 } ) ;
0 commit comments