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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
|
/*
* Copyright 2009- ECMWF.
*
* This software is licensed under the terms of the Apache Licence version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation
* nor does it submit to any jurisdiction.
*/
#include <string>
#include <vector>
#include <boost/test/unit_test.hpp>
#include "ecflow/core/File.hpp"
#include "ecflow/core/WhiteListFile.hpp"
#include "ecflow/test/scaffold/Naming.hpp"
using namespace ecf;
// #define DEBUG_ME 1
BOOST_AUTO_TEST_SUITE(U_Core)
BOOST_AUTO_TEST_SUITE(T_WhiteListFile)
void test_white_list_files(const std::string& directory, bool pass) {
auto full_path = fs::absolute(directory);
BOOST_CHECK(fs::exists(full_path));
BOOST_CHECK(fs::is_directory(full_path));
// std::cout << "\nIn directory: " << full_path.directory_string() << "\n\n";
fs::directory_iterator end_iter;
for (fs::directory_iterator dir_itr(full_path); dir_itr != end_iter; ++dir_itr) {
try {
fs::path relPath(directory + "/" + dir_itr->path().filename().string());
// recurse down directories
if (fs::is_directory(dir_itr->status())) {
test_white_list_files(relPath.string(), pass);
continue;
}
#if DEBUG_ME
std::cout << "......Parsing file " << relPath.string() << "\n";
#endif
WhiteListFile theFile;
std::string errorMsg;
bool parsedOk = theFile.load(relPath.string(), false /*debug*/, errorMsg);
if (pass) {
// Test expected to pass
BOOST_CHECK_MESSAGE(parsedOk,
"Failed to parse file " << relPath << "\n"
<< errorMsg << "\n"
<< theFile.dump_valid_users());
}
else {
// test expected to fail
BOOST_CHECK_MESSAGE(!parsedOk,
"Parse expected to fail for " << relPath << "\n"
<< errorMsg << "\n"
<< theFile.dump_valid_users());
#if DEBUG_ME
cout << "\n" << errorMsg << "\n";
#endif
}
}
catch (const std::exception& ex) {
std::cout << dir_itr->path().filename() << " " << ex.what() << std::endl;
}
}
}
BOOST_AUTO_TEST_CASE(test_parsing_for_good_white_list_files) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/goodWhiteListFiles", "libs/core");
// All the files in this directory are expected to pass
test_white_list_files(path, true);
}
BOOST_AUTO_TEST_CASE(test_parsing_for_bad_white_list_files) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/badWhiteListFiles", "libs/core");
// All the files in this directory are expected to fail
test_white_list_files(path, false);
}
BOOST_AUTO_TEST_CASE(test_white_list_default) {
ECF_NAME_THIS_TEST();
WhiteListFile theFile;
BOOST_REQUIRE_MESSAGE(0 == theFile.read_access_size(),
"expected 0 users with read access but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(0 == theFile.write_access_size(),
"expected 0 users with write access but found " << theFile.write_access_size());
// test random user
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxtt", "/x"), "Expected user xxtt to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxtt", paths), "Expected user xxtt to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("yyyy"), "Expected user yyyy to have write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzz", "/y"), "Expected user zzzz to have write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzz", paths), "Expected user zzzz to have write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list_empty_file) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/goodWhiteListFiles/empty.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
BOOST_REQUIRE_MESSAGE(0 == theFile.read_access_size(),
"expected 0 users with read access but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(0 == theFile.write_access_size(),
"expected 0 users with write access but found " << theFile.write_access_size());
// test random user
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxtt", "/x"), "Expected user xxtt to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxtt", paths), "Expected user xxtt to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("yyyy"), "Expected user yyyy to have write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzz", "/y"), "Expected user zzzz to have write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzz", paths), "Expected user zzzz to have write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/goodWhiteListFiles/good1.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
// make sure we find all the users and the access right are correct
// uid1 # a comment
// uid2 # a comment
// cog # a comment
//
// #
// # Read only uisers
// #
// -fred # a comment
// -bill # a comment
// -jake # a comment
// avi /suite/write
// -avi /suite/read
std::vector<std::string> expected_users_with_read_access;
expected_users_with_read_access.emplace_back("fred");
expected_users_with_read_access.emplace_back("bill");
expected_users_with_read_access.emplace_back("jake");
expected_users_with_read_access.emplace_back("uid1"); // users with write access also have read access
expected_users_with_read_access.emplace_back("uid2"); // users with write access also have read access
expected_users_with_read_access.emplace_back("cog"); // users with write access also have read access
std::vector<std::string> expected_users_with_read_write_access;
expected_users_with_read_write_access.emplace_back("uid1");
expected_users_with_read_write_access.emplace_back("uid2");
expected_users_with_read_write_access.emplace_back("cog");
std::vector<std::string> expected_users_with_read_access_to_paths_only;
expected_users_with_read_access_to_paths_only.emplace_back("avi");
std::vector<std::string> expected_users_with_write_access_to_paths_only;
expected_users_with_write_access_to_paths_only.emplace_back("avi");
BOOST_REQUIRE_MESSAGE(
expected_users_with_read_access.size() + expected_users_with_read_access_to_paths_only.size() ==
theFile.read_access_size(),
" expected " << expected_users_with_read_access.size() + expected_users_with_write_access_to_paths_only.size()
<< " users with read access but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(expected_users_with_read_write_access.size() +
expected_users_with_write_access_to_paths_only.size() ==
theFile.write_access_size(),
" expected " << expected_users_with_read_write_access.size() +
expected_users_with_write_access_to_paths_only.size()
<< " users with write access but found " << theFile.write_access_size());
// Users who have read access, to all including paths
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
std::vector<std::string>::const_iterator i;
for (i = expected_users_with_read_access.begin(); i != expected_users_with_read_access.end(); ++i) {
BOOST_CHECK_MESSAGE(theFile.verify_read_access(*i), "Expected user " << *i << " to have read access ");
BOOST_CHECK_MESSAGE(theFile.verify_read_access(*i, "/x"), "Expected user " << *i << " to have read access ");
BOOST_CHECK_MESSAGE(theFile.verify_read_access(*i, paths), "Expected user " << *i << " to have read access ");
}
for (i = expected_users_with_read_write_access.begin(); i != expected_users_with_read_write_access.end(); ++i) {
BOOST_CHECK_MESSAGE(theFile.verify_write_access(*i), "Expected user " << *i << " to have write access ");
BOOST_CHECK_MESSAGE(theFile.verify_write_access(*i, "/x"), "Expected user " << *i << " to have write access ");
BOOST_CHECK_MESSAGE(theFile.verify_write_access(*i, paths), "Expected user " << *i << " to have write access ");
}
// Users who have restricted read/write access to certain paths only.
std::vector<std::string> read_paths;
read_paths.emplace_back("/suite/read");
read_paths.emplace_back("/suite/read/f1");
read_paths.emplace_back("/suite/read/f1/t1");
for (i = expected_users_with_read_access_to_paths_only.begin();
i != expected_users_with_read_access_to_paths_only.end();
++i) {
BOOST_CHECK_MESSAGE(theFile.verify_read_access(*i), "Expected user " << *i << " to have read access ");
BOOST_CHECK_MESSAGE(theFile.verify_read_access(*i, read_paths),
"Expected user " << *i << " to have read access to paths");
BOOST_CHECK_MESSAGE(!theFile.verify_read_access(*i, paths),
"Expected user " << *i << " to NOT have read access to paths /a, /b , /c");
BOOST_CHECK_MESSAGE(!theFile.verify_read_access(*i, "/suite"),
"Expected user " << *i << " to NOT have read access to paths /suite only /suite/read");
BOOST_CHECK_MESSAGE(!theFile.verify_read_access(*i, "/suite/read_me"),
"Expected user "
<< *i << " with path '/suite/read_me' to NOT have read access to path /suite/read");
}
std::vector<std::string> write_paths;
write_paths.emplace_back("/suite/write");
write_paths.emplace_back("/suite/write/f1");
write_paths.emplace_back("/suite/write/f1/t1");
for (i = expected_users_with_write_access_to_paths_only.begin();
i != expected_users_with_write_access_to_paths_only.end();
++i) {
BOOST_CHECK_MESSAGE(!theFile.verify_write_access(*i),
"Expected user " << *i << " to NOT have generic write access ");
BOOST_CHECK_MESSAGE(theFile.verify_write_access(*i, write_paths),
"Expected user " << *i << " to have write access to paths");
BOOST_CHECK_MESSAGE(!theFile.verify_write_access(*i, paths),
"Expected user " << *i << " to have NOT has write access to paths /a, /b , /c");
BOOST_CHECK_MESSAGE(!theFile.verify_write_access(*i, "/suite"),
"Expected user " << *i << " to NOT have write access to paths /suite only /suite/write");
BOOST_CHECK_MESSAGE(!theFile.verify_write_access(*i, "/suite/write_me"),
"Expected user "
<< *i << " with path '/suite/write_me' to NOT have write access to paths /suite/write");
}
// test random user
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("xxxx"), "Expected user xxxx to NOT have read access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("xxxx", "/x"), "Expected user xxxx to NOT have read access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("xxxx", paths), "Expected user xxxx to NOT have read access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("*"), "Expected user * to NOT have read access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("yyyy"), "Expected user yyyy to NOT have write access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("zzzz", "/x"), "Expected user zzzz to NOT have write access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("zzzz", paths), "Expected user zzzz to NOT have write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list_all_users_have_read_access) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/goodWhiteListFiles/all_read_access.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
// make sure we find all the users and the access right are correct
// # These user have read and write access to the server
// uid1 # a comment
// uid2 # a comment
// cog # a comment
//
//
// # Read only users
//-*
//-fred # a comment
//-bill # a comment
//-jake # a comment
std::vector<std::string> expected_users_with_read_write_access;
expected_users_with_read_write_access.emplace_back("uid1");
expected_users_with_read_write_access.emplace_back("uid2");
expected_users_with_read_write_access.emplace_back("cog");
// When all users have read access, the read access size should be empty
BOOST_REQUIRE_MESSAGE(theFile.read_access_size() == 0, " expected 0 but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(expected_users_with_read_write_access.size() == theFile.write_access_size(),
" expected " << expected_users_with_read_write_access.size()
<< " users with write access but found " << theFile.write_access_size());
// Any user should have read access
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", "/x"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", paths), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("bill"), "Expected user bill to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("uid1"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("uid2"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("cog"), "Expected user xxxx to have read access ");
std::vector<std::string>::const_iterator i;
for (i = expected_users_with_read_write_access.begin(); i != expected_users_with_read_write_access.end(); ++i) {
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access(*i), "Expected user " << *i << " to have write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access(*i, "/x"),
"Expected user " << *i << " to have write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access(*i, paths),
"Expected user " << *i << " to have write access ");
}
// test random user for write access
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("yyyy"), "Expected user yyyy to NOT have write access ");
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("zzzz"), "Expected user zzzz to NOT have write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list_all_users_have_write_access) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/goodWhiteListFiles/all_write_access.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
// make sure we find all the users and the access right are correct
// uid1 # a comment
// uid2 # a comment
// cog # a comment
// *
//
// # Read only users
// -*
// -fred # a comment
// -bill # a comment
// -jake # a comment
// When all users have read access, the read access size should be empty
BOOST_REQUIRE_MESSAGE(theFile.read_access_size() == 0, " expected 0 but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(theFile.write_access_size() == 0, " expected 0 but found " << theFile.read_access_size());
// Any user should have read access
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", "/x"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", paths), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("bill"), "Expected user bill to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx", "/x"), "Expected user xxxx to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx", paths), "Expected user xxxx to have read access ");
// Any user should have read write access
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred"), "Expected user fred to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzzzz"), "Expected user zzzzzz to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzzzz", "/x"),
"Expected user zzzzzz to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("zzzzzz", paths),
"Expected user zzzzzz to have read/write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list_all_path_users_have_write_access) {
ECF_NAME_THIS_TEST();
std::string path =
File::test_data("libs/core/test/data/goodWhiteListFiles/all_path_write_access.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
// 4.4.14
// * / # same as '*'
// When all users have read/write access, the read/write access size should be empty
BOOST_REQUIRE_MESSAGE(theFile.read_access_size() == 0, " expected 0 but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(theFile.write_access_size() == 0, " expected 0 but found " << theFile.write_access_size());
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
std::vector<std::string> paths1;
paths1.emplace_back("/a");
paths1.emplace_back("/b");
// Any user should have read/write access
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", "/x"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", paths), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", paths1), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred"), "Expected user fred to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred", "/x"), "Expected user fred to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred", paths), "Expected user fred to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred", paths1),
"Expected user fred to have read/write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list_all_path_users_have_read_access) {
ECF_NAME_THIS_TEST();
std::string path =
File::test_data("libs/core/test/data/goodWhiteListFiles/all_path_read_access.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
// 4.4.14
// -* / # same as '*'
// When all users have read/write access, the size should be empty
BOOST_REQUIRE_MESSAGE(theFile.read_access_size() == 0, " expected 0 but found " << theFile.read_access_size());
BOOST_REQUIRE_MESSAGE(theFile.write_access_size() == 0, " expected 0 but found " << theFile.write_access_size());
// When no write access specified all user have write access
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
std::vector<std::string> paths1;
paths1.emplace_back("/a");
paths1.emplace_back("/b");
// Any user should have read/write access
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred"), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", paths), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("fred", paths1), "Expected user fred to have read access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred", paths), "Expected user fred to have read/write access ");
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("fred", paths1),
"Expected user fred to have read/write access ");
}
BOOST_AUTO_TEST_CASE(test_white_list_path_access_list) {
ECF_NAME_THIS_TEST();
std::string path = File::test_data("libs/core/test/data/goodWhiteListFiles/path_access.lists", "libs/core");
WhiteListFile theFile;
std::string errorMsg;
BOOST_CHECK_MESSAGE(theFile.load(path, false, errorMsg), "Failed to parse file " << path << "\n" << errorMsg);
// 4.4.14
//
// user1 /a,/b,/c # user1 has read write access to suite /a /b /c
// user2 /a
// user2 /b
// user2 /c # user2 has read write access to suite /a /b /c
// user3 /a /b /c # user3 has read write access to suite /a /b /c
//
// /a /b /c userx # userx has read write access to suite /a /b /c
// /a,/b,/c usery # userx has read write access to suite /a /b /c
//
// /a userz
// /b userz
// /c userz
//
// -user4 /a,/b,/c # user4 has read access to suite /a /b /c
// -user5 /a
// -user5 /b
// -user5 /c # user5 has read access to suite /a /b /c
// -user6 /a /b /c # user6 has read access to suite /a /b /c
//
// /a /b /c -userxx # userxx has read access to suite /a /b /c
// /a,/b,/c -useryy # userxy has read access to suite /a /b /c
//
// /a -userzz
// /b -userzz
// /c -userzz
//
// ##################################
//* /x /y # all user have read/write access suites /x /y
//-* /w /z # all user have read access to suite /w /z
// When all users have read access, the read access size should be empty
BOOST_REQUIRE_MESSAGE(theFile.read_access_size() == 7,
" expected 7 but found " << theFile.read_access_size() << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.write_access_size() == 7,
" expected 7 but found " << theFile.write_access_size() << theFile.dump_valid_users());
// When no write access specified all user have write access
std::vector<std::string> paths;
paths.emplace_back("/a");
paths.emplace_back("/b");
paths.emplace_back("/c");
std::vector<std::string> partial_paths;
partial_paths.emplace_back("/a");
partial_paths.emplace_back("/b");
// read/write
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user1", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user1", partial_paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user1", paths),
"Expected user to have read/write access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user1", partial_paths),
"Expected user to have read/write access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user2", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user2", paths),
"Expected user to have read/write access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user3", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user3", paths),
"Expected user to have read/write access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("userx", paths),
"Expected userx to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("userx", paths),
"Expected userx to have read/write access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("usery", paths),
"Expected userx to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("usery", paths),
"Expected userx to have read/write access to /a,/b,/c" << theFile.dump_valid_users());
// read only
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user4", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user5", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user6", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("userxx", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("useryy", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("userzz", paths),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
// single path, read/write
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user1", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user1", "/a"),
"Expected user to have read/write access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user2", "/a"),
"Expected user to have read access to /a,/b,/c" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user2", "/a"),
"Expected user to have read/write access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user3", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("user3", "/a"),
"Expected user to have read/write access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("userx", "/a"),
"Expected userx to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("userx", "/a"),
"Expected userx to have read/write access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("usery", "/a"),
"Expected userx to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("usery", "/a"),
"Expected userx to have read/write access to /a" << theFile.dump_valid_users());
// single path, read
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user4", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user5", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user6", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("userxx", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("useryy", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("userzz", "/a"),
"Expected user to have read access to /a" << theFile.dump_valid_users());
// ============================================================================================
// test * user, * means all users
//* /x /y # all user have read/write access suites /x /y
//-* /w /z # all user have read access to suite /w /z
std::vector<std::string> single_pathx;
single_pathx.emplace_back("/x");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx"),
"Expected *ALL* user to have read access" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx", single_pathx),
"Expected *ALL* user to have read access to /x" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("xxxx", single_pathx),
"Expected *ALL* user to have read/write access to /x" << theFile.dump_valid_users());
std::vector<std::string> single_pathw;
single_pathw.emplace_back("/w");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx", single_pathw),
"Expected *ALL* user to have read access to /w" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("xxxx", single_pathw),
"Expected failure for write access to /w" << theFile.dump_valid_users());
std::vector<std::string> multiple_pathsxy;
multiple_pathsxy.emplace_back("/x");
multiple_pathsxy.emplace_back("/y");
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("xxxx", multiple_pathsxy),
"Expected *ALL* user to have read access to /x,/y" << theFile.dump_valid_users());
// ============================================================================================
// Failure
// ============================================================================================
// single path failure
// user1 /a,/b,/c # user1 has read write access to suite /a /b /c
std::vector<std::string> single_path_failure;
single_path_failure.emplace_back("/fail");
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("user1", "/fail"),
"Expected user to not have read access to /fail" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("user1", single_path_failure),
"Expected user to not have read access to /fail" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("user1", "/fail"),
"Expected user to not have read/write access to /fail" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("user1", single_path_failure),
"Expected user to not have read/write access to /fail" << theFile.dump_valid_users());
// multi path failure
// user1 /a,/b,/c # user1 has read write access to suite /a /b /c
std::vector<std::string> multiple_paths_failure;
multiple_paths_failure.emplace_back("/a");
multiple_paths_failure.emplace_back("/b");
multiple_paths_failure.emplace_back("/fail");
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("user1", multiple_paths_failure),
"Expected user to not have read access to /fail\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("user1", multiple_paths_failure),
"Expected user to not have read/write access to /fail\n"
<< theFile.dump_valid_users());
// Presence of *, should allow read access to all including unknown users
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("unknown"),
"Expected unknown user to pass due to presence of *\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("unknown", "/x"),
"Expected pass \n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("unknown", "/y"), "Expected pass\n" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("unknown", "/w"), "Expected pass\n" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("unknown", "/z"), "Expected pass\n" << theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("unknown", "/x"),
"Expected pass\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(theFile.verify_write_access("unknown", "/y"),
"Expected pass\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("unknown", "/a"),
"Expected failure for unknown user for path /a\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("unknown", "/a"),
"Expected failure for unknown user for path /a\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("unknown", paths),
"Expected failure for unknown user\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("unknown", paths),
"Expected failure for unknown user\n"
<< theFile.dump_valid_users());
// user1 /a,/b,/c # user1 has read write access to suite /a /b /c
BOOST_REQUIRE_MESSAGE(theFile.verify_read_access("user1"),
"Expected user1 to not have read access, EVEN if no paths specified, --news has no paths\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("user1", std::vector<std::string>()),
"Expected user to not have read access if no paths specified\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_read_access("user1", ""),
"Expected user to not have read access if no paths specified\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("user1"),
"Expected user to not have read/write if no paths specified\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("user1", ""),
"Expected user to not have read/write if no paths specified\n"
<< theFile.dump_valid_users());
BOOST_REQUIRE_MESSAGE(!theFile.verify_write_access("user1", std::vector<std::string>()),
"Expected user to not have read/write if no paths specified\n"
<< theFile.dump_valid_users());
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
|