Ejemplo n.º 1
0
def test__create_basic_auth_data(kubernetes: Kubernetes) -> None:
    basic_auth_users = [
        BasicAuthUser(username="******", password="******"),
        BasicAuthUser(username="******", password="******"),
    ]

    data = kubernetes._create_basic_auth_data(
        basic_auth_users=basic_auth_users)
    auth_data = data["auth"]

    decoded_data = base64.b64decode(auth_data).decode("UTF-8")
    user_split = decoded_data.split("\n")[:-1]

    for i, user in enumerate(user_split):
        username, password = user.split(":")
        assert password
        assert username == basic_auth_users[i].username
def basicauth_parser(value: str) -> List[BasicAuthUser]:
    if not value:
        return []

    credentials = BASIC_AUTH_REGEX.findall(value)
    users = []
    for credential in credentials:
        if credential:
            user = BasicAuthUser.from_colon_string(credential)
            if user:
                users.append(user)
    return users
Ejemplo n.º 3
0
    def validate(cls, v: Union[None, str, List[BasicAuthUser]]) -> List[BasicAuthUser]:
        if v is None:
            return []
        elif not isinstance(v, str):
            return v

        credentials = BASIC_AUTH_REGEX.findall(v)
        users = []
        for credential in credentials:
            if credential:
                user = BasicAuthUser.from_colon_string(credential)
                if user:
                    users.append(user)
        return users
Ejemplo n.º 4
0
from typing import List

import pytest

from kolga.utils.fields import BasicAuthUserList
from kolga.utils.models import BasicAuthUser


@pytest.mark.parametrize(
    "input, expected",
    [
        ("test:test", [BasicAuthUser(username="******", password="******")]),
        (
            "test:test, testing:testing",
            [
                BasicAuthUser(username="******", password="******"),
                BasicAuthUser(username="******", password="******"),
            ],
        ),
        (
            "test:test testing::testing",
            [BasicAuthUser(username="******", password="******")],
        ),
        ("test:test testing",
         [BasicAuthUser(username="******", password="******")]),
        (
            "aja899€#:()Jtr4ng83",
            [BasicAuthUser(username="******", password="******")],
        ),
        (
            "username:firstpart:only",
Ejemplo n.º 5
0
        ("KOLGA_DEBUG", "n", False),
        ("KOLGA_DEBUG", "False", False),
        ("KOLGA_DEBUG", "1", True),
        ("KOLGA_DEBUG", "Yes", True),
        ("KOLGA_DEBUG", "Y", True),
        ("KOLGA_DEBUG", "True", True),
        ("KOLGA_DEBUG", "", ValidationError),
        ("KOLGA_DEBUG", "2", ValidationError),
        # List[BasicAuthUser]
        ("K8S_INGRESS_BASIC_AUTH", None, []),
        ("K8S_INGRESS_BASIC_AUTH", "", []),
        ("K8S_INGRESS_BASIC_AUTH", "username", []),
        (
            "K8S_INGRESS_BASIC_AUTH",
            "username:password",
            [BasicAuthUser(username="******", password="******")],
        ),
        (
            "K8S_INGRESS_BASIC_AUTH",
            "username:password username:password",
            [
                BasicAuthUser(username="******", password="******"),
                BasicAuthUser(username="******", password="******"),
            ],
        ),
    ),
)
def test_settings_parsers(
    mockenv: MockEnv,
    variable: str,
    input: Optional[str],