Skip to content

Commit

Permalink
Default SecuritySettings.env to prod (#5326)
Browse files Browse the repository at this point in the history
  • Loading branch information
galvana committed Sep 25, 2024
1 parent 155e1fd commit ba2e4ee
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The types of changes are:

### Changed
- Updated privacy notices to support notice hierarchies [#5272](https://github.com/ethyca/fides/pull/5272)
- Defaulting SecuritySettings.env to prod [#5326](https://github.com/ethyca/fides/pull/5326)

## [2.45.2](https://github.com/ethyca/fides/compare/2.45.1...2.45.2)

Expand Down
2 changes: 1 addition & 1 deletion src/fides/config/security_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class SecuritySettings(FidesSettings):
default="UTF-8", description="Text encoding to use for the application."
)
env: str = Field(
default="dev",
default="prod",
description="The default, `dev`, does not apply authentication to endpoints typically used by the CLI. The other option, `prod`, requires authentication for _all_ endpoints that may contain sensitive information.",
)
identity_verification_attempt_limit: int = Field(
Expand Down
4 changes: 4 additions & 0 deletions tests/ctl/core/config/test_security_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ def test_assemble_root_access_token_none(self):
def test_validate_request_rate_limit_invalid_format(self):
with pytest.raises(ValueError):
SecuritySettings(request_rate_limit="invalid")

def test_security_settings_env_default_to_prod(self):
settings = SecuritySettings()
assert settings.env == "prod"
40 changes: 39 additions & 1 deletion tests/ops/api/v1/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from fastapi import FastAPI
from httpx import AsyncClient
from starlette.testclient import TestClient

from fides.api.main import create_fides_app, lifespan
Expand All @@ -10,6 +11,8 @@
verify_oauth_client,
verify_oauth_client_prod,
)
from fides.common.api.v1.urn_registry import V1_URL_PREFIX
from fides.config.security_settings import SecuritySettings


def test_read_autogenerated_docs(api_client: TestClient):
Expand All @@ -19,6 +22,7 @@ def test_read_autogenerated_docs(api_client: TestClient):


class TestConfigureSecurityEnvOverrides:

def test_configure_security_env_overrides_dev(self) -> None:
"""
This test verifies that when set to 'dev', only the
Expand All @@ -31,7 +35,8 @@ def test_configure_security_env_overrides_dev(self) -> None:
test_app.dependency_overrides[verify_oauth_client_prod] == get_root_client
)

def test_configure_security_env_overrides_prod(self) -> None:
@pytest.mark.asyncio
async def test_configure_security_env_overrides_prod(self) -> None:
"""
This test verifies that when set to 'prod', there are no
dependency overrides for the oauth clients.
Expand All @@ -44,3 +49,36 @@ def test_configure_security_env_overrides_prod(self) -> None:

with pytest.raises(KeyError):
test_app.dependency_overrides[verify_oauth_client_prod]

# an endpoint using verify_oauth_client_prod
async with AsyncClient(
app=test_app, base_url="http://0.0.0.0:8080", follow_redirects=True
) as client:
response = await client.get(V1_URL_PREFIX + "/system")
assert response.status_code == 401

@pytest.mark.asyncio
async def test_configure_security_env_defaults_to_prod(self) -> None:
"""
This test verifies that when env is not set, there are no
dependency overrides for the oauth clients.
"""

# simulates a config with default settings, not loading from any env variables
default_security_settings = SecuritySettings()
test_app = FastAPI(title="test")
test_app = create_fides_app(
lifespan=lifespan, security_env=default_security_settings.env
)
with pytest.raises(KeyError):
test_app.dependency_overrides[verify_oauth_client]

with pytest.raises(KeyError):
test_app.dependency_overrides[verify_oauth_client_prod]

# an endpoint using verify_oauth_client_prod
async with AsyncClient(
app=test_app, base_url="http://0.0.0.0:8080", follow_redirects=True
) as client:
response = await client.get(V1_URL_PREFIX + "/system")
assert response.status_code == 401

0 comments on commit ba2e4ee

Please sign in to comment.