TestUser::createTemporary("sm_test_26_1a_user_name", GUM_USERTYPE_NORMAL);
AppInstallHelperExt app("sm_test_26_1a", "sm_test_26_1a", testUser.getUid());
ScopedInstaller appInstall(app);
+ SynchronizationPipe pipe;
+ uid_t owner_uid = 0;
+ pid_t pid;
- ScopedAppLauncher(app, testUser, [&] {
- uid_t owner_uid = 0;
+ ScopedAppLauncher launched_app(app, testUser, [&] {
+ pipe.claimChildEp();
+ pid = getpid();
+ pipe.post(&pid, sizeof(pid)); // let the parent know that the app is started
RUNNER_ASSERT_MSG(
- security_manager_get_app_owner_uid(getpid(), &owner_uid) == SECURITY_MANAGER_SUCCESS,
+ security_manager_get_app_owner_uid(pid, &owner_uid) == SECURITY_MANAGER_SUCCESS,
"Invalid return from security_manager_get_app_owner_uid()");
RUNNER_ASSERT_MSG(owner_uid == testUser.getUid(), "Invalid uid returned - expected: "
<< testUser.getUid() << " returned: " << owner_uid);
+ pipe.wait(); // wait until parent checks our owner
});
+
+ pipe.claimParentEp();
+ pipe.wait(&pid, sizeof(pid)); // wait for the child app to start
+ RUNNER_ASSERT_MSG(
+ security_manager_get_app_owner_uid(pid, &owner_uid) == SECURITY_MANAGER_SUCCESS,
+ "Invalid return from security_manager_get_app_owner_uid()");
+
+ RUNNER_ASSERT_MSG(owner_uid == testUser.getUid(), "Invalid uid returned - expected: "
+ << testUser.getUid() << " returned: " << owner_uid);
+ pipe.post(); // let the child die
}
RUNNER_CHILD_TEST(security_manager_26_1b_security_manager_get_app_owner_uid)
app.checkAfterUninstall();
}
-RUNNER_CHILD_TEST(security_manager_26_4a_security_manager_get_app_full_credentials_from_pid)
+namespace {
+void getAppFullCredentialsTest(bool hybrid)
{
- TestUser testUser = TestUser::createTemporary("sm_test_26_4a_user_name", GUM_USERTYPE_NORMAL);
-
- AppInstallHelperExt app("sm_test_26_4a", "sm_test_26_4a", testUser.getUid());
+ SynchronizationPipe pipe;
+ auto testUser = TestUser::createTemporary("sm_app_full_creds_test_user_name",
+ GUM_USERTYPE_NORMAL);
+ AppInstallHelperExt app("sm_app_full_creds_test", "sm_app_full_creds_test", testUser.getUid());
+ if (hybrid)
+ app.setHybrid();
ScopedInstaller appInstall(app);
- ScopedAppLauncher(app, testUser, [&]{
+
+ auto credentialsCheck = [&](pid_t pid){
uid_t owner_uid = 0;
char* pkgId = nullptr;
char* appId = nullptr;
+ int ret = security_manager_get_app_full_credentials_from_pid(
+ pid,
+ &owner_uid,
+ &pkgId,
+ &appId);
RUNNER_ASSERT_MSG(
- security_manager_get_app_full_credentials_from_pid(getpid(), &owner_uid, &pkgId, &appId) == SECURITY_MANAGER_SUCCESS,
- "Invalid return from ecurity_manager_get_app_full_credentials_from_pid()");
-
- CStringPtr pkgPtr(pkgId);
- CStringPtr appPtr(appId);
+ ret == SECURITY_MANAGER_SUCCESS,
+ "Invalid return from security_manager_get_app_full_credentials_from_pid()");
RUNNER_ASSERT_MSG(owner_uid == testUser.getUid(), "Invalid uid returned - expected: "
<< testUser.getUid() << " returned: " << owner_uid);
+ CStringPtr pkgPtr(pkgId);
+ CStringPtr appPtr(appId);
+
RUNNER_ASSERT_MSG(
- pkgId != nullptr && app.getPkgId() == pkgId,
+ pkgId != nullptr && pkgId == app.getPkgId(),
"Invalid pkgId returned from security_manager_get_app_full_credentials_from_pid"
);
- // non-hybrid app
+
RUNNER_ASSERT_MSG(
- appId == nullptr,
+ hybrid ? appId != nullptr && appId == app.getAppId() : appId == nullptr,
"Invalid appId returned from security_manager_get_app_full_credentials_from_pid"
);
+ };
+
+ pid_t pid;
+ ScopedAppLauncher launched_app(app, testUser, [&]{
+ pipe.claimChildEp();
+ // child - the actual application
+ pid = getpid();
+ pipe.post(&pid, sizeof(pid)); // let the parent know that the app is started
+ credentialsCheck(pid);
+ pipe.wait(); // wait until parent checks our creds
});
+
+ pipe.claimParentEp();
+ pipe.wait(&pid, sizeof(pid)); // wait for the child app to start
+ credentialsCheck(pid);
+ pipe.post(); // let the child die
}
+} // namespace
-RUNNER_CHILD_TEST(security_manager_26_4b_security_manager_get_app_full_credentials_from_pid)
+RUNNER_CHILD_TEST(security_manager_26_4a_security_manager_get_app_full_credentials_from_pid)
{
- TestUser testUser = TestUser::createTemporary("sm_test_26_4b_user_name", GUM_USERTYPE_NORMAL);
-
- AppInstallHelperExt app("sm_test_26_4b", "sm_test_26_4b", testUser.getUid());
- app.setHybrid();
- ScopedInstaller appInstall(app);
- ScopedAppLauncher(app, testUser, [&]{
- uid_t owner_uid = 0;
- char* pkgId = nullptr;
- char* appId = nullptr;
- RUNNER_ASSERT_MSG(
- security_manager_get_app_full_credentials_from_pid(getpid(), &owner_uid, &pkgId, &appId) == SECURITY_MANAGER_SUCCESS,
- "Invalid return from ecurity_manager_get_app_full_credentials_from_pid()");
-
- CStringPtr pkgPtr(pkgId);
- CStringPtr appPtr(appId);
-
- RUNNER_ASSERT_MSG(owner_uid == testUser.getUid(), "Invalid uid returned - expected: "
- << testUser.getUid() << " returned: " << owner_uid);
+ getAppFullCredentialsTest(false);
+}
- RUNNER_ASSERT_MSG(
- pkgId != nullptr && app.getPkgId() == pkgId,
- "Invalid pkgId returned from security_manager_get_app_full_credentials_from_pid"
- );
- // hybrid app
- RUNNER_ASSERT_MSG(
- appId != nullptr && app.getAppId() == appId,
- "Invalid appId returned from security_manager_get_app_full_credentials_from_pid"
- );
- });
+RUNNER_CHILD_TEST(security_manager_26_4b_security_manager_get_app_full_credentials_from_pid)
+{
+ getAppFullCredentialsTest(true);
}