Skip to content

WIP: Implement basic token scopes #5528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/controllers/krate/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::auth::AuthCheck;
use crate::controllers::prelude::*;
use crate::models::token::EndpointScope;
use crate::models::{Crate, Owner, Rights, Team, User};
use crate::views::EncodableOwner;

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

fn modify_owners(req: &mut dyn RequestExt, add: bool) -> EndpointResult {
let auth = AuthCheck::default().check(req)?;
let crate_name = &req.params()["crate_id"];

let auth = AuthCheck::default()
.with_endpoint_scope(EndpointScope::ChangeOwners)
.for_crate(crate_name)
.check(req)?;

let logins = parse_owners_request(req)?;
let app = req.app();
Expand Down
20 changes: 4 additions & 16 deletions src/tests/owners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,17 +321,11 @@ fn owner_change_via_change_owner_token() {
let body = json!({ "owners": [user2.gh_login] });
let body = serde_json::to_vec(&body).unwrap();
let response = token.put::<()>(&url, &body);
assert_eq!(response.status(), StatusCode::FORBIDDEN);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.into_json(),
json!({ "errors": [{ "detail": "must be logged in to perform that action" }] })
json!({ "ok": true, "msg": "user user-2 has been invited to be an owner of crate foo_crate" })
);
// TODO swap these assertions once token scopes are activated for this endpoint
// assert_eq!(response.status(), StatusCode::OK);
// assert_eq!(
// response.into_json(),
// json!({ "ok": true, "msg": "user user-2 has been invited to be an owner of crate foo_crate" })
// );
}

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

#[test]
Expand Down