ipa_hbac-tests.c revision 05d7defd242466f376af8eb0d06ea49fb8320224
/*
SSSD
Authors:
Stephen Gallagher <sgallagh@redhat.com>
Copyright (C) 2011 Red Hat
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <check.h>
#include <unistd.h>
#include <talloc.h>
#include "tests/common_check.h"
#include "providers/ipa/ipa_hbac.h"
#define HBAC_TEST_USER "testuser"
#define HBAC_TEST_INVALID_USER "nosuchuser"
#define HBAC_TEST_GROUP1 "testgroup1"
#define HBAC_TEST_GROUP2 "testgroup2"
#define HBAC_TEST_INVALID_GROUP "nosuchgroup"
#define HBAC_TEST_SERVICE "testservice"
#define HBAC_TEST_INVALID_SERVICE "nosuchservice"
#define HBAC_TEST_SERVICEGROUP1 "login_services"
#define HBAC_TEST_SERVICEGROUP2 "all_services"
#define HBAC_TEST_INVALID_SERVICEGROUP "nosuchservicegroup"
#define HBAC_TEST_SRCHOST "client.example.com"
#define HBAC_TEST_INVALID_SRCHOST "nosuchsrchost"
#define HBAC_TEST_SRCHOSTGROUP1 "site_hosts"
#define HBAC_TEST_SRCHOSTGROUP2 "corp_hosts"
#define HBAC_TEST_INVALID_SRCHOSTGROUP "nosuchsrchostgroup"
* every one is from a different codepage */
/* Latin Extended A - "Czech" */
/* Latin 1 Supplement - "Munchen" */
/* Greek - "AlphaBetaGamma" */
/* Turkish "capital I" and "dotless i" */
struct hbac_rule **allow_rule)
{
/* Create a rule that ALLOWs all services, users and
* remote hosts.
*/
*allow_rule = rule;
}
struct hbac_request_element **user)
{
struct hbac_request_element *new_user;
}
struct hbac_request_element **service)
{
struct hbac_request_element *new_service;
*service = new_service;
}
struct hbac_request_element **srchost)
{
struct hbac_request_element *new_srchost;
*srchost = new_srchost;
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a specific user */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Override the with UTF8 values */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a specific user */
/* Modify the rule to allow only a specific service */
/* Modify the rule to allow only a specific service */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test - a different letter */
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test - Turkish dotless i. We cannot know that capital I
* casefolds into dotless i unless we know the language is Turkish */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a group of users */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a specific service */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a group of users */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a specific service */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s](%s)",
}
{
enum hbac_eval_result result;
struct hbac_eval_req *eval_req;
bool is_valid;
/* Create a request */
/* Create the rules to evaluate against */
/* Modify the rule to allow only a group of users */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
/* Negative test */
/* Validate this rule */
fail_unless(missing_attrs == 0);
/* Evaluate the rules */
"Expected [%s], got [%s]; "
"Error: [%s]",
}
{
bool is_valid;
/* Validate this rule */
}
Suite *hbac_test_suite (void)
{
suite_add_tcase(s, tc_hbac);
return s;
}
{
int number_failed;
Suite *s = hbac_test_suite();
/* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
srunner_free (sr);
}