root/lib/common/tests/acl/xml_acl_enabled_test.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. is_xml_acl_enabled_without_node
  2. is_xml_acl_enabled_with_node
  3. main

   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 
  20 static void
  21 is_xml_acl_enabled_without_node(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 
  36 static void
  37 is_xml_acl_enabled_with_node(void **state)
     /* [previous][next][first][last][top][bottom][index][help] */
  38 {
  39     xml_private_t *p;
  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
  52     p->flags |= pcmk__xf_acl_denied;
  53 
  54     assert_false(xml_acl_enabled(test_xml));
  55 
  56     // enable pcmk__xf_acl_enabled
  57     p->flags |= pcmk__xf_acl_enabled;
  58 
  59     assert_true(xml_acl_enabled(test_xml));
  60 }
  61 
  62 int
  63 main(int argc, char **argv)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 }

/* [previous][next][first][last][top][bottom][index][help] */