Esempio n. 1
0
void ifp_test_req_create(void **state)
{
    struct ifp_req *ireq;
    struct sbus_request *sr;
    struct ifp_ctx *ifp_ctx;
    errno_t ret;

    assert_true(leak_check_setup());

    ifp_ctx = mock_ifp_ctx(global_talloc_context);
    assert_non_null(ifp_ctx);
    check_leaks_push(ifp_ctx);

    sr = mock_sbus_request(ifp_ctx, geteuid());
    assert_non_null(sr);
    check_leaks_push(sr);

    ret = ifp_req_create(sr, ifp_ctx, &ireq);
    assert_int_equal(ret, EOK);
    talloc_free(ireq);

    assert_true(check_leaks_pop(sr) == true);
    talloc_free(sr);

    assert_true(check_leaks_pop(ifp_ctx) == true);
    talloc_free(ifp_ctx);

    assert_true(leak_check_teardown());
}
Esempio n. 2
0
/* Testsuite setup and teardown */
void dyndns_test_setup(void **state)
{
    struct sss_test_conf_param params[] = {
        { "dyndns_update", "true" },
        { "dyndns_refresh_interval", "2" },
        { NULL, NULL },             /* Sentinel */
    };

    assert_true(leak_check_setup());
    dyndns_test_ctx = talloc_zero(global_talloc_context, struct dyndns_test_ctx);
    assert_non_null(dyndns_test_ctx);

    dyndns_test_ctx->tctx = create_dom_test_ctx(dyndns_test_ctx, TESTS_PATH,
                                                TEST_CONF_DB, TEST_SYSDB_FILE,
                                                TEST_DOM_NAME, TEST_ID_PROVIDER,
                                                params);
    assert_non_null(dyndns_test_ctx->tctx);

    dyndns_test_ctx->be_ctx = talloc_zero(dyndns_test_ctx, struct be_ctx);
    assert_non_null(dyndns_test_ctx->be_ctx);

    dyndns_test_ctx->be_ctx->cdb = dyndns_test_ctx->tctx->confdb;
    dyndns_test_ctx->be_ctx->ev  = dyndns_test_ctx->tctx->ev;
    dyndns_test_ctx->be_ctx->conf_path = talloc_asprintf(dyndns_test_ctx,
                                                         CONFDB_DOMAIN_PATH_TMPL,
                                                         TEST_DOM_NAME);
    assert_non_null(dyndns_test_ctx->be_ctx->conf_path);
}
Esempio n. 3
0
void test_path_escape_unescape(void **state)
{
    char *escaped;
    char *raw;
    TALLOC_CTX *mem_ctx;

    assert_true(leak_check_setup());
    mem_ctx = talloc_new(global_talloc_context);

    escaped = ifp_bus_path_escape(mem_ctx, "noescape");
    assert_non_null(escaped);
    assert_string_equal(escaped, "noescape");
    raw = ifp_bus_path_unescape(mem_ctx, escaped);
    talloc_free(escaped);
    assert_non_null(raw);
    assert_string_equal(raw, "noescape");
    talloc_free(raw);

    escaped = ifp_bus_path_escape(mem_ctx, "redhat.com");
    assert_non_null(escaped);
    assert_string_equal(escaped, "redhat_2ecom"); /* dot is 0x2E in ASCII */
    raw = ifp_bus_path_unescape(mem_ctx, escaped);
    talloc_free(escaped);
    assert_non_null(raw);
    assert_string_equal(raw, "redhat.com");
    talloc_free(raw);

    escaped = ifp_bus_path_escape(mem_ctx, "path_with_underscore");
    assert_non_null(escaped);
    /* underscore is 0x5F in ascii */
    assert_string_equal(escaped, "path_5fwith_5funderscore");
    raw = ifp_bus_path_unescape(mem_ctx, escaped);
    talloc_free(escaped);
    assert_non_null(raw);
    assert_string_equal(raw, "path_with_underscore");
    talloc_free(raw);

    /* empty string */
    escaped = ifp_bus_path_escape(mem_ctx, "");
    assert_non_null(escaped);
    assert_string_equal(escaped, "_");
    raw = ifp_bus_path_unescape(mem_ctx, escaped);
    talloc_free(escaped);
    assert_non_null(raw);
    assert_string_equal(raw, "");
    talloc_free(raw);

    /* negative tests */
    escaped = ifp_bus_path_escape(mem_ctx, NULL);
    assert_null(escaped);
    raw = ifp_bus_path_unescape(mem_ctx, "wrongpath_");
    assert_null(raw);

    assert_true(leak_check_teardown());
}
Esempio n. 4
0
void test_switch_user(void **state)
{
    errno_t ret;
    struct passwd *sssd;
    TALLOC_CTX *tmp_ctx;
    struct sss_creds *saved_creds;
    struct sss_creds *saved_creds2 = NULL;

    assert_true(leak_check_setup());

    tmp_ctx = talloc_new(global_talloc_context);
    assert_non_null(tmp_ctx);

    /* Must root as root, real or fake */
    assert_int_equal(geteuid(), 0);

    sssd = getpwnam("sssd");
    assert_non_null(sssd);

    check_leaks_push(tmp_ctx);

    ret = switch_creds(tmp_ctx, sssd->pw_uid, sssd->pw_gid,
                       0, NULL, &saved_creds);
    assert_int_equal(ret, EOK);
    assert_int_equal(geteuid(), sssd->pw_uid);
    assert_int_equal(getegid(), sssd->pw_gid);
    /* Only effective UID is changed.. */
    assert_int_equal(getuid(), 0);
    assert_int_equal(getgid(), 0);

    assert_non_null(saved_creds);
    assert_int_equal(saved_creds->uid, 0);
    assert_int_equal(saved_creds->gid, 0);

    /* Attempt to restore creds again */
    ret = switch_creds(tmp_ctx, sssd->pw_uid, sssd->pw_gid,
                       0, NULL, &saved_creds2);
    assert_int_equal(ret, EOK);
    assert_null(saved_creds2);

    /* restore root */
    ret = restore_creds(saved_creds);
    assert_int_equal(ret, EOK);
    assert_int_equal(geteuid(), 0);
    assert_int_equal(getegid(), 0);
    assert_int_equal(getuid(), 0);
    assert_int_equal(getgid(), 0);

    talloc_free(saved_creds);
    assert_true(check_leaks_pop(tmp_ctx));
    talloc_free(tmp_ctx);

    assert_true(leak_check_teardown());
}
Esempio n. 5
0
static int test_sss_idmap_setup(void **state)
{
    struct test_ctx *test_ctx;
    enum idmap_error_code err;

    assert_true(leak_check_setup());

    test_ctx = talloc_zero(global_talloc_context, struct test_ctx);
    assert_non_null(test_ctx);

    check_leaks_push(test_ctx);

    test_ctx->mem_idmap = talloc_new(test_ctx);
    assert_non_null(test_ctx->mem_idmap);

    err = sss_idmap_init(idmap_talloc, test_ctx->mem_idmap, idmap_free,
                         &test_ctx->idmap_ctx);
    assert_int_equal(err, IDMAP_SUCCESS);

    *state = test_ctx;
    return 0;
}
Esempio n. 6
0
static int test_ncache_setup(void **state)
{
    struct ncache_test_ctx *test_ctx;

    assert_true(leak_check_setup());

    test_ctx = talloc_zero(global_talloc_context, struct ncache_test_ctx);
    assert_non_null(test_ctx);

    test_dom_suite_setup(TESTS_PATH);

    test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH, TEST_CONF_DB,
                                         TEST_DOM_NAME, "ipa", NULL);
    assert_non_null(test_ctx->tctx);

    create_groups(test_ctx, test_ctx->tctx->dom);
    create_users(test_ctx, test_ctx->tctx->dom);

    check_leaks_push(test_ctx);

    *state = (void *)test_ctx;

    return 0;
}