pacemaker 2.1.4-dc6eb4362e
Scalable High-Availability cluster resource manager
xml_acl_enabled_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2021 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11#include <crm/common/acl.h>
12#include "../../crmcommon_private.h"
13
14#include <stdarg.h>
15#include <stddef.h>
16#include <stdint.h>
17#include <setjmp.h>
18#include <cmocka.h>
19
20static void
21is_xml_acl_enabled_without_node(void **state)
22{
23 xmlNode *test_xml = create_xml_node(NULL, "test_xml");
24 assert_false(xml_acl_enabled(test_xml));
25
26 test_xml->doc->_private = NULL;
27 assert_false(xml_acl_enabled(test_xml));
28
29 test_xml->doc = NULL;
30 assert_false(xml_acl_enabled(test_xml));
31
32 test_xml = NULL;
33 assert_false(xml_acl_enabled(test_xml));
34}
35
36static void
37is_xml_acl_enabled_with_node(void **state)
38{
40
41 xmlNode *test_xml = create_xml_node(NULL, "test_xml");
42
43 // allocate memory for _private, which is NULL by default
44 test_xml->doc->_private = calloc(1, sizeof(xml_private_t));
45
46 assert_false(xml_acl_enabled(test_xml));
47
48 // cast _private from void* to xml_private_t*
49 p = test_xml->doc->_private;
50
51 // enable an irrelevant flag
53
54 assert_false(xml_acl_enabled(test_xml));
55
56 // enable pcmk__xf_acl_enabled
58
59 assert_true(xml_acl_enabled(test_xml));
60}
61
62int
63main(int argc, char **argv)
64{
65 const struct CMUnitTest tests[] = {
66 cmocka_unit_test(is_xml_acl_enabled_without_node),
67 cmocka_unit_test(is_xml_acl_enabled_with_node),
68 };
69
70 cmocka_set_message_output(CM_OUTPUT_TAP);
71 return cmocka_run_group_tests(tests, NULL, NULL);
72}
Low-level API for XML Access Control Lists (ACLs)
bool xml_acl_enabled(xmlNode *xml)
Definition: acl.c:600
xmlNode * create_xml_node(xmlNode *parent, const char *name)
Definition: xml.c:696
int main(int argc, char **argv)
@ pcmk__xf_acl_enabled
Definition: xml_internal.h:327
@ pcmk__xf_acl_denied
Definition: xml_internal.h:333