Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/WebRequest.cpp

Issue 29377825: Issue 4951 - Restrict request headers in XMLHttpRequest.Also test Accept-Encoding with th… (Closed) Base URL: https://hg.adblockplus.org/libadblockplus/
Left Patch Set: Forgot one more change from the review feedback. Created March 6, 2017, 5:56 p.m.
Right Patch Set: Updated based on the feedback. Created March 8, 2017, 4:15 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/compat.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <sstream> 18 #include <sstream>
19 #include "BaseJsTest.h" 19 #include "BaseJsTest.h"
20 #include "../src/Thread.h" 20 #include "../src/Thread.h"
21 21
22 namespace 22 namespace
23 { 23 {
24 class MockWebRequest : public AdblockPlus::WebRequest 24 class MockWebRequest : public AdblockPlus::WebRequest
25 { 25 {
26 public: 26 public:
27 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::H eaderList& requestHeaders) const 27 AdblockPlus::ServerResponse GET(const std::string& url, const AdblockPlus::H eaderList& requestHeaders) const
28 { 28 {
29 lastRequestHeaders.clear(); 29 lastRequestHeaders.clear();
sergei 2017/03/13 09:56:57 Sorry, I forgot to say it again when my comments h
sergei 2017/03/16 11:08:25 What about this point? Actually I find it very imp
30 for (auto header : requestHeaders) 30 for (auto header : requestHeaders)
31 { 31 {
32 lastRequestHeaders.insert(header.first); 32 lastRequestHeaders.insert(header.first);
33 } 33 }
34 34
35 AdblockPlus::Sleep(50); 35 AdblockPlus::Sleep(50);
36 36
37 AdblockPlus::ServerResponse result; 37 AdblockPlus::ServerResponse result;
38 result.status = NS_OK; 38 result.status = NS_OK;
39 result.responseStatus = 123; 39 result.responseStatus = 123;
(...skipping 18 matching lines...) Expand all
58 { 58 {
59 BaseJsTest::SetUp(); 59 BaseJsTest::SetUp();
60 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new T)); 60 jsEngine->SetWebRequest(AdblockPlus::WebRequestPtr(new T));
61 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem)); 61 jsEngine->SetFileSystem(AdblockPlus::FileSystemPtr(new LazyFileSystem));
62 } 62 }
63 }; 63 };
64 64
65 typedef WebRequestTest<MockWebRequest> MockWebRequestTest; 65 typedef WebRequestTest<MockWebRequest> MockWebRequestTest;
66 typedef WebRequestTest<AdblockPlus::DefaultWebRequest> DefaultWebRequestTest; 66 typedef WebRequestTest<AdblockPlus::DefaultWebRequest> DefaultWebRequestTest;
67 typedef WebRequestTest<MockWebRequest> XMLHttpRequestTest; 67 typedef WebRequestTest<MockWebRequest> XMLHttpRequestTest;
68
69 void
Felix Dahlke 2017/03/09 15:10:58 Nit: Why the new line? Not really consistent with
hub 2017/03/09 15:33:02 probably habit. I'll remove it when I send you the
sergei 2017/03/13 09:56:56 Just in case for future, I would rather prefer to
70 ResetTestXHR(const AdblockPlus::JsEnginePtr& jsEngine)
71 {
72 jsEngine->Evaluate("\
73 var result;\
74 var request = new XMLHttpRequest();\
75 request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.t xt');\
76 request.overrideMimeType('text/plain');\
77 request.addEventListener('load', function() {result = request.responseText ;}, false);\
78 request.addEventListener('error', function() {result = 'error';}, false);\
79 ");
80 }
81
82 void WaitForVariable(const std::string& variable, const AdblockPlus::JsEngineP tr& jsEngine)
83 {
84 do
85 {
86 AdblockPlus::Sleep(60);
sergei 2017/03/13 09:56:56 Since we touched it here I would say that I person
hub 2017/03/13 14:16:51 I'll file an issue for that.
hub 2017/03/13 14:29:32 filed https://issues.adblockplus.org/ticket/4983
87 } while (jsEngine->Evaluate(variable)->IsUndefined());
88 }
89
68 } 90 }
69 91
70 TEST_F(MockWebRequestTest, BadCall) 92 TEST_F(MockWebRequestTest, BadCall)
71 { 93 {
72 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET()")); 94 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET()"));
73 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('', {}, function(){})")); 95 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('', {}, function(){})"));
74 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET({toString: false}, {}, fu nction(){})")); 96 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET({toString: false}, {}, fu nction(){})"));
75 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('http://example.com/', nu ll, function(){})")); 97 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('http://example.com/', nu ll, function(){})"));
76 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('http://example.com/', {} , null)")); 98 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('http://example.com/', {} , null)"));
77 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('http://example.com/', {} , function(){}, 0)")); 99 ASSERT_ANY_THROW(jsEngine->Evaluate("_webRequest.GET('http://example.com/', {} , function(){}, 0)"));
78 } 100 }
79 101
80 TEST_F(MockWebRequestTest, SuccessfulRequest) 102 TEST_F(MockWebRequestTest, SuccessfulRequest)
81 { 103 {
82 jsEngine->Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function( result) {foo = result;} )"); 104 jsEngine->Evaluate("_webRequest.GET('http://example.com/', {X: 'Y'}, function( result) {foo = result;} )");
83 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined()); 105 ASSERT_TRUE(jsEngine->Evaluate("this.foo")->IsUndefined());
84 AdblockPlus::Sleep(200); 106 AdblockPlus::Sleep(200);
85 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int()); 107 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int());
86 ASSERT_EQ(123, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 108 ASSERT_EQ(123, jsEngine->Evaluate("foo.responseStatus")->AsInt());
87 ASSERT_EQ("http://example.com/\nX\nY", jsEngine->Evaluate("foo.responseText")- >AsString()); 109 ASSERT_EQ("http://example.com/\nX\nY", jsEngine->Evaluate("foo.responseText")- >AsString());
88 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine->Evaluate("JSON.stringify(foo.response Headers)")->AsString()); 110 ASSERT_EQ("{\"Foo\":\"Bar\"}", jsEngine->Evaluate("JSON.stringify(foo.response Headers)")->AsString());
89 } 111 }
90 112
91 #if defined(HAVE_CURL) || defined(_WIN32) 113 #if defined(HAVE_CURL) || defined(_WIN32)
92 TEST_F(DefaultWebRequestTest, RealWebRequest) 114 TEST_F(DefaultWebRequestTest, RealWebRequest)
93 { 115 {
94 // This URL should redirect to easylist-downloads.adblockplus.org and we 116 // This URL should redirect to easylist-downloads.adblockplus.org and we
95 // should get the actual filter list back. 117 // should get the actual filter list back.
96 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )"); 118 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
97 do 119 WaitForVariable("this.foo", jsEngine);
98 {
99 AdblockPlus::Sleep(200);
100 } while (jsEngine->Evaluate("this.foo")->IsUndefined());
101 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString()); 120 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString());
102 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int()); 121 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("foo.status")->As Int());
103 ASSERT_EQ(200, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 122 ASSERT_EQ(200, jsEngine->Evaluate("foo.responseStatus")->AsInt());
104 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ")->AsString()); 123 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("foo.responseText.substr(0, 14) ")->AsString());
105 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString()); 124 ASSERT_EQ("text/plain", jsEngine->Evaluate("foo.responseHeaders['content-type' ].substr(0, 10)")->AsString());
106 #if defined(HAVE_CURL) 125 #if defined(HAVE_CURL)
107 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)")->AsString()); 126 ASSERT_EQ("gzip", jsEngine->Evaluate("foo.responseHeaders['content-encoding']. substr(0, 4)")->AsString());
108 #endif 127 #endif
109 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']")->IsUndefined ()); 128 ASSERT_TRUE(jsEngine->Evaluate("foo.responseHeaders['location']")->IsUndefined ());
110 } 129 }
111 130
112 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 131 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
113 { 132 {
114 AdblockPlus::FilterEngine filterEngine(jsEngine); 133 AdblockPlus::FilterEngine filterEngine(jsEngine);
115 134
116 jsEngine->Evaluate("\ 135 ResetTestXHR(jsEngine);
117 var result;\ 136 jsEngine->Evaluate("\
118 var request = new XMLHttpRequest();\
119 request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.txt ');\
120 request.setRequestHeader('X', 'Y');\ 137 request.setRequestHeader('X', 'Y');\
121 request.setRequestHeader('X2', 'Y2');\ 138 request.setRequestHeader('X2', 'Y2');\
122 request.overrideMimeType('text/plain');\
123 request.addEventListener('load', function() {result = request.responseText;} , false);\
124 request.addEventListener('error', function() {result = 'error';}, false);\
125 request.send(null);"); 139 request.send(null);");
126 do 140 WaitForVariable("result", jsEngine);
127 {
128 AdblockPlus::Sleep(200);
129 } while (jsEngine->Evaluate("result")->IsUndefined());
130 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("request.channel. status")->AsInt()); 141 ASSERT_EQ(AdblockPlus::WebRequest::NS_OK, jsEngine->Evaluate("request.channel. status")->AsInt());
131 ASSERT_EQ(200, jsEngine->Evaluate("request.status")->AsInt()); 142 ASSERT_EQ(200, jsEngine->Evaluate("request.status")->AsInt());
132 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)")->AsStri ng()); 143 ASSERT_EQ("[Adblock Plus ", jsEngine->Evaluate("result.substr(0, 14)")->AsStri ng());
133 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)")->AsString()); 144 ASSERT_EQ("text/plain", jsEngine->Evaluate("request.getResponseHeader('Content -Type').substr(0, 10)")->AsString());
134 #if defined(HAVE_CURL) 145 #if defined(HAVE_CURL)
sergei 2017/03/13 09:56:56 It seems, it should be in commit https://github.co
135 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)")->AsString()); 146 ASSERT_EQ("gzip", jsEngine->Evaluate("request.getResponseHeader('Content-Encod ing').substr(0, 4)")->AsString());
136 #endif 147 #endif
137 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')")->IsNul l()); 148 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Location')")->IsNul l());
138 } 149 }
139 #else 150 #else
140 TEST_F(DefaultWebRequestTest, DummyWebRequest) 151 TEST_F(DefaultWebRequestTest, DummyWebRequest)
141 { 152 {
142 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )"); 153 jsEngine->Evaluate("_webRequest.GET('https://easylist-downloads.adblockplus.or g/easylist.txt', {}, function(result) {foo = result;} )");
143 do 154 WaitForVariable("this.foo", jsEngine);
144 {
145 AdblockPlus::Sleep(200);
146 } while (jsEngine->Evaluate("this.foo")->IsUndefined());
147 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.s tatus")->AsInt()); 155 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("foo.s tatus")->AsInt());
148 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus")->AsInt()); 156 ASSERT_EQ(0, jsEngine->Evaluate("foo.responseStatus")->AsInt());
149 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText")->AsString()); 157 ASSERT_EQ("", jsEngine->Evaluate("foo.responseText")->AsString());
150 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)")->AsS tring()); 158 ASSERT_EQ("{}", jsEngine->Evaluate("JSON.stringify(foo.responseHeaders)")->AsS tring());
151 } 159 }
152 160
153 TEST_F(DefaultWebRequestTest, XMLHttpRequest) 161 TEST_F(DefaultWebRequestTest, XMLHttpRequest)
154 { 162 {
155 AdblockPlus::FilterEngine filterEngine(jsEngine); 163 AdblockPlus::FilterEngine filterEngine(jsEngine);
156 164
157 jsEngine->Evaluate("\ 165 ResetTestXHR(jsEngine);
158 var result;\ 166 jsEngine->Evaluate("\
159 var request = new XMLHttpRequest();\
160 request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.txt ');\
161 request.setRequestHeader('X', 'Y');\ 167 request.setRequestHeader('X', 'Y');\
162 request.overrideMimeType('text/plain');\
163 request.addEventListener('load', function() {result = request.responseText;} , false);\
164 request.addEventListener('error', function() {result = 'error';}, false);\
165 request.send(null);"); 168 request.send(null);");
166 do 169 WaitForVariable("result", jsEngine);
167 {
168 AdblockPlus::Sleep(200);
169 } while (jsEngine->Evaluate("result")->IsUndefined());
170 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt()); 170 ASSERT_EQ(AdblockPlus::WebRequest::NS_ERROR_FAILURE, jsEngine->Evaluate("reque st.channel.status")->AsInt());
171 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt()); 171 ASSERT_EQ(0, jsEngine->Evaluate("request.status")->AsInt());
172 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString()); 172 ASSERT_EQ("error", jsEngine->Evaluate("result")->AsString());
173 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull()); 173 ASSERT_TRUE(jsEngine->Evaluate("request.getResponseHeader('Content-Type')")->I sNull());
174 } 174 }
175 175
176 #endif 176 #endif
177 177
178 namespace 178 namespace
179 { 179 {
(...skipping 17 matching lines...) Expand all
197 } 197 }
198 198
199 void clear() 199 void clear()
200 { 200 {
201 lastLogLevel = AdblockPlus::LogSystem::LOG_LEVEL_TRACE; 201 lastLogLevel = AdblockPlus::LogSystem::LOG_LEVEL_TRACE;
202 lastMessage.clear(); 202 lastMessage.clear();
203 } 203 }
204 }; 204 };
205 205
206 typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr; 206 typedef std::shared_ptr<CatchLogSystem> CatchLogSystemPtr;
207
208 void
209 ResetTestXHR(const AdblockPlus::JsEnginePtr& jsEngine, const CatchLogSystemPtr & logger)
210 {
211 jsEngine->Evaluate("\
212 var result;\
213 var request = new XMLHttpRequest();\
214 request.open('GET', 'https://easylist-downloads.adblockplus.org/easylist.t xt');\
215 request.overrideMimeType('text/plain');\
216 request.addEventListener('load', function() {result = request.responseText ;}, false);\
217 request.addEventListener('error', function() {result = 'error';}, false);\
218 ");
219 logger->clear();
220 }
221 } 207 }
222 208
223 TEST_F(XMLHttpRequestTest, RequestHeaderValidation) 209 TEST_F(XMLHttpRequestTest, RequestHeaderValidation)
224 { 210 {
225 #define WAIT_FOR_XHR_RESULT do\
226 {\
227 AdblockPlus::Sleep(200);\
228 } while (jsEngine->Evaluate("result")->IsUndefined())
229
230 auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem); 211 auto catchLogSystem = CatchLogSystemPtr(new CatchLogSystem);
sergei 2017/03/13 09:56:56 Could we please always use either () or {} for con
sergei 2017/03/13 09:56:57 I would prefer to have std::make_shared<CatchLogSy
Felix Dahlke 2017/03/13 10:05:47 I definitely prefer omitting these when not necess
sergei 2017/03/13 10:31:02 It seems Mozilla's coding style does not mention i
Felix Dahlke 2017/03/13 11:05:42 We are talking a bout `new CatchLogSystem` vs `new
sergei 2017/03/13 11:39:16 Yes.
Felix Dahlke 2017/03/13 11:55:06 I see - rusty after all :P Looking at our existing
sergei 2017/03/13 12:19:58 On 2017/03/13 11:55:06, Felix Dahlke wrote: ...
hub 2017/03/13 14:16:51 I see two occurences, line 60 and 61 of this file.
hub 2017/03/13 14:16:51 I did submit a follow up patch to address these. I
231 jsEngine->SetLogSystem(catchLogSystem); 212 jsEngine->SetLogSystem(catchLogSystem);
232 213
233 AdblockPlus::FilterEngine filterEngine(jsEngine); 214 AdblockPlus::FilterEngine filterEngine(jsEngine);
234 auto webRequest = 215 auto webRequest =
235 std::static_pointer_cast<MockWebRequest>(jsEngine->GetWebRequest()); 216 std::static_pointer_cast<MockWebRequest>(jsEngine->GetWebRequest());
sergei 2017/03/13 09:56:56 Although it's fine here, I would rather prefer to
236 217
237 ASSERT_TRUE(webRequest); 218 ASSERT_TRUE(webRequest);
238 219
239 const std::string msg = "Attempt to set a forbidden header was denied: "; 220 const std::string msg = "Attempt to set a forbidden header was denied: ";
240 221
241 // The test will check that console.warn has been called when the 222 // The test will check that console.warn has been called when the
242 // header is rejected. While this is an implementation detail, we 223 // header is rejected. While this is an implementation detail, we
243 // have no other way to check this 224 // have no other way to check this
244 225
245 // test 'Accept-Encoding' is rejected 226 // test 'Accept-Encoding' is rejected
246 ResetTestXHR(jsEngine, catchLogSystem); 227 catchLogSystem->clear();
228 ResetTestXHR(jsEngine);
247 jsEngine->Evaluate("\ 229 jsEngine->Evaluate("\
248 request.setRequestHeader('Accept-Encoding', 'gzip');\nrequest.send();"); 230 request.setRequestHeader('Accept-Encoding', 'gzip');\nrequest.send();");
249 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel ); 231 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel );
250 EXPECT_EQ(msg + "Accept-Encoding", catchLogSystem->lastMessage); 232 EXPECT_EQ(msg + "Accept-Encoding", catchLogSystem->lastMessage);
251 WAIT_FOR_XHR_RESULT; 233 WaitForVariable("result", jsEngine);
252 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() == 234 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() ==
253 webRequest->lastRequestHeaders.find("Accept-Encoding")); 235 webRequest->lastRequestHeaders.find("Accept-Encoding"));
254 236
255 // test 'DNT' is rejected 237 // test 'DNT' is rejected
256 ResetTestXHR(jsEngine, catchLogSystem); 238 catchLogSystem->clear();
239 ResetTestXHR(jsEngine);
257 jsEngine->Evaluate("\ 240 jsEngine->Evaluate("\
258 request.setRequestHeader('DNT', '1');\nrequest.send();"); 241 request.setRequestHeader('DNT', '1');\nrequest.send();");
259 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel ); 242 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel );
260 EXPECT_EQ(msg + "DNT", catchLogSystem->lastMessage); 243 EXPECT_EQ(msg + "DNT", catchLogSystem->lastMessage);
261 WAIT_FOR_XHR_RESULT; 244 WaitForVariable("result", jsEngine);
262 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() == 245 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() ==
263 webRequest->lastRequestHeaders.find("DNT")); 246 webRequest->lastRequestHeaders.find("DNT"));
264 247
265 // test random 'X' header is accepted 248 // test random 'X' header is accepted
266 ResetTestXHR(jsEngine, catchLogSystem); 249 catchLogSystem->clear();
250 ResetTestXHR(jsEngine);
267 jsEngine->Evaluate("\ 251 jsEngine->Evaluate("\
268 request.setRequestHeader('X', 'y');\nrequest.send();"); 252 request.setRequestHeader('X', 'y');\nrequest.send();");
269 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l); 253 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l);
270 EXPECT_EQ("", catchLogSystem->lastMessage); 254 EXPECT_EQ("", catchLogSystem->lastMessage);
271 WAIT_FOR_XHR_RESULT; 255 WaitForVariable("result", jsEngine);
272 EXPECT_FALSE(webRequest->lastRequestHeaders.cend() == 256 EXPECT_FALSE(webRequest->lastRequestHeaders.cend() ==
273 webRequest->lastRequestHeaders.find("X")); 257 webRequest->lastRequestHeaders.find("X"));
274 258
275 // test /^Proxy-/ is rejected. 259 // test /^Proxy-/ is rejected.
276 ResetTestXHR(jsEngine, catchLogSystem); 260 catchLogSystem->clear();
261 ResetTestXHR(jsEngine);
277 jsEngine->Evaluate("\ 262 jsEngine->Evaluate("\
278 request.setRequestHeader('Proxy-foo', 'bar');\nrequest.send();"); 263 request.setRequestHeader('Proxy-foo', 'bar');\nrequest.send();");
279 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel ); 264 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel );
280 EXPECT_EQ(msg + "Proxy-foo", catchLogSystem->lastMessage); 265 EXPECT_EQ(msg + "Proxy-foo", catchLogSystem->lastMessage);
281 WAIT_FOR_XHR_RESULT; 266 WaitForVariable("result", jsEngine);
282 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() == 267 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() ==
283 webRequest->lastRequestHeaders.find("Proxy-foo")); 268 webRequest->lastRequestHeaders.find("Proxy-foo"));
284 269
285 // test /^Sec-/ is rejected. 270 // test /^Sec-/ is rejected.
286 ResetTestXHR(jsEngine, catchLogSystem); 271 catchLogSystem->clear();
272 ResetTestXHR(jsEngine);
287 jsEngine->Evaluate("\ 273 jsEngine->Evaluate("\
288 request.setRequestHeader('Sec-foo', 'bar');\nrequest.send();"); 274 request.setRequestHeader('Sec-foo', 'bar');\nrequest.send();");
289 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel ); 275 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_WARN, catchLogSystem->lastLogLevel );
290 EXPECT_EQ(msg + "Sec-foo", catchLogSystem->lastMessage); 276 EXPECT_EQ(msg + "Sec-foo", catchLogSystem->lastMessage);
291 WAIT_FOR_XHR_RESULT; 277 WaitForVariable("result", jsEngine);
292 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() == 278 EXPECT_TRUE(webRequest->lastRequestHeaders.cend() ==
293 webRequest->lastRequestHeaders.find("Sec-foo")); 279 webRequest->lastRequestHeaders.find("Sec-foo"));
294 280
295 // test 'Security' is accepted. 281 // test 'Security' is accepted.
296 ResetTestXHR(jsEngine, catchLogSystem); 282 catchLogSystem->clear();
283 ResetTestXHR(jsEngine);
297 jsEngine->Evaluate("\ 284 jsEngine->Evaluate("\
298 request.setRequestHeader('Security', 'theater');\nrequest.send();"); 285 request.setRequestHeader('Security', 'theater');\nrequest.send();");
299 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l); 286 EXPECT_EQ(AdblockPlus::LogSystem::LOG_LEVEL_TRACE, catchLogSystem->lastLogLeve l);
300 EXPECT_EQ("", catchLogSystem->lastMessage); 287 EXPECT_EQ("", catchLogSystem->lastMessage);
301 WAIT_FOR_XHR_RESULT; 288 WaitForVariable("result", jsEngine);
302 EXPECT_FALSE(webRequest->lastRequestHeaders.cend() == 289 EXPECT_FALSE(webRequest->lastRequestHeaders.cend() ==
303 webRequest->lastRequestHeaders.find("Security")); 290 webRequest->lastRequestHeaders.find("Security"));
304 } 291 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld