~serge-hallyn/ubuntu/raring/libvirt/libvirt-hugepages

« back to all changes in this revision

Viewing changes to tests/virauthconfigtest.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-13 15:44:12 UTC
  • mfrom: (1.2.13)
  • Revision ID: package-import@ubuntu.com-20120513154412-fgmn5sxqdzgnzlx3
Tags: 0.9.12-0ubuntu1
* New upstream version:
  * Synchronize with debian packaging:
    - debian/control: Update build depends.
    - debian/libvirt-bin.postrm: Cleanup /var/log/libvirt
      on purge.
    - Bump standards verson (no changes).
    - debian/patches/Don-t-fail-if-we-can-t-setup-avahi.patch: Added
  * Dropped patches:
    - debian/patches/Debianize-libvirt-guests.patch
    - debian/patches/rewrite-lxc-controller-eof-handling-yet-again
    - debian/patches/ubuntu/libnl13.patch
    - debian/patches/ubuntu/fix-lxc-startup-error.patch
    - debian/patches/ubuntu/fix-bridge-fd.patch
    - debian/patches/ubuntu/skip-labelling-network-disks.patch
    - debian/patches/ubuntu/xen-xend-shutdown-detection.patch
    - debian/patches/ubuntu/xen-config-no-vfb-for-hvm.patch
    - debian/patches/debian/Disable-daemon-start-test.patch
    - debian/patches/debian/Disable-gnulib-s-test-nonplocking-pipe.sh.patch
    - debian/patches/ubuntu/9006-default-config-test-case.patch
    - debian/patches/fix-block-migration.patch
    - debian/patches/ubuntu/9022-qemu-unescape-HMP-commands-before-converting-them-to.patch
    - debian/patches/ubuntu/9023-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/9024-qemu-allow-snapshotting-of-sheepdog-and-rbd-disks.patch
    - debian/patches/9025-qemu-change-rbd-auth_supported-separation-character-.patch
    - debian/patches/ubuntu/arm-gcc-workaround.patch
  * Rediffed:
    - debian/patches/Allow-libvirt-group-to-access-the-socket.patch
    - debian/patches/Disable-failing-virnetsockettest.patch
    - debian/patches/dnsmasq-as-priv-user
    - debian/patches/9002-better_default_uri_virsh.patch
  * debian/control: Add libnl-route-3-dev ass a build depends.
  * debian/patches/libnl3-build-fix.patch: Fix build with libnl3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Red Hat, Inc.
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 *
 
18
 * Author: Daniel P. Berrange <berrange@redhat.com>
 
19
 */
 
20
 
 
21
#include <config.h>
 
22
 
 
23
#include <stdlib.h>
 
24
#include <signal.h>
 
25
 
 
26
#include "testutils.h"
 
27
#include "util.h"
 
28
#include "virterror_internal.h"
 
29
#include "memory.h"
 
30
#include "logging.h"
 
31
 
 
32
#include "virauthconfig.h"
 
33
 
 
34
#define VIR_FROM_THIS VIR_FROM_RPC
 
35
 
 
36
struct ConfigLookupData {
 
37
    virAuthConfigPtr config;
 
38
    const char *hostname;
 
39
    const char *service;
 
40
    const char *credname;
 
41
    const char *expect;
 
42
};
 
43
 
 
44
static int testAuthLookup(const void *args)
 
45
{
 
46
    int ret = -1;
 
47
    const struct ConfigLookupData *data = args;
 
48
    const char *actual = NULL;
 
49
    int rv;
 
50
 
 
51
    rv = virAuthConfigLookup(data->config,
 
52
                             data->service,
 
53
                             data->hostname,
 
54
                             data->credname,
 
55
                             &actual);
 
56
 
 
57
    if (rv < 0)
 
58
        goto cleanup;
 
59
 
 
60
    if (data->expect) {
 
61
        if (!actual ||
 
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,
 
66
                     NULLSTR(actual));
 
67
            goto cleanup;
 
68
        }
 
69
    } else {
 
70
        if (actual) {
 
71
            VIR_WARN("Did not expect a value for '%s' '%s' '%s', but got '%s'",
 
72
                     data->hostname,
 
73
                     data->service, data->credname,
 
74
                     actual);
 
75
            goto cleanup;
 
76
        }
 
77
    }
 
78
 
 
79
    ret = 0;
 
80
cleanup:
 
81
    return ret;
 
82
}
 
83
 
 
84
 
 
85
static int
 
86
mymain(void)
 
87
{
 
88
    int ret = 0;
 
89
 
 
90
    virAuthConfigPtr config;
 
91
 
 
92
    signal(SIGPIPE, SIG_IGN);
 
93
 
 
94
#define TEST_LOOKUP(config, hostname, service, credname, expect)        \
 
95
    do  {                                                               \
 
96
        const struct ConfigLookupData data = {                          \
 
97
            config, hostname, service, credname, expect                 \
 
98
        };                                                              \
 
99
        if (virtTestRun("Test Lookup " hostname "-" service "-" credname, \
 
100
                        1, testAuthLookup, &data) < 0)                   \
 
101
            ret = -1;                                                   \
 
102
    } while (0)
 
103
 
 
104
    const char *confdata =
 
105
        "[credentials-test]\n"
 
106
        "username=fred\n"
 
107
        "password=123456\n"
 
108
        "\n"
 
109
        "[credentials-prod]\n"
 
110
        "username=bar\n"
 
111
        "password=letmein\n"
 
112
        "\n"
 
113
        "[auth-libvirt-test1.example.com]\n"
 
114
        "credentials=test\n"
 
115
        "\n"
 
116
        "[auth-libvirt-test2.example.com]\n"
 
117
        "credentials=test\n"
 
118
        "\n"
 
119
        "[auth-libvirt-demo3.example.com]\n"
 
120
        "credentials=test\n"
 
121
        "\n"
 
122
        "[auth-libvirt-prod1.example.com]\n"
 
123
        "credentials=prod\n";
 
124
 
 
125
    if (!(config = virAuthConfigNewData("auth.conf", confdata, strlen(confdata))))
 
126
        return EXIT_FAILURE;
 
127
 
 
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");
 
134
 
 
135
    virAuthConfigFree(config);
 
136
 
 
137
    return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
 
138
}
 
139
 
 
140
VIRT_TEST_MAIN(mymain)