import { ensureNoUnsafeProperties } from './ensure_no_unsafe_properties' ; test ( `fails on circular references` , ( ) => { const foo = { } ; foo . myself = foo ; expect ( ( ) => ensureNoUnsafeProperties ( { payload : foo , } ) ) . toThrowErrorMatchingInlineSnapshot ( `"circular reference detected"` ) ; } ) ; [ { foo : true , bar : '__proto__' , baz : 1.1 , qux : undefined , quux : ( ) => null , quuz : Object . create ( null ) , } , { foo : { foo : true , bar : '__proto__' , baz : 1.1 , qux : undefined , quux : ( ) => null , quuz : Object . create ( null ) , } , } , { constructor : { foo : { prototype : null } } } , { prototype : { foo : { constructor : null } } } , ] . forEach ( ( value ) => { [ 'headers' , 'payload' , 'query' , 'params' ] . forEach ( ( property ) => { const obj = { [ property ] : value , } ; test ( `can submit ${ JSON . stringify ( obj ) }` , ( ) => { expect ( ( ) => ensureNoUnsafeProperties ( obj ) ) . not . toThrowError ( ) ; } ) ; } ) ; } ) ; [ JSON . parse ( `{ "__proto__": null }` ) , JSON . parse ( `{ "foo": { "__proto__": true } }` ) , JSON . parse ( `{ "foo": { "bar": { "__proto__": {} } } }` ) , JSON . parse ( `{ "constructor": { "prototype" : null } }` ) , JSON . parse ( `{ "foo": { "constructor": { "prototype" : null } } }` ) , JSON . parse ( `{ "foo": { "bar": { "constructor": { "prototype" : null } } } }` ) , ] . forEach ( ( value ) => { test ( `can't submit ${ JSON . stringify ( value ) }` , ( ) => { expect ( ( ) => ensureNoUnsafeProperties ( value ) ) . toThrowErrorMatchingSnapshot ( ) ; } ) ; } ) ;