import pytest

import virtool.users.db
import virtool.users.utils
import virtool.utils


@pytest.mark.parametrize(
    "password,salt,result",
    [
        ("hello_world", "6rn1x86nnlqfj5bqg1n5qhcd", True),
        ("bye_world", "6rn1x86nnlqfj5bqg1n5qhcd", False),
        ("hello_world", "abc1x86nnlqfj5bqg1n5q123", False),
    ],
    ids=["success", "failure_password", "failure_salt"],
)
def test_check_legacy_password(password, salt, result):
    assert (
        virtool.users.utils.check_legacy_password(
            password,
            salt,
            "<PASSWORD>",
        )
        is result
    )


@pytest.mark.parametrize(
    "password,hashed,result",
    [
        (
            "foobar",
            b"$2b$12$rCRx7p4HlrNXxIcqwWXmLe5CR2MUCPh00bOLnNsAeCxzUJzR6MkLu",
            True,
        ),
        (
            "foobar",
            b"$2b$12$4Hj5m9ytlq.yUCNNXmZyGepaMWVnZM/SP6zWGsKpN.HYCP7J99pZe",
            False,
        ),
    ],
    ids=["success", "failure"],
)
def test_check_password(password, hashed, result):
    """
    Test that passwords are validated against bcrypt hashed ones correctly in success and failure
    cases.

    """
    assert virtool.users.utils.check_password(password, hashed) is result


def test_generate_base_permissions():
    assert virtool.users.utils.generate_base_permissions() == {
        p: False for p in virtool.users.utils.PERMISSIONS
    }

import pytest

import virtool.users.db
import virtool.users.utils
import virtool.utils


@pytest.mark.parametrize(
    "password,salt,result",
    [
        ("hello_world", "6rn1x86nnlqfj5bqg1n5qhcd", True),
        ("bye_world", "6rn1x86nnlqfj5bqg1n5qhcd", False),
        ("hello_world", "abc1x86nnlqfj5bqg1n5q123", False),
    ],
    ids=["success", "failure_password", "failure_salt"],
)
def test_check_legacy_password(password, salt, result):
    assert (
        virtool.users.utils.check_legacy_password(
            password,
            salt,
            "<PASSWORD>",
        )
        is result
    )


@pytest.mark.parametrize(
    "password,hashed,result",
    [
        (
            "foobar",
            b"$2b$12$rCRx7p4HlrNXxIcqwWXmLe5CR2MUCPh00bOLnNsAeCxzUJzR6MkLu",
            True,
        ),
        (
            "foobar",
            b"$2b$12$4Hj5m9ytlq.yUCNNXmZyGepaMWVnZM/SP6zWGsKpN.HYCP7J99pZe",
            False,
        ),
    ],
    ids=["success", "failure"],
)
def test_check_password(password, hashed, result):
    """
    Test that passwords are validated against bcrypt hashed ones correctly in success and failure
    cases.

    """
    assert virtool.users.utils.check_password(password, hashed) is result


def test_generate_base_permissions():
    assert virtool.users.utils.generate_base_permissions() == {
        p: False for p in virtool.users.utils.PERMISSIONS
    }

Test that passwords are validated against bcrypt hashed ones correctly in success and failure     cases.