tests/krb5: Add method to determine if principal is krbtgt
[Samba.git] / source4 / param / tests / share.c
blob9ac43bac9f2b9564efdb856c9b7c41a066823016
1 /*
2 Unix SMB/CIFS implementation.
4 local testing of share code
6 Copyright (C) Jelmer Vernooij 2007
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/>.
22 #include "includes.h"
23 #include "param/share.h"
24 #include "param/param.h"
25 #include "torture/torture.h"
26 #include "torture/local/proto.h"
28 static bool test_list_empty(struct torture_context *tctx,
29 const void *tcase_data,
30 const void *test_data)
32 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
33 int count;
34 const char **names;
36 torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
37 "share_list_all failed");
39 return true;
42 static bool test_create(struct torture_context *tctx,
43 const void *tcase_data,
44 const void *test_data)
46 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
47 int count;
48 const char **names;
49 int i;
50 bool found = false;
51 struct share_info inf[] = {
52 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
53 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
55 NTSTATUS status;
57 status = share_create(ctx, "bloe", inf, 2);
59 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
60 torture_skip(tctx, "Not supported by backend");
62 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
64 torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
65 "share_list_all failed");
67 torture_assert(tctx, count >= 1, "creating share failed");
70 for (i = 0; i < count; i++) {
71 found |= strcmp(names[i], "bloe") == 0;
74 torture_assert(tctx, found, "created share found");
76 return true;
80 static bool test_create_invalid(struct torture_context *tctx,
81 const void *tcase_data,
82 const void *test_data)
84 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
85 NTSTATUS status;
87 status = share_create(ctx, "bla", NULL, 0);
89 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
90 torture_skip(tctx, "Not supported by backend");
92 torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
93 status,
94 "create_share failed");
96 torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
97 share_create(ctx, NULL, NULL, 0),
98 "create_share failed");
100 return true;
103 static bool test_share_remove_invalid(struct torture_context *tctx,
104 const void *tcase_data,
105 const void *test_data)
107 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
108 NTSTATUS status;
110 status = share_remove(ctx, "nonexistent");
112 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
113 torture_skip(tctx, "Not supported by backend");
115 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_UNSUCCESSFUL, "remove fails");
117 return true;
122 static bool test_share_remove(struct torture_context *tctx,
123 const void *tcase_data,
124 const void *test_data)
126 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
127 struct share_info inf[] = {
128 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
129 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
131 NTSTATUS status;
133 status = share_create(ctx, "blie", inf, 2);
135 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
136 torture_skip(tctx, "Not supported by backend");
138 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
140 torture_assert_ntstatus_ok(tctx, share_remove(ctx, "blie"), "remove failed");
142 return true;
145 static bool test_double_create(struct torture_context *tctx,
146 const void *tcase_data,
147 const void *test_data)
149 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
150 struct share_info inf[] = {
151 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
152 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
154 NTSTATUS status;
156 status = share_create(ctx, "bla", inf, 2);
158 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
159 torture_skip(tctx, "Not supported by backend");
161 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
163 torture_assert_ntstatus_equal(tctx, NT_STATUS_OBJECT_NAME_COLLISION,
164 share_create(ctx, "bla", inf, 2),
165 "create_share failed");
167 return true;
170 static void tcase_add_share_tests(struct torture_tcase *tcase)
172 torture_tcase_add_test_const(tcase, "list_empty", test_list_empty,NULL);
173 torture_tcase_add_test_const(tcase, "share_create", test_create, NULL);
174 torture_tcase_add_test_const(tcase, "share_remove", test_share_remove,
175 NULL);
176 torture_tcase_add_test_const(tcase, "share_remove_invalid",
177 test_share_remove_invalid, NULL);
178 torture_tcase_add_test_const(tcase, "share_create_invalid",
179 test_create_invalid, NULL);
180 torture_tcase_add_test_const(tcase, "share_double_create",
181 test_double_create, NULL);
184 static bool setup_classic(struct torture_context *tctx, void **data)
186 return NT_STATUS_IS_OK(share_get_context(tctx, tctx->lp_ctx, (struct share_context **)data));
189 static bool teardown(struct torture_context *tctx, void *data)
191 talloc_free(data);
192 return true;
195 struct torture_suite *torture_local_share(TALLOC_CTX *mem_ctx)
197 struct torture_suite *suite = torture_suite_create(mem_ctx, "share");
198 struct torture_tcase *tcase;
200 share_init();
202 tcase = torture_suite_add_tcase(suite, "classic");
203 torture_tcase_set_fixture(tcase, setup_classic, teardown);
204 tcase_add_share_tests(tcase);
206 return suite;