source: vendor/current/auth/credentials/tests/simple.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

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