2
* Copyright (C) 2012 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, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
* Author: Daniel P. Berrange <berrange@redhat.com>
26
#include "testutils.h"
28
#include "virterror_internal.h"
32
#include "virauthconfig.h"
34
#define VIR_FROM_THIS VIR_FROM_RPC
36
struct ConfigLookupData {
37
virAuthConfigPtr config;
44
static int testAuthLookup(const void *args)
47
const struct ConfigLookupData *data = args;
48
const char *actual = NULL;
51
rv = virAuthConfigLookup(data->config,
62
!STREQ(actual, data->expect)) {
63
VIR_WARN("Expected value '%s' for '%s' '%s' '%s', but got '%s'",
64
data->expect, data->hostname,
65
data->service, data->credname,
71
VIR_WARN("Did not expect a value for '%s' '%s' '%s', but got '%s'",
73
data->service, data->credname,
90
virAuthConfigPtr config;
92
signal(SIGPIPE, SIG_IGN);
94
#define TEST_LOOKUP(config, hostname, service, credname, expect) \
96
const struct ConfigLookupData data = { \
97
config, hostname, service, credname, expect \
99
if (virtTestRun("Test Lookup " hostname "-" service "-" credname, \
100
1, testAuthLookup, &data) < 0) \
104
const char *confdata =
105
"[credentials-test]\n"
109
"[credentials-prod]\n"
113
"[auth-libvirt-test1.example.com]\n"
116
"[auth-libvirt-test2.example.com]\n"
119
"[auth-libvirt-demo3.example.com]\n"
122
"[auth-libvirt-prod1.example.com]\n"
123
"credentials=prod\n";
125
if (!(config = virAuthConfigNewData("auth.conf", confdata, strlen(confdata))))
128
TEST_LOOKUP(config, "test1.example.com", "libvirt", "username", "fred");
129
TEST_LOOKUP(config, "test1.example.com", "vnc", "username", NULL);
130
TEST_LOOKUP(config, "test1.example.com", "libvirt", "realm", NULL);
131
TEST_LOOKUP(config, "test66.example.com", "libvirt", "username", NULL);
132
TEST_LOOKUP(config, "prod1.example.com", "libvirt", "username", "bar");
133
TEST_LOOKUP(config, "prod1.example.com", "libvirt", "password", "letmein");
135
virAuthConfigFree(config);
137
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
140
VIRT_TEST_MAIN(mymain)