Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion airflow/api_fastapi/execution_api/routes/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import logging

from fastapi import HTTPException, status
from fastapi import Depends, HTTPException, status

from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.security import requires_access_connection
from airflow.api_fastapi.execution_api import deps
from airflow.api_fastapi.execution_api.datamodels.connection import ConnectionResponse
from airflow.api_fastapi.execution_api.datamodels.token import TIToken
Expand All @@ -31,6 +32,7 @@
# TODO: Add dependency on JWT token
router = AirflowRouter(
responses={status.HTTP_404_NOT_FOUND: {"description": "Connection not found"}},
dependencies=[Depends(requires_access_connection("GET"))],
)

log = logging.getLogger(__name__)
Expand Down
24 changes: 16 additions & 8 deletions tests/api_fastapi/execution_api/routes/test_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


class TestGetConnection:
def test_connection_get_from_db(self, client, session):
def test_connection_get_from_db(self, test_client, session):
connection = Connection(
conn_id="test_conn",
conn_type="http",
Expand All @@ -43,7 +43,7 @@ def test_connection_get_from_db(self, client, session):
session.add(connection)
session.commit()

response = client.get("/execution/connections/test_conn")
response = test_client.get("/execution/connections/test_conn")

assert response.status_code == 200
assert response.json() == {
Expand All @@ -65,8 +65,8 @@ def test_connection_get_from_db(self, client, session):
"os.environ",
{"AIRFLOW_CONN_TEST_CONN2": '{"uri": "http://root:admin@localhost:8080/https?headers=header"}'},
)
def test_connection_get_from_env_var(self, client, session):
response = client.get("/execution/connections/test_conn2")
def test_connection_get_from_env_var(self, test_client, session):
response = test_client.get("/execution/connections/test_conn2")

assert response.status_code == 200
assert response.json() == {
Expand All @@ -80,8 +80,8 @@ def test_connection_get_from_env_var(self, client, session):
"extra": '{"headers": "header"}',
}

def test_connection_get_not_found(self, client):
response = client.get("/execution/connections/non_existent_test_conn")
def test_connection_get_not_found(self, test_client):
response = test_client.get("/execution/connections/non_existent_test_conn")

assert response.status_code == 404
assert response.json() == {
Expand All @@ -91,11 +91,11 @@ def test_connection_get_not_found(self, client):
}
}

def test_connection_get_access_denied(self, client):
def test_connection_get_access_denied(self, test_client):
with mock.patch(
"airflow.api_fastapi.execution_api.routes.connections.has_connection_access", return_value=False
):
response = client.get("/execution/connections/test_conn")
response = test_client.get("/execution/connections/test_conn")

# Assert response status code and detail for access denied
assert response.status_code == 403
Expand All @@ -105,3 +105,11 @@ def test_connection_get_access_denied(self, client):
"message": "Task does not have access to connection test_conn",
}
}

def test_get_config_should_response_401(self, unauthenticated_test_client):
response = unauthenticated_test_client.get("/execution/connections/test_conn")
assert response.status_code == 401

def test_get_config_should_response_403(self, unauthorized_test_client):
response = unauthorized_test_client.get("/execution/connections/test_conn")
assert response.status_code == 403
Loading