backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / virauthconfigtest.c
blob42e62cd874ac53f54606455c1086a96d46a0b2bf
1 /*
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/>.
19 #include <config.h>
21 #include <signal.h>
23 #include "testutils.h"
24 #include "virerror.h"
25 #include "viralloc.h"
26 #include "virlog.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;
36 const char *hostname;
37 const char *service;
38 const char *credname;
39 const char *expect;
42 static int testAuthLookup(const void *args)
44 int ret = -1;
45 const struct ConfigLookupData *data = args;
46 const char *actual = NULL;
47 int rv;
49 rv = virAuthConfigLookup(data->config,
50 data->service,
51 data->hostname,
52 data->credname,
53 &actual);
55 if (rv < 0)
56 goto cleanup;
58 if (data->expect) {
59 if (!actual ||
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,
64 NULLSTR(actual));
65 goto cleanup;
67 } else {
68 if (actual) {
69 VIR_WARN("Did not expect a value for '%s' '%s' '%s', but got '%s'",
70 data->hostname,
71 data->service, data->credname,
72 actual);
73 goto cleanup;
77 ret = 0;
78 cleanup:
79 return ret;
83 static int
84 mymain(void)
86 int ret = 0;
88 virAuthConfigPtr config;
90 signal(SIGPIPE, SIG_IGN);
92 #define TEST_LOOKUP(config, hostname, service, credname, expect) \
93 do { \
94 const struct ConfigLookupData data = { \
95 config, hostname, service, credname, expect \
96 }; \
97 if (virTestRun("Test Lookup " hostname "-" service "-" credname, \
98 testAuthLookup, &data) < 0) \
99 ret = -1; \
100 } while (0)
102 const char *confdata =
103 "[credentials-test]\n"
104 "username=fred\n"
105 "password=123456\n"
106 "\n"
107 "[credentials-prod]\n"
108 "username=bar\n"
109 "password=letmein\n"
110 "\n"
111 "[auth-libvirt-test1.example.com]\n"
112 "credentials=test\n"
113 "\n"
114 "[auth-libvirt-test2.example.com]\n"
115 "credentials=test\n"
116 "\n"
117 "[auth-libvirt-demo3.example.com]\n"
118 "credentials=test\n"
119 "\n"
120 "[auth-libvirt-prod1.example.com]\n"
121 "credentials=prod\n";
123 if (!(config = virAuthConfigNewData("auth.conf", confdata, strlen(confdata))))
124 return EXIT_FAILURE;
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)