OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "net/base/force_tls_state.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 |
| 8 namespace { |
| 9 |
| 10 class ForceTLSStateTest : public testing::Test { |
| 11 }; |
| 12 |
| 13 TEST_F(ForceTLSStateTest, BogusHeaders) { |
| 14 int max_age = 42; |
| 15 bool include_subdomains = false; |
| 16 |
| 17 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 18 "", &max_age, &include_subdomains)); |
| 19 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 20 " ", &max_age, &include_subdomains)); |
| 21 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 22 "abc", &max_age, &include_subdomains)); |
| 23 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 24 " abc", &max_age, &include_subdomains)); |
| 25 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 26 " abc ", &max_age, &include_subdomains)); |
| 27 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 28 "max-age", &max_age, &include_subdomains)); |
| 29 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 30 " max-age", &max_age, &include_subdomains)); |
| 31 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 32 " max-age ", &max_age, &include_subdomains)); |
| 33 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 34 "max-age=", &max_age, &include_subdomains)); |
| 35 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 36 " max-age=", &max_age, &include_subdomains)); |
| 37 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 38 " max-age =", &max_age, &include_subdomains)); |
| 39 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 40 " max-age= ", &max_age, &include_subdomains)); |
| 41 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 42 " max-age = ", &max_age, &include_subdomains)); |
| 43 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 44 " max-age = xy", &max_age, &include_subdomains)); |
| 45 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 46 " max-age = 3488a923", &max_age, &include_subdomains)); |
| 47 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 48 "max-age=3488a923 ", &max_age, &include_subdomains)); |
| 49 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 50 "max-ag=3488923", &max_age, &include_subdomains)); |
| 51 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 52 "max-aged=3488923", &max_age, &include_subdomains)); |
| 53 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 54 "max-age==3488923", &max_age, &include_subdomains)); |
| 55 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 56 "amax-age=3488923", &max_age, &include_subdomains)); |
| 57 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 58 "max-age=-3488923", &max_age, &include_subdomains)); |
| 59 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 60 "max-age=3488923;", &max_age, &include_subdomains)); |
| 61 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 62 "max-age=3488923 e", &max_age, &include_subdomains)); |
| 63 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 64 "max-age=3488923 includesubdomain", &max_age, &include_subdomains)); |
| 65 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 66 "max-age=3488923includesubdomains", &max_age, &include_subdomains)); |
| 67 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 68 "max-age=3488923=includesubdomains", &max_age, &include_subdomains)); |
| 69 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 70 "max-age=3488923 includesubdomainx", &max_age, &include_subdomains)); |
| 71 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 72 "max-age=3488923 includesubdomain=", &max_age, &include_subdomains)); |
| 73 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 74 "max-age=3488923 includesubdomain=true", &max_age, &include_subdomains)); |
| 75 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 76 "max-age=3488923 includesubdomainsx", &max_age, &include_subdomains)); |
| 77 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 78 "max-age=3488923 includesubdomains x", &max_age, &include_subdomains)); |
| 79 EXPECT_FALSE(net::ForceTLSState::ParseHeader( |
| 80 "max-age=34889.23 includesubdomains", &max_age, &include_subdomains)); |
| 81 |
| 82 EXPECT_EQ(max_age, 42); |
| 83 EXPECT_FALSE(include_subdomains); |
| 84 } |
| 85 |
| 86 TEST_F(ForceTLSStateTest, ValidHeaders) { |
| 87 int max_age = 42; |
| 88 bool include_subdomains = true; |
| 89 |
| 90 EXPECT_TRUE(net::ForceTLSState::ParseHeader( |
| 91 "max-age=243", &max_age, &include_subdomains)); |
| 92 EXPECT_EQ(max_age, 243); |
| 93 EXPECT_FALSE(include_subdomains); |
| 94 |
| 95 EXPECT_TRUE(net::ForceTLSState::ParseHeader( |
| 96 " Max-agE = 567", &max_age, &include_subdomains)); |
| 97 EXPECT_EQ(max_age, 567); |
| 98 EXPECT_FALSE(include_subdomains); |
| 99 |
| 100 EXPECT_TRUE(net::ForceTLSState::ParseHeader( |
| 101 " mAx-aGe = 890 ", &max_age, &include_subdomains)); |
| 102 EXPECT_EQ(max_age, 890); |
| 103 EXPECT_FALSE(include_subdomains); |
| 104 |
| 105 EXPECT_TRUE(net::ForceTLSState::ParseHeader( |
| 106 "max-age=123 incLudesUbdOmains", &max_age, &include_subdomains)); |
| 107 EXPECT_EQ(max_age, 123); |
| 108 EXPECT_TRUE(include_subdomains); |
| 109 |
| 110 EXPECT_TRUE(net::ForceTLSState::ParseHeader( |
| 111 "max-age=394082038 incLudesUbdOmains", &max_age, &include_subdomains)); |
| 112 EXPECT_EQ(max_age, 394082038); |
| 113 EXPECT_TRUE(include_subdomains); |
| 114 |
| 115 EXPECT_TRUE(net::ForceTLSState::ParseHeader( |
| 116 " max-age=0 incLudesUbdOmains ", &max_age, &include_subdomains)); |
| 117 EXPECT_EQ(max_age, 0); |
| 118 EXPECT_TRUE(include_subdomains); |
| 119 } |
| 120 |
| 121 } // namespace |
OLD | NEW |