blob: 97e361ecf9f9a58d653b3da5c4a560e1790a8775 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* Copyright 2020-2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU General Public License version 2
* or later (GPLv2+) WITHOUT ANY WARRANTY.
*/
#include <crm_internal.h>
#include <crm/common/unittest_internal.h>
#include <crm/common/acl.h>
#include "../../crmcommon_private.h"
static void
is_xml_acl_enabled_without_node(void **state)
{
xmlNode *test_xml = pcmk__xe_create(NULL, "test_xml");
assert_false(xml_acl_enabled(test_xml));
test_xml->doc->_private = NULL;
assert_false(xml_acl_enabled(test_xml));
test_xml->doc = NULL;
assert_false(xml_acl_enabled(test_xml));
test_xml = NULL;
assert_false(xml_acl_enabled(test_xml));
}
static void
is_xml_acl_enabled_with_node(void **state)
{
xml_doc_private_t *docpriv;
xmlNode *test_xml = pcmk__xe_create(NULL, "test_xml");
// allocate memory for _private, which is NULL by default
test_xml->doc->_private = pcmk__assert_alloc(1, sizeof(xml_doc_private_t));
assert_false(xml_acl_enabled(test_xml));
// cast _private from void* to xml_doc_private_t*
docpriv = test_xml->doc->_private;
// enable an irrelevant flag
docpriv->flags |= pcmk__xf_acl_denied;
assert_false(xml_acl_enabled(test_xml));
// enable pcmk__xf_acl_enabled
docpriv->flags |= pcmk__xf_acl_enabled;
assert_true(xml_acl_enabled(test_xml));
}
PCMK__UNIT_TEST(pcmk__xml_test_setup_group, NULL,
cmocka_unit_test(is_xml_acl_enabled_without_node),
cmocka_unit_test(is_xml_acl_enabled_with_node))
|