Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions nexus/src/external_api/console_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,7 +63,8 @@ pub struct SpoofLoginBody {
pub async fn login_spoof(
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
params: TypedBody<SpoofLoginBody>,
) -> Result<HttpResponseSeeOther, HttpError> {
) -> Result<HttpResponseHeaders<HttpResponseOk<SpoofLoginResponse>>, HttpError>
{
let apictx = rqctx.context();
let handler = async {
let nexus = &apictx.nexus;
Expand All @@ -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 {},
));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was kind of a weird API, had to look at the Dropshot source to find a way that works. But I get the feeling what I'm trying to do here is a little unusual.

{
let headers = response.headers_mut();
headers.append(
Expand Down
2 changes: 1 addition & 1 deletion nexus/tests/integration_tests/console_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down