File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,35 @@ async fn test_file_upload() -> actix_web::Result<()> {
156
156
Ok ( ( ) )
157
157
}
158
158
159
+ #[ actix_web:: test]
160
+ async fn test_file_upload_too_large ( ) -> actix_web:: Result < ( ) > {
161
+ // Files larger than 12345 bytes should be rejected as per the test_config
162
+ let req = get_request_to ( "/tests/upload_file_test.sql" )
163
+ . await ?
164
+ . insert_header ( ( "content-type" , "multipart/form-data; boundary=1234567890" ) )
165
+ . set_payload (
166
+ "--1234567890\r \n \
167
+ Content-Disposition: form-data; name=\" my_file\" ; filename=\" testfile.txt\" \r \n \
168
+ Content-Type: text/plain\r \n \
169
+ \r \n \
170
+ "
171
+ . to_string ( )
172
+ + "a" . repeat ( 12346 ) . as_str ( )
173
+ + "\r \n \
174
+ --1234567890--\r \n ",
175
+ )
176
+ . to_srv_request ( ) ;
177
+ let err_str = main_handler ( req)
178
+ . await
179
+ . expect_err ( "Expected an error response" )
180
+ . to_string ( ) ;
181
+ assert ! (
182
+ err_str. to_ascii_lowercase( ) . contains( "max file size" ) ,
183
+ "{err_str}\n expected to contain: File too large"
184
+ ) ;
185
+ Ok ( ( ) )
186
+ }
187
+
159
188
#[ actix_web:: test]
160
189
async fn test_csv_upload ( ) -> actix_web:: Result < ( ) > {
161
190
let req = get_request_to ( "/tests/upload_csv_test.sql" )
@@ -243,6 +272,7 @@ pub fn test_config() -> AppConfig {
243
272
"database_connection_retries": 2,
244
273
"database_connection_acquire_timeout_seconds": 10,
245
274
"allow_exec": true,
275
+ "max_uploaded_file_size": 12345,
246
276
"listen_on": "111.111.111.111:1"
247
277
}}"# ,
248
278
db_url
You can’t perform that action at this time.
0 commit comments