|
6 | 6 |
|
7 | 7 | from ..test_crypto import PRIVATE_KEY_PASSWORD, PRIVATE_KEY_PEM_BASE64, PUBLIC_KEY
|
8 | 8 | from apify import Actor
|
9 |
| -from apify._consts import ENCRYPTED_INPUT_VALUE_PREFIX |
| 9 | +from apify._consts import ENCRYPTED_JSON_VALUE_PREFIX, ENCRYPTED_STRING_VALUE_PREFIX |
10 | 10 | from apify._crypto import public_encrypt
|
11 | 11 |
|
12 | 12 |
|
@@ -59,15 +59,49 @@ async def test_get_input_with_encrypted_secrets(monkeypatch: pytest.MonkeyPatch)
|
59 | 59 | monkeypatch.setenv(ApifyEnvVars.INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE, PRIVATE_KEY_PASSWORD)
|
60 | 60 |
|
61 | 61 | input_key = 'INPUT'
|
| 62 | + secret_string_legacy = 'secret-string' |
62 | 63 | secret_string = 'secret-string'
|
63 |
| - encrypted_secret = public_encrypt(secret_string, public_key=PUBLIC_KEY) |
| 64 | + secret_object = {'foo': 'bar', 'baz': 'qux'} |
| 65 | + secret_array = ['foo', 'bar', 'baz'] |
| 66 | + |
| 67 | + # The legacy encryption format uses ENCRYPTED_STRING_VALUE_PREFIX prefix, value in raw string and does |
| 68 | + # not include schemahash. The new format uses ENCRYPTED_JSON_VALUE_PREFIX prefix, value in JSON format |
| 69 | + # and includes schemahash. We are testing both formats to ensure backward compatibility. |
| 70 | + |
| 71 | + encrypted_string_legacy = public_encrypt(secret_string_legacy, public_key=PUBLIC_KEY) |
| 72 | + encrypted_string = public_encrypt(json_dumps(secret_string), public_key=PUBLIC_KEY) |
| 73 | + encrypted_object = public_encrypt(json_dumps(secret_object), public_key=PUBLIC_KEY) |
| 74 | + encrypted_array = public_encrypt(json_dumps(secret_array), public_key=PUBLIC_KEY) |
| 75 | + |
64 | 76 | input_with_secret = {
|
65 | 77 | 'foo': 'bar',
|
66 |
| - 'secret': f'{ENCRYPTED_INPUT_VALUE_PREFIX}:{encrypted_secret["encrypted_password"]}:{encrypted_secret["encrypted_value"]}', # noqa: E501 |
| 78 | + 'secret_string_legacy': ( |
| 79 | + f'{ENCRYPTED_STRING_VALUE_PREFIX}:' |
| 80 | + f'{encrypted_string_legacy["encrypted_password"]}:' |
| 81 | + f'{encrypted_string_legacy["encrypted_value"]}' |
| 82 | + ), |
| 83 | + 'secret_string': ( |
| 84 | + f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:' |
| 85 | + f'{encrypted_string["encrypted_password"]}:' |
| 86 | + f'{encrypted_string["encrypted_value"]}' |
| 87 | + ), |
| 88 | + 'secret_object': ( |
| 89 | + f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:' |
| 90 | + f'{encrypted_object["encrypted_password"]}:' |
| 91 | + f'{encrypted_object["encrypted_value"]}' |
| 92 | + ), |
| 93 | + 'secret_array': ( |
| 94 | + f'{ENCRYPTED_JSON_VALUE_PREFIX}:schemahash:' |
| 95 | + f'{encrypted_array["encrypted_password"]}:' |
| 96 | + f'{encrypted_array["encrypted_value"]}' |
| 97 | + ), |
67 | 98 | }
|
68 | 99 |
|
69 | 100 | async with Actor as actor:
|
70 |
| - await actor.set_value(key=input_key, value=input_with_secret) |
| 101 | + await actor.set_value(key=input_key, value=input_with_secret, content_type='application/json') |
71 | 102 | actor_input = await actor.get_input()
|
72 | 103 | assert actor_input['foo'] == input_with_secret['foo']
|
73 |
| - assert actor_input['secret'] == secret_string |
| 104 | + assert actor_input['secret_string_legacy'] == secret_string_legacy |
| 105 | + assert actor_input['secret_string'] == secret_string |
| 106 | + assert actor_input['secret_object'] == secret_object |
| 107 | + assert actor_input['secret_array'] == secret_array |
0 commit comments