OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/win/src/sandbox_types.h" | 5 #include "sandbox/win/src/sandbox_types.h" |
6 #include "sandbox/win/src/sandbox_nt_types.h" | 6 #include "sandbox/win/src/sandbox_nt_types.h" |
7 #include "sandbox/win/src/policy_engine_params.h" | 7 #include "sandbox/win/src/policy_engine_params.h" |
8 #include "sandbox/win/src/policy_engine_opcodes.h" | 8 #include "sandbox/win/src/policy_engine_opcodes.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 PolicyOpcode* op5 = opcode_maker.MakeOpWStringMatch(0, txt5, kSeekForward, | 279 PolicyOpcode* op5 = opcode_maker.MakeOpWStringMatch(0, txt5, kSeekForward, |
280 CASE_SENSITIVE, kPolNone); | 280 CASE_SENSITIVE, kPolNone); |
281 EXPECT_EQ(EVAL_TRUE, op5->Evaluate(&pp_tc1, 1, &mc1)); | 281 EXPECT_EQ(EVAL_TRUE, op5->Evaluate(&pp_tc1, 1, &mc1)); |
282 EXPECT_EQ(24, mc1.position); | 282 EXPECT_EQ(24, mc1.position); |
283 | 283 |
284 // Test that we don't match because it is not at the end of the string | 284 // Test that we don't match because it is not at the end of the string |
285 PolicyOpcode* op5b = opcode_maker.MakeOpWStringMatch(0, txt5, kSeekToEnd, | 285 PolicyOpcode* op5b = opcode_maker.MakeOpWStringMatch(0, txt5, kSeekToEnd, |
286 CASE_SENSITIVE, | 286 CASE_SENSITIVE, |
287 kPolNone); | 287 kPolNone); |
288 EXPECT_EQ(EVAL_FALSE, op5b->Evaluate(&pp_tc1, 1, &mc1)); | 288 EXPECT_EQ(EVAL_FALSE, op5b->Evaluate(&pp_tc1, 1, &mc1)); |
| 289 EXPECT_EQ(24, mc1.position); |
289 | 290 |
290 // Test that we function if the string does not fit. In this case we | 291 // Test that we function if the string does not fit. In this case we |
291 // try to match 'the lazy dog' against 'he lazy dog'. | 292 // try to match 'the lazy dog' against 'he lazy dog'. |
| 293 // !!! Are we supposed to Evaluate() this opcode and test the result? |
292 PolicyOpcode* op6 = opcode_maker.MakeOpWStringMatch(0, txt4, 2, | 294 PolicyOpcode* op6 = opcode_maker.MakeOpWStringMatch(0, txt4, 2, |
293 CASE_SENSITIVE, kPolNone); | 295 CASE_SENSITIVE, kPolNone); |
294 EXPECT_EQ(24, mc1.position); | 296 EXPECT_EQ(EVAL_FALSE, op6->Evaluate(&pp_tc1, 1, &mc1)); |
295 | 297 |
296 // Testing matching against 'g' which should be the last char. | 298 // Testing matching against 'g' which should be the last char. |
297 MatchContext mc2; | 299 MatchContext mc2; |
298 PolicyOpcode* op7 = opcode_maker.MakeOpWStringMatch(0, txt6, kSeekForward, | 300 PolicyOpcode* op7 = opcode_maker.MakeOpWStringMatch(0, txt6, kSeekForward, |
299 CASE_SENSITIVE, kPolNone); | 301 CASE_SENSITIVE, kPolNone); |
300 EXPECT_EQ(EVAL_TRUE, op7->Evaluate(&pp_tc1, 1, &mc2)); | 302 EXPECT_EQ(EVAL_TRUE, op7->Evaluate(&pp_tc1, 1, &mc2)); |
| 303 EXPECT_EQ(37, mc2.position); |
301 | 304 |
302 // Trying to match again should fail since we are in the last char. | 305 // Trying to match again should fail since we are in the last char. |
303 // This also covers a couple of boundary conditions. | 306 // This also covers a couple of boundary conditions. |
304 EXPECT_EQ(EVAL_FALSE, op7->Evaluate(&pp_tc1, 1, &mc2)); | 307 EXPECT_EQ(EVAL_FALSE, op7->Evaluate(&pp_tc1, 1, &mc2)); |
| 308 EXPECT_EQ(37, mc2.position); |
305 } | 309 } |
306 | 310 |
307 TEST(PolicyEngineTest, WCharOpcodes2) { | 311 TEST(PolicyEngineTest, WCharOpcodes2) { |
308 SetupNtdllImports(); | 312 SetupNtdllImports(); |
309 | 313 |
310 const wchar_t* path1 = L"c:\\documents and settings\\Microsoft\\BLAH.txt"; | 314 const wchar_t* path1 = L"c:\\documents and settings\\Microsoft\\BLAH.txt"; |
311 const wchar_t txt1[] = L"Settings\\microsoft"; | 315 const wchar_t txt1[] = L"Settings\\microsoft"; |
312 ParameterSet pp_tc1 = ParamPickerMake(path1); | 316 ParameterSet pp_tc1 = ParamPickerMake(path1); |
313 | 317 |
314 char memory[256]; | 318 char memory[256]; |
(...skipping 19 matching lines...) Expand all Loading... |
334 MatchContext mc1; | 338 MatchContext mc1; |
335 void* dummy = NULL; | 339 void* dummy = NULL; |
336 ParameterSet ppb1 = ParamPickerMake(dummy); | 340 ParameterSet ppb1 = ParamPickerMake(dummy); |
337 | 341 |
338 PolicyOpcode* op1 = opcode_maker.MakeOpAction(ASK_BROKER, kPolNone); | 342 PolicyOpcode* op1 = opcode_maker.MakeOpAction(ASK_BROKER, kPolNone); |
339 EXPECT_TRUE(op1->IsAction()); | 343 EXPECT_TRUE(op1->IsAction()); |
340 EXPECT_EQ(ASK_BROKER, op1->Evaluate(&ppb1, 1, &mc1)); | 344 EXPECT_EQ(ASK_BROKER, op1->Evaluate(&ppb1, 1, &mc1)); |
341 } | 345 } |
342 | 346 |
343 } // namespace sandbox | 347 } // namespace sandbox |
OLD | NEW |