diff --git a/src/utils/web_security/csp/content_security_policies/content_security_policy_directive.rs b/src/utils/web_security/csp/content_security_policies/content_security_policy_directive.rs index a49526a..be41661 100644 --- a/src/utils/web_security/csp/content_security_policies/content_security_policy_directive.rs +++ b/src/utils/web_security/csp/content_security_policies/content_security_policy_directive.rs @@ -43,7 +43,7 @@ pub enum ContentSecurityPolicyDirective { // 1 extension directive #[serde(deserialize_with = "deserialize_directive_without_value")] UpgradeInsecureRequests, - // 2 experimental directives + // 2 trusted types directives RequireTrustedTypesFor([ContentSecurityPolicyRequireTrustedTypesForDirectiveValue; 1]), TrustedTypes(HashSet), // 2 reporting directives @@ -382,6 +382,13 @@ mod tests { } "###); + assert_json_snapshot!(ContentSecurityPolicyDirective::TrustedTypes(HashSet::new()), @r###" + { + "n": "trusted-types", + "v": [] + } + "###); + assert_json_snapshot!(ContentSecurityPolicyDirective::ReportTo(["https://google.com".to_string()]), @r###" { "n": "report-to", @@ -435,6 +442,13 @@ mod tests { @r###""trusted-types 'allow-duplicates' my-another-policy my-policy""### ); + assert_debug_snapshot!( + String::try_from( + ContentSecurityPolicyDirective::TrustedTypes(HashSet::new()) + )?, + @r###""trusted-types""### + ); + Ok(()) } @@ -675,6 +689,16 @@ mod tests { ContentSecurityPolicyDirective::UpgradeInsecureRequests ); + let directive = serde_json::from_value::(json!({ + "name": "trusted-types", + "value": [] + }))?; + + assert_eq!( + ContentSecurityPolicyDirective::try_from(&directive)?, + ContentSecurityPolicyDirective::TrustedTypes(HashSet::new()) + ); + Ok(()) }