@@ -18,33 +18,33 @@ describe("[Integration] Create server", () => {
1818 res . send ( "Custom error handler" ) ;
1919 } ,
2020 location : "./__tests__/integration/bootstrap/server" ,
21- extensions ( ) {
22- return [
21+ extensions : ( extensions ) =>
22+ [
23+ ...extensions ,
2324 {
2425 name : "my-extension" ,
2526 extendApiMethods : {
26- myFunc ( context ) {
27+ myFunc : ( context ) => {
2728 return context . api . success ( ) ;
2829 } ,
29- myFuncWithDependencyToOtherExtension ( context ) {
30- return ( context . api as any ) . myFunc ( ) ;
30+ myFuncWithDependencyToOtherExtension : ( context ) => {
31+ return context . api . myFunc ( ) ;
3132 } ,
3233 } ,
3334 } ,
3435 {
3536 name : "my-namespaced-extension" ,
3637 isNamespaced : true ,
3738 extendApiMethods : {
38- myFunc ( context ) {
39+ myFunc : ( context ) => {
3940 return context . api . error ( ) ;
4041 } ,
41- myFuncNamespaced ( context ) {
42+ myFuncNamespaced : ( context ) => {
4243 return context . api . success ( ) ;
4344 } ,
4445 } ,
4546 } ,
46- ] ;
47- } ,
47+ ] as any ,
4848 } ,
4949 } ,
5050 } ) ;
@@ -208,4 +208,55 @@ describe("[Integration] Create server", () => {
208208 expect ( status ) . toEqual ( 200 ) ;
209209 expect ( response ) . toEqual ( apiMethodResult ) ;
210210 } ) ;
211+
212+ it ( "should accept only GET and POST methods" , async ( ) => {
213+ const getRes = await request ( app ) . get ( "/test_integration/success" ) . send ( ) ;
214+
215+ expect ( getRes . status ) . toEqual ( 200 ) ;
216+ expect ( getRes . body . message ) . toEqual ( "ok" ) ;
217+
218+ const postRes = await request ( app ) . post ( "/test_integration/success" ) . send ( ) ;
219+
220+ expect ( postRes . status ) . toEqual ( 200 ) ;
221+ expect ( postRes . body . message ) . toEqual ( "ok" ) ;
222+
223+ const putRes = await request ( app ) . put ( "/test_integration/success" ) . send ( ) ;
224+
225+ expect ( putRes . status ) . toEqual ( 405 ) ;
226+ expect ( putRes . error && putRes . error . text ) . toEqual (
227+ "Method PUT is not allowed. Please, use GET or POST method."
228+ ) ;
229+
230+ const deleteRes = await request ( app )
231+ . delete ( "/test_integration/success" )
232+ . send ( ) ;
233+
234+ expect ( deleteRes . status ) . toEqual ( 405 ) ;
235+ expect ( deleteRes . error && deleteRes . error . text ) . toEqual (
236+ "Method DELETE is not allowed. Please, use GET or POST method."
237+ ) ;
238+ } ) ;
239+
240+ describe ( "prevent XSS attacks" , ( ) => {
241+ test . each ( [
242+ [
243+ "/z--%3E%3C!--hi--%3E%3Cimg%20src=x%20onerror=alert('DOM--XSS')%3E%3C!--%3C%3C/success" ,
244+ `"z--><img src>" integration is not configured. Please, check the request path or integration configuration.` ,
245+ ] ,
246+ [
247+ "/test_integration/z--%3E%3C!--hi--%3E%3Cimg%20src=x%20onerror=alert('DOM--XSS')%3E%3C!--%3C%3C" ,
248+ `Failed to resolve apiClient or function: The function "z--><img src>" is not registered.` ,
249+ ] ,
250+ [
251+ "/test_integration/z--%3E%3C!--hi--%3E%3Cimg%20src=x%20onerror=alert('DOM--XSS')%3E%3C!--%3C%3C/success" ,
252+ `Failed to resolve apiClient or function: Extension "z--><img src>" is not namespaced or the function "success" is not available in the namespace.` ,
253+ ] ,
254+ ] ) ( "Use case: %s" , async ( maliciousUrl , expectedMessage ) => {
255+ const res = await request ( app ) . get ( maliciousUrl ) . send ( ) ;
256+ expect ( res . error && res . error . text ) . not . toContain (
257+ "z--><!--hi--><img src=x onerror=alert('DOM--XSS')><!--<<"
258+ ) ;
259+ expect ( res . error && res . error . text ) . toEqual ( expectedMessage ) ;
260+ } ) ;
261+ } ) ;
211262} ) ;
0 commit comments