2 Unix SMB/CIFS implementation.
4 DRSUAPI prefixMap unit tests
6 Copyright (C) Kamen Mazdrashki <kamen.mazdrashki@postpath.com> 2009
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/smbtorture.h"
24 #include "dsdb/samdb/samdb.h"
25 #include "torture/rpc/drsuapi.h"
26 #include "param/param.h"
30 * Private data to be shared among all test in Test case
32 struct drsut_prefixmap_data
{
33 struct dsdb_schema_prefixmap
*pfm_new
;
34 struct dsdb_schema_prefixmap
*pfm_full
;
38 * Test-oid data structure
40 struct drsut_pfm_oid_data
{
43 const char *oid_prefix
;
47 * Default prefixMap initialization data
49 static const struct drsut_pfm_oid_data _prefixmap_test_new_data
[] = {
50 {.id
=0x00000000, .bin_oid
="5504", .oid_prefix
="2.5.4"},
51 {.id
=0x00000001, .bin_oid
="5506", .oid_prefix
="2.5.6"},
52 {.id
=0x00000002, .bin_oid
="2A864886F7140102", .oid_prefix
="1.2.840.113556.1.2"},
53 {.id
=0x00000003, .bin_oid
="2A864886F7140103", .oid_prefix
="1.2.840.113556.1.3"},
54 {.id
=0x00000004, .bin_oid
="6086480165020201", .oid_prefix
="2.16.840.1.101.2.2.1"},
55 {.id
=0x00000005, .bin_oid
="6086480165020203", .oid_prefix
="2.16.840.1.101.2.2.3"},
56 {.id
=0x00000006, .bin_oid
="6086480165020105", .oid_prefix
="2.16.840.1.101.2.1.5"},
57 {.id
=0x00000007, .bin_oid
="6086480165020104", .oid_prefix
="2.16.840.1.101.2.1.4"},
58 {.id
=0x00000008, .bin_oid
="5505", .oid_prefix
="2.5.5"},
59 {.id
=0x00000009, .bin_oid
="2A864886F7140104", .oid_prefix
="1.2.840.113556.1.4"},
60 {.id
=0x0000000A, .bin_oid
="2A864886F7140105", .oid_prefix
="1.2.840.113556.1.5"},
61 {.id
=0x00000013, .bin_oid
="0992268993F22C64", .oid_prefix
="0.9.2342.19200300.100"},
62 {.id
=0x00000014, .bin_oid
="6086480186F84203", .oid_prefix
="2.16.840.1.113730.3"},
63 {.id
=0x00000015, .bin_oid
="0992268993F22C6401", .oid_prefix
="0.9.2342.19200300.100.1"},
64 {.id
=0x00000016, .bin_oid
="6086480186F8420301", .oid_prefix
="2.16.840.1.113730.3.1"},
65 {.id
=0x00000017, .bin_oid
="2A864886F7140105B658", .oid_prefix
="1.2.840.113556.1.5.7000"},
66 {.id
=0x00000018, .bin_oid
="5515", .oid_prefix
="2.5.21"},
67 {.id
=0x00000019, .bin_oid
="5512", .oid_prefix
="2.5.18"},
68 {.id
=0x0000001A, .bin_oid
="5514", .oid_prefix
="2.5.20"},
72 * Data to be used for creating full prefix map for testing
74 static const struct drsut_pfm_oid_data _prefixmap_full_map_data
[] = {
75 {.id
=0x00000000, .bin_oid
="0x5504", .oid_prefix
="2.5.4"},
76 {.id
=0x00000001, .bin_oid
="0x5506", .oid_prefix
="2.5.6"},
77 {.id
=0x00000002, .bin_oid
="0x2A864886F7140102", .oid_prefix
="1.2.840.113556.1.2"},
78 {.id
=0x00000003, .bin_oid
="0x2A864886F7140103", .oid_prefix
="1.2.840.113556.1.3"},
79 {.id
=0x00000004, .bin_oid
="0x6086480165020201", .oid_prefix
="2.16.840.1.101.2.2.1"},
80 {.id
=0x00000005, .bin_oid
="0x6086480165020203", .oid_prefix
="2.16.840.1.101.2.2.3"},
81 {.id
=0x00000006, .bin_oid
="0x6086480165020105", .oid_prefix
="2.16.840.1.101.2.1.5"},
82 {.id
=0x00000007, .bin_oid
="0x6086480165020104", .oid_prefix
="2.16.840.1.101.2.1.4"},
83 {.id
=0x00000008, .bin_oid
="0x5505", .oid_prefix
="2.5.5"},
84 {.id
=0x00000009, .bin_oid
="0x2A864886F7140104", .oid_prefix
="1.2.840.113556.1.4"},
85 {.id
=0x0000000a, .bin_oid
="0x2A864886F7140105", .oid_prefix
="1.2.840.113556.1.5"},
86 {.id
=0x00000013, .bin_oid
="0x0992268993F22C64", .oid_prefix
="0.9.2342.19200300.100"},
87 {.id
=0x00000014, .bin_oid
="0x6086480186F84203", .oid_prefix
="2.16.840.1.113730.3"},
88 {.id
=0x00000015, .bin_oid
="0x0992268993F22C6401", .oid_prefix
="0.9.2342.19200300.100.1"},
89 {.id
=0x00000016, .bin_oid
="0x6086480186F8420301", .oid_prefix
="2.16.840.1.113730.3.1"},
90 {.id
=0x00000017, .bin_oid
="0x2A864886F7140105B658", .oid_prefix
="1.2.840.113556.1.5.7000"},
91 {.id
=0x00000018, .bin_oid
="0x5515", .oid_prefix
="2.5.21"},
92 {.id
=0x00000019, .bin_oid
="0x5512", .oid_prefix
="2.5.18"},
93 {.id
=0x0000001a, .bin_oid
="0x5514", .oid_prefix
="2.5.20"},
94 {.id
=0x0000000b, .bin_oid
="0x2A864886F71401048204", .oid_prefix
="1.2.840.113556.1.4.260"},
95 {.id
=0x0000000c, .bin_oid
="0x2A864886F714010538", .oid_prefix
="1.2.840.113556.1.5.56"},
96 {.id
=0x0000000d, .bin_oid
="0x2A864886F71401048206", .oid_prefix
="1.2.840.113556.1.4.262"},
97 {.id
=0x0000000e, .bin_oid
="0x2A864886F714010539", .oid_prefix
="1.2.840.113556.1.5.57"},
98 {.id
=0x0000000f, .bin_oid
="0x2A864886F71401048207", .oid_prefix
="1.2.840.113556.1.4.263"},
99 {.id
=0x00000010, .bin_oid
="0x2A864886F71401053A", .oid_prefix
="1.2.840.113556.1.5.58"},
100 {.id
=0x00000011, .bin_oid
="0x2A864886F714010549", .oid_prefix
="1.2.840.113556.1.5.73"},
101 {.id
=0x00000012, .bin_oid
="0x2A864886F71401048231", .oid_prefix
="1.2.840.113556.1.4.305"},
102 {.id
=0x0000001b, .bin_oid
="0x2B060104018B3A6577", .oid_prefix
="1.3.6.1.4.1.1466.101.119"},
103 {.id
=0x0000001c, .bin_oid
="0x6086480186F8420302", .oid_prefix
="2.16.840.1.113730.3.2"},
104 {.id
=0x0000001d, .bin_oid
="0x2B06010401817A01", .oid_prefix
="1.3.6.1.4.1.250.1"},
105 {.id
=0x0000001e, .bin_oid
="0x2A864886F70D0109", .oid_prefix
="1.2.840.113549.1.9"},
106 {.id
=0x0000001f, .bin_oid
="0x0992268993F22C6404", .oid_prefix
="0.9.2342.19200300.100.4"},
107 {.id
=0x00000020, .bin_oid
="0x2A864886F714010617", .oid_prefix
="1.2.840.113556.1.6.23"},
108 {.id
=0x00000021, .bin_oid
="0x2A864886F71401061201", .oid_prefix
="1.2.840.113556.1.6.18.1"},
109 {.id
=0x00000022, .bin_oid
="0x2A864886F71401061202", .oid_prefix
="1.2.840.113556.1.6.18.2"},
110 {.id
=0x00000023, .bin_oid
="0x2A864886F71401060D03", .oid_prefix
="1.2.840.113556.1.6.13.3"},
111 {.id
=0x00000024, .bin_oid
="0x2A864886F71401060D04", .oid_prefix
="1.2.840.113556.1.6.13.4"},
112 {.id
=0x00000025, .bin_oid
="0x2B0601010101", .oid_prefix
="1.3.6.1.1.1.1"},
113 {.id
=0x00000026, .bin_oid
="0x2B0601010102", .oid_prefix
="1.3.6.1.1.1.2"},
114 {.id
=0x000003ed, .bin_oid
="0x2A864886F7140104B65866", .oid_prefix
="1.2.840.113556.1.4.7000.102"},
115 {.id
=0x00000428, .bin_oid
="0x2A864886F7140105B6583E", .oid_prefix
="1.2.840.113556.1.5.7000.62"},
116 {.id
=0x0000044c, .bin_oid
="0x2A864886F7140104B6586683", .oid_prefix
="1.2.840.113556.1.4.7000.102:0x83"},
117 {.id
=0x0000044f, .bin_oid
="0x2A864886F7140104B6586681", .oid_prefix
="1.2.840.113556.1.4.7000.102:0x81"},
118 {.id
=0x0000047d, .bin_oid
="0x2A864886F7140105B6583E81", .oid_prefix
="1.2.840.113556.1.5.7000.62:0x81"},
119 {.id
=0x00000561, .bin_oid
="0x2A864886F7140105B6583E83", .oid_prefix
="1.2.840.113556.1.5.7000.62:0x83"},
120 {.id
=0x000007d1, .bin_oid
="0x2A864886F71401061401", .oid_prefix
="1.2.840.113556.1.6.20.1"},
121 {.id
=0x000007e1, .bin_oid
="0x2A864886F71401061402", .oid_prefix
="1.2.840.113556.1.6.20.2"},
122 {.id
=0x00001b86, .bin_oid
="0x2A817A", .oid_prefix
="1.2.250"},
123 {.id
=0x00001c78, .bin_oid
="0x2A817A81", .oid_prefix
="1.2.250:0x81"},
124 {.id
=0x00001c7b, .bin_oid
="0x2A817A8180", .oid_prefix
="1.2.250:0x8180"},
129 * OID-to-ATTID mappings to be used for testing
131 static const struct {
135 } _prefixmap_test_data
[] = {
136 {.oid
="2.5.4.0", .id
=0x00000000, .attid
=0x000000},
137 {.oid
="2.5.4.42", .id
=0x00000000, .attid
=0x00002a},
138 {.oid
="1.2.840.113556.1.2.1", .id
=0x00000002, .attid
=0x020001},
139 {.oid
="1.2.840.113556.1.2.13", .id
=0x00000002, .attid
=0x02000d},
140 {.oid
="1.2.840.113556.1.2.281", .id
=0x00000002, .attid
=0x020119},
141 {.oid
="1.2.840.113556.1.4.125", .id
=0x00000009, .attid
=0x09007d},
142 {.oid
="1.2.840.113556.1.4.146", .id
=0x00000009, .attid
=0x090092},
143 {.oid
="1.2.250.1", .id
=0x00001b86, .attid
=0x1b860001},
144 {.oid
="1.2.250.130", .id
=0x00001b86, .attid
=0x1b860082},
145 {.oid
="1.2.250.16386", .id
=0x00001c78, .attid
=0x1c788002},
146 {.oid
="1.2.250.2097154", .id
=0x00001c7b, .attid
=0x1c7b8002},
151 * Creates dsdb_schema_prefixmap based on predefined data
154 static WERROR
_drsut_prefixmap_new(const struct drsut_pfm_oid_data
*_pfm_init_data
, uint32_t count
,
155 TALLOC_CTX
*mem_ctx
, struct dsdb_schema_prefixmap
**_pfm
)
158 struct dsdb_schema_prefixmap
*pfm
;
160 pfm
= talloc(mem_ctx
, struct dsdb_schema_prefixmap
);
161 W_ERROR_HAVE_NO_MEMORY(pfm
);
164 pfm
->prefixes
= talloc_array(pfm
, struct dsdb_schema_prefixmap_oid
, pfm
->length
);
165 if (!pfm
->prefixes
) {
170 for (i
= 0; i
< pfm
->length
; i
++) {
171 pfm
->prefixes
[i
].id
= _pfm_init_data
[i
].id
;
172 pfm
->prefixes
[i
].bin_oid
= strhex_to_data_blob(pfm
, _pfm_init_data
[i
].bin_oid
);
173 if (!pfm
->prefixes
[i
].bin_oid
.data
) {
184 static bool _torture_drs_pfm_compare_same(struct torture_context
*tctx
,
185 const struct dsdb_schema_prefixmap
*pfm_left
,
186 const struct dsdb_schema_prefixmap
*pfm_right
)
190 torture_assert_int_equal(tctx
, pfm_left
->length
, pfm_right
->length
,
191 "prefixMaps differ in size");
192 for (i
= 0; i
< pfm_left
->length
; i
++) {
193 struct dsdb_schema_prefixmap_oid
*entry_left
= &pfm_left
->prefixes
[i
];
194 struct dsdb_schema_prefixmap_oid
*entry_right
= &pfm_right
->prefixes
[i
];
196 torture_assert(tctx
, entry_left
->id
== entry_right
->id
,
197 talloc_asprintf(tctx
, "Different IDs for index=%d", i
));
198 torture_assert_data_blob_equal(tctx
, entry_left
->bin_oid
, entry_right
->bin_oid
,
199 talloc_asprintf(tctx
, "Different bin_oid for index=%d", i
));
206 * Tests dsdb_schema_pfm_new()
208 static bool torture_drs_unit_pfm_new(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
213 struct dsdb_schema_prefixmap
*pfm
= NULL
;
215 mem_ctx
= talloc_new(priv
);
217 /* create new prefix map */
218 werr
= dsdb_schema_pfm_new(mem_ctx
, &pfm
);
219 torture_assert_werr_ok(tctx
, werr
, "dsdb_schema_pfm_new() failed!");
220 torture_assert(tctx
, pfm
!= NULL
, "NULL prefixMap created!");
221 torture_assert(tctx
, pfm
->length
> 0, "Empty prefixMap created!");
222 torture_assert(tctx
, pfm
->prefixes
!= NULL
, "No prefixes for newly created prefixMap!");
224 /* compare newly created prefixMap with template one */
225 bret
= _torture_drs_pfm_compare_same(tctx
, priv
->pfm_new
, pfm
);
227 talloc_free(mem_ctx
);
233 * Tests dsdb_schema_pfm_make_attid() using full prefixMap.
234 * In this test we know exactly which ATTID and prefixMap->ID
235 * should be returned, i.e. no prefixMap entries should be added.
237 static bool torture_drs_unit_pfm_make_attid_full_map(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
244 count
= ARRAY_SIZE(_prefixmap_test_data
);
245 for (i
= 0; i
< count
; i
++) {
246 werr
= dsdb_schema_pfm_make_attid(priv
->pfm_full
, _prefixmap_test_data
[i
].oid
, &attid
);
247 /* prepare error message */
248 err_msg
= talloc_asprintf(priv
, "dsdb_schema_pfm_make_attid() failed with %s",
249 _prefixmap_test_data
[i
].oid
);
250 torture_assert(tctx
, err_msg
, "Unexpected: Have no memory!");
251 /* verify result and returned ATTID */
252 torture_assert_werr_ok(tctx
, werr
, err_msg
);
253 torture_assert_int_equal(tctx
, attid
, _prefixmap_test_data
[i
].attid
, err_msg
);
254 /* reclaim memory for prepared error message */
255 talloc_free(err_msg
);
262 * Tests dsdb_schema_pfm_make_attid() using initially small prefixMap.
263 * In this test we don't know exactly which ATTID and prefixMap->ID
264 * should be returned, but we can verify lo-word of ATTID.
265 * This test verifies implementation branch when a new
266 * prefix should be added into prefixMap.
268 static bool torture_drs_unit_pfm_make_attid_small_map(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
273 uint32_t attid
, attid_2
;
275 struct dsdb_schema_prefixmap
*pfm
= NULL
;
278 mem_ctx
= talloc_new(priv
);
280 /* create new prefix map */
281 werr
= dsdb_schema_pfm_new(mem_ctx
, &pfm
);
282 torture_assert_werr_ok(tctx
, werr
, "dsdb_schema_pfm_new() failed!");
283 torture_assert(tctx
, pfm
!= NULL
, "NULL prefixMap created!");
284 torture_assert(tctx
, pfm
->length
> 0, "Empty prefixMap created!");
285 torture_assert(tctx
, pfm
->prefixes
!= NULL
, "No prefixes for newly created prefixMap!");
287 /* make some ATTIDs and check result */
288 for (i
= 0; i
< ARRAY_SIZE(_prefixmap_test_data
); i
++) {
289 werr
= dsdb_schema_pfm_make_attid(pfm
, _prefixmap_test_data
[i
].oid
, &attid
);
291 /* prepare error message */
292 err_msg
= talloc_asprintf(mem_ctx
, "dsdb_schema_pfm_make_attid() failed with %s",
293 _prefixmap_test_data
[i
].oid
);
294 torture_assert(tctx
, err_msg
, "Unexpected: Have no memory!");
296 /* verify result and returned ATTID */
297 torture_assert_werr_ok(tctx
, werr
, err_msg
);
298 /* verify ATTID lo-word */
299 torture_assert_int_equal(tctx
, attid
& 0xFFFF, _prefixmap_test_data
[i
].attid
& 0xFFFF, err_msg
);
301 /* try again, this time verify for whole ATTID */
302 werr
= dsdb_schema_pfm_make_attid(pfm
, _prefixmap_test_data
[i
].oid
, &attid_2
);
303 torture_assert_werr_ok(tctx
, werr
, err_msg
);
304 torture_assert_int_equal(tctx
, attid_2
, attid
, err_msg
);
306 /* reclaim memory for prepared error message */
307 talloc_free(err_msg
);
309 /* check there is such an index in modified prefixMap */
311 for (j
= 0; j
< pfm
->length
; j
++) {
312 if (pfm
->prefixes
[j
].id
== idx
)
315 if (j
>= pfm
->length
) {
316 torture_result(tctx
, TORTURE_FAIL
, __location__
": No prefix for ATTID=0x%08X", attid
);
322 talloc_free(mem_ctx
);
328 * Tests dsdb_schema_pfm_oid_from_attid() using full prefixMap.
330 static bool torture_drs_unit_pfm_oid_from_attid(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
337 count
= ARRAY_SIZE(_prefixmap_test_data
);
338 for (i
= 0; i
< count
; i
++) {
340 werr
= dsdb_schema_pfm_oid_from_attid(priv
->pfm_full
, _prefixmap_test_data
[i
].attid
,
342 /* prepare error message */
343 err_msg
= talloc_asprintf(priv
, "dsdb_schema_pfm_oid_from_attid() failed with 0x%08X",
344 _prefixmap_test_data
[i
].attid
);
345 torture_assert(tctx
, err_msg
, "Unexpected: Have no memory!");
346 /* verify result and returned ATTID */
347 torture_assert_werr_ok(tctx
, werr
, err_msg
);
348 torture_assert(tctx
, oid
, "dsdb_schema_pfm_oid_from_attid() returned NULL OID!!!");
349 torture_assert_str_equal(tctx
, oid
, _prefixmap_test_data
[i
].oid
, err_msg
);
350 /* reclaim memory for prepared error message */
351 talloc_free(err_msg
);
352 /* free memory for OID */
353 talloc_free(discard_const(oid
));
360 * Test Schema prefixMap conversions to/from drsuapi prefixMap
363 static bool torture_drs_unit_pfm_to_from_drsuapi(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
366 const char *schema_info
;
367 const char *schema_info_default
= "FF0000000000000000000000000000000123456789";
368 struct dsdb_schema_prefixmap
*pfm
;
369 struct drsuapi_DsReplicaOIDMapping_Ctr
*ctr
;
372 mem_ctx
= talloc_new(tctx
);
373 torture_assert(tctx
, mem_ctx
, "Unexpected: Have no memory!");
375 /* convert Schema_prefixMap to drsuapi_prefixMap */
376 werr
= dsdb_drsuapi_pfm_from_schema_pfm(priv
->pfm_full
, schema_info_default
, mem_ctx
, &ctr
);
377 torture_assert_werr_ok(tctx
, werr
, "dsdb_drsuapi_pfm_from_schema_pfm() failed");
378 torture_assert(tctx
, ctr
&& ctr
->mappings
, "drsuapi_prefixMap not constructed correctly");
379 torture_assert_int_equal(tctx
, ctr
->num_mappings
, priv
->pfm_full
->length
+ 1,
380 "drs_mappings count does not match");
381 /* look for schema_info entry - it should be the last one */
382 schema_info
= hex_encode_talloc(mem_ctx
,
383 ctr
->mappings
[ctr
->num_mappings
- 1].oid
.binary_oid
,
384 ctr
->mappings
[ctr
->num_mappings
- 1].oid
.length
);
385 torture_assert_str_equal(tctx
,
388 "schema_info not stored correctly or not last entry");
390 /* compare schema_prefixMap and drsuapi_prefixMap */
391 werr
= dsdb_schema_pfm_contains_drsuapi_pfm(priv
->pfm_full
, ctr
);
392 torture_assert_werr_ok(tctx
, werr
, "dsdb_schema_pfm_contains_drsuapi_pfm() failed");
394 /* convert back drsuapi_prefixMap to schema_prefixMap */
395 werr
= dsdb_schema_pfm_from_drsuapi_pfm(ctr
, true, mem_ctx
, &pfm
, &schema_info
);
396 torture_assert_werr_ok(tctx
, werr
, "dsdb_schema_pfm_from_drsuapi_pfm() failed");
397 torture_assert_str_equal(tctx
, schema_info
, schema_info_default
, "Fetched schema_info is different");
398 /* compare against the original */
399 if (!_torture_drs_pfm_compare_same(tctx
, priv
->pfm_full
, pfm
)) {
400 talloc_free(mem_ctx
);
404 /* test conversion with partial drsuapi_prefixMap */
406 werr
= dsdb_schema_pfm_from_drsuapi_pfm(ctr
, false, mem_ctx
, &pfm
, NULL
);
407 torture_assert_werr_ok(tctx
, werr
, "dsdb_schema_pfm_from_drsuapi_pfm() failed");
408 /* compare against the original */
409 if (!_torture_drs_pfm_compare_same(tctx
, priv
->pfm_full
, pfm
)) {
410 talloc_free(mem_ctx
);
414 talloc_free(mem_ctx
);
420 * Test Schema prefixMap conversions to/from ldb_val
421 * blob representation.
423 static bool torture_drs_unit_pfm_to_from_ldb_val(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
426 const char *schema_info
;
427 const char *schema_info_default
= "FF0000000000000000000000000000000123456789";
428 struct dsdb_schema
*schema
;
429 struct ldb_val pfm_ldb_val
;
430 struct ldb_val schema_info_ldb_val
;
433 mem_ctx
= talloc_new(tctx
);
434 torture_assert(tctx
, mem_ctx
, "Unexpected: Have no memory!");
436 schema
= dsdb_new_schema(mem_ctx
, lp_iconv_convenience(tctx
->lp_ctx
));
437 torture_assert(tctx
, schema
, "Unexpected: failed to allocate schema object");
439 /* set priv->pfm_full as prefixMap for new schema object */
440 schema
->prefixmap
= priv
->pfm_full
;
441 schema
->schema_info
= schema_info_default
;
443 /* convert schema_prefixMap to ldb_val blob */
444 werr
= dsdb_get_oid_mappings_ldb(schema
, mem_ctx
, &pfm_ldb_val
, &schema_info_ldb_val
);
445 torture_assert_werr_ok(tctx
, werr
, "dsdb_get_oid_mappings_ldb() failed");
446 torture_assert(tctx
, pfm_ldb_val
.data
&& pfm_ldb_val
.length
,
447 "pfm_ldb_val not constructed correctly");
448 torture_assert(tctx
, schema_info_ldb_val
.data
&& schema_info_ldb_val
.length
,
449 "schema_info_ldb_val not constructed correctly");
450 /* look for schema_info entry - it should be the last one */
451 schema_info
= hex_encode_talloc(mem_ctx
,
452 schema_info_ldb_val
.data
,
453 schema_info_ldb_val
.length
);
454 torture_assert_str_equal(tctx
,
457 "schema_info not stored correctly or not last entry");
459 /* convert pfm_ldb_val back to schema_prefixMap */
460 schema
->prefixmap
= NULL
;
461 schema
->schema_info
= NULL
;
462 werr
= dsdb_load_oid_mappings_ldb(schema
, &pfm_ldb_val
, &schema_info_ldb_val
);
463 torture_assert_werr_ok(tctx
, werr
, "dsdb_load_oid_mappings_ldb() failed");
464 /* compare against the original */
465 if (!_torture_drs_pfm_compare_same(tctx
, schema
->prefixmap
, priv
->pfm_full
)) {
466 talloc_free(mem_ctx
);
470 talloc_free(mem_ctx
);
476 * Setup/Teardown for test case
478 static bool torture_drs_unit_prefixmap_setup(struct torture_context
*tctx
, struct drsut_prefixmap_data
**priv
)
482 *priv
= talloc_zero(tctx
, struct drsut_prefixmap_data
);
483 torture_assert(tctx
, *priv
!= NULL
, "Not enough memory");
485 werr
= _drsut_prefixmap_new(_prefixmap_test_new_data
, ARRAY_SIZE(_prefixmap_test_new_data
), tctx
, &(*priv
)->pfm_new
);
486 torture_assert_werr_ok(tctx
, werr
, "failed to create pfm_new");
488 werr
= _drsut_prefixmap_new(_prefixmap_full_map_data
, ARRAY_SIZE(_prefixmap_full_map_data
), tctx
, &(*priv
)->pfm_full
);
489 torture_assert_werr_ok(tctx
, werr
, "failed to create pfm_test");
494 static bool torture_drs_unit_prefixmap_teardown(struct torture_context
*tctx
, struct drsut_prefixmap_data
*priv
)
502 * Test case initialization for
505 struct torture_tcase
* torture_drs_unit_prefixmap(struct torture_suite
*suite
)
507 typedef bool (*pfn_setup
)(struct torture_context
*, void **);
508 typedef bool (*pfn_teardown
)(struct torture_context
*, void *);
509 typedef bool (*pfn_run
)(struct torture_context
*, void *);
511 struct torture_tcase
* tc
= torture_suite_add_tcase(suite
, "prefixMap");
513 torture_tcase_set_fixture(tc
,
514 (pfn_setup
)torture_drs_unit_prefixmap_setup
,
515 (pfn_teardown
)torture_drs_unit_prefixmap_teardown
);
517 tc
->description
= talloc_strdup(tc
, "Unit tests for DRSUAPI::prefixMap implementation");
519 torture_tcase_add_simple_test(tc
, "new", (pfn_run
)torture_drs_unit_pfm_new
);
521 torture_tcase_add_simple_test(tc
, "make_attid_full_map", (pfn_run
)torture_drs_unit_pfm_make_attid_full_map
);
522 torture_tcase_add_simple_test(tc
, "make_attid_small_map", (pfn_run
)torture_drs_unit_pfm_make_attid_small_map
);
523 torture_tcase_add_simple_test(tc
, "oid_from_attid_full_map", (pfn_run
)torture_drs_unit_pfm_oid_from_attid
);
525 torture_tcase_add_simple_test(tc
, "pfm_to_from_drsuapi", (pfn_run
)torture_drs_unit_pfm_to_from_drsuapi
);
527 torture_tcase_add_simple_test(tc
, "pfm_to_from_ldb_val", (pfn_run
)torture_drs_unit_pfm_to_from_ldb_val
);