Mercurial > hg > orthanc-authorization
comparison UnitTestsSources/UnitTestsMain.cpp @ 112:572955904411
added tools/labels + removed forbidden_labels
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 31 Aug 2023 16:51:15 +0200 |
parents | 2b1a95c7d263 |
children | f294a3c6dbe6 |
comparison
equal
deleted
inserted
replaced
111:2b1a95c7d263 | 112:572955904411 |
---|---|
312 } | 312 } |
313 } | 313 } |
314 return false; | 314 return false; |
315 } | 315 } |
316 | 316 |
317 TEST(ToolsFindLabels, AdjustQueryForUserWithoutAuthorizedLabels) | |
318 { | |
319 // user who has access no authorized labels | |
320 OrthancPlugins::IAuthorizationService::UserProfile profile; | |
321 | |
322 { // any call to tools/find for such a user should fail since it does not have access to anything | |
323 Json::Value query; | |
324 query["Query"] = Json::objectValue; | |
325 query["Query"]["PatientID"] = "*"; | |
326 | |
327 ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); | |
328 } | |
329 | |
330 } | |
331 | |
332 | |
333 | |
317 TEST(ToolsFindLabels, AdjustQueryForUserWithoutRestrictions) | 334 TEST(ToolsFindLabels, AdjustQueryForUserWithoutRestrictions) |
318 { | 335 { |
319 // user who has access to all labels | 336 // user who has access to all labels |
320 OrthancPlugins::IAuthorizationService::UserProfile profile; | 337 OrthancPlugins::IAuthorizationService::UserProfile profile; |
321 profile.authorizedLabels.insert("*"); | 338 profile.authorizedLabels.insert("*"); |
322 | 339 |
323 { // no labels before transformation -> no labels after | 340 { // no labels filtering before transformation -> no labels filtering after |
324 Json::Value query; | 341 Json::Value query; |
325 query["Query"] = Json::objectValue; | 342 query["Query"] = Json::objectValue; |
326 query["Query"]["PatientID"] = "*"; | 343 query["Query"]["PatientID"] = "*"; |
327 | 344 |
328 AdjustToolsFindQueryLabels(query, profile); | 345 AdjustToolsFindQueryLabels(query, profile); |
540 | 557 |
541 ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); | 558 ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); |
542 } | 559 } |
543 } | 560 } |
544 | 561 |
545 TEST(ToolsFindLabels, AdjustQueryForUserWithForbiddenLabelsRestrictions) | 562 // TEST(ToolsFindLabels, AdjustQueryForUserWithForbiddenLabelsRestrictions) |
546 { | 563 // { |
547 // user who has forbidden access to "b" and "c" | 564 // // user who has forbidden access to "b" and "c" |
548 OrthancPlugins::IAuthorizationService::UserProfile profile; | 565 // OrthancPlugins::IAuthorizationService::UserProfile profile; |
549 profile.forbiddenLabels.insert("b"); | 566 // profile.forbiddenLabels.insert("b"); |
550 profile.forbiddenLabels.insert("c"); | 567 // profile.forbiddenLabels.insert("c"); |
551 | 568 |
552 { // no labels before transformation -> "b", "c" label after (with a 'None' constraint) | 569 // { // no labels before transformation -> "b", "c" label after (with a 'None' constraint) |
553 Json::Value query; | 570 // Json::Value query; |
554 query["Query"] = Json::objectValue; | 571 // query["Query"] = Json::objectValue; |
555 query["Query"]["PatientID"] = "*"; | 572 // query["Query"]["PatientID"] = "*"; |
556 | 573 |
557 AdjustToolsFindQueryLabels(query, profile); | 574 // AdjustToolsFindQueryLabels(query, profile); |
558 | 575 |
559 ASSERT_EQ(2u, query["Labels"].size()); | 576 // ASSERT_EQ(2u, query["Labels"].size()); |
560 ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); | 577 // ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); |
561 ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); | 578 // ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); |
562 ASSERT_EQ("None", query["LabelsConstraint"].asString()); | 579 // ASSERT_EQ("None", query["LabelsConstraint"].asString()); |
563 } | 580 // } |
564 | 581 |
565 { // missing LabelsConstraint -> throw | 582 // { // missing LabelsConstraint -> throw |
566 Json::Value query; | 583 // Json::Value query; |
567 query["Query"] = Json::objectValue; | 584 // query["Query"] = Json::objectValue; |
568 query["Query"]["PatientID"] = "*"; | 585 // query["Query"]["PatientID"] = "*"; |
569 query["Labels"] = Json::arrayValue; | 586 // query["Labels"] = Json::arrayValue; |
570 query["Labels"].append("a"); | 587 // query["Labels"].append("a"); |
571 | 588 |
572 ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); | 589 // ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); |
573 } | 590 // } |
574 | 591 |
575 { // 'All' label constraint can not be modified for user with forbidden labels | 592 // { // 'All' label constraint can not be modified for user with forbidden labels |
576 Json::Value query; | 593 // Json::Value query; |
577 query["Query"] = Json::objectValue; | 594 // query["Query"] = Json::objectValue; |
578 query["Query"]["PatientID"] = "*"; | 595 // query["Query"]["PatientID"] = "*"; |
579 query["Labels"] = Json::arrayValue; | 596 // query["Labels"] = Json::arrayValue; |
580 query["Labels"].append("b"); | 597 // query["Labels"].append("b"); |
581 query["Labels"].append("c"); | 598 // query["Labels"].append("c"); |
582 query["LabelsConstraint"] = "All"; | 599 // query["LabelsConstraint"] = "All"; |
583 | 600 |
584 ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); | 601 // ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); |
585 } | 602 // } |
586 | 603 |
587 { // 'Any' label constraint can not be modified for user with forbidden labels | 604 // { // 'Any' label constraint can not be modified for user with forbidden labels |
588 Json::Value query; | 605 // Json::Value query; |
589 query["Query"] = Json::objectValue; | 606 // query["Query"] = Json::objectValue; |
590 query["Query"]["PatientID"] = "*"; | 607 // query["Query"]["PatientID"] = "*"; |
591 query["Labels"] = Json::arrayValue; | 608 // query["Labels"] = Json::arrayValue; |
592 query["Labels"].append("b"); | 609 // query["Labels"].append("b"); |
593 query["Labels"].append("c"); | 610 // query["Labels"].append("c"); |
594 query["LabelsConstraint"] = "Any"; | 611 // query["LabelsConstraint"] = "Any"; |
595 | 612 |
596 ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); | 613 // ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); |
597 } | 614 // } |
598 | 615 |
599 { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user | 616 // { // 'Any' label constraint can not be modified for user with forbidden labels |
600 Json::Value query; | 617 // Json::Value query; |
601 query["Query"] = Json::objectValue; | 618 // query["Query"] = Json::objectValue; |
602 query["Query"]["PatientID"] = "*"; | 619 // query["Query"]["PatientID"] = "*"; |
603 query["Labels"] = Json::arrayValue; | 620 // query["Labels"] = Json::arrayValue; |
604 query["Labels"].append("b"); | 621 // query["Labels"].append("a"); |
605 query["LabelsConstraint"] = "None"; | 622 // query["LabelsConstraint"] = "Any"; |
606 | 623 |
607 AdjustToolsFindQueryLabels(query, profile); | 624 // ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); |
608 ASSERT_EQ(2u, query["Labels"].size()); | 625 // } |
609 ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); | 626 |
610 ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); | 627 |
611 ASSERT_EQ("None", query["LabelsConstraint"].asString()); | 628 // { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user |
612 } | 629 // Json::Value query; |
613 | 630 // query["Query"] = Json::objectValue; |
614 { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user | 631 // query["Query"]["PatientID"] = "*"; |
615 Json::Value query; | 632 // query["Labels"] = Json::arrayValue; |
616 query["Query"] = Json::objectValue; | 633 // query["Labels"].append("b"); |
617 query["Query"]["PatientID"] = "*"; | 634 // query["LabelsConstraint"] = "None"; |
618 query["Labels"] = Json::arrayValue; | 635 |
619 query["Labels"].append("d"); | 636 // AdjustToolsFindQueryLabels(query, profile); |
620 query["LabelsConstraint"] = "None"; | 637 // ASSERT_EQ(2u, query["Labels"].size()); |
621 | 638 // ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); |
622 AdjustToolsFindQueryLabels(query, profile); | 639 // ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); |
623 ASSERT_EQ(3u, query["Labels"].size()); | 640 // ASSERT_EQ("None", query["LabelsConstraint"].asString()); |
624 ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); | 641 // } |
625 ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); | 642 |
626 ASSERT_TRUE(IsInJsonArray("d", query["Labels"])); | 643 // { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user |
627 ASSERT_EQ("None", query["LabelsConstraint"].asString()); | 644 // Json::Value query; |
628 } | 645 // query["Query"] = Json::objectValue; |
629 } | 646 // query["Query"]["PatientID"] = "*"; |
647 // query["Labels"] = Json::arrayValue; | |
648 // query["Labels"].append("d"); | |
649 // query["LabelsConstraint"] = "None"; | |
650 | |
651 // AdjustToolsFindQueryLabels(query, profile); | |
652 // ASSERT_EQ(3u, query["Labels"].size()); | |
653 // ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); | |
654 // ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); | |
655 // ASSERT_TRUE(IsInJsonArray("d", query["Labels"])); | |
656 // ASSERT_EQ("None", query["LabelsConstraint"].asString()); | |
657 // } | |
658 // } | |
630 | 659 |
631 } | 660 } |
632 | 661 |
633 int main(int argc, char **argv) | 662 int main(int argc, char **argv) |
634 { | 663 { |