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

Unified Diff: net/cert/ct_policy_enforcer_unittest.cc

Issue 2090713003: Make callers of FromUTC(Local)Exploded in net/ use new time API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments from eroman@ Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/cert/x509_cert_types.cc » ('j') | net/cert/x509_cert_types.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/ct_policy_enforcer_unittest.cc
diff --git a/net/cert/ct_policy_enforcer_unittest.cc b/net/cert/ct_policy_enforcer_unittest.cc
index 59544094c29c26b8dbeab36c6c4c1060a7105ce1..23a2578582082e51527580a8c624689007dbaf3e 100644
--- a/net/cert/ct_policy_enforcer_unittest.cc
+++ b/net/cert/ct_policy_enforcer_unittest.cc
@@ -85,11 +85,11 @@ class CTPolicyEnforcerTest : public ::testing::Test {
sct->log_id = std::string(crypto::kSHA256Length, static_cast<char>(i));
if (timestamp_past_enforcement_date) {
- sct->timestamp =
- base::Time::FromUTCExploded({2015, 8, 0, 15, 0, 0, 0, 0});
+ EXPECT_TRUE(base::Time::FromUTCExploded({2015, 8, 0, 15, 0, 0, 0, 0},
+ &sct->timestamp));
} else {
- sct->timestamp =
- base::Time::FromUTCExploded({2015, 6, 0, 15, 0, 0, 0, 0});
+ EXPECT_TRUE(base::Time::FromUTCExploded({2015, 6, 0, 15, 0, 0, 0, 0},
+ &sct->timestamp));
}
verified_scts->push_back(sct);
@@ -111,10 +111,11 @@ class CTPolicyEnforcerTest : public ::testing::Test {
sct->origin = desired_origin;
sct->log_id = std::string(kCertlyLogID, crypto::kSHA256Length);
if (timestamp_after_disqualification_date) {
- sct->timestamp =
- base::Time::FromUTCExploded({2016, 4, 0, 16, 0, 0, 0, 0});
+ EXPECT_TRUE(base::Time::FromUTCExploded({2016, 4, 0, 16, 0, 0, 0, 0},
+ &sct->timestamp));
} else {
- sct->timestamp = base::Time::FromUTCExploded({2016, 4, 0, 1, 0, 0, 0, 0});
+ EXPECT_TRUE(base::Time::FromUTCExploded({2016, 4, 0, 1, 0, 0, 0, 0},
+ &sct->timestamp));
}
verified_scts->push_back(sct);
@@ -130,6 +131,14 @@ class CTPolicyEnforcerTest : public ::testing::Test {
verified_scts);
}
+ base::Time CreateTime(const base::Time::Exploded& exploded) {
+ base::Time result;
+ if (!base::Time::FromUTCExploded(exploded, &result)) {
+ ADD_FAILURE() << "Failed FromUTCExploded";
+ }
+ return result;
+ }
+
protected:
std::unique_ptr<CTPolicyEnforcer> policy_enforcer_;
scoped_refptr<X509Certificate> chain_;
@@ -443,38 +452,48 @@ TEST_F(CTPolicyEnforcerTest,
ASSERT_TRUE(private_key);
// Test multiple validity periods
+ base::Time time_2015_3_0_25_11_25_0_0 =
+ CreateTime({2015, 3, 0, 25, 11, 25, 0, 0});
+
+ base::Time time_2016_6_0_6_11_25_0_0 =
+ CreateTime({2016, 6, 0, 6, 11, 25, 0, 0});
+
+ base::Time time_2016_6_0_25_11_25_0_0 =
+ CreateTime({2016, 6, 0, 25, 11, 25, 0, 0});
+
+ base::Time time_2016_6_0_27_11_25_0_0 =
+ CreateTime({2016, 6, 0, 27, 11, 25, 0, 0});
+
+ base::Time time_2017_6_0_25_11_25_0_0 =
+ CreateTime({2017, 6, 0, 25, 11, 25, 0, 0});
+
+ base::Time time_2017_6_0_28_11_25_0_0 =
+ CreateTime({2017, 6, 0, 28, 11, 25, 0, 0});
+
+ base::Time time_2018_6_0_25_11_25_0_0 =
+ CreateTime({2018, 6, 0, 25, 11, 25, 0, 0});
+
+ base::Time time_2018_6_0_27_11_25_0_0 =
+ CreateTime({2018, 6, 0, 27, 11, 25, 0, 0});
+
const struct TestData {
base::Time validity_start;
base::Time validity_end;
size_t scts_required;
} kTestData[] = {{// Cert valid for 14 months, needs 2 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2016, 6, 0, 6, 11, 25, 0, 0}),
- 2},
+ time_2015_3_0_25_11_25_0_0, time_2016_6_0_6_11_25_0_0, 2},
{// Cert valid for exactly 15 months, needs 3 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2016, 6, 0, 25, 11, 25, 0, 0}),
- 3},
+ time_2015_3_0_25_11_25_0_0, time_2016_6_0_25_11_25_0_0, 3},
{// Cert valid for over 15 months, needs 3 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2016, 6, 0, 27, 11, 25, 0, 0}),
- 3},
+ time_2015_3_0_25_11_25_0_0, time_2016_6_0_27_11_25_0_0, 3},
{// Cert valid for exactly 27 months, needs 3 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2017, 6, 0, 25, 11, 25, 0, 0}),
- 3},
+ time_2015_3_0_25_11_25_0_0, time_2017_6_0_25_11_25_0_0, 3},
{// Cert valid for over 27 months, needs 4 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2017, 6, 0, 28, 11, 25, 0, 0}),
- 4},
+ time_2015_3_0_25_11_25_0_0, time_2017_6_0_28_11_25_0_0, 4},
{// Cert valid for exactly 39 months, needs 4 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2018, 6, 0, 25, 11, 25, 0, 0}),
- 4},
+ time_2015_3_0_25_11_25_0_0, time_2018_6_0_25_11_25_0_0, 4},
{// Cert valid for over 39 months, needs 5 SCTs.
- base::Time::FromUTCExploded({2015, 3, 0, 25, 11, 25, 0, 0}),
- base::Time::FromUTCExploded({2018, 6, 0, 27, 11, 25, 0, 0}),
- 5}};
+ time_2015_3_0_25_11_25_0_0, time_2018_6_0_27_11_25_0_0, 5}};
for (size_t i = 0; i < arraysize(kTestData); ++i) {
SCOPED_TRACE(i);
« no previous file with comments | « no previous file | net/cert/x509_cert_types.cc » ('j') | net/cert/x509_cert_types.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698