def test_localhost_cors_middleware_is_allowed_origin_localhost(app):
    """Test that localhost origins are allowed regardless of port."""
    app.add_middleware(LocalhostCORSMiddleware)
    client = TestClient(app)

    # Test with localhost
    response = client.get('/test', headers={'Origin': 'http://localhost:8000'})
    assert response.status_code == 200
    assert response.headers['access-control-allow-origin'] == 'http://localhost:8000'

    # Test with different port
    response = client.get('/test', headers={'Origin': 'http://localhost:3000'})
    assert response.status_code == 200
    assert response.headers['access-control-allow-origin'] == 'http://localhost:3000'

    # Test with 127.0.0.1
    response = client.get('/test', headers={'Origin': 'http://127.0.0.1:8000'})
    assert response.status_code == 200
    assert response.headers['access-control-allow-origin'] == 'http://127.0.0.1:8000'
Test that localhost origins are allowed regardless of port.
tests/unit/test_middleware.py