|
5 | 5 | from enum import Enum
|
6 | 6 |
|
7 | 7 | from apify_shared.utils import (
|
| 8 | + create_hmac_signature, |
| 9 | + encode_base62, |
8 | 10 | filter_out_none_values_recursively,
|
9 | 11 | filter_out_none_values_recursively_internal,
|
10 | 12 | ignore_docs,
|
@@ -146,3 +148,26 @@ def testing_function(_a: str, _b: str) -> str:
|
146 | 148 | return 'dummy'
|
147 | 149 |
|
148 | 150 | assert testing_function is ignore_docs(testing_function)
|
| 151 | + |
| 152 | + |
| 153 | +def test_encode_base62() -> None: |
| 154 | + assert encode_base62(0) == '0' |
| 155 | + assert encode_base62(10) == 'a' |
| 156 | + assert encode_base62(999999999) == '15FTGf' |
| 157 | + |
| 158 | + |
| 159 | +# This test ensures compatibility with the JavaScript version of the same method. |
| 160 | +# https://github.com/apify/apify-shared-js/blob/master/packages/utilities/src/hmac.ts |
| 161 | +def test_create_valid_hmac_signature() -> None: |
| 162 | + # This test uses the same secret key and message as in JS tests. |
| 163 | + secret_key = 'hmac-secret-key' |
| 164 | + message = 'hmac-message-to-be-authenticated' |
| 165 | + assert create_hmac_signature(secret_key, message) == 'pcVagAsudj8dFqdlg7mG' |
| 166 | + |
| 167 | + |
| 168 | +def test_create_same_hmac() -> None: |
| 169 | + # This test uses the same secret key and message as in JS tests. |
| 170 | + secret_key = 'hmac-same-secret-key' |
| 171 | + message = 'hmac-same-message-to-be-authenticated' |
| 172 | + assert create_hmac_signature(secret_key, message) == 'FYMcmTIm3idXqleF1Sw5' |
| 173 | + assert create_hmac_signature(secret_key, message) == 'FYMcmTIm3idXqleF1Sw5' |
0 commit comments