55// Tests security properties, invariants, and edge cases.
66
77use presswerk_core:: {
8- AppConfig , DocumentType , PrintJob , PrintSettings , JobSource , PageRange , PaperSize ,
8+ AppConfig , DocumentType , JobSource , PageRange , PaperSize , PrintJob , PrintSettings ,
99} ;
1010
1111// ============================================================================
@@ -34,8 +34,11 @@ fn aspect_html_injection_in_document_name() {
3434 for name in malicious_names {
3535 // These should be detected as suspicious by the application
3636 assert ! (
37- name. contains( '<' ) || name. contains( '>' ) || name. contains( '\'' )
38- || name. contains( '/' ) || name. contains( '.' ) ,
37+ name. contains( '<' )
38+ || name. contains( '>' )
39+ || name. contains( '\'' )
40+ || name. contains( '/' )
41+ || name. contains( '.' ) ,
3942 "Potential injection in: {}" ,
4043 name
4144 ) ;
@@ -55,7 +58,11 @@ fn aspect_path_traversal_prevention() {
5558 // Check for path traversal indicators
5659 let has_traversal = path. contains ( "../" ) || path. contains ( "..\\ " ) || path. starts_with ( '/' ) ;
5760 if should_be_suspicious {
58- assert ! ( has_traversal, "Path traversal pattern should be detected in: {}" , path) ;
61+ assert ! (
62+ has_traversal,
63+ "Path traversal pattern should be detected in: {}" ,
64+ path
65+ ) ;
5966 }
6067 }
6168}
@@ -90,7 +97,10 @@ fn aspect_page_count_validation() {
9097 "hash" . to_string ( ) ,
9198 ) ;
9299
93- job. settings . page_range = Some ( PageRange { start : 100 , end : 50 } ) ;
100+ job. settings . page_range = Some ( PageRange {
101+ start : 100 ,
102+ end : 50 ,
103+ } ) ;
94104
95105 // Invalid range: start > end should be detected
96106 if let Some ( range) = & job. settings . page_range {
@@ -113,7 +123,11 @@ fn aspect_invalid_dpi_detection() {
113123 const MAX_DPI : u32 = 1200 ;
114124
115125 for dpi in valid_dpis {
116- assert ! ( dpi >= MIN_DPI && dpi <= MAX_DPI , "DPI {} should be valid" , dpi) ;
126+ assert ! (
127+ dpi >= MIN_DPI && dpi <= MAX_DPI ,
128+ "DPI {} should be valid" ,
129+ dpi
130+ ) ;
117131 }
118132
119133 for dpi in invalid_dpis {
@@ -177,7 +191,10 @@ fn aspect_error_message_sanitization() {
177191 // Check for common sensitive patterns
178192 let contains_password = msg. contains ( "password" ) ;
179193 let contains_ip = msg. contains ( "192.168" ) ;
180- assert ! ( contains_password || contains_ip, "Error message should contain sensitive data (for testing)" ) ;
194+ assert ! (
195+ contains_password || contains_ip,
196+ "Error message should contain sensitive data (for testing)"
197+ ) ;
181198 // In production, these should be redacted
182199 }
183200}
@@ -246,7 +263,10 @@ fn aspect_max_copies_limit() {
246263
247264 // Beyond practical limits would need manual override
248265 let excessive_copies = 10_000u32 ;
249- assert ! ( excessive_copies > MAX_COPIES , "Excessive copies should be detectable" ) ;
266+ assert ! (
267+ excessive_copies > MAX_COPIES ,
268+ "Excessive copies should be detectable"
269+ ) ;
250270}
251271
252272#[ test]
0 commit comments