9
9
10
10
from ..test_crypto import PRIVATE_KEY_PASSWORD , PRIVATE_KEY_PEM_BASE64 , PUBLIC_KEY
11
11
from apify import Actor
12
- from apify ._consts import ENCRYPTED_INPUT_VALUE_PREFIX
12
+ from apify ._consts import ENCRYPTED_STRING_VALUE_PREFIX , ENCRYPTED_JSON_VALUE_PREFIX
13
13
from apify ._crypto import public_encrypt
14
14
15
15
if TYPE_CHECKING :
@@ -74,11 +74,26 @@ async def test_get_input_with_encrypted_secrets(
74
74
monkeypatch .setenv (ApifyEnvVars .INPUT_SECRETS_PRIVATE_KEY_PASSPHRASE , PRIVATE_KEY_PASSWORD )
75
75
76
76
input_key = 'INPUT'
77
+ secret_string_legacy = 'secret-string'
77
78
secret_string = 'secret-string'
78
- encrypted_secret = public_encrypt (secret_string , public_key = PUBLIC_KEY )
79
+ secret_object = {'foo' : 'bar' , 'baz' : 'qux' }
80
+ secret_array = ['foo' , 'bar' , 'baz' ]
81
+
82
+ # The legacy encryption format uses ENCRYPTED_STRING_VALUE_PREFIX prefix, value in raw string and does not include schemahash.
83
+ # The new format uses ENCRYPTED_JSON_VALUE_PREFIX prefix, value in JSON format and includes schemahash.
84
+ # We are testing both formats to ensure backward compatibility.
85
+
86
+ encrypted_string_legacy = public_encrypt (secret_string_legacy , public_key = PUBLIC_KEY )
87
+ encrypted_string = public_encrypt (json_dumps (secret_string ), public_key = PUBLIC_KEY )
88
+ encrypted_object = public_encrypt (json_dumps (secret_object ), public_key = PUBLIC_KEY )
89
+ encrypted_array = public_encrypt (json_dumps (secret_array ), public_key = PUBLIC_KEY )
90
+
79
91
input_with_secret = {
80
92
'foo' : 'bar' ,
81
- 'secret' : f'{ ENCRYPTED_INPUT_VALUE_PREFIX } :{ encrypted_secret ["encrypted_password" ]} :{ encrypted_secret ["encrypted_value" ]} ' , # noqa: E501
93
+ 'secret_string_legacy' : f'{ ENCRYPTED_STRING_VALUE_PREFIX } :{ encrypted_string_legacy ["encrypted_password" ]} :{ encrypted_string_legacy ["encrypted_value" ]} ' ,
94
+ 'secret_string' : f'{ ENCRYPTED_JSON_VALUE_PREFIX } :schemahash:{ encrypted_string ["encrypted_password" ]} :{ encrypted_string ["encrypted_value" ]} ' ,
95
+ 'secret_object' : f'{ ENCRYPTED_JSON_VALUE_PREFIX } :schemahash:{ encrypted_object ["encrypted_password" ]} :{ encrypted_object ["encrypted_value" ]} ' ,
96
+ 'secret_array' : f'{ ENCRYPTED_JSON_VALUE_PREFIX } :schemahash:{ encrypted_array ["encrypted_password" ]} :{ encrypted_array ["encrypted_value" ]} ' ,
82
97
}
83
98
84
99
await memory_storage_client .key_value_stores ().get_or_create (id = 'default' )
@@ -91,4 +106,7 @@ async def test_get_input_with_encrypted_secrets(
91
106
async with Actor as my_actor :
92
107
input = await my_actor .get_input () # noqa: A001
93
108
assert input ['foo' ] == input_with_secret ['foo' ]
94
- assert input ['secret' ] == secret_string
109
+ assert input ['secret_string_legacy' ] == secret_string_legacy
110
+ assert input ['secret_string' ] == secret_string
111
+ assert input ['secret_object' ] == secret_object
112
+ assert input ['secret_array' ] == secret_array
0 commit comments