Finish removal of iconv_convenience in public API's.
[samba.git] / source4 / torture / drs / unit / prefixmap_tests.c
index 03f30de106c567d60905897ec010fe6f1a4e8465..a4521eb675d360252a46c65ce53a5ef6d793c3fd 100644 (file)
 #include "torture/smbtorture.h"
 #include "dsdb/samdb/samdb.h"
 #include "torture/rpc/drsuapi.h"
+#include "torture/drs/proto.h"
 #include "param/param.h"
 
 
-/**
- * Default schema_info string to be used for testing
- */
-#define SCHEMA_INFO_DEFAULT    "FF0000000000000000000000000000000123456789"
-
 /**
  * Private data to be shared among all test in Test case
  */
@@ -39,6 +35,10 @@ struct drsut_prefixmap_data {
        struct dsdb_schema_prefixmap *pfm_new;
        struct dsdb_schema_prefixmap *pfm_full;
 
+       /* default schemaInfo value to test with */
+       const char *schi_default_str;
+       struct dsdb_schema_info *schi_default;
+
        struct ldb_context *ldb_ctx;
 };
 
@@ -382,6 +382,48 @@ static bool torture_drs_unit_pfm_oid_from_attid(struct torture_context *tctx, st
        return true;
 }
 
+/**
+ * Tests dsdb_schema_pfm_oid_from_attid() for handling
+ * correctly different type of attid values.
+ * See: MS-ADTS, 3.1.1.2.6 ATTRTYP
+ */
+static bool torture_drs_unit_pfm_oid_from_attid_check_attid(struct torture_context *tctx,
+                                                           struct drsut_prefixmap_data *priv)
+{
+       WERROR werr;
+       const char *oid;
+
+       /* Test with valid prefixMap attid */
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0x00000000, tctx, &oid);
+       torture_assert_werr_ok(tctx, werr, "Testing prefixMap type attid = 0x0000000");
+
+       /* Test with attid in msDS-IntId range */
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0x80000000, tctx, &oid);
+       torture_assert_werr_equal(tctx, werr, WERR_INVALID_PARAMETER,
+                                 "Testing msDS-IntId type attid = 0x80000000");
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0xBFFFFFFF, tctx, &oid);
+       torture_assert_werr_equal(tctx, werr, WERR_INVALID_PARAMETER,
+                                 "Testing msDS-IntId type attid = 0xBFFFFFFF");
+
+       /* Test with attid in RESERVED range */
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0xC0000000, tctx, &oid);
+       torture_assert_werr_equal(tctx, werr, WERR_INVALID_PARAMETER,
+                                 "Testing RESERVED type attid = 0xC0000000");
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0xFFFEFFFF, tctx, &oid);
+       torture_assert_werr_equal(tctx, werr, WERR_INVALID_PARAMETER,
+                                 "Testing RESERVED type attid = 0xFFFEFFFF");
+
+       /* Test with attid in INTERNAL range */
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0xFFFF0000, tctx, &oid);
+       torture_assert_werr_equal(tctx, werr, WERR_INVALID_PARAMETER,
+                                 "Testing INTERNAL type attid = 0xFFFF0000");
+       werr = dsdb_schema_pfm_oid_from_attid(priv->pfm_full, 0xFFFFFFFF, tctx, &oid);
+       torture_assert_werr_equal(tctx, werr, WERR_INVALID_PARAMETER,
+                                 "Testing INTERNAL type attid = 0xFFFFFFFF");
+
+       return true;
+}
+
 /**
  * Test Schema prefixMap conversions to/from drsuapi prefixMap
  * representation.
@@ -398,7 +440,7 @@ static bool torture_drs_unit_pfm_to_from_drsuapi(struct torture_context *tctx, s
        torture_assert(tctx, mem_ctx, "Unexpected: Have no memory!");
 
        /* convert Schema_prefixMap to drsuapi_prefixMap */
-       werr = dsdb_drsuapi_pfm_from_schema_pfm(priv->pfm_full, SCHEMA_INFO_DEFAULT, mem_ctx, &ctr);
+       werr = dsdb_drsuapi_pfm_from_schema_pfm(priv->pfm_full, priv->schi_default_str, mem_ctx, &ctr);
        torture_assert_werr_ok(tctx, werr, "dsdb_drsuapi_pfm_from_schema_pfm() failed");
        torture_assert(tctx, ctr && ctr->mappings, "drsuapi_prefixMap not constructed correctly");
        torture_assert_int_equal(tctx, ctr->num_mappings, priv->pfm_full->length + 1,
@@ -409,7 +451,7 @@ static bool torture_drs_unit_pfm_to_from_drsuapi(struct torture_context *tctx, s
                                        ctr->mappings[ctr->num_mappings - 1].oid.length);
        torture_assert_str_equal(tctx,
                                 schema_info,
-                                SCHEMA_INFO_DEFAULT,
+                                priv->schi_default_str,
                                 "schema_info not stored correctly or not last entry");
 
        /* compare schema_prefixMap and drsuapi_prefixMap */
@@ -419,7 +461,7 @@ static bool torture_drs_unit_pfm_to_from_drsuapi(struct torture_context *tctx, s
        /* convert back drsuapi_prefixMap to schema_prefixMap */
        werr = dsdb_schema_pfm_from_drsuapi_pfm(ctr, true, mem_ctx, &pfm, &schema_info);
        torture_assert_werr_ok(tctx, werr, "dsdb_schema_pfm_from_drsuapi_pfm() failed");
-       torture_assert_str_equal(tctx, schema_info, SCHEMA_INFO_DEFAULT, "Fetched schema_info is different");
+       torture_assert_str_equal(tctx, schema_info, priv->schi_default_str, "Fetched schema_info is different");
 
        /* compare against the original */
        if (!_torture_drs_pfm_compare_same(tctx, priv->pfm_full, pfm, true)) {
@@ -458,12 +500,12 @@ static bool torture_drs_unit_pfm_to_from_ldb_val(struct torture_context *tctx, s
        mem_ctx = talloc_new(tctx);
        torture_assert(tctx, mem_ctx, "Unexpected: Have no memory!");
 
-       schema = dsdb_new_schema(mem_ctx, lp_iconv_convenience(tctx->lp_ctx));
+       schema = dsdb_new_schema(mem_ctx);
        torture_assert(tctx, schema, "Unexpected: failed to allocate schema object");
 
        /* set priv->pfm_full as prefixMap for new schema object */
        schema->prefixmap = priv->pfm_full;
-       schema->schema_info = SCHEMA_INFO_DEFAULT;
+       schema->schema_info = priv->schi_default_str;
 
        /* convert schema_prefixMap to ldb_val blob */
        werr = dsdb_get_oid_mappings_ldb(schema, mem_ctx, &pfm_ldb_val, &schema_info_ldb_val);
@@ -478,7 +520,7 @@ static bool torture_drs_unit_pfm_to_from_ldb_val(struct torture_context *tctx, s
                                        schema_info_ldb_val.length);
        torture_assert_str_equal(tctx,
                                 schema_info,
-                                SCHEMA_INFO_DEFAULT,
+                                priv->schi_default_str,
                                 "schema_info not stored correctly or not last entry");
 
        /* convert pfm_ldb_val back to schema_prefixMap */
@@ -510,11 +552,11 @@ static bool torture_drs_unit_pfm_read_write_ldb(struct torture_context *tctx, st
        torture_assert(tctx, mem_ctx, "Unexpected: Have no memory!");
 
        /* makeup a dsdb_schema to test with */
-       schema = dsdb_new_schema(mem_ctx, lp_iconv_convenience(tctx->lp_ctx));
+       schema = dsdb_new_schema(mem_ctx);
        torture_assert(tctx, schema, "Unexpected: failed to allocate schema object");
        /* set priv->pfm_full as prefixMap for new schema object */
        schema->prefixmap = priv->pfm_full;
-       schema->schema_info = SCHEMA_INFO_DEFAULT;
+       schema->schema_info = priv->schi_default_str;
 
        /* write prfixMap to ldb */
        werr = dsdb_write_prefixes_from_schema_to_ldb(mem_ctx, priv->ldb_ctx, schema);
@@ -564,10 +606,10 @@ static bool torture_drs_unit_dsdb_create_prefix_mapping(struct torture_context *
        torture_assert(tctx, mem_ctx, "Unexpected: Have no memory!");
 
        /* makeup a dsdb_schema to test with */
-       schema = dsdb_new_schema(mem_ctx, lp_iconv_convenience(tctx->lp_ctx));
+       schema = dsdb_new_schema(mem_ctx);
        torture_assert(tctx, schema, "Unexpected: failed to allocate schema object");
        /* set priv->pfm_full as prefixMap for new schema object */
-       schema->schema_info = SCHEMA_INFO_DEFAULT;
+       schema->schema_info = priv->schi_default_str;
        werr = _drsut_prefixmap_new(_prefixmap_test_new_data, ARRAY_SIZE(_prefixmap_test_new_data),
                                    schema, &schema->prefixmap);
        torture_assert_werr_ok(tctx, werr, "_drsut_prefixmap_new() failed");
@@ -653,7 +695,7 @@ static bool torture_drs_unit_ldb_setup(struct torture_context *tctx, struct drsu
        /* add prefixMap attribute so tested layer could work properly */
        {
                struct ldb_message *msg = ldb_msg_new(mem_ctx);
-               msg->dn = samdb_schema_dn(priv->ldb_ctx);
+               msg->dn = ldb_get_schema_basedn(priv->ldb_ctx);
                ldb_err = ldb_msg_add_string(msg, "prefixMap", "prefixMap");
                torture_assert_int_equal_goto(tctx, ldb_err, LDB_SUCCESS, bret, DONE,
                                              "ldb_msg_add_empty() failed");
@@ -663,7 +705,6 @@ static bool torture_drs_unit_ldb_setup(struct torture_context *tctx, struct drsu
        }
 
 DONE:
-       unlink(ldb_url);
        talloc_free(mem_ctx);
        return bret;
 }
@@ -671,21 +712,33 @@ DONE:
 /*
  * Setup/Teardown for test case
  */
-static bool torture_drs_unit_prefixmap_setup(struct torture_context *tctx, struct drsut_prefixmap_data **priv)
+static bool torture_drs_unit_prefixmap_setup(struct torture_context *tctx, struct drsut_prefixmap_data **_priv)
 {
        WERROR werr;
+       DATA_BLOB blob;
+       struct drsut_prefixmap_data *priv;
 
-       *priv = talloc_zero(tctx, struct drsut_prefixmap_data);
-       torture_assert(tctx, *priv != NULL, "Not enough memory");
+       priv = *_priv = talloc_zero(tctx, struct drsut_prefixmap_data);
+       torture_assert(tctx, priv != NULL, "Not enough memory");
 
-       werr = _drsut_prefixmap_new(_prefixmap_test_new_data, ARRAY_SIZE(_prefixmap_test_new_data), tctx, &(*priv)->pfm_new);
+       werr = _drsut_prefixmap_new(_prefixmap_test_new_data, ARRAY_SIZE(_prefixmap_test_new_data),
+                                   tctx, &priv->pfm_new);
        torture_assert_werr_ok(tctx, werr, "failed to create pfm_new");
 
-       werr = _drsut_prefixmap_new(_prefixmap_full_map_data, ARRAY_SIZE(_prefixmap_full_map_data), tctx, &(*priv)->pfm_full);
+       werr = _drsut_prefixmap_new(_prefixmap_full_map_data, ARRAY_SIZE(_prefixmap_full_map_data),
+                                   tctx, &priv->pfm_full);
        torture_assert_werr_ok(tctx, werr, "failed to create pfm_test");
 
+       torture_assert(tctx, drsut_schemainfo_new(tctx, &priv->schi_default),
+                      "drsut_schemainfo_new() failed");
+
+       werr = dsdb_blob_from_schema_info(priv->schi_default, priv, &blob);
+       torture_assert_werr_ok(tctx, werr, "dsdb_blob_from_schema_info() failed");
+
+       priv->schi_default_str = data_blob_hex_string_upper(priv, &blob);
+
        /* create temporary LDB and populate with data */
-       if (!torture_drs_unit_ldb_setup(tctx, *priv)) {
+       if (!torture_drs_unit_ldb_setup(tctx, priv)) {
                return false;
        }
 
@@ -722,6 +775,8 @@ struct torture_tcase * torture_drs_unit_prefixmap(struct torture_suite *suite)
        torture_tcase_add_simple_test(tc, "make_attid_full_map", (pfn_run)torture_drs_unit_pfm_make_attid_full_map);
        torture_tcase_add_simple_test(tc, "make_attid_small_map", (pfn_run)torture_drs_unit_pfm_make_attid_small_map);
        torture_tcase_add_simple_test(tc, "oid_from_attid_full_map", (pfn_run)torture_drs_unit_pfm_oid_from_attid);
+       torture_tcase_add_simple_test(tc, "oid_from_attid_check_attid",
+                                     (pfn_run)torture_drs_unit_pfm_oid_from_attid_check_attid);
 
        torture_tcase_add_simple_test(tc, "pfm_to_from_drsuapi", (pfn_run)torture_drs_unit_pfm_to_from_drsuapi);