Knossos Oauth 2 Flow Changes (#752)

* adjust type and response format

* Replace Found with Ok for handled redirects

* scope parse fix

* change apps query from body to query

* adjust tests for new response type

* remove unused imports

* Clippy fixes
This commit is contained in:
Carter
2023-11-11 09:42:01 -08:00
committed by GitHub
parent a818199b5a
commit 97ccb7df94
7 changed files with 50 additions and 29 deletions

View File

@@ -125,7 +125,7 @@ pub async fn get_authorize_accept_flow_id(response: ServiceResponse) -> String {
}
pub async fn get_auth_code_from_redirect_params(response: &ServiceResponse) -> String {
assert_status(response, StatusCode::FOUND);
assert_status(response, StatusCode::OK);
let query_params = get_redirect_location_query_params(response);
query_params.get("code").unwrap().to_string()
}
@@ -140,7 +140,13 @@ pub async fn get_access_token(response: ServiceResponse) -> String {
pub fn get_redirect_location_query_params(
response: &ServiceResponse,
) -> actix_web::web::Query<HashMap<String, String>> {
let redirect_location = response.headers().get(LOCATION).unwrap().to_str().unwrap();
let redirect_location = response
.headers()
.get(LOCATION)
.unwrap()
.to_str()
.unwrap()
.to_string();
actix_web::web::Query::<HashMap<String, String>>::from_query(
redirect_location.split_once('?').unwrap().1,
)

View File

@@ -42,7 +42,7 @@ async fn oauth_flow_happy_path() {
// Accept the authorization request
let resp = env.v3.oauth_accept(&flow_id, FRIEND_USER_PAT).await;
assert_status(&resp, StatusCode::FOUND);
assert_status(&resp, StatusCode::OK);
let query = get_redirect_location_query_params(&resp);
let auth_code = query.get("code").unwrap();
@@ -105,7 +105,7 @@ async fn oauth_authorize_for_already_authorized_scopes_returns_auth_code() {
USER_USER_PAT,
)
.await;
assert_status(&resp, StatusCode::FOUND);
assert_status(&resp, StatusCode::OK);
})
.await;
}
@@ -231,10 +231,10 @@ async fn reject_authorize_ends_authorize_flow() {
let flow_id = get_authorize_accept_flow_id(resp).await;
let resp = env.v3.oauth_reject(&flow_id, USER_USER_PAT).await;
assert_status(&resp, StatusCode::FOUND);
assert_status(&resp, StatusCode::OK);
let resp = env.v3.oauth_accept(&flow_id, USER_USER_PAT).await;
assert_any_status_except(&resp, StatusCode::FOUND);
assert_any_status_except(&resp, StatusCode::OK);
})
.await;
}
@@ -249,7 +249,7 @@ async fn accept_authorize_after_already_accepting_fails() {
.await;
let flow_id = get_authorize_accept_flow_id(resp).await;
let resp = env.v3.oauth_accept(&flow_id, USER_USER_PAT).await;
assert_status(&resp, StatusCode::FOUND);
assert_status(&resp, StatusCode::OK);
let resp = env.v3.oauth_accept(&flow_id, USER_USER_PAT).await;
assert_status(&resp, StatusCode::BAD_REQUEST);