2 * Copyright (C) 2012, 2014 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
23 #include "testutils.h"
28 #include "virauthconfig.h"
30 #define VIR_FROM_THIS VIR_FROM_RPC
32 VIR_LOG_INIT("tests.authconfigtest");
34 struct ConfigLookupData
{
35 virAuthConfigPtr config
;
42 static int testAuthLookup(const void *args
)
45 const struct ConfigLookupData
*data
= args
;
46 const char *actual
= NULL
;
49 rv
= virAuthConfigLookup(data
->config
,
60 STRNEQ(actual
, data
->expect
)) {
61 VIR_WARN("Expected value '%s' for '%s' '%s' '%s', but got '%s'",
62 data
->expect
, data
->hostname
,
63 data
->service
, data
->credname
,
69 VIR_WARN("Did not expect a value for '%s' '%s' '%s', but got '%s'",
71 data
->service
, data
->credname
,
88 virAuthConfigPtr config
;
90 signal(SIGPIPE
, SIG_IGN
);
92 #define TEST_LOOKUP(config, hostname, service, credname, expect) \
94 const struct ConfigLookupData data = { \
95 config, hostname, service, credname, expect \
97 if (virTestRun("Test Lookup " hostname "-" service "-" credname, \
98 testAuthLookup, &data) < 0) \
102 const char *confdata
=
103 "[credentials-test]\n"
107 "[credentials-prod]\n"
111 "[auth-libvirt-test1.example.com]\n"
114 "[auth-libvirt-test2.example.com]\n"
117 "[auth-libvirt-demo3.example.com]\n"
120 "[auth-libvirt-prod1.example.com]\n"
121 "credentials=prod\n";
123 if (!(config
= virAuthConfigNewData("auth.conf", confdata
, strlen(confdata
))))
126 TEST_LOOKUP(config
, "test1.example.com", "libvirt", "username", "fred");
127 TEST_LOOKUP(config
, "test1.example.com", "vnc", "username", NULL
);
128 TEST_LOOKUP(config
, "test1.example.com", "libvirt", "realm", NULL
);
129 TEST_LOOKUP(config
, "test66.example.com", "libvirt", "username", NULL
);
130 TEST_LOOKUP(config
, "prod1.example.com", "libvirt", "username", "bar");
131 TEST_LOOKUP(config
, "prod1.example.com", "libvirt", "password", "letmein");
133 virAuthConfigFree(config
);
135 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
138 VIR_TEST_MAIN(mymain
)