From 4dda092eff59bb83eefcb5c5e4015c237a3fba59 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Tue, 4 Oct 2022 23:06:26 -0500 Subject: [PATCH 1/3] change spoof login response back to 200 --- nexus/src/external_api/console_api.rs | 10 ++++++++-- nexus/tests/integration_tests/console_api.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/nexus/src/external_api/console_api.rs b/nexus/src/external_api/console_api.rs index ada514bcb68..7e59eee2de0 100644 --- a/nexus/src/external_api/console_api.rs +++ b/nexus/src/external_api/console_api.rs @@ -47,6 +47,9 @@ pub struct SpoofLoginBody { pub username: String, } +#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] +pub struct SpoofLoginResponse {} + // This is just for demo purposes. we will probably end up with a real // username/password login endpoint, but I think it will only be for use while // setting up the rack @@ -60,7 +63,8 @@ pub struct SpoofLoginBody { pub async fn login_spoof( rqctx: Arc>>, params: TypedBody, -) -> Result { +) -> Result>, HttpError> +{ let apictx = rqctx.context(); let handler = async { let nexus = &apictx.nexus; @@ -85,7 +89,9 @@ pub async fn login_spoof( let authn_opctx = nexus.opctx_external_authn(); let session = nexus.session_create(&authn_opctx, user_id).await?; - let mut response = http_response_see_other(String::from("/"))?; + let mut response = HttpResponseHeaders::new_unnamed(HttpResponseOk( + SpoofLoginResponse {}, + )); { let headers = response.headers_mut(); headers.append( diff --git a/nexus/tests/integration_tests/console_api.rs b/nexus/tests/integration_tests/console_api.rs index 2094a105c55..7e0bfd0f448 100644 --- a/nexus/tests/integration_tests/console_api.rs +++ b/nexus/tests/integration_tests/console_api.rs @@ -398,7 +398,7 @@ fn get_header_value(resp: TestResponse, header_name: HeaderName) -> String { async fn log_in_and_extract_token(testctx: &ClientTestContext) -> String { let login = RequestBuilder::new(&testctx, Method::POST, "/login") .body(Some(&SpoofLoginBody { username: "unprivileged".to_string() })) - .expect_status(Some(StatusCode::SEE_OTHER)) + .expect_status(Some(StatusCode::OK)) .execute() .await .expect("failed to log in"); From 8737025d6397d70ef3a403caf9c3229562b828fa Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 5 Oct 2022 12:42:16 -0500 Subject: [PATCH 2/3] 200 -> 204, update openapi spec --- nexus/src/external_api/console_api.rs | 11 +++-------- openapi/nexus.json | 14 ++------------ 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/nexus/src/external_api/console_api.rs b/nexus/src/external_api/console_api.rs index 7e59eee2de0..e31eecb6012 100644 --- a/nexus/src/external_api/console_api.rs +++ b/nexus/src/external_api/console_api.rs @@ -47,9 +47,6 @@ pub struct SpoofLoginBody { pub username: String, } -#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)] -pub struct SpoofLoginResponse {} - // This is just for demo purposes. we will probably end up with a real // username/password login endpoint, but I think it will only be for use while // setting up the rack @@ -63,8 +60,7 @@ pub struct SpoofLoginResponse {} pub async fn login_spoof( rqctx: Arc>>, params: TypedBody, -) -> Result>, HttpError> -{ +) -> Result, HttpError> { let apictx = rqctx.context(); let handler = async { let nexus = &apictx.nexus; @@ -89,9 +85,8 @@ pub async fn login_spoof( let authn_opctx = nexus.opctx_external_authn(); let session = nexus.session_create(&authn_opctx, user_id).await?; - let mut response = HttpResponseHeaders::new_unnamed(HttpResponseOk( - SpoofLoginResponse {}, - )); + let mut response = + HttpResponseHeaders::new_unnamed(HttpResponseUpdatedNoContent()); { let headers = response.headers_mut(); headers.append( diff --git a/openapi/nexus.json b/openapi/nexus.json index b91b2fd282a..60613076261 100644 --- a/openapi/nexus.json +++ b/openapi/nexus.json @@ -547,18 +547,8 @@ "required": true }, "responses": { - "303": { - "description": "redirect (see other)", - "headers": { - "location": { - "description": "HTTP \"Location\" header", - "style": "simple", - "required": true, - "schema": { - "type": "string" - } - } - } + "204": { + "description": "resource updated" }, "4XX": { "$ref": "#/components/responses/Error" From 35b00ce79b7611dbacc971ea818a21c95d1ed248 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 5 Oct 2022 13:52:19 -0500 Subject: [PATCH 3/3] forgot to update test --- nexus/tests/integration_tests/console_api.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nexus/tests/integration_tests/console_api.rs b/nexus/tests/integration_tests/console_api.rs index 7e0bfd0f448..77e796507ee 100644 --- a/nexus/tests/integration_tests/console_api.rs +++ b/nexus/tests/integration_tests/console_api.rs @@ -398,7 +398,7 @@ fn get_header_value(resp: TestResponse, header_name: HeaderName) -> String { async fn log_in_and_extract_token(testctx: &ClientTestContext) -> String { let login = RequestBuilder::new(&testctx, Method::POST, "/login") .body(Some(&SpoofLoginBody { username: "unprivileged".to_string() })) - .expect_status(Some(StatusCode::OK)) + .expect_status(Some(StatusCode::NO_CONTENT)) .execute() .await .expect("failed to log in");