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

Unified Diff: net/quic/crypto/strike_register_test.cc

Issue 388333005: Reject reasons from strike register when nonce validation fails. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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
Index: net/quic/crypto/strike_register_test.cc
diff --git a/net/quic/crypto/strike_register_test.cc b/net/quic/crypto/strike_register_test.cc
index 32295ad5ee3565a15786693b658219cdcd29bc9f..df723579a1b25949ba702f1827aed2c6c5f4d2bc 100644
--- a/net/quic/crypto/strike_register_test.cc
+++ b/net/quic/crypto/strike_register_test.cc
@@ -13,6 +13,7 @@
namespace {
+using net::InsertStatus;
using net::StrikeRegister;
using std::make_pair;
using std::min;
@@ -40,9 +41,9 @@ TEST(StrikeRegisterTest, SimpleHorizon) {
StrikeRegister::DENY_REQUESTS_AT_STARTUP);
uint8 nonce[32];
SetNonce(nonce, 999, kOrbit);
- ASSERT_FALSE(set.Insert(nonce, 1000));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce, 1000));
SetNonce(nonce, 1000, kOrbit);
- ASSERT_FALSE(set.Insert(nonce, 1000));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce, 1000));
EXPECT_EQ(0u, set.GetCurrentValidWindowSecs(1000 /* current time */));
EXPECT_EQ(0u, set.GetCurrentValidWindowSecs(1100 /* current time */));
@@ -60,8 +61,8 @@ TEST(StrikeRegisterTest, NoStartupMode) {
StrikeRegister::NO_STARTUP_PERIOD_NEEDED);
uint8 nonce[32];
SetNonce(nonce, 1000, kOrbit);
- ASSERT_TRUE(set.Insert(nonce, 1000));
- ASSERT_FALSE(set.Insert(nonce, 1000));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce, 1000));
+ EXPECT_EQ(net::NONCE_NOT_UNIQUE_FAILURE, set.Insert(nonce, 1000));
EXPECT_EQ(101u, set.GetCurrentValidWindowSecs(1000 /* current time */));
EXPECT_EQ(101u, set.GetCurrentValidWindowSecs(1050 /* current time */));
@@ -77,9 +78,9 @@ TEST(StrikeRegisterTest, WindowFuture) {
StrikeRegister::DENY_REQUESTS_AT_STARTUP);
uint8 nonce[32];
SetNonce(nonce, 1101, kOrbit);
- ASSERT_FALSE(set.Insert(nonce, 1000));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce, 1000));
SetNonce(nonce, 999, kOrbit);
- ASSERT_FALSE(set.Insert(nonce, 1100));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce, 1100));
}
TEST(StrikeRegisterTest, BadOrbit) {
@@ -90,7 +91,7 @@ TEST(StrikeRegisterTest, BadOrbit) {
uint8 nonce[32];
static const uint8 kBadOrbit[8] = { 0, 0, 0, 0, 1, 1, 1, 1 };
SetNonce(nonce, 1101, kBadOrbit);
- ASSERT_FALSE(set.Insert(nonce, 1100));
+ EXPECT_EQ(net::NONCE_INVALID_ORBIT_FAILURE, set.Insert(nonce, 1100));
}
TEST(StrikeRegisterTest, OneValue) {
@@ -99,7 +100,7 @@ TEST(StrikeRegisterTest, OneValue) {
StrikeRegister::DENY_REQUESTS_AT_STARTUP);
uint8 nonce[32];
SetNonce(nonce, 1101, kOrbit);
- ASSERT_TRUE(set.Insert(nonce, 1101));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce, 1101));
}
TEST(StrikeRegisterTest, RejectDuplicate) {
@@ -109,8 +110,8 @@ TEST(StrikeRegisterTest, RejectDuplicate) {
StrikeRegister::DENY_REQUESTS_AT_STARTUP);
uint8 nonce[32];
SetNonce(nonce, 1101, kOrbit);
- ASSERT_TRUE(set.Insert(nonce, 1101));
- ASSERT_FALSE(set.Insert(nonce, 1101));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce, 1101));
+ EXPECT_EQ(net::NONCE_NOT_UNIQUE_FAILURE, set.Insert(nonce, 1101));
}
TEST(StrikeRegisterTest, HorizonUpdating) {
@@ -127,7 +128,7 @@ TEST(StrikeRegisterTest, HorizonUpdating) {
for (unsigned i = 0; i < 5; i++) {
SetNonce(nonce[i], 1101 + i, kOrbit);
nonce[i][31] = i;
- ASSERT_TRUE(set.Insert(nonce[i], 1100));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce[i], 1100));
}
// Valid window is still equal to |window_secs + 1|.
@@ -136,34 +137,34 @@ TEST(StrikeRegisterTest, HorizonUpdating) {
// This should push the oldest value out and force the horizon to
// be updated.
SetNonce(nonce[5], 1110, kOrbit);
- ASSERT_TRUE(set.Insert(nonce[5], 1110));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce[5], 1110));
// Effective horizon is computed based on the timestamp of the
// value that was pushed out.
EXPECT_EQ(9u, set.GetCurrentValidWindowSecs(1110));
SetNonce(nonce[5], 1111, kOrbit);
- EXPECT_TRUE(set.Insert(nonce[5], 1110));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce[5], 1110));
EXPECT_EQ(8u, set.GetCurrentValidWindowSecs(1110));
// This should be behind the horizon now:
SetNonce(nonce[5], 1101, kOrbit);
nonce[5][31] = 10;
- EXPECT_FALSE(set.Insert(nonce[5], 1110));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce[5], 1110));
// Insert beyond the valid range.
SetNonce(nonce[5], 1117, kOrbit);
nonce[5][31] = 2;
- EXPECT_FALSE(set.Insert(nonce[5], 1110));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce[5], 1110));
// Insert at the upper valid range.
SetNonce(nonce[5], 1116, kOrbit);
nonce[5][31] = 1;
- EXPECT_TRUE(set.Insert(nonce[5], 1110));
+ EXPECT_EQ(net::NONCE_OK, set.Insert(nonce[5], 1110));
// This should be beyond the upper valid range now:
SetNonce(nonce[5], 1116, kOrbit);
nonce[5][31] = 2;
- EXPECT_FALSE(set.Insert(nonce[5], 1110));
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce[5], 1110));
}
}
@@ -177,7 +178,7 @@ TEST(StrikeRegisterTest, InsertMany) {
for (unsigned i = 0; i < 100000; i++) {
SetNonce(nonce, 1101 + i/500, kOrbit);
memcpy(nonce + 12, &i, sizeof(i));
- set.Insert(nonce, 1100);
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, set.Insert(nonce, 1100));
}
}
@@ -201,9 +202,9 @@ class SlowStrikeRegister {
memcpy(orbit_, orbit, sizeof(orbit_));
}
- bool Insert(const uint8 nonce_bytes[32],
- const uint32 nonce_time_external,
- const uint32 current_time_external) {
+ InsertStatus Insert(const uint8 nonce_bytes[32],
+ const uint32 nonce_time_external,
+ const uint32 current_time_external) {
if (nonces_.size() == max_entries_) {
DropOldestEntry();
}
@@ -212,7 +213,7 @@ class SlowStrikeRegister {
// Check to see if the orbit is correct.
if (memcmp(nonce_bytes + 4, orbit_, sizeof(orbit_))) {
- return false;
+ return net::NONCE_INVALID_ORBIT_FAILURE;
}
const uint32 nonce_time =
ExternalTimeToInternal(TimeFromBytes(nonce_bytes));
@@ -221,14 +222,14 @@ class SlowStrikeRegister {
// so we have to reject anything with a timestamp less than or
// equal to that.
if (nonce_time < horizon_) {
- return false;
+ return net::NONCE_INVALID_TIME_FAILURE;
}
// Check that the timestamp is in the current window.
if ((current_time > window_secs_ &&
nonce_time < (current_time - window_secs_)) ||
nonce_time > (current_time + window_secs_)) {
- return false;
+ return net::NONCE_INVALID_TIME_FAILURE;
}
pair<uint32, string> nonce = make_pair(
@@ -237,11 +238,11 @@ class SlowStrikeRegister {
set<pair<uint32, string> >::const_iterator it = nonces_.find(nonce);
if (it != nonces_.end()) {
- return false;
+ return net::NONCE_NOT_UNIQUE_FAILURE;
}
nonces_.insert(nonce);
- return true;
+ return net::NONCE_OK;
}
uint32 GetCurrentValidWindowSecs(const uint32 current_time_external) const {
@@ -314,11 +315,16 @@ TEST_F(StrikeRegisterStressTest, InOrderInsertion) {
nonce[30] = v >> 8;
nonce[31] = v;
- const bool r2 = s2->Insert(nonce, time, time);
- const bool r1 = s1->Insert(nonce, time);
- EXPECT_EQ(r1, r2);
+ const InsertStatus nonce_error2 = s2->Insert(nonce, time, time);
+ const InsertStatus nonce_error1 = s1->Insert(nonce, time);
+ EXPECT_EQ(nonce_error1, nonce_error2);
+
// Inserts succeed after the startup period.
- EXPECT_EQ(time > current_time + window, r1);
+ if (time > current_time + window) {
+ EXPECT_EQ(net::NONCE_OK, nonce_error1);
+ } else {
+ EXPECT_EQ(net::NONCE_INVALID_TIME_FAILURE, nonce_error1);
+ }
EXPECT_EQ(s1->GetCurrentValidWindowSecs(time),
s2->GetCurrentValidWindowSecs(time));
@@ -379,9 +385,9 @@ TEST_F(StrikeRegisterStressTest, Stress) {
nonce[30] = v >> 8;
nonce[31] = v;
- const bool r2 = s2->Insert(nonce, time, time);
- const bool r1 = s1->Insert(nonce, time);
- EXPECT_EQ(r1, r2);
+ const InsertStatus nonce_error2 = s2->Insert(nonce, time, time);
+ const InsertStatus nonce_error1 = s1->Insert(nonce, time);
+ EXPECT_EQ(nonce_error1, nonce_error2);
EXPECT_EQ(s1->GetCurrentValidWindowSecs(time),
s2->GetCurrentValidWindowSecs(time));
« net/quic/crypto/quic_crypto_server_config.cc ('K') | « net/quic/crypto/strike_register_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698