/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Tests for IntegrityPolicyWAICT::ParseHeader, which parses the value of the // Integrity-Policy-WAICT-v1 HTTP response header. // // Websites signal that they want user-agents to enforce WAICT through the use // of the HTTP response header: Integrity-Policy-WAICT-v1. // // The header is a structured response header (Dictionary type per RFC 9651). // The following key-value pairs MUST be present: // max-age - An sf-integer that MUST be >= 0. How long (in seconds) // user-agents MUST enforce WAICT after seeing this header. // mode - An sf-token containing either "enforce" or "report". In enforce // mode, subresources that fail integrity checks are blocked. In report // mode, failures are reported but resources are still loaded. // manifest - An sf-string containing a URL where the user-agent can fetch // the WAICT manifest. The URL MAY be relative. // blocked-destinations - An sf-inner-list of one or more sf-tokens // indicating the destination types (e.g., script, style) to which // integrity checks apply. Unrecognized tokens MUST be ignored. // // If one or more mandatory keys is missing or invalid, the entire header MUST // be ignored. The following key-value pairs are optional: // preload - An sf-boolean. Not used directly by user-agents. // endpoints - Indicates endpoint(s) for submitting violations. // // Any other keys MUST be ignored. // // Example: // Integrity-Policy-WAICT-v1: max-age=90, mode=report, // blocked-destinations=(script style), preload=?0, // endpoints=(foo-reports), // manifest="/.well-known/waict/manifests/1.json" // // Tests are organized by field. For each field we test valid values, missing // (required vs optional), and invalid values where applicable.
class WAICTHeaderParsingTest : public ::testing::Test { protected:
nsresult ParseHeader(const nsACString& aHeader) {
RefPtr<IntegrityPolicyWAICT> policy = new IntegrityPolicyWAICT(nullptr); return policy->ParseHeader(aHeader);
}
};
// Manifest: // An sf-string containing a URL where the user-agent can fetch the // WAICT manifest. The URL MAY be relative, in which case it is resolved // against the origin.
// mode must be an SFV token (unquoted), not a string.
TEST_F(WAICTHeaderParsingTest, Mode_AsString) {
EXPECT_NS_FAILED(ParseHeader( "manifest=\"waict-manifest.json\", max-age=86400, mode=\"enforce\", " "blocked-destinations=(script)"_ns));
}
// blocked-destinations - An sf-inner-list of one or more sf-tokens indicating // the destination types to which integrity checks apply. Unrecognised tokens // MUST be ignored.
// The entire header must be rejected if it is not valid SFV.
TEST_F(WAICTHeaderParsingTest, MalformedSFV) {
EXPECT_NS_FAILED(ParseHeader("not valid sfv !!!"_ns));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.