2 Test suite for FSRVP server state
4 Copyright (C) David Disseldorp 2012-2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "librpc/gen_ndr/security.h"
24 #include "lib/param/param.h"
25 #include "lib/util/dlinklist.h"
26 #include "libcli/resolve/resolve.h"
27 #include "librpc/gen_ndr/ndr_fsrvp.h"
28 #include "librpc/gen_ndr/ndr_fsrvp_c.h"
29 #include "source3/rpc_server/fss/srv_fss_private.h"
30 #include "torture/torture.h"
31 #include "torture/local/proto.h"
33 static bool test_fsrvp_state_empty(struct torture_context
*tctx
)
36 struct fss_global fss_global
;
38 char db_dir
[] = "fsrvp_torture_XXXXXX";
39 char *db_path
= talloc_asprintf(NULL
, "%s/%s",
40 mkdtemp(db_dir
), FSS_DB_NAME
);
42 memset(&fss_global
, 0, sizeof(fss_global
));
43 fss_global
.mem_ctx
= talloc_new(NULL
);
44 fss_global
.db_path
= db_path
;
46 status
= fss_state_store(fss_global
.mem_ctx
, fss_global
.sc_sets
,
47 fss_global
.sc_sets_count
, fss_global
.db_path
);
48 torture_assert_ntstatus_ok(tctx
, status
,
49 "failed to store empty fss state");
51 torture_assert_int_equal(tctx
, stat(fss_global
.db_path
, &sbuf
), 0,
52 "failed to stat fss state tdb");
53 talloc_free(fss_global
.mem_ctx
);
55 memset(&fss_global
, 0, sizeof(fss_global
));
56 fss_global
.mem_ctx
= talloc_new(NULL
);
57 fss_global
.db_path
= db_path
;
59 status
= fss_state_retrieve(fss_global
.mem_ctx
, &fss_global
.sc_sets
,
60 &fss_global
.sc_sets_count
,
62 torture_assert_ntstatus_ok(tctx
, status
,
63 "failed to retrieve empty fss state");
64 torture_assert_int_equal(tctx
, fss_global
.sc_sets_count
, 0,
65 "sc_sets_count set when it should be zero");
66 talloc_free(fss_global
.mem_ctx
);
74 static bool test_fsrvp_state_sc_set(struct torture_context
*tctx
,
76 struct fss_sc_set
**sc_set_out
)
78 struct fss_sc_set
*sc_set
;
80 sc_set
= talloc_zero(mem_ctx
, struct fss_sc_set
);
81 sc_set
->id
= GUID_random();
82 sc_set
->id_str
= GUID_string(sc_set
, &sc_set
->id
);
83 sc_set
->state
= FSS_SC_COMMITED
;
84 sc_set
->context
= FSRVP_CTX_FILE_SHARE_BACKUP
;
90 static bool test_fsrvp_state_sc(struct torture_context
*tctx
,
92 struct fss_sc
**sc_out
)
96 sc
= talloc_zero(mem_ctx
, struct fss_sc
);
97 sc
->id
= GUID_random();
98 sc
->id_str
= GUID_string(sc
, &sc
->id
);
99 sc
->volume_name
= talloc_strdup(sc
, "/this/is/a/path");
100 /* keep snap path NULL, i.e. not yet commited */
101 sc
->create_ts
= time(NULL
);
107 static bool test_fsrvp_state_smap(struct torture_context
*tctx
,
109 const char *base_share_name
,
110 const char *sc_share_name
,
111 struct fss_sc_smap
**smap_out
)
113 struct fss_sc_smap
*smap
;
115 smap
= talloc_zero(mem_ctx
, struct fss_sc_smap
);
116 smap
->share_name
= talloc_strdup(mem_ctx
, base_share_name
);
117 smap
->sc_share_name
= talloc_strdup(mem_ctx
, sc_share_name
);
118 smap
->sc_share_comment
= talloc_strdup(mem_ctx
, "test sc share comment");
119 smap
->is_exposed
= false;
125 static bool test_fsrvp_state_smap_compare(struct torture_context
*tctx
,
126 struct fss_sc_smap
*smap_1
,
127 struct fss_sc_smap
*smap_2
)
129 /* already confirmed by caller */
130 torture_assert_str_equal(tctx
, smap_1
->sc_share_name
,
131 smap_2
->sc_share_name
,
132 "smap sc share name strings differ");
134 torture_assert_str_equal(tctx
, smap_1
->share_name
,
136 "smap share name strings differ");
138 torture_assert_str_equal(tctx
, smap_1
->sc_share_comment
,
139 smap_2
->sc_share_comment
,
140 "smap sc share comment strings differ");
142 torture_assert(tctx
, (smap_1
->is_exposed
== smap_2
->is_exposed
),
143 "smap exposure settings differ");
148 static bool test_fsrvp_state_sc_compare(struct torture_context
*tctx
,
152 struct fss_sc_smap
*smap_1
;
153 struct fss_sc_smap
*smap_2
;
156 /* should have already been confirmed by the caller */
157 torture_assert(tctx
, GUID_equal(&sc_1
->id
, &sc_2
->id
),
160 torture_assert_str_equal(tctx
, sc_1
->volume_name
, sc_2
->volume_name
,
161 "sc volume_name strings differ");
163 /* may be null, assert_str_eq handles null ptrs safely */
164 torture_assert_str_equal(tctx
, sc_1
->sc_path
, sc_2
->sc_path
,
165 "sc path strings differ");
167 torture_assert(tctx
, difftime(sc_1
->create_ts
, sc_2
->create_ts
) == 0,
168 "sc create timestamps differ");
170 torture_assert_int_equal(tctx
, sc_1
->smaps_count
, sc_2
->smaps_count
,
171 "sc smaps counts differ");
173 for (smap_1
= sc_1
->smaps
; smap_1
; smap_1
= smap_1
->next
) {
174 bool matched
= false;
175 for (smap_2
= sc_2
->smaps
; smap_2
; smap_2
= smap_2
->next
) {
176 if (strcmp(smap_1
->sc_share_name
,
177 smap_2
->sc_share_name
) == 0) {
179 ok
= test_fsrvp_state_smap_compare(tctx
,
182 torture_assert(tctx
, ok
, "");
186 torture_assert(tctx
, matched
, "no match for smap");
192 static bool test_fsrvp_state_sc_set_compare(struct torture_context
*tctx
,
193 struct fss_sc_set
*sc_set_1
,
194 struct fss_sc_set
*sc_set_2
)
200 /* should have already been confirmed by the caller */
201 torture_assert(tctx
, GUID_equal(&sc_set_1
->id
, &sc_set_2
->id
),
202 "sc_set guids differ");
204 torture_assert_str_equal(tctx
, sc_set_1
->id_str
, sc_set_2
->id_str
,
205 "sc_set guid strings differ");
207 torture_assert_int_equal(tctx
, sc_set_1
->state
, sc_set_2
->state
,
208 "sc_set state enums differ");
210 torture_assert_int_equal(tctx
, sc_set_1
->context
, sc_set_2
->context
,
211 "sc_set contexts differ");
213 torture_assert_int_equal(tctx
, sc_set_1
->scs_count
, sc_set_2
->scs_count
,
214 "sc_set sc counts differ");
216 for (sc_1
= sc_set_1
->scs
; sc_1
; sc_1
= sc_1
->next
) {
217 bool matched
= false;
218 for (sc_2
= sc_set_2
->scs
; sc_2
; sc_2
= sc_2
->next
) {
219 if (GUID_equal(&sc_1
->id
, &sc_2
->id
)) {
221 ok
= test_fsrvp_state_sc_compare(tctx
, sc_1
,
223 torture_assert(tctx
, ok
, "");
227 torture_assert(tctx
, matched
, "no match for sc");
232 static bool test_fsrvp_state_compare(struct torture_context
*tctx
,
233 struct fss_global
*fss_1
,
234 struct fss_global
*fss_2
)
236 struct fss_sc_set
*sc_set_1
;
237 struct fss_sc_set
*sc_set_2
;
240 torture_assert_int_equal(tctx
, fss_1
->sc_sets_count
,
241 fss_2
->sc_sets_count
,
242 "sc_sets_count differ");
244 for (sc_set_1
= fss_1
->sc_sets
; sc_set_1
; sc_set_1
= sc_set_1
->next
) {
245 bool matched
= false;
246 for (sc_set_2
= fss_2
->sc_sets
;
248 sc_set_2
= sc_set_2
->next
) {
249 if (GUID_equal(&sc_set_1
->id
, &sc_set_2
->id
)) {
251 ok
= test_fsrvp_state_sc_set_compare(tctx
,
254 torture_assert(tctx
, ok
, "");
258 torture_assert(tctx
, matched
, "no match for sc_set");
265 * test a simple heirarchy of:
274 static bool test_fsrvp_state_single(struct torture_context
*tctx
)
278 struct fss_global fss_gs
;
279 struct fss_global fss_gr
;
280 struct fss_sc_set
*sc_set
;
282 struct fss_sc_smap
*smap
;
283 char db_dir
[] = "fsrvp_torture_XXXXXX";
284 char *db_path
= talloc_asprintf(NULL
, "%s/%s",
285 mkdtemp(db_dir
), FSS_DB_NAME
);
287 memset(&fss_gs
, 0, sizeof(fss_gs
));
288 fss_gs
.mem_ctx
= talloc_new(NULL
);
289 fss_gs
.db_path
= db_path
;
291 ok
= test_fsrvp_state_sc_set(tctx
, fss_gs
.mem_ctx
, &sc_set
);
292 torture_assert(tctx
, ok
, "failed to create sc set");
294 /* use parent as mem ctx */
295 ok
= test_fsrvp_state_sc(tctx
, sc_set
, &sc
);
296 torture_assert(tctx
, ok
, "failed to create sc");
298 ok
= test_fsrvp_state_smap(tctx
, sc
, "base_share", "sc_share", &smap
);
299 torture_assert(tctx
, ok
, "failed to create smap");
301 DLIST_ADD_END(fss_gs
.sc_sets
, sc_set
, struct fss_sc_set
*);
302 fss_gs
.sc_sets_count
++;
303 DLIST_ADD_END(sc_set
->scs
, sc
, struct fss_sc
*);
306 DLIST_ADD_END(sc
->smaps
, smap
, struct fss_sc_smap
*);
309 status
= fss_state_store(fss_gs
.mem_ctx
, fss_gs
.sc_sets
,
310 fss_gs
.sc_sets_count
, fss_gs
.db_path
);
311 torture_assert_ntstatus_ok(tctx
, status
,
312 "failed to store fss state");
314 memset(&fss_gr
, 0, sizeof(fss_gr
));
315 fss_gr
.mem_ctx
= talloc_new(NULL
);
316 fss_gr
.db_path
= db_path
;
318 status
= fss_state_retrieve(fss_gr
.mem_ctx
, &fss_gr
.sc_sets
,
319 &fss_gr
.sc_sets_count
, fss_gr
.db_path
);
320 torture_assert_ntstatus_ok(tctx
, status
,
321 "failed to retrieve fss state");
323 ok
= test_fsrvp_state_compare(tctx
, &fss_gs
, &fss_gr
);
324 torture_assert(tctx
, ok
,
325 "stored and retrieved state comparison failed");
327 talloc_free(fss_gs
.mem_ctx
);
328 talloc_free(fss_gr
.mem_ctx
);
331 talloc_free(db_path
);
337 * test a complex heirarchy of:
349 static bool test_fsrvp_state_multi(struct torture_context
*tctx
)
353 struct fss_global fss_gs
;
354 struct fss_global fss_gr
;
355 struct fss_sc_set
*sc_set_a
;
356 struct fss_sc_set
*sc_set_b
;
357 struct fss_sc
*sc_aa
;
358 struct fss_sc
*sc_ab
;
359 struct fss_sc_smap
*smap_aaa
;
360 struct fss_sc_smap
*smap_aba
;
361 struct fss_sc_smap
*smap_abb
;
362 char db_dir
[] = "fsrvp_torture_XXXXXX";
363 char *db_path
= talloc_asprintf(NULL
, "%s/%s",
364 mkdtemp(db_dir
), FSS_DB_NAME
);
366 memset(&fss_gs
, 0, sizeof(fss_gs
));
367 fss_gs
.mem_ctx
= talloc_new(NULL
);
368 fss_gs
.db_path
= db_path
;
370 ok
= test_fsrvp_state_sc_set(tctx
, fss_gs
.mem_ctx
, &sc_set_a
);
371 torture_assert(tctx
, ok
, "failed to create sc set");
373 ok
= test_fsrvp_state_sc_set(tctx
, fss_gs
.mem_ctx
, &sc_set_b
);
374 torture_assert(tctx
, ok
, "failed to create sc set");
376 /* use parent as mem ctx */
377 ok
= test_fsrvp_state_sc(tctx
, sc_set_a
, &sc_aa
);
378 torture_assert(tctx
, ok
, "failed to create sc");
380 ok
= test_fsrvp_state_sc(tctx
, sc_set_a
, &sc_ab
);
381 torture_assert(tctx
, ok
, "failed to create sc");
383 ok
= test_fsrvp_state_smap(tctx
, sc_ab
, "share_aa", "sc_share_aaa",
385 torture_assert(tctx
, ok
, "failed to create smap");
387 ok
= test_fsrvp_state_smap(tctx
, sc_ab
, "share_ab", "sc_share_aba",
389 torture_assert(tctx
, ok
, "failed to create smap");
391 ok
= test_fsrvp_state_smap(tctx
, sc_ab
, "share_ab", "sc_share_abb",
393 torture_assert(tctx
, ok
, "failed to create smap");
395 DLIST_ADD_END(fss_gs
.sc_sets
, sc_set_a
, struct fss_sc_set
*);
396 fss_gs
.sc_sets_count
++;
397 DLIST_ADD_END(fss_gs
.sc_sets
, sc_set_b
, struct fss_sc_set
*);
398 fss_gs
.sc_sets_count
++;
400 DLIST_ADD_END(sc_set_a
->scs
, sc_aa
, struct fss_sc
*);
401 sc_set_a
->scs_count
++;
402 sc_aa
->sc_set
= sc_set_a
;
403 DLIST_ADD_END(sc_set_a
->scs
, sc_ab
, struct fss_sc
*);
404 sc_set_a
->scs_count
++;
405 sc_ab
->sc_set
= sc_set_a
;
407 DLIST_ADD_END(sc_aa
->smaps
, smap_aaa
, struct fss_sc_smap
*);
408 sc_aa
->smaps_count
++;
409 DLIST_ADD_END(sc_ab
->smaps
, smap_aba
, struct fss_sc_smap
*);
410 sc_ab
->smaps_count
++;
411 DLIST_ADD_END(sc_ab
->smaps
, smap_abb
, struct fss_sc_smap
*);
412 sc_ab
->smaps_count
++;
414 status
= fss_state_store(fss_gs
.mem_ctx
, fss_gs
.sc_sets
,
415 fss_gs
.sc_sets_count
, fss_gs
.db_path
);
416 torture_assert_ntstatus_ok(tctx
, status
,
417 "failed to store fss state");
419 memset(&fss_gr
, 0, sizeof(fss_gr
));
420 fss_gr
.mem_ctx
= talloc_new(NULL
);
421 fss_gr
.db_path
= db_path
;
422 status
= fss_state_retrieve(fss_gr
.mem_ctx
, &fss_gr
.sc_sets
,
423 &fss_gr
.sc_sets_count
, fss_gr
.db_path
);
424 torture_assert_ntstatus_ok(tctx
, status
,
425 "failed to retrieve fss state");
427 ok
= test_fsrvp_state_compare(tctx
, &fss_gs
, &fss_gr
);
428 torture_assert(tctx
, ok
,
429 "stored and retrieved state comparison failed");
431 talloc_free(fss_gs
.mem_ctx
);
432 talloc_free(fss_gr
.mem_ctx
);
435 talloc_free(db_path
);
440 static bool test_fsrvp_state_none(struct torture_context
*tctx
)
443 struct fss_global fss_global
;
444 char db_dir
[] = "fsrvp_torture_XXXXXX";
445 char *db_path
= talloc_asprintf(NULL
, "%s/%s",
446 mkdtemp(db_dir
), FSS_DB_NAME
);
448 memset(&fss_global
, 0, sizeof(fss_global
));
449 fss_global
.mem_ctx
= talloc_new(NULL
);
450 fss_global
.db_path
= db_path
;
452 status
= fss_state_retrieve(fss_global
.mem_ctx
, &fss_global
.sc_sets
,
453 &fss_global
.sc_sets_count
,
455 torture_assert_ntstatus_ok(tctx
, status
,
456 "failed to retrieve fss state");
457 torture_assert_int_equal(tctx
, fss_global
.sc_sets_count
, 0,
458 "sc_sets_count set when it should be zero");
459 talloc_free(fss_global
.mem_ctx
);
462 talloc_free(db_path
);
467 struct torture_suite
*torture_local_fsrvp(TALLOC_CTX
*mem_ctx
)
469 struct torture_suite
*suite
= torture_suite_create(mem_ctx
,
472 /* dbwrap uses talloc_tos(), hence we need a stackframe :( */
475 torture_suite_add_simple_test(suite
,
477 test_fsrvp_state_empty
);
479 torture_suite_add_simple_test(suite
,
481 test_fsrvp_state_single
);
483 torture_suite_add_simple_test(suite
,
485 test_fsrvp_state_multi
);
487 torture_suite_add_simple_test(suite
,
489 test_fsrvp_state_none
);