Skip to content

Commit 46f6a21

Browse files
committed
crate::owners: Use token scope restrictions
1 parent bb2530e commit 46f6a21

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/controllers/krate/owners.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::auth::AuthCheck;
44
use crate::controllers::prelude::*;
5+
use crate::models::token::EndpointScope;
56
use crate::models::{Crate, Owner, Rights, Team, User};
67
use crate::views::EncodableOwner;
78

@@ -80,7 +81,12 @@ fn parse_owners_request(req: &mut dyn RequestExt) -> AppResult<Vec<String>> {
8081
}
8182

8283
fn modify_owners(req: &mut dyn RequestExt, add: bool) -> EndpointResult {
83-
let auth = AuthCheck::default().check(req)?;
84+
let crate_name = &req.params()["crate_id"];
85+
86+
let auth = AuthCheck::default()
87+
.with_endpoint_scope(EndpointScope::ChangeOwners)
88+
.for_crate(crate_name)
89+
.check(req)?;
8490

8591
let logins = parse_owners_request(req)?;
8692
let app = req.app();

src/tests/owners.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,11 @@ fn owner_change_via_change_owner_token() {
321321
let body = json!({ "owners": [user2.gh_login] });
322322
let body = serde_json::to_vec(&body).unwrap();
323323
let response = token.put::<()>(&url, &body);
324-
assert_eq!(response.status(), StatusCode::FORBIDDEN);
324+
assert_eq!(response.status(), StatusCode::OK);
325325
assert_eq!(
326326
response.into_json(),
327-
json!({ "errors": [{ "detail": "must be logged in to perform that action" }] })
327+
json!({ "ok": true, "msg": "user user-2 has been invited to be an owner of crate foo_crate" })
328328
);
329-
// TODO swap these assertions once token scopes are activated for this endpoint
330-
// assert_eq!(response.status(), StatusCode::OK);
331-
// assert_eq!(
332-
// response.into_json(),
333-
// json!({ "ok": true, "msg": "user user-2 has been invited to be an owner of crate foo_crate" })
334-
// );
335329
}
336330

337331
#[test]
@@ -350,17 +344,11 @@ fn owner_change_via_change_owner_token_with_matching_crate_scope() {
350344
let body = json!({ "owners": [user2.gh_login] });
351345
let body = serde_json::to_vec(&body).unwrap();
352346
let response = token.put::<()>(&url, &body);
353-
assert_eq!(response.status(), StatusCode::FORBIDDEN);
347+
assert_eq!(response.status(), StatusCode::OK);
354348
assert_eq!(
355349
response.into_json(),
356-
json!({ "errors": [{ "detail": "must be logged in to perform that action" }] })
350+
json!({ "ok": true, "msg": "user user-2 has been invited to be an owner of crate foo_crate" })
357351
);
358-
// TODO swap these assertions once token scopes are activated for this endpoint
359-
// assert_eq!(response.status(), StatusCode::OK);
360-
// assert_eq!(
361-
// response.into_json(),
362-
// json!({ "ok": true, "msg": "user user-2 has been invited to be an owner of crate foo_crate" })
363-
// );
364352
}
365353

366354
#[test]

0 commit comments

Comments
 (0)