Coverage for /home/airflow/.local/lib/python3.12/site-packages/airflow/api_fastapi/auth/managers/simple/utils.py: 64%
18 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 14:22 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 14:22 +0000
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17from __future__ import annotations
19from fastapi import HTTPException, Request, status
20from fastapi.exceptions import RequestValidationError
21from pydantic import ValidationError
23from airflow.api_fastapi.auth.managers.simple.datamodels.login import LoginBody
24from airflow.api_fastapi.common.headers import HeaderContentTypeJsonOrForm
25from airflow.api_fastapi.common.types import Mimetype
28async def parse_login_body(
29 request: Request,
30 content_type: HeaderContentTypeJsonOrForm,
31) -> LoginBody:
32 try:
33 if content_type == Mimetype.JSON: 33 ↛ 35line 33 didn't jump to line 35 because the condition on line 33 was always true
34 body = await request.json()
35 elif content_type == Mimetype.FORM:
36 form = await request.form()
37 body = {
38 "username": form.get("username"),
39 "password": form.get("password"),
40 }
41 else:
42 raise HTTPException(
43 status_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
44 detail="Unsupported Media Type",
45 )
46 return LoginBody(**body)
47 except ValidationError as e:
48 raise RequestValidationError(repr(e))