@@ -43,6 +43,18 @@ describe('testing GET bucket', () => {
43
43
expect ( responseJSON . id ) . toBe ( bucketId )
44
44
} )
45
45
46
+ test ( 'checking RLS: anon user is not able to get bucket details' , async ( ) => {
47
+ const bucketId = 'bucket2'
48
+ const response = await app ( ) . inject ( {
49
+ method : 'GET' ,
50
+ url : `/bucket/${ bucketId } ` ,
51
+ headers : {
52
+ authorization : `Bearer ${ anonKey } ` ,
53
+ } ,
54
+ } )
55
+ expect ( response . statusCode ) . toBe ( 400 )
56
+ } )
57
+
46
58
test ( 'user is not able to get bucket details without Auth header' , async ( ) => {
47
59
const response = await app ( ) . inject ( {
48
60
method : 'GET' ,
@@ -80,6 +92,19 @@ describe('testing GET all buckets', () => {
80
92
expect ( responseJSON . length ) . toBe ( 4 )
81
93
} )
82
94
95
+ test ( 'checking RLS: anon user is not able to get all buckets' , async ( ) => {
96
+ const response = await app ( ) . inject ( {
97
+ method : 'GET' ,
98
+ url : `/bucket` ,
99
+ headers : {
100
+ authorization : `Bearer ${ anonKey } ` ,
101
+ } ,
102
+ } )
103
+ expect ( response . statusCode ) . toBe ( 200 )
104
+ const responseJSON = JSON . parse ( response . body )
105
+ expect ( responseJSON . length ) . toBe ( 0 )
106
+ } )
107
+
83
108
test ( 'user is not able to all buckets details without Auth header' , async ( ) => {
84
109
const response = await app ( ) . inject ( {
85
110
method : 'GET' ,
@@ -108,6 +133,20 @@ describe('testing POST bucket', () => {
108
133
expect ( responseJSON . name ) . toBe ( 'newbucket' )
109
134
} )
110
135
136
+ test ( 'checking RLS: anon user is not able to create a bucket' , async ( ) => {
137
+ const response = await app ( ) . inject ( {
138
+ method : 'POST' ,
139
+ url : `/bucket` ,
140
+ headers : {
141
+ authorization : `Bearer ${ anonKey } ` ,
142
+ } ,
143
+ payload : {
144
+ name : 'newbucket1' ,
145
+ } ,
146
+ } )
147
+ expect ( response . statusCode ) . toBe ( 400 )
148
+ } )
149
+
111
150
test ( 'user is not able to create a bucket without Auth header' , async ( ) => {
112
151
const response = await app ( ) . inject ( {
113
152
method : 'POST' ,
@@ -149,6 +188,18 @@ describe('testing DELETE bucket', () => {
149
188
expect ( responseJSON . message ) . toBe ( 'Deleted' )
150
189
} )
151
190
191
+ test ( 'checking RLS: anon user is not able to delete a bucket' , async ( ) => {
192
+ const bucketId = 'bucket5'
193
+ const response = await app ( ) . inject ( {
194
+ method : 'DELETE' ,
195
+ url : `/bucket/${ bucketId } ` ,
196
+ headers : {
197
+ authorization : `Bearer ${ anonKey } ` ,
198
+ } ,
199
+ } )
200
+ expect ( response . statusCode ) . toBe ( 400 )
201
+ } )
202
+
152
203
test ( 'user is not able to delete bucket without Auth header' , async ( ) => {
153
204
const bucketId = 'bucket5'
154
205
const response = await app ( ) . inject ( {
@@ -198,6 +249,18 @@ describe('testing EMPTY bucket', () => {
198
249
expect ( responseJSON . message ) . toBe ( 'Emptied' )
199
250
} )
200
251
252
+ test ( 'user is able to delete a bucket' , async ( ) => {
253
+ const bucketId = 'bucket3'
254
+ const response = await app ( ) . inject ( {
255
+ method : 'POST' ,
256
+ url : `/bucket/${ bucketId } /empty` ,
257
+ headers : {
258
+ authorization : `Bearer ${ anonKey } ` ,
259
+ } ,
260
+ } )
261
+ expect ( response . statusCode ) . toBe ( 400 )
262
+ } )
263
+
201
264
test ( 'user is not able to empty a bucket without Auth Header' , async ( ) => {
202
265
const bucketId = 'bucket3'
203
266
const response = await app ( ) . inject ( {
@@ -216,7 +279,7 @@ describe('testing EMPTY bucket', () => {
216
279
authorization : `Bearer ${ process . env . AUTHENTICATED_KEY } ` ,
217
280
} ,
218
281
} )
219
- expect ( response . statusCode ) . toBe ( 406 )
282
+ expect ( response . statusCode ) . toBe ( 400 )
220
283
} )
221
284
222
285
test ( 'user is able to empty an already empty bucket' , async ( ) => {
0 commit comments