예제 #1
0
static void
_DisconnectCustomTransport()
{
    static bool is_disconnected = false;

    if (!is_disconnected)
    {
        _LSTransportDisconnect(transport_priv, true);
        _LSTransportDeinit(transport_priv);
        _LSTransportDisconnect(transport_pub, true);
        _LSTransportDeinit(transport_pub);
        is_disconnected = true;
    }
}
static void
test_LSHubPermissionMapLookup(void *fixture, gconstpointer user_data)
{
    ConfigSetDefaults();

    char const *dirs[] = { TEST_STEADY_ROLES_DIRECTORY, NULL };
    LSError error;
    LSErrorInit(&error);
    g_assert(ProcessRoleDirectories(dirs, NULL, &error));
    g_assert(!LSErrorIsSet(&error));

    _LSTransportCred *cred = _LSTransportCredNew();
    g_assert(cred);
    pid_t pid = getpid();
    _LSTransportCredSetPid(cred, pid);

    struct LSTransportHandlers test_handlers = {};
    _LSTransport *transport = NULL;
    g_assert(_LSTransportInit(&transport, "com.webos.foo", &test_handlers, NULL));
    _LSTransportSetTransportType(transport, _LSTransportTypeLocal);
    g_assert(transport);

    _LSTransportClient test_client =
    {
        .service_name = "com.webos.foo",
        .cred = cred,
        .transport = transport,
    };

    _LSTransportCredSetExePath(cred, "/bin/foo");
    test_client.service_name = "com.webos.foo";
    g_assert(LSHubIsClientAllowedToRequestName(&test_client, "com.webos.foo"));
    LSHubActiveRoleMapUnref(pid);
    g_assert(!LSHubIsClientAllowedToRequestName(&test_client, "com.webos.foo2"));
    LSHubActiveRoleMapUnref(pid);

    _LSTransportCredSetExePath(cred, "/bin/bar");
    test_client.service_name = "com.webos.bar";
    g_assert(LSHubIsClientAllowedToRequestName(&test_client, "com.webos.bar"));
    LSHubActiveRoleMapUnref(pid);
    g_assert(LSHubIsClientAllowedToRequestName(&test_client, "com.webos.bar2"));
    LSHubActiveRoleMapUnref(pid);

    _LSTransportCredSetExePath(cred, "/bin/foo");
    test_client.service_name = "com.webos.foo";
    g_assert(LSHubIsClientAllowedToQueryName(&test_client, "com.webos.bar", "asdf"));
    _LSTransportCredSetExePath(cred, "/bin/bar");
    test_client.service_name = "com.webos.bar";
    g_assert(LSHubIsClientAllowedToQueryName(&test_client, "com.webos.foo", "asdf"));
    _LSTransportCredSetExePath(cred, "/bin/bar");
    test_client.service_name = "com.webos.bar2";
    g_assert(LSHubIsClientAllowedToQueryName(&test_client, "com.webos.foo", "asdf"));

    _LSTransportDeinit(transport);
    _LSTransportCredFree(cred);
    _ConfigFreeSettings();
}

int
main(int argc, char *argv[])
{
    g_test_init(&argc, &argv, NULL);

    g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
    g_log_set_fatal_mask ("LunaServiceHub", G_LOG_LEVEL_ERROR);

    g_test_add("/hub/LSHubPermissionMapLookup", void, NULL, NULL, test_LSHubPermissionMapLookup, NULL);

    return g_test_run();
}