Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Unit testing Headers and Cognito Authorizer #321

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
leo-suspensify opened this issue May 2, 2021 · 0 comments
Closed

Unit testing Headers and Cognito Authorizer #321

leo-suspensify opened this issue May 2, 2021 · 0 comments

Comments

@leo-suspensify
Copy link

Hi,

What is the recommended flow write unit tests involving headers and cognito authorization? The objective is to write unit tests which mimic frontend requests passing through the http api gateway. For example, suppose we have the function

pub async fn http_404(_request: Request, _context: Context) -> Result<Response<Body>, Error> {
    let body = json!({
        "message": "The requested resource or route do not exist.",
    });

    let response = Response::builder()
        .status(404)
        .header("content-type", "application/json")
        .body(Body::from(serde_json::to_string(&body)?))
        .unwrap();

    Ok(response)
}

#[tokio::test]
async fn get_auth_uri() {
    let global_settings = setup().await;

    let expected = json!({
        "message": "The requested resource or route do not exist.".to_string(),
    }).into_response();

    let request = Request::new(lambda_http::Body::Text("{}"));
    let response = handle_get_auth_uri(request, Context::default())
        .await
        .expect("expected Ok(_) value")
        .into_response();
    assert_eq!(response.body(), expected.body())
}

We can set a few things beside the body, such as query parameters with request.with_query_string_parameters but I don't see how to set headers or Cognito related parameters. This issue mentions that the CognitoIdentity parameters are deprecated and cannot be used in Context, but there also isn't a clear way to set the RequestContext for mocking. What is the recommended way to do this?

@awslabs awslabs locked and limited conversation to collaborators Feb 19, 2022
@calavera calavera converted this issue into discussion #424 Feb 19, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant