88 SecurityMetadata ,
99 SecurityError ,
1010 privileged ,
11- sanitize ,
1211 declassify ,
1312 taint_sources
1413)
@@ -115,30 +114,8 @@ def has_access(self, entitlement: str | None) -> bool:
115114 assert not cblock .is_safe (None )
116115
117116
118- class TestSanitizeDeclassify :
119- """Test sanitize and declassify functions."""
120-
121- def test_sanitize_creates_new_object (self ):
122- """Test that sanitize creates a new object without mutating original."""
123- original = CBlock ("test content" )
124- original .mark_tainted ()
125-
126- sanitized = sanitize (original )
127-
128- # Objects are different
129- assert original is not sanitized
130- assert id (original ) != id (sanitized )
131-
132- # Content is preserved
133- assert original .value == sanitized .value
134-
135- # Security levels are different
136- assert not original .is_safe ()
137- assert sanitized .is_safe ()
138- assert sanitized ._meta ["_security" ].sec_level .level_type == "none"
139-
140- # Original is unchanged
141- assert original ._meta ["_security" ].is_tainted ()
117+ class TestDeclassify :
118+ """Test declassify function."""
142119
143120 def test_declassify_creates_new_object (self ):
144121 """Test that declassify creates a new object without mutating original."""
@@ -162,16 +139,16 @@ def test_declassify_creates_new_object(self):
162139 # Original is unchanged
163140 assert original ._meta ["_security" ].is_tainted ()
164141
165- def test_sanitize_preserves_other_metadata (self ):
166- """Test that sanitize preserves other metadata."""
142+ def test_declassify_preserves_other_metadata (self ):
143+ """Test that declassify preserves other metadata."""
167144 original = CBlock ("test content" , meta = {"custom" : "value" , "other" : 123 })
168145 original .mark_tainted ()
169146
170- sanitized = sanitize (original )
147+ declassified = declassify (original )
171148
172- assert sanitized ._meta ["custom" ] == "value"
173- assert sanitized ._meta ["other" ] == 123
174- assert sanitized ._meta ["_security" ].sec_level .level_type == "none"
149+ assert declassified ._meta ["custom" ] == "value"
150+ assert declassified ._meta ["other" ] == 123
151+ assert declassified ._meta ["_security" ].sec_level .level_type == "none"
175152
176153
177154class TestPrivilegedDecorator :
@@ -189,17 +166,17 @@ def safe_function(cblock: CBlock) -> str:
189166 result = safe_function (safe_cblock )
190167 assert result == "Processed: safe content"
191168
192- def test_privileged_accepts_sanitized_input (self ):
193- """Test that privileged functions accept sanitized input."""
169+ def test_privileged_accepts_declassified_input (self ):
170+ """Test that privileged functions accept declassified input."""
194171 @privileged
195172 def safe_function (cblock : CBlock ) -> str :
196173 return f"Processed: { cblock .value } "
197174
198175 tainted_cblock = CBlock ("tainted content" )
199176 tainted_cblock .mark_tainted ()
200- sanitized_cblock = sanitize (tainted_cblock )
177+ declassified_cblock = declassify (tainted_cblock )
201178
202- result = safe_function (sanitized_cblock )
179+ result = safe_function (declassified_cblock )
203180 assert result == "Processed: tainted content"
204181
205182 def test_privileged_rejects_tainted_input (self ):
@@ -371,8 +348,8 @@ def test_security_flow_through_generation(self):
371348 assert not mot .is_safe ()
372349 assert mot ._meta ["_security" ].is_tainted ()
373350
374- # Sanitize the output
375- safe_mot = sanitize (mot )
351+ # Declassify the output
352+ safe_mot = declassify (mot )
376353 assert safe_mot .is_safe ()
377354 assert safe_mot ._meta ["_security" ].sec_level .level_type == "none"
378355
@@ -398,7 +375,7 @@ def process_response(mot: ModelOutputThunk) -> str:
398375 with pytest .raises (SecurityError ):
399376 process_response (mot )
400377
401- # Sanitize and try again
402- safe_mot = sanitize (mot )
378+ # Declassify and try again
379+ safe_mot = declassify (mot )
403380 result = process_response (safe_mot )
404381 assert result == "Processed: tainted response"
0 commit comments