refactor: fix lint warnings and remove stale type: ignore comments
This commit is contained in:
parent
8c91edf137
commit
64f8c1936b
5 changed files with 34 additions and 28 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -11,3 +11,6 @@ wheels/
|
|||
|
||||
# Git worktrees
|
||||
.worktrees/
|
||||
|
||||
# Runtime data
|
||||
data/
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|||
|
||||
def create_app(settings: Settings | None = None) -> FastAPI:
|
||||
if settings is None:
|
||||
settings = Settings() # type: ignore[call-arg]
|
||||
settings = Settings()
|
||||
|
||||
app = FastAPI(
|
||||
title="Porchlight",
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ def create_invite(
|
|||
note: Annotated[str | None, typer.Option(help="Optional note stored with the link")] = None,
|
||||
) -> None:
|
||||
"""Generate a magic link registration URL for a new user."""
|
||||
settings = Settings() # type: ignore[call-arg]
|
||||
settings = Settings()
|
||||
effective_ttl = ttl if ttl is not None else settings.invite_ttl
|
||||
url = asyncio.run(_create_invite(settings, username, effective_ttl, note))
|
||||
typer.echo(url)
|
||||
|
|
@ -64,7 +64,7 @@ def initial_admin(
|
|||
group: Annotated[list[str] | None, typer.Option(help="Groups to assign (repeatable)")] = None,
|
||||
) -> None:
|
||||
"""Bootstrap the first admin user with a registration link."""
|
||||
settings = Settings() # type: ignore[call-arg]
|
||||
settings = Settings()
|
||||
groups = group if group is not None else ["admin", "users"]
|
||||
url = asyncio.run(_initial_admin(settings, username, groups))
|
||||
typer.echo(url)
|
||||
|
|
|
|||
|
|
@ -19,23 +19,24 @@ scope = ["openid", "profile"]
|
|||
toml_file = tmp_path / "test.toml"
|
||||
toml_file.write_text(toml_content)
|
||||
|
||||
settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg]
|
||||
settings = Settings(_toml_file=str(toml_file))
|
||||
app = create_app(settings)
|
||||
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
# Trigger lifespan
|
||||
async with app.router.lifespan_context(app):
|
||||
response = await client.get("/health")
|
||||
assert response.status_code == 200
|
||||
async with (
|
||||
AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client,
|
||||
app.router.lifespan_context(app),
|
||||
):
|
||||
response = await client.get("/health")
|
||||
assert response.status_code == 200
|
||||
|
||||
oidc_server = app.state.oidc_server
|
||||
assert "test-rp" in oidc_server.context.cdb
|
||||
cdb_entry = oidc_server.context.cdb["test-rp"]
|
||||
assert cdb_entry["client_id"] == "test-rp"
|
||||
assert cdb_entry["client_secret"] == "test-secret-0123456789abcdef"
|
||||
assert ("https://app.example.com/callback", {}) in cdb_entry["redirect_uris"]
|
||||
assert cdb_entry["scope"] == ["openid", "profile"]
|
||||
assert cdb_entry["allowed_scopes"] == ["openid", "profile"]
|
||||
oidc_server = app.state.oidc_server
|
||||
assert "test-rp" in oidc_server.context.cdb
|
||||
cdb_entry = oidc_server.context.cdb["test-rp"]
|
||||
assert cdb_entry["client_id"] == "test-rp"
|
||||
assert cdb_entry["client_secret"] == "test-secret-0123456789abcdef"
|
||||
assert ("https://app.example.com/callback", {}) in cdb_entry["redirect_uris"]
|
||||
assert cdb_entry["scope"] == ["openid", "profile"]
|
||||
assert cdb_entry["allowed_scopes"] == ["openid", "profile"]
|
||||
|
||||
|
||||
async def test_manage_app_always_registered() -> None:
|
||||
|
|
@ -43,10 +44,12 @@ async def test_manage_app_always_registered() -> None:
|
|||
settings = Settings(issuer="https://test.example.com")
|
||||
app = create_app(settings)
|
||||
|
||||
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client:
|
||||
async with app.router.lifespan_context(app):
|
||||
response = await client.get("/health")
|
||||
assert response.status_code == 200
|
||||
async with (
|
||||
AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as client,
|
||||
app.router.lifespan_context(app),
|
||||
):
|
||||
response = await client.get("/health")
|
||||
assert response.status_code == 200
|
||||
|
||||
oidc_server = app.state.oidc_server
|
||||
assert "manage-app" in oidc_server.context.cdb
|
||||
oidc_server = app.state.oidc_server
|
||||
assert "manage-app" in oidc_server.context.cdb
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ def test_settings_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||
monkeypatch.setenv("OIDC_OP_ISSUER", "https://op.example.org")
|
||||
monkeypatch.setenv("OIDC_OP_STORAGE_BACKEND", "mongodb")
|
||||
monkeypatch.setenv("OIDC_OP_MONGODB_URI", "mongodb://remote:27017")
|
||||
settings = Settings() # type: ignore[call-arg]
|
||||
settings = Settings()
|
||||
assert settings.issuer == "https://op.example.org"
|
||||
assert settings.storage_backend == StorageBackend.MONGODB
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ scope = ["openid", "profile"]
|
|||
toml_file = tmp_path / "test.toml"
|
||||
toml_file.write_text(toml_content)
|
||||
|
||||
settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg]
|
||||
settings = Settings(_toml_file=str(toml_file))
|
||||
assert settings.issuer == "https://toml.example.com"
|
||||
assert settings.debug is True
|
||||
assert settings.sqlite_path == "custom/path.db"
|
||||
|
|
@ -80,13 +80,13 @@ debug = false
|
|||
|
||||
monkeypatch.setenv("OIDC_OP_ISSUER", "https://env.example.com")
|
||||
monkeypatch.setenv("OIDC_OP_DEBUG", "true")
|
||||
settings = Settings(_toml_file=str(toml_file)) # type: ignore[call-arg]
|
||||
settings = Settings(_toml_file=str(toml_file))
|
||||
assert settings.issuer == "https://env.example.com"
|
||||
assert settings.debug is True
|
||||
|
||||
|
||||
def test_missing_toml_file_uses_defaults() -> None:
|
||||
settings = Settings(issuer="http://localhost:8000", _toml_file="/nonexistent/path.toml") # type: ignore[call-arg]
|
||||
settings = Settings(issuer="http://localhost:8000", _toml_file="/nonexistent/path.toml")
|
||||
assert settings.issuer == "http://localhost:8000"
|
||||
assert settings.clients == {}
|
||||
|
||||
|
|
@ -96,5 +96,5 @@ def test_config_file_env_var_override(tmp_path: Path, monkeypatch: pytest.Monkey
|
|||
toml_file.write_text('issuer = "https://custom-path.example.com"\n')
|
||||
|
||||
monkeypatch.setenv("OIDC_OP_CONFIG_FILE", str(toml_file))
|
||||
settings = Settings() # type: ignore[call-arg]
|
||||
settings = Settings()
|
||||
assert settings.issuer == "https://custom-path.example.com"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue