@@ -61,6 +61,20 @@ describe('testing GET object', () => {
61
61
expect ( S3Backend . prototype . getObject ) . toBeCalled ( )
62
62
} )
63
63
64
+ test ( 'check if RLS policies are respected: authenticated user is able to read authenticated resource without /authenticated prefix' , async ( ) => {
65
+ const response = await app ( ) . inject ( {
66
+ method : 'GET' ,
67
+ url : '/object/bucket2/authenticated/casestudy.png' ,
68
+ headers : {
69
+ authorization : `Bearer ${ process . env . AUTHENTICATED_KEY } ` ,
70
+ } ,
71
+ } )
72
+ expect ( response . statusCode ) . toBe ( 200 )
73
+ expect ( response . headers [ 'etag' ] ) . toBe ( 'abc' )
74
+ expect ( response . headers [ 'last-modified' ] ) . toBe ( 'Thu, 12 Aug 2021 16:00:00 GMT' )
75
+ expect ( S3Backend . prototype . getObject ) . toBeCalled ( )
76
+ } )
77
+
64
78
test ( 'forward 304 and If-Modified-Since/If-None-Match headers' , async ( ) => {
65
79
const mockGetObject = jest . spyOn ( S3Backend . prototype , 'getObject' )
66
80
mockGetObject . mockRejectedValue ( {
@@ -99,10 +113,48 @@ describe('testing GET object', () => {
99
113
expect ( response . headers [ 'cache-control' ] ) . toBe ( 'no-cache' )
100
114
} )
101
115
116
+ test ( 'get authenticated object info without the /authenticated prefix' , async ( ) => {
117
+ const response = await app ( ) . inject ( {
118
+ method : 'HEAD' ,
119
+ url : '/object/bucket2/authenticated/casestudy.png' ,
120
+ headers : {
121
+ authorization : `Bearer ${ process . env . AUTHENTICATED_KEY } ` ,
122
+ } ,
123
+ } )
124
+ expect ( response . statusCode ) . toBe ( 200 )
125
+ expect ( response . headers [ 'etag' ] ) . toBe ( 'abc' )
126
+ expect ( response . headers [ 'last-modified' ] ) . toBe ( 'Wed, 12 Oct 2022 11:17:02 GMT' )
127
+ expect ( response . headers [ 'content-length' ] ) . toBe ( 3746 )
128
+ expect ( response . headers [ 'cache-control' ] ) . toBe ( 'no-cache' )
129
+ } )
130
+
131
+ test ( 'cannot get authenticated object info without the /authenticated prefix if no jwt is provided' , async ( ) => {
132
+ const response = await app ( ) . inject ( {
133
+ method : 'HEAD' ,
134
+ url : '/object/bucket2/authenticated/casestudy.png' ,
135
+ } )
136
+ expect ( response . statusCode ) . toBe ( 400 )
137
+ } )
138
+
139
+ test ( 'get public object info without using the /public prefix' , async ( ) => {
140
+ const response = await app ( ) . inject ( {
141
+ method : 'HEAD' ,
142
+ url : '/object/public-bucket-2/favicon.ico' ,
143
+ headers : {
144
+ authorization : `` ,
145
+ } ,
146
+ } )
147
+ expect ( response . statusCode ) . toBe ( 200 )
148
+ expect ( response . headers [ 'etag' ] ) . toBe ( 'abc' )
149
+ expect ( response . headers [ 'last-modified' ] ) . toBe ( 'Wed, 12 Oct 2022 11:17:02 GMT' )
150
+ expect ( response . headers [ 'content-length' ] ) . toBe ( 3746 )
151
+ expect ( response . headers [ 'cache-control' ] ) . toBe ( 'no-cache' )
152
+ } )
153
+
102
154
test ( 'get public object info' , async ( ) => {
103
155
const response = await app ( ) . inject ( {
104
156
method : 'HEAD' ,
105
- url : '/object/public/public -bucket-2/favicon.ico' ,
157
+ url : '/object/public-bucket-2/favicon.ico' ,
106
158
headers : {
107
159
authorization : `` ,
108
160
} ,
@@ -158,6 +210,18 @@ describe('testing GET object', () => {
158
210
expect ( S3Backend . prototype . getObject ) . not . toHaveBeenCalled ( )
159
211
} )
160
212
213
+ test ( 'check if RLS policies are respected: anon user is not able to read authenticated resource without /authenticated prefix' , async ( ) => {
214
+ const response = await app ( ) . inject ( {
215
+ method : 'GET' ,
216
+ url : '/object/bucket2/authenticated/casestudy.png' ,
217
+ headers : {
218
+ authorization : `Bearer ${ anonKey } ` ,
219
+ } ,
220
+ } )
221
+ expect ( response . statusCode ) . toBe ( 400 )
222
+ expect ( S3Backend . prototype . getObject ) . not . toHaveBeenCalled ( )
223
+ } )
224
+
161
225
test ( 'user is not able to read a resource without Auth header' , async ( ) => {
162
226
const response = await app ( ) . inject ( {
163
227
method : 'GET' ,
@@ -167,6 +231,15 @@ describe('testing GET object', () => {
167
231
expect ( S3Backend . prototype . getObject ) . not . toHaveBeenCalled ( )
168
232
} )
169
233
234
+ test ( 'user is not able to read a resource without Auth header without the /authenticated prefix' , async ( ) => {
235
+ const response = await app ( ) . inject ( {
236
+ method : 'GET' ,
237
+ url : '/object/bucket2/authenticated/casestudy.png' ,
238
+ } )
239
+ expect ( response . statusCode ) . toBe ( 400 )
240
+ expect ( S3Backend . prototype . getObject ) . not . toHaveBeenCalled ( )
241
+ } )
242
+
170
243
test ( 'return 400 when reading a non existent object' , async ( ) => {
171
244
const response = await app ( ) . inject ( {
172
245
method : 'GET' ,
0 commit comments