diff options
author | Mateusz Cegielka <m.cegielka@samsung.com> | 2020-07-10 16:19:53 +0200 |
---|---|---|
committer | Mateusz Cegielka <m.cegielka@samsung.com> | 2020-07-10 16:19:53 +0200 |
commit | 3ce21bf68c2b97de240af6ae9bb3a23b8609185a (patch) | |
tree | 196b08ae7a57d3658ccce46fdfb6b73ef2df03a7 | |
parent | db0793feb60bd27bdf8ac15831bb294792d77329 (diff) | |
download | security-manager-3ce21bf68c2b97de240af6ae9bb3a23b8609185a.tar.gz security-manager-3ce21bf68c2b97de240af6ae9bb3a23b8609185a.tar.bz2 security-manager-3ce21bf68c2b97de240af6ae9bb3a23b8609185a.zip |
Test recently added queries to privilege database
The PrivilegeDb class contains wrappers for running SQLite requests.
Since unit tests for it were created, more kinds of supported
statements have been added, but the tests were not updated.
I have added new tests that cover the GetAppPkgInfo, GetUserAppsFromPkg
SetSharedROPackage and IsUserPkgInstalled queries. I have also modified
existing privilege license tests to also cover
GetLicenseForClientPrivilegeAndPkg and AddAppDefinedPrivileges queries.
Change-Id: I3b43942f579cfc692b44203a2ea99b8c41d7be80
-rw-r--r-- | test/test_privilege_db_app_defined_privileges.cpp | 38 | ||||
-rw-r--r-- | test/test_privilege_db_app_pkg_getters.cpp | 68 |
2 files changed, 91 insertions, 15 deletions
diff --git a/test/test_privilege_db_app_defined_privileges.cpp b/test/test_privilege_db_app_defined_privileges.cpp index 6e357c30..9d1b849d 100644 --- a/test/test_privilege_db_app_defined_privileges.cpp +++ b/test/test_privilege_db_app_defined_privileges.cpp @@ -34,7 +34,7 @@ namespace { struct AppDefinedPrivilegeFixture : public PrivilegeDBFixture { void checkAppDefinedPrivileges(const std::string &app, uid_t uid, const AppDefinedPrivilegesVector &expected); - void checkClientLicense(const std::string &app, uid_t uid, + void checkClientLicense(const std::string &app, const std::string &pkg, uid_t uid, const std::vector<std::string> &privileges, const std::vector<std::pair<bool, std::string>> &expected); }; @@ -53,7 +53,7 @@ void AppDefinedPrivilegeFixture::checkAppDefinedPrivileges(const std::string &ap } } -void AppDefinedPrivilegeFixture::checkClientLicense(const std::string &app, uid_t uid, +void AppDefinedPrivilegeFixture::checkClientLicense(const std::string &app, const std::string &pkg, uid_t uid, const std::vector<std::string> &privileges, const std::vector<std::pair<bool, std::string>> &expected) { @@ -63,6 +63,8 @@ void AppDefinedPrivilegeFixture::checkClientLicense(const std::string &app, uid_ std::string license; BOOST_REQUIRE(expected[i].first == testPrivDb->GetLicenseForClientPrivilegeAndApp(app, uid, privileges[i], license)); BOOST_REQUIRE(license == expected[i].second); + BOOST_REQUIRE(expected[i].first == testPrivDb->GetLicenseForClientPrivilegeAndPkg(pkg, uid, privileges[i], license)); + BOOST_REQUIRE(license == expected[i].second); } } @@ -140,14 +142,12 @@ NEGATIVE_TEST_CASE(T1300_app_defined_privileges) checkAppDefinedPrivileges(app(1), uid(1), {}); // second application defines privileges - BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivilege(app(2), uid(2), privileges[0])); - BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivilege(app(2), uid(2), privileges[1])); + BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivileges(app(2), uid(2), privileges)); checkAppDefinedPrivileges(app(2), uid(2), privileges); // install second application for different user and add privileges addAppSuccess(app(2), pkg(2), uid(3), tizenVer(1), author(2), Hybrid); - BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivilege(app(2), uid(3), privileges[0])); - BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivilege(app(2), uid(3), privileges[1])); + BOOST_REQUIRE_NO_THROW(testPrivDb->AddAppDefinedPrivileges(app(2), uid(3), privileges)); checkAppDefinedPrivileges(app(2), uid(3), privileges); // uninstall second application and check privileges @@ -174,13 +174,13 @@ NEGATIVE_TEST_CASE(T1400_client_license) "/opt/data/client_appB/res/second_app_client_license")); // non-existing application - checkClientLicense(app(1), uid(1), {privilegesA[0].first}, {{false, ""}}); + checkClientLicense(app(1), pkg(1), uid(1), {privilegesA[0].first}, {{false, ""}}); // add application addAppSuccess(app(1), pkg(1), uid(1), tizenVer(1), author(1), Hybrid); // privileges/licenses not used - checkClientLicense(app(1), uid(1), {privilegesA[0].first}, {{false, ""}}); + checkClientLicense(app(1), pkg(1), uid(1), {privilegesA[0].first}, {{false, ""}}); // add privilege/license to non-existing application BOOST_REQUIRE_THROW(testPrivDb->AddClientPrivilege(app(2), uid(1), privilegesA[0].first, privilegesA[0].second), @@ -198,18 +198,22 @@ NEGATIVE_TEST_CASE(T1400_client_license) BOOST_REQUIRE_NO_THROW(testPrivDb->GetLicenseForClientPrivilegeAndApp(app(1), uid(1), privilegesA[1].first, license)); BOOST_REQUIRE(license.empty()); + // check non-existing privilege in pkg + BOOST_REQUIRE_NO_THROW(testPrivDb->GetLicenseForClientPrivilegeAndPkg(pkg(1), uid(1), privilegesA[1].first, license)); + BOOST_REQUIRE(license.empty()); + // first application use second privilege/license BOOST_REQUIRE_NO_THROW(testPrivDb->AddClientPrivilege(app(1), uid(1), privilegesA[1].first, privilegesA[1].second)); // check existing privilege license - checkClientLicense(app(1), uid(1), {privilegesA[0].first, privilegesA[1].first}, + checkClientLicense(app(1), pkg(1), uid(1), {privilegesA[0].first, privilegesA[1].first}, {{true, privilegesA[0].second}, {true, privilegesA[1].second}}); // add second application addAppSuccess(app(2), pkg(2), uid(2), tizenVer(1), author(2), Hybrid); // privileges/licenses not used - checkClientLicense(app(2), uid(2), {privilegesA[0].first}, {{false, ""}}); + checkClientLicense(app(2), pkg(2), uid(2), {privilegesA[0].first}, {{false, ""}}); // second application use first privilege/license BOOST_REQUIRE_NO_THROW(testPrivDb->AddClientPrivilege(app(2), uid(2), privilegesB[0].first, privilegesB[0].second)); @@ -218,32 +222,36 @@ NEGATIVE_TEST_CASE(T1400_client_license) BOOST_REQUIRE_NO_THROW(testPrivDb->GetLicenseForClientPrivilegeAndApp(app(2), uid(2), privilegesB[1].first, license)); BOOST_REQUIRE(license.empty()); + // check non-existing privilege in pkg + BOOST_REQUIRE_NO_THROW(testPrivDb->GetLicenseForClientPrivilegeAndPkg(pkg(2), uid(2), privilegesB[1].first, license)); + BOOST_REQUIRE(license.empty()); + // second application use second privilege/license BOOST_REQUIRE_NO_THROW(testPrivDb->AddClientPrivilege(app(2), uid(2), privilegesB[1].first, privilegesB[1].second)); // check existing privilege/license - checkClientLicense(app(2), uid(2), {privilegesB[0].first, privilegesB[1].first}, + checkClientLicense(app(2), pkg(2), uid(2), {privilegesB[0].first, privilegesB[1].first}, {{true, privilegesB[0].second}, {true, privilegesB[1].second}}); // remove first application privileges/licenses BOOST_REQUIRE_NO_THROW(testPrivDb->RemoveClientPrivileges(app(1), uid(1))); - checkClientLicense(app(1), uid(1), {privilegesA[0].first, privilegesA[1].first}, + checkClientLicense(app(1), pkg(1), uid(1), {privilegesA[0].first, privilegesA[1].first}, {{false, ""}, {false, ""}}); // install second application for different user and add privileges addAppSuccess(app(2), pkg(2), uid(3), tizenVer(1), author(2), Hybrid); BOOST_REQUIRE_NO_THROW(testPrivDb->AddClientPrivilege(app(2), uid(3), privilegesB[0].first, privilegesB[0].second)); BOOST_REQUIRE_NO_THROW(testPrivDb->AddClientPrivilege(app(2), uid(3), privilegesB[1].first, privilegesB[1].second)); - checkClientLicense(app(2), uid(3), {privilegesB[0].first, privilegesB[1].first}, + checkClientLicense(app(2), pkg(2), uid(3), {privilegesB[0].first, privilegesB[1].first}, {{true, privilegesB[0].second}, {true, privilegesB[1].second}}); // uninstall second application and check privileges/licenses removeAppSuccess(app(2), uid(2)); - checkClientLicense(app(2), uid(2), {privilegesB[0].first, privilegesB[1].first}, + checkClientLicense(app(2), pkg(2), uid(2), {privilegesB[0].first, privilegesB[1].first}, {{false, ""}, {false, ""}}); removeAppSuccess(app(2), uid(3)); - checkClientLicense(app(2), uid(3), {privilegesB[0].first, privilegesB[1].first}, + checkClientLicense(app(2), pkg(2), uid(3), {privilegesB[0].first, privilegesB[1].first}, {{false, ""}, {false, ""}}); } diff --git a/test/test_privilege_db_app_pkg_getters.cpp b/test/test_privilege_db_app_pkg_getters.cpp index 48635385..95ff541c 100644 --- a/test/test_privilege_db_app_pkg_getters.cpp +++ b/test/test_privilege_db_app_pkg_getters.cpp @@ -35,9 +35,13 @@ struct PrivilegeDBGettersFixture : PrivilegeDBFixture { void checkGetAllPackages(std::vector<std::string> expectedPackages); void checkGetAuthorIdByName(const std::string &authorName, int expectedAuthorId); + void checkGetAppPkgInfo(const std::string &app, const std::string &expectedPackage, + bool expectedIsHybrid, bool expectedIsSharedRO); void checkGetPkgApps(const std::string &package, std::vector<std::string> expectedApps); void checkGetPkgAuthorId(const std::string &pkgName, int expectedAuthorId); void checkGetUserApps(const uid_t uid, std::vector<std::string> expectedApps); + void checkGetUserAppsFromPkg(uid_t uid, const std::string &pkgName, + std::vector<std::string> expectedApps); void checkGetUserPkgs(const uid_t uid, std::vector<std::string> expectedPkgs); void checkIsPackageHybrid(const std::string &pkgName, bool expectedIsHybrid); }; @@ -62,6 +66,20 @@ void PrivilegeDBGettersFixture::checkGetAuthorIdByName(const std::string &author << expectedAuthorId); }; +void PrivilegeDBGettersFixture::checkGetAppPkgInfo(const std::string &app, + const std::string &expectedPackage, bool expectedIsHybrid, bool expectedIsSharedRO) +{ + std::string package; + bool isHybrid, isSharedRO; + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetAppPkgInfo(app, package, isHybrid, isSharedRO)); + BOOST_CHECK_MESSAGE(expectedPackage == package, "GetAppPkgInfo for app: " << app << + " returned wrong package: " << package << " expected: " << expectedPackage); + BOOST_CHECK_MESSAGE(expectedIsHybrid == isHybrid, "GetAppPkgInfo for app: " << app << + " returned wrong isHybrid: " << isHybrid << " expected: " << expectedIsHybrid); + BOOST_CHECK_MESSAGE(expectedIsSharedRO == isSharedRO, "GetAppPkgInfo for app: " << app << + " returned wrong isSharedRO: " << isSharedRO << " expected: " << expectedIsSharedRO); +} + void PrivilegeDBGettersFixture::checkGetPkgApps(const std::string &package, std::vector<std::string> expectedApps) { @@ -93,6 +111,17 @@ void PrivilegeDBGettersFixture::checkGetUserApps(const uid_t uid, expectedApps.begin(), expectedApps.end()); }; +void PrivilegeDBGettersFixture::checkGetUserAppsFromPkg(uid_t uid, const std::string &pkgName, + std::vector<std::string> expectedApps) +{ + std::vector<std::string> apps; + BOOST_REQUIRE_NO_THROW(getPrivDb()->GetUserAppsFromPkg(uid, pkgName, apps)); + std::sort(apps.begin(), apps.end()); + std::sort(expectedApps.begin(), expectedApps.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(apps.begin(), apps.end(), + expectedApps.begin(), expectedApps.end()); +} + void PrivilegeDBGettersFixture::checkGetUserPkgs(const uid_t uid, std::vector<std::string> expectedPkgs) { @@ -214,6 +243,19 @@ POSITIVE_TEST_CASE(T335_get_app_version) << app(4) << " to be: " << tizenVer(3) << " got: " << version4); } +POSITIVE_TEST_CASE(T336_get_app_pkg_info) +{ + addAppSuccess(app(1), pkg(1), uid(1), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(2), pkg(2), uid(1), tizenVer(1), author(2), Hybrid); + addAppSuccess(app(3), pkg(3), uid(1), tizenVer(1), author(3), NotHybrid); + + BOOST_REQUIRE_NO_THROW(getPrivDb()->SetSharedROPackage(pkg(3), true)); + + checkGetAppPkgInfo(app(1), pkg(1), false, false); + checkGetAppPkgInfo(app(2), pkg(2), true, false); + checkGetAppPkgInfo(app(3), pkg(3), false, true); +} + POSITIVE_TEST_CASE(T340_get_app_package_finds_nothing) { std::string package; @@ -260,6 +302,19 @@ POSITIVE_TEST_CASE(T350_get_user_apps) checkGetUserApps(uid(4), {app(2), app(3), app(5)}); } +POSITIVE_TEST_CASE(T351_get_user_apps_from_pkg) +{ + addAppSuccess(app(1), pkg(1), uid(1), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(2), pkg(1), uid(1), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(3), pkg(2), uid(2), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(4), pkg(2), uid(2), tizenVer(1), author(1), NotHybrid); + + checkGetUserAppsFromPkg(uid(1), pkg(1), {app(1), app(2)}); + checkGetUserAppsFromPkg(uid(1), pkg(2), {}); + checkGetUserAppsFromPkg(uid(2), pkg(1), {}); + checkGetUserAppsFromPkg(uid(2), pkg(2), {app(3), app(4)}); +} + POSITIVE_TEST_CASE(T355_get_user_packages) { addAppSuccess(app(1), pkg(1), uid(2), tizenVer(1), author(1), NotHybrid); @@ -396,4 +451,17 @@ POSITIVE_TEST_CASE(T380_is_package_Hybrid) checkIsPackageHybrid(pkg(3), Hybrid); } +POSITIVE_TEST_CASE(T390_is_user_pkg_installed) +{ + addAppSuccess(app(1), pkg(1), uid(1), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(2), pkg(1), uid(1), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(3), pkg(2), uid(2), tizenVer(1), author(1), NotHybrid); + addAppSuccess(app(4), pkg(2), uid(2), tizenVer(1), author(1), NotHybrid); + + BOOST_CHECK(getPrivDb()->IsUserPkgInstalled(pkg(1), uid(1))); + BOOST_CHECK(!getPrivDb()->IsUserPkgInstalled(pkg(2), uid(1))); + BOOST_CHECK(!getPrivDb()->IsUserPkgInstalled(pkg(1), uid(2))); + BOOST_CHECK(getPrivDb()->IsUserPkgInstalled(pkg(2), uid(2))); +} + BOOST_AUTO_TEST_SUITE_END() |