Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 :
4 : local testing of share code
5 :
6 : Copyright (C) Jelmer Vernooij 2007
7 :
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.
12 :
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.
17 :
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/>.
20 : */
21 :
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"
27 :
28 1 : static bool test_list_empty(struct torture_context *tctx,
29 : const void *tcase_data,
30 : const void *test_data)
31 : {
32 1 : struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
33 1 : int count;
34 1 : const char **names;
35 :
36 1 : torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
37 : "share_list_all failed");
38 :
39 1 : return true;
40 : }
41 :
42 1 : static bool test_create(struct torture_context *tctx,
43 : const void *tcase_data,
44 : const void *test_data)
45 : {
46 1 : struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
47 1 : int count;
48 1 : const char **names;
49 1 : int i;
50 1 : bool found = false;
51 1 : 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") }
54 : };
55 1 : NTSTATUS status;
56 :
57 1 : status = share_create(ctx, "bloe", inf, 2);
58 :
59 1 : if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
60 1 : torture_skip(tctx, "Not supported by backend");
61 :
62 0 : torture_assert_ntstatus_ok(tctx, status, "create_share failed");
63 :
64 0 : torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
65 : "share_list_all failed");
66 :
67 0 : torture_assert(tctx, count >= 1, "creating share failed");
68 :
69 :
70 0 : for (i = 0; i < count; i++) {
71 0 : found |= strcmp(names[i], "bloe") == 0;
72 : }
73 :
74 0 : torture_assert(tctx, found, "created share found");
75 :
76 0 : return true;
77 : }
78 :
79 :
80 1 : static bool test_create_invalid(struct torture_context *tctx,
81 : const void *tcase_data,
82 : const void *test_data)
83 : {
84 1 : struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
85 1 : NTSTATUS status;
86 :
87 1 : status = share_create(ctx, "bla", NULL, 0);
88 :
89 1 : if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
90 1 : torture_skip(tctx, "Not supported by backend");
91 :
92 0 : torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
93 : status,
94 : "create_share failed");
95 :
96 0 : torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
97 : share_create(ctx, NULL, NULL, 0),
98 : "create_share failed");
99 :
100 0 : return true;
101 : }
102 :
103 1 : static bool test_share_remove_invalid(struct torture_context *tctx,
104 : const void *tcase_data,
105 : const void *test_data)
106 : {
107 1 : struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
108 1 : NTSTATUS status;
109 :
110 1 : status = share_remove(ctx, "nonexistent");
111 :
112 1 : if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
113 1 : torture_skip(tctx, "Not supported by backend");
114 :
115 0 : torture_assert_ntstatus_equal(tctx, status, NT_STATUS_UNSUCCESSFUL, "remove fails");
116 :
117 0 : return true;
118 : }
119 :
120 :
121 :
122 1 : static bool test_share_remove(struct torture_context *tctx,
123 : const void *tcase_data,
124 : const void *test_data)
125 : {
126 1 : struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
127 1 : 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") }
130 : };
131 1 : NTSTATUS status;
132 :
133 1 : status = share_create(ctx, "blie", inf, 2);
134 :
135 1 : if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
136 1 : torture_skip(tctx, "Not supported by backend");
137 :
138 0 : torture_assert_ntstatus_ok(tctx, status, "create_share failed");
139 :
140 0 : torture_assert_ntstatus_ok(tctx, share_remove(ctx, "blie"), "remove failed");
141 :
142 0 : return true;
143 : }
144 :
145 1 : static bool test_double_create(struct torture_context *tctx,
146 : const void *tcase_data,
147 : const void *test_data)
148 : {
149 1 : struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
150 1 : 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") }
153 : };
154 1 : NTSTATUS status;
155 :
156 1 : status = share_create(ctx, "bla", inf, 2);
157 :
158 1 : if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
159 1 : torture_skip(tctx, "Not supported by backend");
160 :
161 0 : torture_assert_ntstatus_ok(tctx, status, "create_share failed");
162 :
163 0 : torture_assert_ntstatus_equal(tctx, NT_STATUS_OBJECT_NAME_COLLISION,
164 : share_create(ctx, "bla", inf, 2),
165 : "create_share failed");
166 :
167 0 : return true;
168 : }
169 :
170 2354 : static void tcase_add_share_tests(struct torture_tcase *tcase)
171 : {
172 2354 : torture_tcase_add_test_const(tcase, "list_empty", test_list_empty,NULL);
173 2354 : torture_tcase_add_test_const(tcase, "share_create", test_create, NULL);
174 2354 : torture_tcase_add_test_const(tcase, "share_remove", test_share_remove,
175 : NULL);
176 2354 : torture_tcase_add_test_const(tcase, "share_remove_invalid",
177 : test_share_remove_invalid, NULL);
178 2354 : torture_tcase_add_test_const(tcase, "share_create_invalid",
179 : test_create_invalid, NULL);
180 2354 : torture_tcase_add_test_const(tcase, "share_double_create",
181 : test_double_create, NULL);
182 2354 : }
183 :
184 1 : static bool setup_classic(struct torture_context *tctx, void **data)
185 : {
186 1 : return NT_STATUS_IS_OK(share_get_context(tctx, tctx->lp_ctx, (struct share_context **)data));
187 : }
188 :
189 1 : static bool teardown(struct torture_context *tctx, void *data)
190 : {
191 1 : talloc_free(data);
192 1 : return true;
193 : }
194 :
195 2354 : struct torture_suite *torture_local_share(TALLOC_CTX *mem_ctx)
196 : {
197 2354 : struct torture_suite *suite = torture_suite_create(mem_ctx, "share");
198 125 : struct torture_tcase *tcase;
199 :
200 2354 : share_init();
201 :
202 2354 : tcase = torture_suite_add_tcase(suite, "classic");
203 2354 : torture_tcase_set_fixture(tcase, setup_classic, teardown);
204 2354 : tcase_add_share_tests(tcase);
205 :
206 2354 : return suite;
207 : }
|