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

Side by Side Diff: sandbox/win/src/policy_low_level_unittest.cc

Issue 1539423002: Revert of Switch to standard integer types in sandbox/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « sandbox/win/src/policy_low_level.cc ('k') | sandbox/win/src/policy_opcodes_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h>
6 #include <stdint.h>
7
8 #include "sandbox/win/src/policy_engine_params.h" 5 #include "sandbox/win/src/policy_engine_params.h"
9 #include "sandbox/win/src/policy_engine_processor.h" 6 #include "sandbox/win/src/policy_engine_processor.h"
10 #include "sandbox/win/src/policy_low_level.h" 7 #include "sandbox/win/src/policy_low_level.h"
11 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
12 9
13 #define POLPARAMS_BEGIN(x) sandbox::ParameterSet x[] = { 10 #define POLPARAMS_BEGIN(x) sandbox::ParameterSet x[] = {
14 #define POLPARAM(p) sandbox::ParamPickerMake(p), 11 #define POLPARAM(p) sandbox::ParamPickerMake(p),
15 #define POLPARAMS_END } 12 #define POLPARAMS_END }
16 13
17 namespace sandbox { 14 namespace sandbox {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 49
53 // The simplest test using LowLevelPolicy it should test a single opcode which 50 // The simplest test using LowLevelPolicy it should test a single opcode which
54 // does a exact string comparison. 51 // does a exact string comparison.
55 TEST(PolicyEngineTest, SimpleStrMatch) { 52 TEST(PolicyEngineTest, SimpleStrMatch) {
56 SetupNtdllImports(); 53 SetupNtdllImports();
57 PolicyRule pr(ASK_BROKER); 54 PolicyRule pr(ASK_BROKER);
58 EXPECT_TRUE(pr.AddStringMatch(IF, 0, L"z:\\Directory\\domo.txt", 55 EXPECT_TRUE(pr.AddStringMatch(IF, 0, L"z:\\Directory\\domo.txt",
59 CASE_INSENSITIVE)); 56 CASE_INSENSITIVE));
60 57
61 PolicyGlobal* policy = MakePolicyMemory(); 58 PolicyGlobal* policy = MakePolicyMemory();
62 const uint32_t kFakeService = 2; 59 const uint32 kFakeService = 2;
63 60
64 LowLevelPolicy policyGen(policy); 61 LowLevelPolicy policyGen(policy);
65 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr)); 62 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr));
66 EXPECT_TRUE(policyGen.Done()); 63 EXPECT_TRUE(policyGen.Done());
67 64
68 const wchar_t* filename = L"Z:\\Directory\\domo.txt"; 65 const wchar_t* filename = L"Z:\\Directory\\domo.txt";
69 66
70 POLPARAMS_BEGIN(eval_params) 67 POLPARAMS_BEGIN(eval_params)
71 POLPARAM(filename) // Argument 0 68 POLPARAM(filename) // Argument 0
72 POLPARAMS_END; 69 POLPARAMS_END;
(...skipping 12 matching lines...) Expand all
85 delete [] reinterpret_cast<char*>(policy); 82 delete [] reinterpret_cast<char*>(policy);
86 } 83 }
87 84
88 TEST(PolicyEngineTest, SimpleIfNotStrMatch) { 85 TEST(PolicyEngineTest, SimpleIfNotStrMatch) {
89 SetupNtdllImports(); 86 SetupNtdllImports();
90 PolicyRule pr(ASK_BROKER); 87 PolicyRule pr(ASK_BROKER);
91 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\", 88 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\",
92 CASE_SENSITIVE)); 89 CASE_SENSITIVE));
93 90
94 PolicyGlobal* policy = MakePolicyMemory(); 91 PolicyGlobal* policy = MakePolicyMemory();
95 const uint32_t kFakeService = 2; 92 const uint32 kFakeService = 2;
96 LowLevelPolicy policyGen(policy); 93 LowLevelPolicy policyGen(policy);
97 94
98 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr)); 95 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr));
99 EXPECT_TRUE(policyGen.Done()); 96 EXPECT_TRUE(policyGen.Done());
100 97
101 const wchar_t* filename = NULL; 98 const wchar_t* filename = NULL;
102 POLPARAMS_BEGIN(eval_params) 99 POLPARAMS_BEGIN(eval_params)
103 POLPARAM(filename) // Argument 0 100 POLPARAM(filename) // Argument 0
104 POLPARAMS_END; 101 POLPARAMS_END;
105 102
(...skipping 17 matching lines...) Expand all
123 delete [] reinterpret_cast<char*>(policy); 120 delete [] reinterpret_cast<char*>(policy);
124 } 121 }
125 122
126 TEST(PolicyEngineTest, SimpleIfNotStrMatchWild1) { 123 TEST(PolicyEngineTest, SimpleIfNotStrMatchWild1) {
127 SetupNtdllImports(); 124 SetupNtdllImports();
128 PolicyRule pr(ASK_BROKER); 125 PolicyRule pr(ASK_BROKER);
129 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\*", 126 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\*",
130 CASE_SENSITIVE)); 127 CASE_SENSITIVE));
131 128
132 PolicyGlobal* policy = MakePolicyMemory(); 129 PolicyGlobal* policy = MakePolicyMemory();
133 const uint32_t kFakeService = 3; 130 const uint32 kFakeService = 3;
134 LowLevelPolicy policyGen(policy); 131 LowLevelPolicy policyGen(policy);
135 132
136 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr)); 133 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr));
137 EXPECT_TRUE(policyGen.Done()); 134 EXPECT_TRUE(policyGen.Done());
138 135
139 const wchar_t* filename = NULL; 136 const wchar_t* filename = NULL;
140 POLPARAMS_BEGIN(eval_params) 137 POLPARAMS_BEGIN(eval_params)
141 POLPARAM(filename) // Argument 0 138 POLPARAM(filename) // Argument 0
142 POLPARAMS_END; 139 POLPARAMS_END;
143 140
(...skipping 12 matching lines...) Expand all
156 delete [] reinterpret_cast<char*>(policy); 153 delete [] reinterpret_cast<char*>(policy);
157 } 154 }
158 155
159 TEST(PolicyEngineTest, SimpleIfNotStrMatchWild2) { 156 TEST(PolicyEngineTest, SimpleIfNotStrMatchWild2) {
160 SetupNtdllImports(); 157 SetupNtdllImports();
161 PolicyRule pr(ASK_BROKER); 158 PolicyRule pr(ASK_BROKER);
162 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\*.txt", 159 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\*.txt",
163 CASE_SENSITIVE)); 160 CASE_SENSITIVE));
164 161
165 PolicyGlobal* policy = MakePolicyMemory(); 162 PolicyGlobal* policy = MakePolicyMemory();
166 const uint32_t kFakeService = 3; 163 const uint32 kFakeService = 3;
167 LowLevelPolicy policyGen(policy); 164 LowLevelPolicy policyGen(policy);
168 165
169 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr)); 166 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr));
170 EXPECT_TRUE(policyGen.Done()); 167 EXPECT_TRUE(policyGen.Done());
171 168
172 const wchar_t* filename = NULL; 169 const wchar_t* filename = NULL;
173 POLPARAMS_BEGIN(eval_params) 170 POLPARAMS_BEGIN(eval_params)
174 POLPARAM(filename) // Argument 0 171 POLPARAM(filename) // Argument 0
175 POLPARAMS_END; 172 POLPARAMS_END;
176 173
(...skipping 18 matching lines...) Expand all
195 } 192 }
196 193
197 TEST(PolicyEngineTest, IfNotStrMatchTwoRulesWild1) { 194 TEST(PolicyEngineTest, IfNotStrMatchTwoRulesWild1) {
198 SetupNtdllImports(); 195 SetupNtdllImports();
199 PolicyRule pr(ASK_BROKER); 196 PolicyRule pr(ASK_BROKER);
200 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\*", 197 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\Microsoft\\*",
201 CASE_SENSITIVE)); 198 CASE_SENSITIVE));
202 EXPECT_TRUE(pr.AddNumberMatch(IF, 1, 24, EQUAL)); 199 EXPECT_TRUE(pr.AddNumberMatch(IF, 1, 24, EQUAL));
203 200
204 PolicyGlobal* policy = MakePolicyMemory(); 201 PolicyGlobal* policy = MakePolicyMemory();
205 const uint32_t kFakeService = 3; 202 const uint32 kFakeService = 3;
206 LowLevelPolicy policyGen(policy); 203 LowLevelPolicy policyGen(policy);
207 204
208 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr)); 205 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr));
209 EXPECT_TRUE(policyGen.Done()); 206 EXPECT_TRUE(policyGen.Done());
210 207
211 const wchar_t* filename = NULL; 208 const wchar_t* filename = NULL;
212 uint32_t access = 0; 209 uint32 access = 0;
213 POLPARAMS_BEGIN(eval_params) 210 POLPARAMS_BEGIN(eval_params)
214 POLPARAM(filename) // Argument 0 211 POLPARAM(filename) // Argument 0
215 POLPARAM(access) // Argument 1 212 POLPARAM(access) // Argument 1
216 POLPARAMS_END; 213 POLPARAMS_END;
217 214
218 PolicyResult result; 215 PolicyResult result;
219 PolicyProcessor pol_ev(policy->entry[kFakeService]); 216 PolicyProcessor pol_ev(policy->entry[kFakeService]);
220 217
221 filename = L"c:\\Microsoft\\domo.txt"; 218 filename = L"c:\\Microsoft\\domo.txt";
222 access = 24; 219 access = 24;
(...skipping 21 matching lines...) Expand all
244 241
245 TEST(PolicyEngineTest, IfNotStrMatchTwoRulesWild2) { 242 TEST(PolicyEngineTest, IfNotStrMatchTwoRulesWild2) {
246 SetupNtdllImports(); 243 SetupNtdllImports();
247 PolicyRule pr(ASK_BROKER); 244 PolicyRule pr(ASK_BROKER);
248 EXPECT_TRUE(pr.AddNumberMatch(IF, 1, 24, EQUAL)); 245 EXPECT_TRUE(pr.AddNumberMatch(IF, 1, 24, EQUAL));
249 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\GoogleV?\\*.txt", 246 EXPECT_TRUE(pr.AddStringMatch(IF_NOT, 0, L"c:\\GoogleV?\\*.txt",
250 CASE_SENSITIVE)); 247 CASE_SENSITIVE));
251 EXPECT_TRUE(pr.AddNumberMatch(IF, 2, 66, EQUAL)); 248 EXPECT_TRUE(pr.AddNumberMatch(IF, 2, 66, EQUAL));
252 249
253 PolicyGlobal* policy = MakePolicyMemory(); 250 PolicyGlobal* policy = MakePolicyMemory();
254 const uint32_t kFakeService = 3; 251 const uint32 kFakeService = 3;
255 LowLevelPolicy policyGen(policy); 252 LowLevelPolicy policyGen(policy);
256 253
257 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr)); 254 EXPECT_TRUE(policyGen.AddRule(kFakeService, &pr));
258 EXPECT_TRUE(policyGen.Done()); 255 EXPECT_TRUE(policyGen.Done());
259 256
260 const wchar_t* filename = NULL; 257 const wchar_t* filename = NULL;
261 uint32_t access = 0; 258 uint32 access = 0;
262 uint32_t sharing = 66; 259 uint32 sharing = 66;
263 260
264 POLPARAMS_BEGIN(eval_params) 261 POLPARAMS_BEGIN(eval_params)
265 POLPARAM(filename) // Argument 0 262 POLPARAM(filename) // Argument 0
266 POLPARAM(access) // Argument 1 263 POLPARAM(access) // Argument 1
267 POLPARAM(sharing) // Argument 2 264 POLPARAM(sharing) // Argument 2
268 POLPARAMS_END; 265 POLPARAMS_END;
269 266
270 PolicyResult result; 267 PolicyResult result;
271 PolicyProcessor pol_ev(policy->entry[kFakeService]); 268 PolicyProcessor pol_ev(policy->entry[kFakeService]);
272 269
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 TEST(PolicyEngineTest, OneRuleTest) { 315 TEST(PolicyEngineTest, OneRuleTest) {
319 SetupNtdllImports(); 316 SetupNtdllImports();
320 PolicyRule pr(ASK_BROKER); 317 PolicyRule pr(ASK_BROKER);
321 EXPECT_TRUE(pr.AddStringMatch(IF, 0, L"c:\\*Microsoft*\\*.txt", 318 EXPECT_TRUE(pr.AddStringMatch(IF, 0, L"c:\\*Microsoft*\\*.txt",
322 CASE_SENSITIVE)); 319 CASE_SENSITIVE));
323 EXPECT_TRUE(pr.AddNumberMatch(IF_NOT, 1, CREATE_ALWAYS, EQUAL)); 320 EXPECT_TRUE(pr.AddNumberMatch(IF_NOT, 1, CREATE_ALWAYS, EQUAL));
324 EXPECT_TRUE(pr.AddNumberMatch(IF, 2, FILE_ATTRIBUTE_NORMAL, EQUAL)); 321 EXPECT_TRUE(pr.AddNumberMatch(IF, 2, FILE_ATTRIBUTE_NORMAL, EQUAL));
325 322
326 PolicyGlobal* policy = MakePolicyMemory(); 323 PolicyGlobal* policy = MakePolicyMemory();
327 324
328 const uint32_t kNtFakeCreateFile = 7; 325 const uint32 kNtFakeCreateFile = 7;
329 326
330 LowLevelPolicy policyGen(policy); 327 LowLevelPolicy policyGen(policy);
331 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr)); 328 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr));
332 EXPECT_TRUE(policyGen.Done()); 329 EXPECT_TRUE(policyGen.Done());
333 330
334 const wchar_t* filename = L"c:\\Documents and Settings\\Microsoft\\BLAH.txt"; 331 const wchar_t* filename = L"c:\\Documents and Settings\\Microsoft\\BLAH.txt";
335 uint32_t creation_mode = OPEN_EXISTING; 332 uint32 creation_mode = OPEN_EXISTING;
336 uint32_t flags = FILE_ATTRIBUTE_NORMAL; 333 uint32 flags = FILE_ATTRIBUTE_NORMAL;
337 void* security_descriptor = NULL; 334 void* security_descriptor = NULL;
338 335
339 POLPARAMS_BEGIN(eval_params) 336 POLPARAMS_BEGIN(eval_params)
340 POLPARAM(filename) // Argument 0 337 POLPARAM(filename) // Argument 0
341 POLPARAM(creation_mode) // Argument 1 338 POLPARAM(creation_mode) // Argument 1
342 POLPARAM(flags) // Argument 2 339 POLPARAM(flags) // Argument 2
343 POLPARAM(security_descriptor) 340 POLPARAM(security_descriptor)
344 POLPARAMS_END; 341 POLPARAMS_END;
345 342
346 PolicyResult result; 343 PolicyResult result;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 421
425 PolicyRule pr_none(GIVE_FIRST); 422 PolicyRule pr_none(GIVE_FIRST);
426 EXPECT_TRUE(pr_none.AddNumberMatch(IF, 2, FILE_ATTRIBUTE_READONLY, AND)); 423 EXPECT_TRUE(pr_none.AddNumberMatch(IF, 2, FILE_ATTRIBUTE_READONLY, AND));
427 EXPECT_TRUE(pr_none.AddNumberMatch(IF, 2, FILE_ATTRIBUTE_SYSTEM, AND)); 424 EXPECT_TRUE(pr_none.AddNumberMatch(IF, 2, FILE_ATTRIBUTE_SYSTEM, AND));
428 425
429 size_t opc5 = pr_none.GetOpcodeCount(); 426 size_t opc5 = pr_none.GetOpcodeCount();
430 EXPECT_EQ(2u, opc5); 427 EXPECT_EQ(2u, opc5);
431 428
432 PolicyGlobal* policy = MakePolicyMemory(); 429 PolicyGlobal* policy = MakePolicyMemory();
433 430
434 const uint32_t kNtFakeNone = 4; 431 const uint32 kNtFakeNone = 4;
435 const uint32_t kNtFakeCreateFile = 5; 432 const uint32 kNtFakeCreateFile = 5;
436 const uint32_t kNtFakeOpenFile = 6; 433 const uint32 kNtFakeOpenFile = 6;
437 434
438 LowLevelPolicy policyGen(policy); 435 LowLevelPolicy policyGen(policy);
439 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr_pipe)); 436 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr_pipe));
440 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr_dump)); 437 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr_dump));
441 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr_winexe)); 438 EXPECT_TRUE(policyGen.AddRule(kNtFakeCreateFile, &pr_winexe));
442 439
443 EXPECT_TRUE(policyGen.AddRule(kNtFakeOpenFile, &pr_adobe)); 440 EXPECT_TRUE(policyGen.AddRule(kNtFakeOpenFile, &pr_adobe));
444 EXPECT_TRUE(policyGen.AddRule(kNtFakeOpenFile, &pr_pipe)); 441 EXPECT_TRUE(policyGen.AddRule(kNtFakeOpenFile, &pr_pipe));
445 442
446 EXPECT_TRUE(policyGen.AddRule(kNtFakeNone, &pr_none)); 443 EXPECT_TRUE(policyGen.AddRule(kNtFakeNone, &pr_none));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 policy->entry[kNtFakeCreateFile]->opcodes[0].GetID()); 479 policy->entry[kNtFakeCreateFile]->opcodes[0].GetID());
483 EXPECT_EQ(OP_ACTION, 480 EXPECT_EQ(OP_ACTION,
484 policy->entry[kNtFakeCreateFile]->opcodes[tc2-1].GetID()); 481 policy->entry[kNtFakeCreateFile]->opcodes[tc2-1].GetID());
485 EXPECT_EQ(OP_WSTRING_MATCH, 482 EXPECT_EQ(OP_WSTRING_MATCH,
486 policy->entry[kNtFakeOpenFile]->opcodes[0].GetID()); 483 policy->entry[kNtFakeOpenFile]->opcodes[0].GetID());
487 EXPECT_EQ(OP_ACTION, policy->entry[kNtFakeOpenFile]->opcodes[tc3-1].GetID()); 484 EXPECT_EQ(OP_ACTION, policy->entry[kNtFakeOpenFile]->opcodes[tc3-1].GetID());
488 485
489 // Test the policy evaluation. 486 // Test the policy evaluation.
490 487
491 const wchar_t* filename = L""; 488 const wchar_t* filename = L"";
492 uint32_t creation_mode = OPEN_EXISTING; 489 uint32 creation_mode = OPEN_EXISTING;
493 uint32_t flags = FILE_ATTRIBUTE_NORMAL; 490 uint32 flags = FILE_ATTRIBUTE_NORMAL;
494 void* security_descriptor = NULL; 491 void* security_descriptor = NULL;
495 492
496 POLPARAMS_BEGIN(params) 493 POLPARAMS_BEGIN(params)
497 POLPARAM(filename) // Argument 0 494 POLPARAM(filename) // Argument 0
498 POLPARAM(creation_mode) // Argument 1 495 POLPARAM(creation_mode) // Argument 1
499 POLPARAM(flags) // Argument 2 496 POLPARAM(flags) // Argument 2
500 POLPARAM(security_descriptor) 497 POLPARAM(security_descriptor)
501 POLPARAMS_END; 498 POLPARAMS_END;
502 499
503 PolicyResult result; 500 PolicyResult result;
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 name = L"domo.txt"; 609 name = L"domo.txt";
613 result = pol_ev_copy.Evaluate(kShortEval, eval_params, _countof(eval_params)); 610 result = pol_ev_copy.Evaluate(kShortEval, eval_params, _countof(eval_params));
614 EXPECT_EQ(NO_POLICY_MATCH, result); 611 EXPECT_EQ(NO_POLICY_MATCH, result);
615 612
616 name = L"hello.bmp"; 613 name = L"hello.bmp";
617 result = pol_ev_copy.Evaluate(kShortEval, eval_params, _countof(eval_params)); 614 result = pol_ev_copy.Evaluate(kShortEval, eval_params, _countof(eval_params));
618 EXPECT_EQ(POLICY_MATCH, result); 615 EXPECT_EQ(POLICY_MATCH, result);
619 EXPECT_EQ(ASK_BROKER, pol_ev_copy.GetAction()); 616 EXPECT_EQ(ASK_BROKER, pol_ev_copy.GetAction());
620 } 617 }
621 } // namespace sandbox 618 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/win/src/policy_low_level.cc ('k') | sandbox/win/src/policy_opcodes_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698