File: test_model.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (52 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytest

from moto.kms.models import KmsBackend

PLAINTEXT = b"text"
REGION = "us-east-1"


@pytest.fixture(name="backend")
def fixture_backend():
    return KmsBackend(REGION)


@pytest.fixture(name="key")
def fixture_key(backend):
    return backend.create_key(
        None, "ENCRYPT_DECRYPT", "SYMMETRIC_DEFAULT", "Test key", None
    )


def test_encrypt_key_id(backend, key):
    ciphertext, arn = backend.encrypt(key.id, PLAINTEXT, {})

    assert ciphertext is not None
    assert arn == key.arn


def test_encrypt_key_arn(backend, key):
    ciphertext, arn = backend.encrypt(key.arn, PLAINTEXT, {})

    assert ciphertext is not None
    assert arn == key.arn


def test_encrypt_alias_name(backend, key):
    backend.create_alias(key.id, "alias/test/test")

    ciphertext, arn = backend.encrypt("alias/test/test", PLAINTEXT, {})

    assert ciphertext is not None
    assert arn == key.arn


def test_encrypt_alias_arn(backend, key):
    backend.create_alias(key.id, "alias/test/test")

    ciphertext, arn = backend.encrypt(
        f"arn:aws:kms:{REGION}:{key.account_id}:alias/test/test", PLAINTEXT, {}
    )

    assert ciphertext is not None
    assert arn == key.arn