File tree 6 files changed +15
-7
lines changed
tests/e2e/web/api/v1/contexts
6 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,11 @@ pub enum ServiceError {
111
111
#[ display( fmt = "Unauthorized action." ) ]
112
112
UnauthorizedAction ,
113
113
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
+
114
119
#[ display( fmt = "This torrent already exists in our database." ) ]
115
120
InfoHashAlreadyExists ,
116
121
@@ -301,6 +306,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
301
306
ServiceError :: InvalidCategory => StatusCode :: BAD_REQUEST ,
302
307
ServiceError :: InvalidTag => StatusCode :: BAD_REQUEST ,
303
308
ServiceError :: UnauthorizedAction => StatusCode :: FORBIDDEN ,
309
+ ServiceError :: UnauthorizedActionForGuests => StatusCode :: UNAUTHORIZED ,
304
310
ServiceError :: InfoHashAlreadyExists => StatusCode :: BAD_REQUEST ,
305
311
ServiceError :: CanonicalInfoHashAlreadyExists => StatusCode :: CONFLICT ,
306
312
ServiceError :: OriginalInfoHashAlreadyExists => StatusCode :: CONFLICT ,
Original file line number Diff line number Diff line change @@ -80,11 +80,13 @@ impl Service {
80
80
let enforcer = self . casbin_enforcer . enforcer . read ( ) . await ;
81
81
82
82
let authorize = enforcer
83
- . enforce ( ( role, action) )
83
+ . enforce ( ( & role, action) )
84
84
. map_err ( |_| ServiceError :: UnauthorizedAction ) ?;
85
85
86
86
if authorize {
87
87
Ok ( ( ) )
88
+ } else if role == UserRole :: Guest {
89
+ Err ( ServiceError :: UnauthorizedActionForGuests )
88
90
} else {
89
91
Err ( ServiceError :: UnauthorizedAction )
90
92
}
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() {
61
61
} )
62
62
. await ;
63
63
64
- assert_eq ! ( response. status, 403 ) ;
64
+ assert_eq ! ( response. status, 401 ) ;
65
65
}
66
66
67
67
#[ tokio:: test]
@@ -194,5 +194,5 @@ async fn it_should_not_allow_guests_to_delete_categories() {
194
194
} )
195
195
. await ;
196
196
197
- assert_eq ! ( response. status, 403 ) ;
197
+ assert_eq ! ( response. status, 401 ) ;
198
198
}
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() {
63
63
} )
64
64
. await ;
65
65
66
- assert_eq ! ( response. status, 403 ) ;
66
+ assert_eq ! ( response. status, 401 ) ;
67
67
}
68
68
69
69
#[ tokio:: test]
@@ -174,5 +174,5 @@ async fn it_should_not_allow_guests_to_delete_tags() {
174
174
175
175
let response = client. delete_tag ( DeleteTagForm { tag_id } ) . await ;
176
176
177
- assert_eq ! ( response. status, 403 ) ;
177
+ assert_eq ! ( response. status, 401 ) ;
178
178
}
Original file line number Diff line number Diff line change @@ -442,7 +442,7 @@ mod for_guests {
442
442
443
443
let response = client. upload_torrent ( form. into ( ) ) . await ;
444
444
445
- assert_eq ! ( response. status, 403 ) ;
445
+ assert_eq ! ( response. status, 401 ) ;
446
446
}
447
447
448
448
#[ tokio:: test]
Original file line number Diff line number Diff line change @@ -231,6 +231,6 @@ mod banned_user_list {
231
231
232
232
let response = client. ban_user ( Username :: new ( registered_user. username . clone ( ) ) ) . await ;
233
233
234
- assert_eq ! ( response. status, 403 ) ;
234
+ assert_eq ! ( response. status, 401 ) ;
235
235
}
236
236
}
You can’t perform that action at this time.
0 commit comments