@@ -45,6 +45,71 @@ def test_trims_trailing_slashes_on_uris():
4545 assert config .stream_base_uri == "https://blog.launchdarkly.com"
4646
4747
48+ def test_sdk_key_validation_valid_keys ():
49+ """Test that valid SDK keys are accepted"""
50+ valid_keys = [
51+ "sdk-12345678-1234-1234-1234-123456789012" ,
52+ "valid-sdk-key-123" ,
53+ "VALID_SDK_KEY_456" ,
54+ "test.key_with.dots" ,
55+ "test-key-with-hyphens"
56+ ]
57+
58+ for key in valid_keys :
59+ config = Config (sdk_key = key )
60+ assert config .sdk_key == key
61+
62+
63+ def test_sdk_key_validation_invalid_keys ():
64+ """Test that invalid SDK keys are not set"""
65+ invalid_keys = [
66+ "sdk-key-with-\x00 -null" ,
67+ "sdk-key-with-\n -newline" ,
68+ "sdk-key-with-\t -tab" ,
69+ "sdk key with spaces" ,
70+ "sdk@key#with$special%chars" ,
71+ "sdk/key\\ with/slashes"
72+ ]
73+
74+ for key in invalid_keys :
75+ config = Config (sdk_key = key )
76+ assert config .sdk_key == ''
77+
78+
79+ def test_sdk_key_validation_empty_key ():
80+ """Test that empty SDK keys are accepted"""
81+ config = Config (sdk_key = "" )
82+ assert config .sdk_key == ""
83+
84+
85+ def test_sdk_key_validation_none_key ():
86+ """Test that None SDK keys are accepted"""
87+ config = Config (sdk_key = None )
88+ assert config .sdk_key == ''
89+
90+
91+ def test_sdk_key_validation_max_length ():
92+ """Test SDK key maximum length validation"""
93+ valid_key = "a" * 8192
94+ config = Config (sdk_key = valid_key )
95+ assert config .sdk_key == valid_key
96+
97+ invalid_key = "a" * 8193
98+ config = Config (sdk_key = invalid_key )
99+ assert config .sdk_key == ''
100+
101+
102+ def test_copy_with_new_sdk_key_validation ():
103+ """Test that copy_with_new_sdk_key validates the new key"""
104+ original_config = Config (sdk_key = "valid-key" )
105+
106+ new_config = original_config .copy_with_new_sdk_key ("another-valid-key" )
107+ assert new_config .sdk_key == "another-valid-key"
108+
109+ invalid_config = original_config .copy_with_new_sdk_key ("invalid key with spaces" )
110+ assert invalid_config .sdk_key == ''
111+
112+
48113def application_can_be_set_and_read ():
49114 application = {"id" : "my-id" , "version" : "abcdef" }
50115 config = Config (sdk_key = "SDK_KEY" , application = application )
0 commit comments