Skip to content

Maintenance: cors is opt out if enabled #4881

Closed
@tonnico

Description

@tonnico

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

Metadata

Metadata

Labels

internalMaintenance changes

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions