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

Side by Side Diff: net/http/http_security_headers_unittest.cc

Issue 2895373002: Do not require Expect-CT report-uris to be quoted (Closed)
Patch Set: Created 3 years, 7 months 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 unified diff | Download patch
« no previous file with comments | « net/http/http_security_headers.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h> 5 #include <stdint.h>
6 #include <algorithm> 6 #include <algorithm>
7 7
8 #include "base/base64.h" 8 #include "base/base64.h"
9 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
10 #include "crypto/sha2.h" 10 #include "crypto/sha2.h"
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 &enforce, &report_uri)); 987 &enforce, &report_uri));
988 EXPECT_FALSE(ParseExpectCTHeader(",", &max_age, &enforce, &report_uri)); 988 EXPECT_FALSE(ParseExpectCTHeader(",", &max_age, &enforce, &report_uri));
989 EXPECT_FALSE( 989 EXPECT_FALSE(
990 ParseExpectCTHeader("max-age, ,", &max_age, &enforce, &report_uri)); 990 ParseExpectCTHeader("max-age, ,", &max_age, &enforce, &report_uri));
991 991
992 // Test that the parser rejects misquoted or invalid report-uris. 992 // Test that the parser rejects misquoted or invalid report-uris.
993 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=\"http://foo;bar\'", 993 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=\"http://foo;bar\'",
994 &max_age, &enforce, &report_uri)); 994 &max_age, &enforce, &report_uri));
995 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=\"foo;bar\"", 995 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=\"foo;bar\"",
996 &max_age, &enforce, &report_uri)); 996 &max_age, &enforce, &report_uri));
997 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=http://blah",
998 &max_age, &enforce, &report_uri));
999 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=\"\"", &max_age, 997 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, report-uri=\"\"", &max_age,
1000 &enforce, &report_uri)); 998 &enforce, &report_uri));
1001 999
1002 // Test that the parser does not fix up misquoted values. 1000 // Test that the parser does not fix up misquoted values.
1003 EXPECT_FALSE( 1001 EXPECT_FALSE(
1004 ParseExpectCTHeader("max-age=\"999", &max_age, &enforce, &report_uri)); 1002 ParseExpectCTHeader("max-age=\"999", &max_age, &enforce, &report_uri));
1005 1003
1006 // Test that the parser rejects headers that contain duplicate directives. 1004 // Test that the parser rejects headers that contain duplicate directives.
1007 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, enforce, max-age=99999", 1005 EXPECT_FALSE(ParseExpectCTHeader("max-age=999, enforce, max-age=99999",
1008 &max_age, &enforce, &report_uri)); 1006 &max_age, &enforce, &report_uri));
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 1076
1079 enforce = false; 1077 enforce = false;
1080 report_uri = GURL(); 1078 report_uri = GURL();
1081 EXPECT_TRUE( 1079 EXPECT_TRUE(
1082 ParseExpectCTHeader("enforce,report-uri=\"https://foo.test\",max-age=123", 1080 ParseExpectCTHeader("enforce,report-uri=\"https://foo.test\",max-age=123",
1083 &max_age, &enforce, &report_uri)); 1081 &max_age, &enforce, &report_uri));
1084 EXPECT_EQ(base::TimeDelta::FromSeconds(123), max_age); 1082 EXPECT_EQ(base::TimeDelta::FromSeconds(123), max_age);
1085 EXPECT_TRUE(enforce); 1083 EXPECT_TRUE(enforce);
1086 EXPECT_EQ(GURL("https://foo.test"), report_uri); 1084 EXPECT_EQ(GURL("https://foo.test"), report_uri);
1087 1085
1086 enforce = false;
1087 report_uri = GURL();
1088 EXPECT_TRUE(
1089 ParseExpectCTHeader("enforce,report-uri=https://foo.test,max-age=123",
1090 &max_age, &enforce, &report_uri));
1091 EXPECT_EQ(base::TimeDelta::FromSeconds(123), max_age);
1092 EXPECT_TRUE(enforce);
1093 EXPECT_EQ(GURL("https://foo.test"), report_uri);
1094
1088 report_uri = GURL(); 1095 report_uri = GURL();
1089 enforce = false; 1096 enforce = false;
1090 EXPECT_TRUE(ParseExpectCTHeader("report-uri=\"https://foo.test\",max-age=123", 1097 EXPECT_TRUE(ParseExpectCTHeader("report-uri=\"https://foo.test\",max-age=123",
1091 &max_age, &enforce, &report_uri)); 1098 &max_age, &enforce, &report_uri));
1092 EXPECT_EQ(base::TimeDelta::FromSeconds(123), max_age); 1099 EXPECT_EQ(base::TimeDelta::FromSeconds(123), max_age);
1093 EXPECT_FALSE(enforce); 1100 EXPECT_FALSE(enforce);
1094 EXPECT_EQ(GURL("https://foo.test"), report_uri); 1101 EXPECT_EQ(GURL("https://foo.test"), report_uri);
1095 1102
1096 report_uri = GURL(); 1103 report_uri = GURL();
1097 EXPECT_TRUE(ParseExpectCTHeader(" enFORcE, max-age=123, pumpkin=kitten", 1104 EXPECT_TRUE(ParseExpectCTHeader(" enFORcE, max-age=123, pumpkin=kitten",
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 EXPECT_TRUE(ParseExpectCTHeader( 1193 EXPECT_TRUE(ParseExpectCTHeader(
1187 " max-age=999999999999999999999999999999999999999999999 ," 1194 " max-age=999999999999999999999999999999999999999999999 ,"
1188 " enforce ", 1195 " enforce ",
1189 &max_age, &enforce, &report_uri)); 1196 &max_age, &enforce, &report_uri));
1190 EXPECT_EQ(base::TimeDelta::FromSeconds(kMaxExpectCTAgeSecs), max_age); 1197 EXPECT_EQ(base::TimeDelta::FromSeconds(kMaxExpectCTAgeSecs), max_age);
1191 EXPECT_TRUE(enforce); 1198 EXPECT_TRUE(enforce);
1192 EXPECT_TRUE(report_uri.is_empty()); 1199 EXPECT_TRUE(report_uri.is_empty());
1193 } 1200 }
1194 1201
1195 }; // namespace net 1202 }; // namespace net
OLDNEW
« no previous file with comments | « net/http/http_security_headers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698