-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathtest_util.py
More file actions
65 lines (50 loc) · 2.16 KB
/
test_util.py
File metadata and controls
65 lines (50 loc) · 2.16 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
import logging
from ldclient.impl.util import validate_sdk_key_format
def test_validate_sdk_key_format_valid():
"""Test validation of valid SDK keys"""
logger = logging.getLogger('test')
valid_keys = [
"sdk-12345678-1234-1234-1234-123456789012",
"valid-sdk-key-123",
"VALID_SDK_KEY_456",
"test.key_with.dots",
"test-key-with-hyphens"
]
for key in valid_keys:
result = validate_sdk_key_format(key, logger)
assert result == key # Should return the same key if valid
def test_validate_sdk_key_format_invalid():
"""Test validation of invalid SDK keys"""
logger = logging.getLogger('test')
invalid_keys = [
"sdk-key-with-\x00-null",
"sdk-key-with-\n-newline",
"sdk-key-with-\t-tab",
"sdk key with spaces",
"sdk@key#with$special%chars",
"sdk/key\\with/slashes"
]
for key in invalid_keys:
result = validate_sdk_key_format(key, logger)
assert result == '' # Should return empty string for invalid keys
def test_validate_sdk_key_format_non_string():
"""Test validation of non-string SDK keys"""
logger = logging.getLogger('test')
non_string_values = [123, object(), [], {}]
for value in non_string_values:
result = validate_sdk_key_format(value, logger)
assert result == '' # Should return empty string for non-string values
def test_validate_sdk_key_format_empty_and_none():
"""Test validation of empty and None SDK keys"""
logger = logging.getLogger('test')
assert validate_sdk_key_format("", logger) == '' # Empty string should return empty string
assert validate_sdk_key_format(None, logger) == '' # None should return empty string
def test_validate_sdk_key_format_max_length():
"""Test validation of SDK key maximum length"""
logger = logging.getLogger('test')
valid_key = "a" * 8192
result = validate_sdk_key_format(valid_key, logger)
assert result == valid_key # Should return the same key if valid
invalid_key = "a" * 8193
result = validate_sdk_key_format(invalid_key, logger)
assert result == '' # Should return empty string for keys that are too long