@@ -10,6 +10,85 @@ import { getDatabaseAdapter } from '../utils/testHelper'
1010import { RoleEnum } from 'generated/wabe'
1111
1212describe ( 'Server' , ( ) => {
13+ it ( 'should throw error if no jwt secret provided but cookie session choosen' , async ( ) => {
14+ const databaseId = uuid ( )
15+
16+ const port = await getPort ( )
17+ const wabe = new Wabe ( {
18+ isProduction : false ,
19+ rootKey :
20+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc' ,
21+ database : {
22+ // @ts -expect-error
23+ adapter : await getDatabaseAdapter ( databaseId ) ,
24+ } ,
25+ port,
26+ authentication : {
27+ // @ts -expect-error
28+ session : {
29+ cookieSession : true ,
30+ } ,
31+ } ,
32+ routes : [
33+ {
34+ handler : ( ctx ) => ctx . res . send ( 'Hello World!' ) ,
35+ path : '/hello' ,
36+ method : 'GET' ,
37+ } ,
38+ ] ,
39+ schema : {
40+ classes : [
41+ {
42+ name : 'Collection1' ,
43+ fields : { name : { type : 'String' } } ,
44+ } ,
45+ ] ,
46+ } ,
47+ } )
48+
49+ expect ( wabe . start ( ) ) . rejects . toThrow (
50+ 'Authentication with cookie needs jwt secret' ,
51+ )
52+ } )
53+
54+ it ( 'should throw error if no jwt secret provided but csrf protection is enabled' , async ( ) => {
55+ const databaseId = uuid ( )
56+
57+ const port = await getPort ( )
58+ const wabe = new Wabe ( {
59+ isProduction : false ,
60+ rootKey :
61+ 'eIUbb9abFa8PJGRfRwgiGSCU0fGnLErph2QYjigDRjLsbyNA3fZJ8Npd0FJNzxAc' ,
62+ database : {
63+ // @ts -expect-error
64+ adapter : await getDatabaseAdapter ( databaseId ) ,
65+ } ,
66+ port,
67+ security : {
68+ disableCSRFProtection : false ,
69+ } ,
70+ routes : [
71+ {
72+ handler : ( ctx ) => ctx . res . send ( 'Hello World!' ) ,
73+ path : '/hello' ,
74+ method : 'GET' ,
75+ } ,
76+ ] ,
77+ schema : {
78+ classes : [
79+ {
80+ name : 'Collection1' ,
81+ fields : { name : { type : 'String' } } ,
82+ } ,
83+ ] ,
84+ } ,
85+ } )
86+
87+ expect ( wabe . start ( ) ) . rejects . toThrow (
88+ 'Authentication with cookie needs jwt secret' ,
89+ )
90+ } )
91+
1392 it ( 'should mask graphql errors message' , async ( ) => {
1493 spyOn ( console , 'error' ) . mockReturnValue ( )
1594 const databaseId = uuid ( )
@@ -25,6 +104,7 @@ describe('Server', () => {
25104 } ,
26105 security : {
27106 hideSensitiveErrorMessage : true ,
107+ disableCSRFProtection : true ,
28108 } ,
29109 port,
30110 schema : {
@@ -68,6 +148,9 @@ describe('Server', () => {
68148 // @ts -expect-error
69149 adapter : await getDatabaseAdapter ( databaseId ) ,
70150 } ,
151+ security : {
152+ disableCSRFProtection : true ,
153+ } ,
71154 port,
72155 routes : [
73156 {
@@ -105,6 +188,9 @@ describe('Server', () => {
105188 // @ts -expect-error
106189 adapter : await getDatabaseAdapter ( databaseId ) ,
107190 } ,
191+ security : {
192+ disableCSRFProtection : true ,
193+ } ,
108194 port,
109195 schema : {
110196 classes : [
@@ -158,6 +244,9 @@ describe('Server', () => {
158244 // @ts -expect-error
159245 adapter : await getDatabaseAdapter ( databaseId ) ,
160246 } ,
247+ security : {
248+ disableCSRFProtection : true ,
249+ } ,
161250 port,
162251 schema : {
163252 classes : [
@@ -191,6 +280,9 @@ describe('Server', () => {
191280 adapter : await getDatabaseAdapter ( databaseId ) ,
192281 } ,
193282 port,
283+ security : {
284+ disableCSRFProtection : true ,
285+ } ,
194286 schema : {
195287 classes : [
196288 {
@@ -223,6 +315,9 @@ describe('Server', () => {
223315 // @ts -expect-error
224316 adapter : await getDatabaseAdapter ( databaseId ) ,
225317 } ,
318+ security : {
319+ disableCSRFProtection : true ,
320+ } ,
226321 port,
227322 hooks : [
228323 {
@@ -244,6 +339,9 @@ describe('Server', () => {
244339 // @ts -expect-error
245340 adapter : await getDatabaseAdapter ( databaseId ) ,
246341 } ,
342+ security : {
343+ disableCSRFProtection : true ,
344+ } ,
247345 port,
248346 hooks : [ ] ,
249347 } ) ,
@@ -260,6 +358,9 @@ describe('Server', () => {
260358 adapter : await getDatabaseAdapter ( databaseId ) ,
261359 } ,
262360 port,
361+ security : {
362+ disableCSRFProtection : true ,
363+ } ,
263364 hooks : [
264365 {
265366 operationType : OperationType . BeforeCreate ,
@@ -284,6 +385,9 @@ describe('Server', () => {
284385 adapter : await getDatabaseAdapter ( databaseId ) ,
285386 } ,
286387 port,
388+ security : {
389+ disableCSRFProtection : true ,
390+ } ,
287391 } )
288392
289393 await wabe . start ( )
@@ -311,6 +415,9 @@ describe('Server', () => {
311415 adapter : await getDatabaseAdapter ( databaseId ) ,
312416 } ,
313417 port,
418+ security : {
419+ disableCSRFProtection : true ,
420+ } ,
314421 schema : {
315422 classes : [
316423 {
@@ -350,6 +457,9 @@ describe('Server', () => {
350457 adapter : await getDatabaseAdapter ( databaseId ) ,
351458 } ,
352459 port,
460+ security : {
461+ disableCSRFProtection : true ,
462+ } ,
353463 schema : {
354464 classes : [
355465 {
@@ -396,6 +506,9 @@ describe('Server', () => {
396506 roles : [ 'Client' ] ,
397507 } ,
398508 port,
509+ security : {
510+ disableCSRFProtection : true ,
511+ } ,
399512 } )
400513
401514 await wabeMain . start ( )
@@ -424,6 +537,9 @@ describe('Server', () => {
424537 }
425538 } ,
426539 } ,
540+ security : {
541+ disableCSRFProtection : true ,
542+ } ,
427543 schema : {
428544 classes : [
429545 {
0 commit comments