source: trunk/server/source4/auth/credentials/tests/simple.c

Last change on this file was 745, checked in by Silvan Scherrer, 13 years ago

Samba Server: updated trunk to 3.6.0

File size: 3.5 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
5
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.
10
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.
15
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/>.
18*/
19
20#include "includes.h"
21#include "auth/credentials/credentials.h"
22#include "torture/torture.h"
23
24static bool test_init(struct torture_context *tctx)
25{
26 struct cli_credentials *creds = cli_credentials_init(tctx);
27
28 cli_credentials_set_domain(creds, "bla", CRED_SPECIFIED);
29
30 torture_assert_str_equal(tctx, "BLA", cli_credentials_get_domain(creds),
31 "domain");
32
33 cli_credentials_set_username(creds, "someuser", CRED_SPECIFIED);
34
35 torture_assert_str_equal(tctx, "someuser",
36 cli_credentials_get_username(creds),
37 "username");
38
39 cli_credentials_set_password(creds, "p4ssw0rd", CRED_SPECIFIED);
40
41 torture_assert_str_equal(tctx, "p4ssw0rd",
42 cli_credentials_get_password(creds),
43 "password");
44
45 return true;
46}
47
48static bool test_init_anonymous(struct torture_context *tctx)
49{
50 struct cli_credentials *creds = cli_credentials_init_anon(tctx);
51
52 torture_assert_str_equal(tctx, cli_credentials_get_domain(creds),
53 "", "domain");
54
55 torture_assert_str_equal(tctx, cli_credentials_get_username(creds),
56 "", "username");
57
58 torture_assert(tctx, cli_credentials_get_password(creds) == NULL,
59 "password");
60
61 return true;
62}
63
64static bool test_parse_string(struct torture_context *tctx)
65{
66 struct cli_credentials *creds = cli_credentials_init_anon(tctx);
67
68 /* anonymous */
69 cli_credentials_parse_string(creds, "%", CRED_SPECIFIED);
70
71 torture_assert_str_equal(tctx, cli_credentials_get_domain(creds),
72 "", "domain");
73
74 torture_assert_str_equal(tctx, cli_credentials_get_username(creds),
75 "", "username");
76
77 torture_assert(tctx, cli_credentials_get_password(creds) == NULL,
78 "password");
79
80 /* username + password */
81 cli_credentials_parse_string(creds, "somebody%secret",
82 CRED_SPECIFIED);
83
84 torture_assert_str_equal(tctx, cli_credentials_get_domain(creds),
85 "", "domain");
86
87 torture_assert_str_equal(tctx, cli_credentials_get_username(creds),
88 "somebody", "username");
89
90 torture_assert_str_equal(tctx, cli_credentials_get_password(creds),
91 "secret", "password");
92
93 /* principal */
94 cli_credentials_parse_string(creds, "prin@styx",
95 CRED_SPECIFIED);
96
97 torture_assert_str_equal(tctx, cli_credentials_get_realm(creds),
98 "STYX", "realm");
99
100 torture_assert_str_equal(tctx,
101 cli_credentials_get_principal(creds, tctx),
102 "prin@styx", "principal");
103
104 return true;
105}
106
107struct torture_suite *torture_local_credentials(TALLOC_CTX *mem_ctx)
108{
109 struct torture_suite *suite = torture_suite_create(mem_ctx, "credentials");
110
111 torture_suite_add_simple_test(suite, "init", test_init);
112 torture_suite_add_simple_test(suite, "init anonymous",
113 test_init_anonymous);
114 torture_suite_add_simple_test(suite, "parse_string",
115 test_parse_string);
116
117 return suite;
118}
119
Note: See TracBrowser for help on using the repository browser.