Ejemplo n.º 1
0
def test_secret_immutable():
    secret = Secret(
        name="name",
        description="desc",
        values={"key": "value"},
    )

    with pytest.raises(AttributeError):
        secret.name = "test"

    with pytest.raises(AttributeError):
        secret.description = "test"

    with pytest.raises(TypeError):
        secret["key"] = "test"
Ejemplo n.º 2
0
def test_secret_update():
    secret = Secret(
        name="name-value",
        description="description-value",
        values={
            "key_one": "value_one",
            "key_two": "value_two"
        },
    )

    secret.update({"key_three": "value_three"})
    expected = {
        "key_one": "value_one",
        "key_two": "value_two",
        "key_three": "value_three",
    }

    assert secret == expected
Ejemplo n.º 3
0
def test_secret_properties():
    secret = Secret(
        name="name-value",
        description="description-value",
        values={},
    )

    assert secret.name == "name-value"
    assert secret.description == "description-value"
Ejemplo n.º 4
0
def test_secret_contains():
    secret = Secret(
        name="name-value",
        description="description-value",
        values={
            "key_one": "value_one",
            "key_two": "value_two"
        },
    )

    assert "key_two" in secret
Ejemplo n.º 5
0
def test_secret_iterate():
    secret = Secret(
        name="name-value",
        description="description-value",
        values={
            "key_one": "value_one",
            "key_two": "value_two"
        },
    )

    assert list(secret) == ["key_one", "key_two"]
Ejemplo n.º 6
0
def test_set_key_vault_error_empty():
    lib = Crypto()
    lib._secrets = mock_secrets = mock.Mock()

    key = lib.generate_key()
    mock_secrets.get_secret.return_value = Secret("MockSecret", "", {})

    with pytest.raises(ValueError):
        lib.use_encryption_key_from_vault("SomeKeyValue")
    assert mock_secrets.get_secret.called_once_with("SomeKeyValue")
    assert lib._key is None
Ejemplo n.º 7
0
def test_set_key_vault_no_key():
    lib = Crypto()
    lib._secrets = mock_secrets = mock.Mock()

    key = lib.generate_key()
    mock_secrets.get_secret.return_value = Secret("MockSecret", "",
                                                  {"key": key})

    lib.use_encryption_key_from_vault("SomeKeyValue")
    assert mock_secrets.get_secret.called_once_with("SomeKeyValue")
    assert lib._key is not None
Ejemplo n.º 8
0
def test_secret_get():
    secret = Secret(
        name="name-value",
        description="description-value",
        values={
            "key_one": "value_one",
            "key_two": "value_two"
        },
    )

    assert secret["key_one"] == "value_one"
    assert secret["key_two"] == "value_two"
    with pytest.raises(KeyError):
        _ = secret["key_invalid"]
Ejemplo n.º 9
0
def test_secret_print():
    secret = Secret(
        name="name-value",
        description="description-value",
        values={
            "key_one": "value_one",
            "key_two": "value_two"
        },
    )

    repr_string = repr(secret)
    assert "value_one" not in repr_string
    assert "value_two" not in repr_string

    str_string = str(secret)
    assert "value_one" not in str_string
    assert "value_two" not in str_string