Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Unified Diff: third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp

Issue 2589273003: CSP: fix bugs in parseHost (+ add unit test) (Closed)
Patch Set: Addressed comments. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp
diff --git a/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp b/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp
index 73697a53f75f57011d30e14ca61784761b9ce565..c0cca7e0840d43bd92b04b4547c6f8048fdaed8e 100644
--- a/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp
+++ b/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp
@@ -1336,4 +1336,40 @@ TEST_F(SourceListDirectiveTest, GetSources) {
}
}
+TEST_F(SourceListDirectiveTest, ParseHost) {
+ struct TestCase {
+ String sources;
+ bool expected;
+ } cases[] = {
+ // Wildcard.
+ {"*", true},
+ {"*.", false},
+ {"*.a", true},
+ {"a.*.a", false},
+ {"a.*", false},
+
+ // Dots.
+ {"a.b.c", true},
+ {"a.b.", false},
+ {".b.c", false},
+ {"a..c", false},
+
+ // Valid/Invalid characters.
+ {"az09-", true},
+ {"+", false},
+ };
+
+ for (const auto& test : cases) {
+ String host;
+ CSPSource::WildcardDisposition disposition = CSPSource::NoWildcard;
+ Vector<UChar> characters;
+ test.sources.appendTo(characters);
+ const UChar* start = characters.data();
+ const UChar* end = start + characters.size();
+ EXPECT_EQ(test.expected,
+ SourceListDirective::parseHost(start, end, host, disposition))
+ << "SourceListDirective::parseHost fail to parse: " << test.sources;
+ }
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/core/frame/csp/SourceListDirective.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698