File tree Expand file tree Collapse file tree 6 files changed +16
-8
lines changed
tests/e2e/web/api/v1/contexts Expand file tree Collapse file tree 6 files changed +16
-8
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,11 @@ pub enum ServiceError {
111111 #[ display( fmt = "Unauthorized action." ) ]
112112 UnauthorizedAction ,
113113
114+ #[ display(
115+ fmt = "Unauthorized actions for guest users. Try logging in to check if you have permission to perform the action"
116+ ) ]
117+ UnauthorizedActionForGuests ,
118+
114119 #[ display( fmt = "This torrent already exists in our database." ) ]
115120 InfoHashAlreadyExists ,
116121
@@ -301,6 +306,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
301306 ServiceError :: InvalidCategory => StatusCode :: BAD_REQUEST ,
302307 ServiceError :: InvalidTag => StatusCode :: BAD_REQUEST ,
303308 ServiceError :: UnauthorizedAction => StatusCode :: FORBIDDEN ,
309+ ServiceError :: UnauthorizedActionForGuests => StatusCode :: UNAUTHORIZED ,
304310 ServiceError :: InfoHashAlreadyExists => StatusCode :: BAD_REQUEST ,
305311 ServiceError :: CanonicalInfoHashAlreadyExists => StatusCode :: CONFLICT ,
306312 ServiceError :: OriginalInfoHashAlreadyExists => StatusCode :: CONFLICT ,
Original file line number Diff line number Diff line change @@ -80,11 +80,13 @@ impl Service {
8080 let enforcer = self . casbin_enforcer . enforcer . read ( ) . await ;
8181
8282 let authorize = enforcer
83- . enforce ( ( role, action) )
83+ . enforce ( ( & role, action) )
8484 . map_err ( |_| ServiceError :: UnauthorizedAction ) ?;
8585
8686 if authorize {
8787 Ok ( ( ) )
88+ } else if role == UserRole :: Guest {
89+ Err ( ServiceError :: UnauthorizedActionForGuests )
8890 } else {
8991 Err ( ServiceError :: UnauthorizedAction )
9092 }
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ async fn it_should_not_allow_adding_a_new_category_to_unauthenticated_users() {
6161 } )
6262 . await ;
6363
64- assert_eq ! ( response. status, 403 ) ;
64+ assert_eq ! ( response. status, 401 ) ;
6565}
6666
6767#[ tokio:: test]
@@ -194,5 +194,5 @@ async fn it_should_not_allow_guests_to_delete_categories() {
194194 } )
195195 . await ;
196196
197- assert_eq ! ( response. status, 403 ) ;
197+ assert_eq ! ( response. status, 401 ) ;
198198}
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ async fn it_should_not_allow_adding_a_new_tag_to_unauthenticated_users() {
6363 } )
6464 . await ;
6565
66- assert_eq ! ( response. status, 403 ) ;
66+ assert_eq ! ( response. status, 401 ) ;
6767}
6868
6969#[ tokio:: test]
@@ -174,5 +174,5 @@ async fn it_should_not_allow_guests_to_delete_tags() {
174174
175175 let response = client. delete_tag ( DeleteTagForm { tag_id } ) . await ;
176176
177- assert_eq ! ( response. status, 403 ) ;
177+ assert_eq ! ( response. status, 401 ) ;
178178}
Original file line number Diff line number Diff line change @@ -442,7 +442,7 @@ mod for_guests {
442442
443443 let response = client. upload_torrent ( form. into ( ) ) . await ;
444444
445- assert_eq ! ( response. status, 403 ) ;
445+ assert_eq ! ( response. status, 401 ) ;
446446 }
447447
448448 #[ tokio:: test]
@@ -462,7 +462,7 @@ mod for_guests {
462462
463463 let response = client. delete_torrent ( & test_torrent. file_info_hash ( ) ) . await ;
464464
465- assert_eq ! ( response. status, 403 ) ;
465+ assert_eq ! ( response. status, 401 ) ;
466466 }
467467}
468468
Original file line number Diff line number Diff line change @@ -231,6 +231,6 @@ mod banned_user_list {
231231
232232 let response = client. ban_user ( Username :: new ( registered_user. username . clone ( ) ) ) . await ;
233233
234- assert_eq ! ( response. status, 403 ) ;
234+ assert_eq ! ( response. status, 401 ) ;
235235 }
236236}
You can’t perform that action at this time.
0 commit comments