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