1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | local testing of random data routines.
|
---|
5 |
|
---|
6 | Copyright (C) Jelmer Vernooij <jelmer@samba.org>
|
---|
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 "torture/torture.h"
|
---|
24 |
|
---|
25 | static void dummy_reseed(void *userdata, int *d)
|
---|
26 | {
|
---|
27 | *d = 42;
|
---|
28 | }
|
---|
29 |
|
---|
30 | static bool test_reseed_callback(struct torture_context *tctx)
|
---|
31 | {
|
---|
32 | set_rand_reseed_callback(dummy_reseed, NULL);
|
---|
33 | return true;
|
---|
34 | }
|
---|
35 |
|
---|
36 | static bool test_check_password_quality(struct torture_context *tctx)
|
---|
37 | {
|
---|
38 | torture_assert(tctx, !check_password_quality(""), "empty password");
|
---|
39 | torture_assert(tctx, !check_password_quality("a"), "one char password");
|
---|
40 | torture_assert(tctx, !check_password_quality("aaaaaaaaaaaa"), "same char password");
|
---|
41 | torture_assert(tctx, !check_password_quality("BLA"), "multiple upcases password");
|
---|
42 | torture_assert(tctx, !check_password_quality("123"), "digits only");
|
---|
43 | torture_assert(tctx, !check_password_quality("matthiéu"), "not enough high symbols");
|
---|
44 | torture_assert(tctx, check_password_quality("abcdééà çÚ"), "valid");
|
---|
45 | torture_assert(tctx, check_password_quality("A2e"), "valid");
|
---|
46 | torture_assert(tctx, check_password_quality("BA2eLi443"), "valid");
|
---|
47 | return true;
|
---|
48 | }
|
---|
49 |
|
---|
50 | static bool test_generate_random_str(struct torture_context *tctx)
|
---|
51 | {
|
---|
52 | TALLOC_CTX *mem_ctx = talloc_init(__FUNCTION__);
|
---|
53 | char *r = generate_random_str(mem_ctx, 10);
|
---|
54 | torture_assert_int_equal(tctx, strlen(r), 10, "right length generated");
|
---|
55 | r = generate_random_str(mem_ctx, 5);
|
---|
56 | torture_assert_int_equal(tctx, strlen(r), 5, "right length generated");
|
---|
57 | return true;
|
---|
58 | }
|
---|
59 |
|
---|
60 | struct torture_suite *torture_local_genrand(TALLOC_CTX *mem_ctx)
|
---|
61 | {
|
---|
62 | struct torture_suite *suite = torture_suite_create(mem_ctx, "GENRAND");
|
---|
63 | torture_suite_add_simple_test(suite, "reseed_callback", test_reseed_callback);
|
---|
64 | torture_suite_add_simple_test(suite, "check_password_quality", test_check_password_quality);
|
---|
65 | torture_suite_add_simple_test(suite, "generate_random_str", test_generate_random_str);
|
---|
66 | return suite;
|
---|
67 | }
|
---|