This is an automated email from the git hooks/post-receive script.
firstyear pushed a commit to branch master
in repository 389-ds-base.
commit 6df837c47df9218260fc334b94e9c0a78feaa5cf
Author: William Brown <firstyear(a)redhat.com>
Date: Wed Feb 8 13:29:59 2017 +1000
Ticket 49086 - public api compatability test for SDN changes.
Bug Description: In order to resolve the SDN premangaling issue, we need to
assert that as we change the pblock and operation code we do not violate our
api behaviours.
Fix Description: This adds a set of initial tests to assert the behaviours of
the plugin v3 api via the pblock, and partially via the internal operation
api. With this set of tests, changes to the pblock structures and pointers can
be asserted to "behave the same way", which means we will keep the public
api
working for existing plugins.
https://fedorahosted.org/389/ticket/49086
Author: wibrown
Review by: mreynolds (Thanks!)
---
Makefile.am | 8 +-
test/libslapd/operation/v3_compat.c | 53 ++++++++++
test/libslapd/pblock/v3_compat.c | 204 ++++++++++++++++++++++++++++++++++++
test/libslapd/test.c | 5 +
test/test_slapd.h | 9 ++
5 files changed, 277 insertions(+), 2 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 7c7ab0a..112b8f1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1843,10 +1843,14 @@ check_PROGRAMS = test_slapd
test_slapd_SOURCES = test/main.c \
test/libslapd/test.c \
- test/libslapd/pblock/analytics.c
+ test/libslapd/pblock/analytics.c \
+ test/libslapd/pblock/v3_compat.c \
+ test/libslapd/operation/v3_compat.c
test_slapd_LDADD = libslapd.la
test_slapd_LDFLAGS = $(AM_CPPFLAGS) $(CMOCKA_LINKS)
-test_slapd_CPPFLAGS = $(AM_CPPFLAGS) @nspr_inc@
+### WARNING: Slap.h needs cert.h, which requires the -I/lib/ldaputil!!!
+### WARNING: Slap.h pulls ssl.h, which requires nss!!!!
+test_slapd_CPPFLAGS = $(AM_CPPFLAGS) @nspr_inc@ @nss_inc@ -I$(srcdir)/include/ldaputil
diff --git a/test/libslapd/operation/v3_compat.c b/test/libslapd/operation/v3_compat.c
new file mode 100644
index 0000000..c69a670
--- /dev/null
+++ b/test/libslapd/operation/v3_compat.c
@@ -0,0 +1,53 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * License: GPL (version 3 or any later version).
+ * See LICENSE for details.
+ * END COPYRIGHT BLOCK **/
+
+#include "../../test_slapd.h"
+
+/* This is somewhat internal to the server! Thus the slap.h */
+/* WARNING: Slap.h needs cert.h, which requires the -I/lib/ldaputil!!! */
+/* It also pulls in nspr! Bad! */
+
+#include <slap.h>
+
+/*
+ * Assert that the compatability requirements of the plugin V3 pblock API
+ * are upheld.
+ *
+ * This is for checking the operation type maintains a correct interface.
+ */
+
+void
+test_libslapd_operation_v3c_target_spec(void **state __attribute__((unused))) {
+ /* Will we need to test PB / op interactions? */
+ /* Test the operation of the target spec is maintained. */
+ Slapi_Operation *op = slapi_operation_new(SLAPI_OP_FLAG_INTERNAL);
+ Slapi_DN *test_a_sdn = slapi_sdn_new_dn_byval("cn=a,cn=test");
+ Slapi_DN *a_sdn = NULL;
+ Slapi_DN *b_sdn = NULL;
+
+ /* Create an SDN */
+ /* Set it. */
+ operation_set_target_spec(op, test_a_sdn);
+ /* Assert the pointers are different because target_spec DUPS */
+ a_sdn = operation_get_target_spec(op);
+ assert_ptr_not_equal(a_sdn, test_a_sdn);
+ assert_int_equal(slapi_sdn_compare(a_sdn, test_a_sdn), 0);
+
+ /* Set a new SDN */
+ operation_set_target_spec_str(op, "cn=b,cn=test");
+ /* Assert the old SDN is there, as we don't free on set */
+ b_sdn = operation_get_target_spec(op);
+ assert_ptr_not_equal(b_sdn, a_sdn);
+ assert_ptr_not_equal(b_sdn, test_a_sdn);
+ assert_int_not_equal(slapi_sdn_compare(a_sdn, b_sdn), 0);
+
+ /* free everything */
+ slapi_sdn_free(&test_a_sdn);
+ slapi_sdn_free(&a_sdn);
+ slapi_sdn_free(&b_sdn);
+}
diff --git a/test/libslapd/pblock/v3_compat.c b/test/libslapd/pblock/v3_compat.c
new file mode 100644
index 0000000..66c167c
--- /dev/null
+++ b/test/libslapd/pblock/v3_compat.c
@@ -0,0 +1,204 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright (C) 2017 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * License: GPL (version 3 or any later version).
+ * See LICENSE for details.
+ * END COPYRIGHT BLOCK **/
+
+#include "../../test_slapd.h"
+#include <string.h>
+
+/*
+ * Assert that the compatability requirements of the plugin V3 pblock API
+ * are upheld.
+ *
+ * This will be critical in the migration to V4 so that refactors can guarantee
+ * we are not altering code behaviours.
+ */
+
+
+void
+test_libslapd_pblock_v3c_target_dn(void **state __attribute__((unused))) {
+ /* Create a pblock */
+ Slapi_PBlock *pb = slapi_pblock_new();
+ Slapi_Operation *op = slapi_operation_new(SLAPI_OP_FLAG_INTERNAL);
+ slapi_pblock_init(pb);
+
+ char *dn = NULL;
+ char *test_dn = "cn=Directory Manager";
+ Slapi_DN *sdn = NULL;
+
+ /* SLAPI_TARGET_DN */
+ /* Check that with no operation we get -1 */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn), -1);
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_TARGET_DN, &dn), -1);
+
+ /* Add the operation */
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_OPERATION, op), 0);
+
+ /* Check that with a null target_address we get NULL */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn), 0);
+ assert_null(dn);
+
+ /* Set a DN */
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_TARGET_DN, test_dn), 0);
+ /* Check it was set */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_DN, &dn), 0);
+ assert_int_equal(strcmp(dn, test_dn), 0);
+ /* Check that TARGET_SDN is not null now */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn), 0);
+ assert_non_null(sdn);
+
+ /* Assert we did not influence ORIGINAL_TARGET_DN or UNIQUEID */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET_DN, &dn), 0);
+ assert_null(dn);
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_UNIQUEID, &dn), 0);
+ assert_null(dn);
+
+ /* A property we cannot easily test is that setting a new DN frees the
+ * OLD sdn. But, we can test in SDN that setting via SDN does NOT free.
+ *
+ * The only effective way to test this would be to crash sadly.
+ */
+
+ /* It works! */
+ slapi_pblock_destroy(pb);
+}
+
+
+void
+test_libslapd_pblock_v3c_target_sdn(void **state __attribute__((unused))) {
+ /* SLAPI_TARGET_SDN */
+ Slapi_PBlock *pb = slapi_pblock_new();
+ Slapi_Operation *op = slapi_operation_new(SLAPI_OP_FLAG_INTERNAL);
+ slapi_pblock_init(pb);
+
+ char *dn = NULL;
+ Slapi_DN *sdn = NULL;
+ Slapi_DN *test_a_sdn = NULL;
+ Slapi_DN *test_b_sdn = NULL;
+
+ /* Check our aliases - once we assert these are the same
+ * we can then extend to say that these behaviours hold for all these
+ * pblock aliases.
+ */
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_ADD_TARGET_SDN);
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_BIND_TARGET_SDN);
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_COMPARE_TARGET_SDN);
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_DELETE_TARGET_SDN);
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_MODIFY_TARGET_SDN);
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_MODRDN_TARGET_SDN);
+ assert_int_equal(SLAPI_TARGET_SDN, SLAPI_SEARCH_TARGET_SDN);
+
+ /* Check that with no operation we get -1 */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn), -1);
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_TARGET_SDN, sdn), -1);
+ /* Add the operation */
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_OPERATION, op), 0);
+
+ /* Check that with a null target_address we get NULL */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn), 0);
+ assert_null(sdn);
+
+ /* Create and SDN and set it. */
+ test_a_sdn = slapi_sdn_new_dn_byval("cn=a,cn=test");
+ test_b_sdn = slapi_sdn_new_dn_byval("cn=b,cn=test");
+
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_TARGET_SDN, test_a_sdn), 0);
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn), 0);
+ /* Assert we get it back, not a dup, the real pointer */
+ assert_ptr_equal(test_a_sdn, sdn);
+ assert_int_equal(slapi_sdn_compare(sdn, test_a_sdn), 0);
+
+ /* Make a new one, and assert we haven't freed the previous. */
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_TARGET_SDN, test_b_sdn), 0);
+ assert_int_equal(slapi_sdn_compare(sdn, test_a_sdn), 0);
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_SDN, &sdn), 0);
+ /* Assert we get it back, not a dup, the real pointer */
+ assert_ptr_equal(test_b_sdn, sdn);
+ assert_int_equal(slapi_sdn_compare(sdn, test_b_sdn), 0);
+ assert_int_not_equal(slapi_sdn_compare(sdn, test_a_sdn), 0);
+
+ /* Assert we did not influence ORIGINAL_TARGET_DN or UNIQUEID */
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET_DN, &dn), 0);
+ assert_null(dn);
+ assert_int_equal(slapi_pblock_get(pb, SLAPI_TARGET_UNIQUEID, &dn), 0);
+ assert_null(dn);
+
+ /* Free everything ourselves! */
+ slapi_sdn_free(&test_a_sdn);
+ slapi_sdn_free(&test_b_sdn);
+
+ /* It works! */
+ slapi_pblock_destroy(pb);
+}
+
+/* nf here means "no implicit free". For now implies no dup */
+void
+_test_libslapi_pblock_v3c_generic_nf_char(Slapi_PBlock *pb, int type, int *conflicts) {
+ /* We have to accept a valid PB, because some tests require operations etc. */
+ char *out = NULL;
+ char *test_a_in = slapi_ch_strdup("some awesome value");
+ char *test_b_in = slapi_ch_strdup("some other value");
+
+ /* Check we start nulled. */
+ assert_int_equal(slapi_pblock_get(pb, type, &out), 0);
+ assert_null(out);
+ /* Now, set a value into the pblock. */
+ assert_int_equal(slapi_pblock_set(pb, type, test_a_in), 0);
+ assert_int_equal(slapi_pblock_get(pb, type, &out), 0);
+ assert_ptr_equal(test_a_in, out);
+ assert_int_equal(strcmp(out, test_a_in), 0);
+
+ /* Test another value, and does not free a. */
+ assert_int_equal(slapi_pblock_set(pb, type, test_b_in), 0);
+ assert_int_equal(slapi_pblock_get(pb, type, &out), 0);
+ assert_ptr_equal(test_b_in, out);
+ assert_int_equal(strcmp(out, test_b_in), 0);
+ assert_int_not_equal(strcmp(out, test_a_in), 0);
+
+ /* conflicts takes a null terminated array of values that we want to assert we do not
influence */
+ for (size_t i = 0; conflicts[i] != 0; i++) {
+ assert_int_equal(slapi_pblock_get(pb, conflicts[i], &out), 0);
+ assert_null(out);
+ }
+
+ slapi_ch_free_string(&test_a_in);
+ slapi_ch_free_string(&test_b_in);
+}
+
+void
+test_libslapd_pblock_v3c_original_target_dn(void **state __attribute__((unused))) {
+ /* SLAPI_ORIGINAL_TARGET_DN */
+ Slapi_PBlock *pb = slapi_pblock_new();
+ Slapi_Operation *op = slapi_operation_new(SLAPI_OP_FLAG_INTERNAL);
+ int conflicts[] = {SLAPI_TARGET_UNIQUEID, SLAPI_TARGET_SDN, 0};
+ slapi_pblock_init(pb);
+
+ /* Add the operation */
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_OPERATION, op), 0);
+ /* Run the generic char * tests */
+ _test_libslapi_pblock_v3c_generic_nf_char(pb, SLAPI_ORIGINAL_TARGET_DN, conflicts);
+
+ /* It works! */
+ slapi_pblock_destroy(pb);
+}
+
+void
+test_libslapd_pblock_v3c_target_uniqueid(void **state __attribute__((unused))) {
+ /* SLAPI_TARGET_UNIQUEID */
+ Slapi_PBlock *pb = slapi_pblock_new();
+ Slapi_Operation *op = slapi_operation_new(SLAPI_OP_FLAG_INTERNAL);
+ int conflicts[] = {SLAPI_ORIGINAL_TARGET_DN, SLAPI_TARGET_SDN, 0};
+ slapi_pblock_init(pb);
+
+ /* Add the operation */
+ assert_int_equal(slapi_pblock_set(pb, SLAPI_OPERATION, op), 0);
+ /* Run the generic char * tests */
+ _test_libslapi_pblock_v3c_generic_nf_char(pb, SLAPI_TARGET_UNIQUEID, conflicts);
+
+ /* It works! */
+ slapi_pblock_destroy(pb);
+}
+
diff --git a/test/libslapd/test.c b/test/libslapd/test.c
index 62831c6..37d5543 100644
--- a/test/libslapd/test.c
+++ b/test/libslapd/test.c
@@ -19,6 +19,11 @@ run_libslapd_tests (void) {
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_libslapd_hello),
cmocka_unit_test(test_libslapd_pblock_analytics),
+ cmocka_unit_test(test_libslapd_pblock_v3c_target_dn),
+ cmocka_unit_test(test_libslapd_pblock_v3c_target_sdn),
+ cmocka_unit_test(test_libslapd_pblock_v3c_original_target_dn),
+ cmocka_unit_test(test_libslapd_pblock_v3c_target_uniqueid),
+ cmocka_unit_test(test_libslapd_operation_v3c_target_spec),
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
diff --git a/test/test_slapd.h b/test/test_slapd.h
index 1f35b7f..02eefdd 100644
--- a/test/test_slapd.h
+++ b/test/test_slapd.h
@@ -28,4 +28,13 @@ void test_libslapd_hello(void **state);
/* libslapd-pblock-analytics */
void test_libslapd_pblock_analytics(void **state);
+/* libslapd-pblock-v3_compat */
+void test_libslapd_pblock_v3c_target_dn(void **state);
+void test_libslapd_pblock_v3c_target_sdn(void **state);
+void test_libslapd_pblock_v3c_original_target_dn(void **state);
+void test_libslapd_pblock_v3c_target_uniqueid(void **state);
+
+/* libslapd-operation-v3_compat */
+void test_libslapd_operation_v3c_target_spec(void **state);
+
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.