Skip to content

Commit 259a5f3

Browse files
Lee-Wnailo2c
authored andcommitted
feat(AIP-84): Add auth for ui config (apache#47487)
1 parent b073689 commit 259a5f3

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

airflow/api_fastapi/core_api/openapi/v1-generated.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ paths:
5656
application/json:
5757
schema:
5858
$ref: '#/components/schemas/HTTPExceptionResponse'
59+
security:
60+
- OAuth2PasswordBearer: []
5961
/ui/dags/recent_dag_runs:
6062
get:
6163
tags:

airflow/api_fastapi/core_api/routes/ui/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
from typing import Any
2020

21-
from fastapi import status
21+
from fastapi import Depends, status
2222

2323
from airflow.api_fastapi.common.router import AirflowRouter
2424
from airflow.api_fastapi.core_api.datamodels.ui.config import ConfigResponse
2525
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
26+
from airflow.api_fastapi.core_api.security import requires_access_configuration
2627
from airflow.configuration import conf
2728
from airflow.settings import STATE_COLORS
2829

@@ -49,6 +50,7 @@
4950
@config_router.get(
5051
"/config",
5152
responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
53+
dependencies=[Depends(requires_access_configuration("GET"))],
5254
)
5355
def get_configs() -> ConfigResponse:
5456
"""Get configs for UI."""

tests/api_fastapi/core_api/routes/ui/test_config.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,21 @@ def mock_config_data():
105105
yield mock_conf
106106

107107

108-
def test_get_configs_basic(mock_config_data, test_client):
109-
"""
110-
Test the /ui/config endpoint to verify response matches mock data.
111-
"""
108+
class TestGetConfig:
109+
def test_should_response_200(self, mock_config_data, test_client):
110+
"""
111+
Test the /ui/config endpoint to verify response matches mock data.
112+
"""
113+
114+
response = test_client.get("/ui/config")
115+
116+
assert response.status_code == 200
117+
assert response.json() == mock_config_response
112118

113-
response = test_client.get("/ui/config")
119+
def test_get_config_should_response_401(self, unauthenticated_test_client):
120+
response = unauthenticated_test_client.get("/ui/config")
121+
assert response.status_code == 401
114122

115-
assert response.status_code == 200
116-
assert response.json() == mock_config_response
123+
def test_get_config_should_response_403(self, unauthorized_test_client):
124+
response = unauthorized_test_client.get("/ui/config")
125+
assert response.status_code == 403

0 commit comments

Comments
 (0)