583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek/*
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek Copyright (C) 2015 Red Hat
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek SSSD tests: Simple access provider tests
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek This program is free software; you can redistribute it and/or modify
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek it under the terms of the GNU General Public License as published by
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek (at your option) any later version.
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek This program is distributed in the hope that it will be useful,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek GNU General Public License for more details.
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek You should have received a copy of the GNU General Public License
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek*/
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include <talloc.h>
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include <tevent.h>
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include <errno.h>
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include <popt.h>
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek#include <security/pam_appl.h>
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include "tests/cmocka/common_mock.h"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include "tests/cmocka/common_mock_be.h"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include "tests/cmocka/common_mock_resp.h"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include "db/sysdb_private.h" /* new_subdomain() */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#include "providers/simple/simple_access.h"
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek#include "providers/simple/simple_access_pvt.h"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#define TESTS_PATH "tp_" BASE_FILE_STEM
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#define TEST_CONF_DB "test_simple_conf.ldb"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#define TEST_DOM_NAME "simple_test"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#define TEST_SUBDOM_NAME "test.subdomain"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek#define TEST_ID_PROVIDER "ldap"
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstruct simple_test_ctx {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_ctx *tctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct be_ctx *be_ctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_domain_info *subdom;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek bool access_granted;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_ctx *ctx;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct pam_data *pd;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct dp_req_params *params;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek};
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int test_simple_setup(struct sss_test_conf_param params[], void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx = talloc_zero(NULL, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (simple_test_ctx == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ENOMEM;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx = create_dom_test_ctx(simple_test_ctx, TESTS_PATH,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek TEST_CONF_DB, TEST_DOM_NAME,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek TEST_ID_PROVIDER, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_non_null(simple_test_ctx->tctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (simple_test_ctx->tctx == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ENOMEM;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sss_names_init(simple_test_ctx, simple_test_ctx->tctx->confdb,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek TEST_DOM_NAME, &simple_test_ctx->tctx->dom->names);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ENOMEM;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->be_ctx = mock_be_ctx(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (simple_test_ctx->be_ctx == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ENOMEM;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd = talloc_zero(simple_test_ctx, struct pam_data);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek if (simple_test_ctx->pd == NULL) {
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek return ENOMEM;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek }
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd->cmd = SSS_PAM_ACCT_MGMT;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->params = talloc_zero(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct dp_req_params);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek if (simple_test_ctx->params == NULL) {
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek return ENOMEM;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek }
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->params->ev = simple_test_ctx->tctx->ev;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek *state = simple_test_ctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 0;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int set_simple_lists(struct simple_test_ctx *test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_domain_info *dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[])
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek const char *val[2] = { NULL, NULL };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *cdb_path;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cdb_path = talloc_asprintf(test_ctx, CONFDB_DOMAIN_PATH_TMPL, dom->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (cdb_path == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ENOMEM;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = EOK;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (params != NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek for (int i = 0; params[i].key != NULL; i++) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek val[0] = params[i].value;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = confdb_add_param(test_ctx->tctx->confdb,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek true, cdb_path, params[i].key, val);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE, "Unable to add parameter %s [%d]: "
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek "%s\n", params[i].key, ret, sss_strerror(ret));
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek break;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_free(cdb_path);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int setup_with_params(struct simple_test_ctx *test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_domain_info *dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[])
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = set_simple_lists(test_ctx, dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek test_ctx->ctx = talloc_zero(test_ctx, struct simple_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (test_ctx->ctx == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return ENOMEM;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->ctx->be_ctx = test_ctx->be_ctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->ctx->domain = test_ctx->tctx->dom;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return EOK;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int simple_test_setup(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_dom_suite_setup(TESTS_PATH);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return test_simple_setup(NULL, state);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int simple_test_teardown(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek /* make sure there are no leftovers from previous tests */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_free(simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 0;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozekstatic void simple_access_handler_done(struct tevent_req *req)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx =
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek tevent_req_callback_data(req, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->error = simple_access_handler_recv(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek req, &simple_test_ctx->pd);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->access_granted = (simple_test_ctx->pd->pam_status == PAM_SUCCESS);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_free(req);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->done = true;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void run_simple_access_check(struct simple_test_ctx *simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek const char *username,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int expected_rv,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek bool allow_access)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct tevent_req *req;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->done = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd->user = discard_const(username);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek req = simple_access_handler_send(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_non_null(req);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek tevent_req_set_callback(req, simple_access_handler_done, simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = test_ev_loop(simple_test_ctx->tctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, expected_rv);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek /* otherwise the output is undefined */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (expected_rv == EOK) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_true(simple_test_ctx->access_granted == allow_access);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_both_empty(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, NULL);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_allow_empty(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_deny_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u3@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_deny_empty(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u3@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_both_set(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_deny_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u3@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_deny_wrong_case(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "U1@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_allow_case_insensitive(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom->case_sensitive = false;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "U1@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_unknown_user(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_users", "u1, u2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "foo@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_space(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_users", "space user, another user@simple_test" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "space user@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "another user@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "not allowed@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int simple_group_test_setup(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *u1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *u2;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *u3;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *g1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *g2;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *sp;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *sp2;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *pvt;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *test_ctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = simple_test_setup((void **) &test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u1 = sss_create_internal_fqname(test_ctx, "u1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u2 = sss_create_internal_fqname(test_ctx, "u2",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u3 = sss_create_internal_fqname(test_ctx, "u3",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek g1 = sss_create_internal_fqname(test_ctx, "g1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek g2 = sss_create_internal_fqname(test_ctx, "g2",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek sp = sss_create_internal_fqname(test_ctx, "space group",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek sp2 = sss_create_internal_fqname(test_ctx, "another space",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek pvt = sss_create_internal_fqname(test_ctx, "pvt",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (u1 == NULL || u2 == NULL || u3 == NULL
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek || g1 == NULL || g2 == NULL || pvt == NULL
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek || sp == NULL || sp2 == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group(test_ctx->be_ctx->domain, pvt, 999, NULL, 0, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_store_user(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u1, NULL, 123, 999, "u1", "/home/u1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek "/bin/bash", NULL, NULL, NULL, -1, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_store_user(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u2, NULL, 456, 999, "u1", "/home/u1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek "/bin/bash", NULL, NULL, NULL, -1, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_store_user(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u3, NULL, 789, 999, "u1", "/home/u1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek "/bin/bash", NULL, NULL, NULL, -1, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group(test_ctx->be_ctx->domain, g1, 321, NULL, 0, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group(test_ctx->be_ctx->domain, g2, 654, NULL, 0, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group(test_ctx->be_ctx->domain, sp, 1234, NULL, 0, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group(test_ctx->be_ctx->domain, sp2, 5678, NULL, 0, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group_member(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek g1, u1, SYSDB_MEMBER_USER, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group_member(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek sp, u1, SYSDB_MEMBER_USER, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group_member(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek g2, u2, SYSDB_MEMBER_USER, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_add_group_member(test_ctx->be_ctx->domain,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek sp2, u2, SYSDB_MEMBER_USER, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek *state = test_ctx;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 0;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic int simple_group_test_teardown(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *u1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *u2;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *u3;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *g1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *g2;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *sp;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *sp2;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek char *pvt;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u1 = sss_create_internal_fqname(test_ctx, "u1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u2 = sss_create_internal_fqname(test_ctx, "u2",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek u3 = sss_create_internal_fqname(test_ctx, "u3",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek g1 = sss_create_internal_fqname(test_ctx, "g1",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek g2 = sss_create_internal_fqname(test_ctx, "g2",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek sp = sss_create_internal_fqname(test_ctx, "space group",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek sp2 = sss_create_internal_fqname(test_ctx, "another space",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek pvt = sss_create_internal_fqname(test_ctx, "pvt",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_ctx->be_ctx->domain->name);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (u1 == NULL || u2 == NULL || u3 == NULL
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek || g1 == NULL || g2 == NULL || pvt == NULL
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek || sp == NULL || sp2 == NULL) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_user(test_ctx->be_ctx->domain, u1, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_user(test_ctx->be_ctx->domain, u2, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_user(test_ctx->be_ctx->domain, u3, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_group(test_ctx->be_ctx->domain, g1, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_group(test_ctx->be_ctx->domain, g2, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_group(test_ctx->be_ctx->domain, sp, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_group(test_ctx->be_ctx->domain, sp2, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = sysdb_delete_group(test_ctx->be_ctx->domain, pvt, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (ret != EOK) return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek /* make sure there are no leftovers from previous tests */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_free(test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 0;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_group_allow_empty(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct tevent_req *req;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_deny_groups", "g1, g2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek ret = setup_with_params(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd->user = discard_const("u1@simple_test");
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek req = simple_access_handler_send(simple_test_ctx, simple_test_ctx->ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_non_null(req);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek tevent_req_set_callback(req, simple_access_handler_done, simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = test_ev_loop(simple_test_ctx->tctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_false(simple_test_ctx->access_granted);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->done = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd->user = discard_const("u3@simple_test");
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek req = simple_access_handler_send(simple_test_ctx, simple_test_ctx->ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->pd,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_non_null(req);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek tevent_req_set_callback(req, simple_access_handler_done, simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = test_ev_loop(simple_test_ctx->tctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_true(simple_test_ctx->access_granted);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_group_deny_empty(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_groups", "g1, g2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u3@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_group_both_set(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_groups", "g1, g2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_deny_groups", "g1, g2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u3@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_group_deny_wrong_case(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_groups", "G1, G2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_group_allow_case_insensitive(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_groups", "G1, G2" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek /* Case-sensitive domain, wrong case */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->done = false;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_ctx->tctx->dom->case_sensitive = false;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozekstatic void test_unparseable_allow_user(void **state)
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek{
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek errno_t ret;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct sss_test_conf_param params[] = {
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { "simple_allow_users", "u1, user@no.such.domain" },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { NULL, NULL },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek };
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek ret = setup_with_params(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek params);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek assert_int_equal(ret, EOK);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* Case-sensitive domain, wrong case */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->done = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom->case_sensitive = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A user that would normally be denied access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u2@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A user that would normally be allowed access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek}
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozekstatic void test_unparseable_deny_user(void **state)
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek{
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek errno_t ret;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct sss_test_conf_param params[] = {
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { "simple_deny_users", "u2, user@no.such.domain" },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { NULL, NULL },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek };
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek ret = setup_with_params(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek params);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek assert_int_equal(ret, EOK);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* Case-sensitive domain, wrong case */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->done = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom->case_sensitive = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A user that would normally be denied access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u2@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A user that would normally be allowed access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek}
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozekstatic void test_unparseable_allow_group(void **state)
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek{
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek errno_t ret;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct sss_test_conf_param params[] = {
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { "simple_allow_groups", "g1, group@no.such.domain" },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { NULL, NULL },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek };
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek ret = setup_with_params(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek params);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek assert_int_equal(ret, EOK);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* Case-sensitive domain, wrong case */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->done = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom->case_sensitive = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A group that would normally be denied access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u2@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A group that would normally be allowed access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek}
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozekstatic void test_unparseable_deny_group(void **state)
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek{
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek errno_t ret;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek struct sss_test_conf_param params[] = {
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { "simple_deny_groups", "g2, group@no.such.domain" },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek { NULL, NULL },
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek };
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek ret = setup_with_params(simple_test_ctx,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek params);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek assert_int_equal(ret, EOK);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* Case-sensitive domain, wrong case */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->done = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_ctx->tctx->dom->case_sensitive = false;
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A group that would normally be denied access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u2@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek /* A group that would normally be allowed access will be denied because
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek * the access list can't be parsed
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek */
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, false);
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek}
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekstatic void test_group_space(void **state)
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek errno_t ret;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct simple_test_ctx *simple_test_ctx = \
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek talloc_get_type(*state, struct simple_test_ctx);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct sss_test_conf_param params[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { "simple_allow_groups", "space group, another space@simple_test" },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek { NULL, NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek ret = setup_with_params(simple_test_ctx, simple_test_ctx->tctx->dom, params);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek assert_int_equal(ret, EOK);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u1@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u2@simple_test", EOK, true);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek run_simple_access_check(simple_test_ctx, "u3@simple_test", EOK, false);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozekint main(int argc, const char *argv[])
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek{
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int rv;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int no_cleanup = 0;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek poptContext pc;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek int opt;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek struct poptOption long_options[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek POPT_AUTOHELP
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek SSSD_DEBUG_OPTS
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek _("Do not delete the test database after a test run"), NULL },
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek POPT_TABLEEND
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek const struct CMUnitTest tests[] = {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_both_empty,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_allow_empty,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_deny_empty,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_both_set,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_deny_wrong_case,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_allow_case_insensitive,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_unknown_user,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_space,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_group_allow_empty,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_group_deny_empty,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_group_both_set,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_group_deny_wrong_case,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_group_allow_case_insensitive,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek cmocka_unit_test_setup_teardown(test_group_space,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_setup,
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek simple_group_test_teardown),
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek cmocka_unit_test_setup_teardown(test_unparseable_allow_user,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_setup,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_teardown),
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek cmocka_unit_test_setup_teardown(test_unparseable_deny_user,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_setup,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_teardown),
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek cmocka_unit_test_setup_teardown(test_unparseable_allow_group,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_setup,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_teardown),
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek cmocka_unit_test_setup_teardown(test_unparseable_deny_group,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_setup,
95de2cd9ea8083115f3bbbf0867aaf6b218cb624Jakub Hrozek simple_test_teardown),
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek };
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek /* Set debug level to invalid value so we can decide if -d 0 was used. */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek debug_level = SSSDBG_INVALID;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek switch(opt) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek default:
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek poptPrintUsage(pc, stderr, 0);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return 1;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek poptFreeContext(pc);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek DEBUG_CLI_INIT(debug_level);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek /* Even though normally the tests should clean up after themselves
57c5ea8825c7179fd93382dbcbb07e828e5aec19René Genz * they might not after a failed run. Remove the old DB to be sure */
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek tests_set_cwd();
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_dom_suite_setup(TESTS_PATH);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek rv = cmocka_run_group_tests(tests, NULL, NULL);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek if (rv == 0 && !no_cleanup) {
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek }
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek return rv;
583c1b9a052f4eb5ba046c5f2b7d2ed2a81b6d66Jakub Hrozek}