pacemaker 3.0.1-16e74fc4da
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
xml_acl_enabled_test.c
Go to the documentation of this file.
1/*
2 * Copyright 2020-2024 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 General Public License version 2
7 * or later (GPLv2+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
13#include <crm/common/acl.h>
14
16
17static void
18is_xml_acl_enabled_without_node(void **state)
19{
20 xmlNode *test_xml = pcmk__xe_create(NULL, "test_xml");
21 assert_false(xml_acl_enabled(test_xml));
22
23 test_xml->doc->_private = NULL;
24 assert_false(xml_acl_enabled(test_xml));
25
26 test_xml->doc = NULL;
27 assert_false(xml_acl_enabled(test_xml));
28
29 test_xml = NULL;
30 assert_false(xml_acl_enabled(test_xml));
31}
32
33static void
34is_xml_acl_enabled_with_node(void **state)
35{
36 xml_doc_private_t *docpriv;
37
38 xmlNode *test_xml = pcmk__xe_create(NULL, "test_xml");
39
40 // allocate memory for _private, which is NULL by default
41 test_xml->doc->_private = pcmk__assert_alloc(1, sizeof(xml_doc_private_t));
42
43 assert_false(xml_acl_enabled(test_xml));
44
45 // cast _private from void* to xml_doc_private_t*
46 docpriv = test_xml->doc->_private;
47
48 // enable an irrelevant flag
49 docpriv->flags |= pcmk__xf_acl_denied;
50
51 assert_false(xml_acl_enabled(test_xml));
52
53 // enable pcmk__xf_acl_enabled
54 docpriv->flags |= pcmk__xf_acl_enabled;
55
56 assert_true(xml_acl_enabled(test_xml));
57}
58
60 cmocka_unit_test(is_xml_acl_enabled_without_node),
61 cmocka_unit_test(is_xml_acl_enabled_with_node))
Low-level API for XML Access Control Lists (ACLs)
bool xml_acl_enabled(const xmlNode *xml)
Check whether or not an XML node is ACL-enabled.
Definition acl.c:702
#define pcmk__assert_alloc(nmemb, size)
Definition internal.h:246
uint32_t flags
Group of enum pcmk__xml_flags
int pcmk__xml_test_teardown_group(void **state)
Definition unittest.c:105
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
int pcmk__xml_test_setup_group(void **state)
Definition unittest.c:87
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
@ pcmk__xf_acl_enabled
ACLs are enabled (set for document only)
@ pcmk__xf_acl_denied
ACLs deny the user access (set for document only)