Mercurial > hg > orthanc-authorization
diff 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 |
line wrap: on
line diff
--- a/UnitTestsSources/UnitTestsMain.cpp Wed Aug 30 18:10:09 2023 +0200 +++ b/UnitTestsSources/UnitTestsMain.cpp Thu Aug 31 16:51:15 2023 +0200 @@ -314,13 +314,30 @@ return false; } +TEST(ToolsFindLabels, AdjustQueryForUserWithoutAuthorizedLabels) +{ + // user who has access no authorized labels + OrthancPlugins::IAuthorizationService::UserProfile profile; + + { // any call to tools/find for such a user should fail since it does not have access to anything + Json::Value query; + query["Query"] = Json::objectValue; + query["Query"]["PatientID"] = "*"; + + ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); + } + +} + + + TEST(ToolsFindLabels, AdjustQueryForUserWithoutRestrictions) { // user who has access to all labels OrthancPlugins::IAuthorizationService::UserProfile profile; profile.authorizedLabels.insert("*"); - { // no labels before transformation -> no labels after + { // no labels filtering before transformation -> no labels filtering after Json::Value query; query["Query"] = Json::objectValue; query["Query"]["PatientID"] = "*"; @@ -542,91 +559,103 @@ } } -TEST(ToolsFindLabels, AdjustQueryForUserWithForbiddenLabelsRestrictions) -{ - // user who has forbidden access to "b" and "c" - OrthancPlugins::IAuthorizationService::UserProfile profile; - profile.forbiddenLabels.insert("b"); - profile.forbiddenLabels.insert("c"); +// TEST(ToolsFindLabels, AdjustQueryForUserWithForbiddenLabelsRestrictions) +// { +// // user who has forbidden access to "b" and "c" +// OrthancPlugins::IAuthorizationService::UserProfile profile; +// profile.forbiddenLabels.insert("b"); +// profile.forbiddenLabels.insert("c"); - { // no labels before transformation -> "b", "c" label after (with a 'None' constraint) - Json::Value query; - query["Query"] = Json::objectValue; - query["Query"]["PatientID"] = "*"; +// { // no labels before transformation -> "b", "c" label after (with a 'None' constraint) +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; - AdjustToolsFindQueryLabels(query, profile); +// AdjustToolsFindQueryLabels(query, profile); - ASSERT_EQ(2u, query["Labels"].size()); - ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); - ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); - ASSERT_EQ("None", query["LabelsConstraint"].asString()); - } +// ASSERT_EQ(2u, query["Labels"].size()); +// ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); +// ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); +// ASSERT_EQ("None", query["LabelsConstraint"].asString()); +// } - { // missing LabelsConstraint -> throw - Json::Value query; - query["Query"] = Json::objectValue; - query["Query"]["PatientID"] = "*"; - query["Labels"] = Json::arrayValue; - query["Labels"].append("a"); +// { // missing LabelsConstraint -> throw +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; +// query["Labels"] = Json::arrayValue; +// query["Labels"].append("a"); - ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); - } +// ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); +// } - { // 'All' label constraint can not be modified for user with forbidden labels - Json::Value query; - query["Query"] = Json::objectValue; - query["Query"]["PatientID"] = "*"; - query["Labels"] = Json::arrayValue; - query["Labels"].append("b"); - query["Labels"].append("c"); - query["LabelsConstraint"] = "All"; +// { // 'All' label constraint can not be modified for user with forbidden labels +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; +// query["Labels"] = Json::arrayValue; +// query["Labels"].append("b"); +// query["Labels"].append("c"); +// query["LabelsConstraint"] = "All"; - ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); - } +// ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); +// } - { // 'Any' label constraint can not be modified for user with forbidden labels - Json::Value query; - query["Query"] = Json::objectValue; - query["Query"]["PatientID"] = "*"; - query["Labels"] = Json::arrayValue; - query["Labels"].append("b"); - query["Labels"].append("c"); - query["LabelsConstraint"] = "Any"; +// { // 'Any' label constraint can not be modified for user with forbidden labels +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; +// query["Labels"] = Json::arrayValue; +// query["Labels"].append("b"); +// query["Labels"].append("c"); +// query["LabelsConstraint"] = "Any"; + +// ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); +// } - ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); - } +// { // 'Any' label constraint can not be modified for user with forbidden labels +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; +// query["Labels"] = Json::arrayValue; +// query["Labels"].append("a"); +// query["LabelsConstraint"] = "Any"; - { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user - Json::Value query; - query["Query"] = Json::objectValue; - query["Query"]["PatientID"] = "*"; - query["Labels"] = Json::arrayValue; - query["Labels"].append("b"); - query["LabelsConstraint"] = "None"; +// ASSERT_THROW(AdjustToolsFindQueryLabels(query, profile), Orthanc::OrthancException); +// } + - AdjustToolsFindQueryLabels(query, profile); - ASSERT_EQ(2u, query["Labels"].size()); - ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); - ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); - ASSERT_EQ("None", query["LabelsConstraint"].asString()); - } +// { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; +// query["Labels"] = Json::arrayValue; +// query["Labels"].append("b"); +// query["LabelsConstraint"] = "None"; + +// AdjustToolsFindQueryLabels(query, profile); +// ASSERT_EQ(2u, query["Labels"].size()); +// ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); +// ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); +// ASSERT_EQ("None", query["LabelsConstraint"].asString()); +// } - { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user - Json::Value query; - query["Query"] = Json::objectValue; - query["Query"]["PatientID"] = "*"; - query["Labels"] = Json::arrayValue; - query["Labels"].append("d"); - query["LabelsConstraint"] = "None"; +// { // 'None' label constraint are modified to always contain at least all forbidden_labels of the user +// Json::Value query; +// query["Query"] = Json::objectValue; +// query["Query"]["PatientID"] = "*"; +// query["Labels"] = Json::arrayValue; +// query["Labels"].append("d"); +// query["LabelsConstraint"] = "None"; - AdjustToolsFindQueryLabels(query, profile); - ASSERT_EQ(3u, query["Labels"].size()); - ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); - ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); - ASSERT_TRUE(IsInJsonArray("d", query["Labels"])); - ASSERT_EQ("None", query["LabelsConstraint"].asString()); - } -} +// AdjustToolsFindQueryLabels(query, profile); +// ASSERT_EQ(3u, query["Labels"].size()); +// ASSERT_TRUE(IsInJsonArray("b", query["Labels"])); +// ASSERT_TRUE(IsInJsonArray("c", query["Labels"])); +// ASSERT_TRUE(IsInJsonArray("d", query["Labels"])); +// ASSERT_EQ("None", query["LabelsConstraint"].asString()); +// } +// } }