Skip to content

Maintenance: cors is opt out if enabled #4881

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
1 of 2 tasks
tonnico opened this issue Aug 3, 2024 · 2 comments · Fixed by #4882
Closed
1 of 2 tasks

Maintenance: cors is opt out if enabled #4881

tonnico opened this issue Aug 3, 2024 · 2 comments · Fixed by #4882
Assignees
Labels
internal Maintenance changes

Comments

@tonnico
Copy link
Contributor

tonnico commented Aug 3, 2024

Why is this needed?

Some cors tests did not opt out for non-cors endpoints.

def test_cors_allow_all_request_origins():
    # GIVEN a function with cors=True
    # AND http method set to GET
    app = ApiGatewayResolver(
        cors=CORSConfig(
            allow_origin="*",
            allow_credentials=True,
        ),
    )

    @app.get("/my/path", cors=True)
    def with_cors() -> Response:
        return Response(200, content_types.TEXT_HTML, "test")

    @app.get("/without-cors")
    def without_cors() -> Response:
        return Response(200, content_types.TEXT_HTML, "test")

Which area does this relate to?

Tests

Solution

opt out cors instead of opt-in.

def test_cors_allow_all_request_origins():
    # GIVEN a function
    # AND http method set to GET
    app = ApiGatewayResolver(
        cors=CORSConfig(
            allow_origin="*",
            allow_credentials=True,
        ),
    )

    @app.get("/my/path")
    def with_cors() -> Response:
        return Response(200, content_types.TEXT_HTML, "test")

    @app.get("/without-cors", cors=False)
    def without_cors() -> Response:
        return Response(200, content_types.TEXT_HTML, "test")

Acknowledgment

@leandrodamascena
Copy link
Contributor

Nice one @wurstnase! Thanks!

@leandrodamascena leandrodamascena moved this from Triage to Pending customer in Powertools for AWS Lambda (Python) Aug 4, 2024
@leandrodamascena leandrodamascena moved this from Pending customer to Pending review in Powertools for AWS Lambda (Python) Aug 4, 2024
@leandrodamascena leandrodamascena removed the triage Pending triage from maintainers label Aug 4, 2024
@leandrodamascena leandrodamascena self-assigned this Aug 4, 2024
@github-project-automation github-project-automation bot moved this from Pending review to Coming soon in Powertools for AWS Lambda (Python) Aug 5, 2024
Copy link
Contributor

github-actions bot commented Aug 5, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@leandrodamascena leandrodamascena moved this from Coming soon to Shipped in Powertools for AWS Lambda (Python) Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Maintenance changes
Projects
Status: Shipped
Development

Successfully merging a pull request may close this issue.

2 participants