@@ -6,44 +6,44 @@ use crate::utils::web_security::{
66use anyhow:: anyhow;
77use content_security_policy:: Directive ;
88use serde:: { Deserialize , Deserializer , Serialize , de} ;
9- use std:: collections:: HashSet ;
9+ use std:: collections:: BTreeSet ;
1010
1111#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq ) ]
1212#[ serde( rename_all = "kebab-case" , tag = "name" , content = "value" ) ]
1313pub enum ContentSecurityPolicyDirective {
1414 // 15 fetch directives
15- ChildSrc ( HashSet < String > ) ,
16- ConnectSrc ( HashSet < String > ) ,
17- DefaultSrc ( HashSet < String > ) ,
18- FontSrc ( HashSet < String > ) ,
19- FrameSrc ( HashSet < String > ) ,
20- ImgSrc ( HashSet < String > ) ,
21- ManifestSrc ( HashSet < String > ) ,
22- MediaSrc ( HashSet < String > ) ,
23- ObjectSrc ( HashSet < String > ) ,
24- ScriptSrc ( HashSet < String > ) ,
25- ScriptSrcElem ( HashSet < String > ) ,
26- ScriptSrcAttr ( HashSet < String > ) ,
27- StyleSrc ( HashSet < String > ) ,
28- StyleSrcElem ( HashSet < String > ) ,
29- StyleSrcAttr ( HashSet < String > ) ,
15+ ChildSrc ( BTreeSet < String > ) ,
16+ ConnectSrc ( BTreeSet < String > ) ,
17+ DefaultSrc ( BTreeSet < String > ) ,
18+ FontSrc ( BTreeSet < String > ) ,
19+ FrameSrc ( BTreeSet < String > ) ,
20+ ImgSrc ( BTreeSet < String > ) ,
21+ ManifestSrc ( BTreeSet < String > ) ,
22+ MediaSrc ( BTreeSet < String > ) ,
23+ ObjectSrc ( BTreeSet < String > ) ,
24+ ScriptSrc ( BTreeSet < String > ) ,
25+ ScriptSrcElem ( BTreeSet < String > ) ,
26+ ScriptSrcAttr ( BTreeSet < String > ) ,
27+ StyleSrc ( BTreeSet < String > ) ,
28+ StyleSrcElem ( BTreeSet < String > ) ,
29+ StyleSrcAttr ( BTreeSet < String > ) ,
3030 // 2 other directives
3131 Webrtc ( [ ContentSecurityPolicyWebrtcDirectiveValue ; 1 ] ) ,
32- WorkerSrc ( HashSet < String > ) ,
32+ WorkerSrc ( BTreeSet < String > ) ,
3333 // 2 document directives
34- BaseUri ( HashSet < String > ) ,
35- Sandbox ( HashSet < ContentSecurityPolicySandboxDirectiveValue > ) ,
34+ BaseUri ( BTreeSet < String > ) ,
35+ Sandbox ( BTreeSet < ContentSecurityPolicySandboxDirectiveValue > ) ,
3636 // 2 navigation directives
37- FormAction ( HashSet < String > ) ,
38- FrameAncestors ( HashSet < String > ) ,
37+ FormAction ( BTreeSet < String > ) ,
38+ FrameAncestors ( BTreeSet < String > ) ,
3939 // 1 extension directive
4040 #[ serde( deserialize_with = "deserialize_directive_without_value" ) ]
4141 UpgradeInsecureRequests ,
4242 // 2 trusted types directives
4343 RequireTrustedTypesFor ( [ ContentSecurityPolicyRequireTrustedTypesForDirectiveValue ; 1 ] ) ,
44- TrustedTypes ( HashSet < ContentSecurityPolicyTrustedTypesDirectiveValue > ) ,
44+ TrustedTypes ( BTreeSet < ContentSecurityPolicyTrustedTypesDirectiveValue > ) ,
4545 // 2 reporting directives
46- ReportUri ( HashSet < String > ) ,
46+ ReportUri ( BTreeSet < String > ) ,
4747 ReportTo ( [ String ; 1 ] ) ,
4848}
4949
@@ -139,11 +139,11 @@ mod tests {
139139 use content_security_policy:: Directive ;
140140 use insta:: { assert_debug_snapshot, assert_json_snapshot} ;
141141 use serde_json:: json;
142- use std:: collections:: HashSet ;
142+ use std:: collections:: BTreeSet ;
143143
144144 #[ test]
145145 fn serialization_to_json ( ) -> anyhow:: Result < ( ) > {
146- let sources = [ "'self'" . to_string ( ) ] . into_iter ( ) . collect :: < HashSet < _ > > ( ) ;
146+ let sources = [ "'self'" . to_string ( ) ] . into_iter ( ) . collect :: < BTreeSet < _ > > ( ) ;
147147 assert_json_snapshot ! ( ContentSecurityPolicyDirective :: ChildSrc ( sources. clone( ) ) , @r###"
148148 {
149149 "name": "child-src",
@@ -368,7 +368,7 @@ mod tests {
368368 }
369369 "### ) ;
370370
371- assert_json_snapshot ! ( ContentSecurityPolicyDirective :: TrustedTypes ( HashSet :: new( ) ) , @r###"
371+ assert_json_snapshot ! ( ContentSecurityPolicyDirective :: TrustedTypes ( BTreeSet :: new( ) ) , @r###"
372372 {
373373 "name": "trusted-types",
374374 "value": []
@@ -401,7 +401,7 @@ mod tests {
401401 assert_debug_snapshot ! (
402402 String :: try_from( ContentSecurityPolicyDirective :: DefaultSrc ( [ "'self'" . to_string( ) , "https:" . to_string( ) ]
403403 . into_iter( )
404- . collect:: <HashSet <_>>( ) ) ) ?, @r###""default-src 'self' https:""### ) ;
404+ . collect:: <BTreeSet <_>>( ) ) ) ?, @r###""default-src 'self' https:""### ) ;
405405
406406 assert_debug_snapshot ! (
407407 String :: try_from( ContentSecurityPolicyDirective :: UpgradeInsecureRequests ) ?,
@@ -430,7 +430,7 @@ mod tests {
430430
431431 assert_debug_snapshot ! (
432432 String :: try_from(
433- ContentSecurityPolicyDirective :: TrustedTypes ( HashSet :: new( ) )
433+ ContentSecurityPolicyDirective :: TrustedTypes ( BTreeSet :: new( ) )
434434 ) ?,
435435 @r###""trusted-types""###
436436 ) ;
@@ -440,7 +440,7 @@ mod tests {
440440
441441 #[ test]
442442 fn deserialization ( ) -> anyhow:: Result < ( ) > {
443- let sources = [ "'self'" . to_string ( ) ] . into_iter ( ) . collect :: < HashSet < _ > > ( ) ;
443+ let sources = [ "'self'" . to_string ( ) ] . into_iter ( ) . collect :: < BTreeSet < _ > > ( ) ;
444444 assert_eq ! (
445445 serde_json:: from_str:: <ContentSecurityPolicyDirective >(
446446 r#"{ "name": "child-src", "value": ["'self'"] }"#
@@ -682,7 +682,7 @@ mod tests {
682682
683683 assert_eq ! (
684684 ContentSecurityPolicyDirective :: try_from( & directive) ?,
685- ContentSecurityPolicyDirective :: TrustedTypes ( HashSet :: new( ) )
685+ ContentSecurityPolicyDirective :: TrustedTypes ( BTreeSet :: new( ) )
686686 ) ;
687687
688688 Ok ( ( ) )
@@ -729,7 +729,7 @@ mod tests {
729729 fn should_correctly_determine_if_supported_for_source ( ) -> anyhow:: Result < ( ) > {
730730 let sources = [ "'self'" . to_string ( ) ]
731731 . into_iter ( )
732- . collect :: < HashSet < String > > ( ) ;
732+ . collect :: < BTreeSet < String > > ( ) ;
733733 let all_directives = vec ! [
734734 ContentSecurityPolicyDirective :: ChildSrc ( sources. clone( ) ) ,
735735 ContentSecurityPolicyDirective :: ConnectSrc ( sources. clone( ) ) ,
0 commit comments