File: proxy-core-test.c

package info (click to toggle)
globus-gsi-proxy-core 9.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,844 kB
  • sloc: ansic: 7,310; sh: 4,268; makefile: 92
file content (215 lines) | stat: -rw-r--r-- 5,871 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * Copyright 1999-2006 University of Chicago
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


#include "globus_common.h"
#include "globus_gsi_proxy.h"

#include <stdbool.h>

struct test_case
{
    const char                         *test_name;
    bool                              (*test_func)(void);
};

#define TEST_CASE_INITIALIZER(c) { #c, c }
#define ARRAY_LEN(x) sizeof(x)/sizeof(*x)

static
bool
create_req_null_test(void)
{
    bool                                ok = true;
    globus_result_t                     result = GLOBUS_SUCCESS;
    BIO                                *bio = BIO_new(BIO_s_mem());
    globus_gsi_proxy_handle_t           handle = NULL;

    result = globus_gsi_proxy_create_req(NULL, NULL);
    if (result == GLOBUS_SUCCESS)
    {
        ok = false;
    }
    result = globus_gsi_proxy_create_req(NULL, bio);
    if (result == GLOBUS_SUCCESS)
    {
        ok = false;
    }
    result = globus_gsi_proxy_handle_init(&handle, NULL);
    if (result != GLOBUS_SUCCESS)
    {
        ok = false;
        goto no_handle;
    }
    result = globus_gsi_proxy_create_req(handle, NULL);
    if (result == GLOBUS_SUCCESS)
    {
        ok = false;
    }
    globus_gsi_proxy_handle_destroy(handle);

no_handle:
    BIO_free(bio);
    return ok;
}

static
bool
inquire_req_null_test(void)
{
    bool                                ok = true;
    globus_result_t                     result = GLOBUS_SUCCESS;
    BIO                                *bio = BIO_new(BIO_s_mem());
    globus_gsi_proxy_handle_t           handle = NULL;

    result = globus_gsi_proxy_inquire_req(NULL, NULL);
    if (result == GLOBUS_SUCCESS)
    {
        ok = false;
    }
    result = globus_gsi_proxy_inquire_req(NULL, bio);
    if (result == GLOBUS_SUCCESS)
    {
        ok = false;
    }
    result = globus_gsi_proxy_handle_init(&handle, NULL);
    if (result != GLOBUS_SUCCESS)
    {
        ok = false;
        goto no_handle;
    }
    result = globus_gsi_proxy_inquire_req(handle, NULL);
    if (result == GLOBUS_SUCCESS)
    {
        ok = false;
    }
    globus_gsi_proxy_handle_destroy(handle);

no_handle:
    BIO_free(bio);
    return ok;
}

static
bool
create_inquire_req_test(void)
{
    bool                                ok = true;
    globus_result_t                     result = GLOBUS_SUCCESS;
    BIO                                *bio = NULL;
    globus_gsi_proxy_handle_t           delegatee_handle = NULL;
    globus_gsi_proxy_handle_t           delegator_handle = NULL;
    int                                 pci_languages[] =
    {
        NID_id_ppl_inheritAll,
        NID_Independent,
    };
    size_t                              num_policies = ARRAY_LEN(pci_languages);
    int                                 lang = 0;
    unsigned char                      *data = NULL;
    int                                 data_len = 0;

    for (size_t i = 0; i < num_policies; i++)
    {
        bio = BIO_new(BIO_s_mem());
        if (bio == NULL)
        {
            ok = false;
            continue;
        }
        result = globus_gsi_proxy_handle_init(&delegatee_handle, NULL);
        if (result != GLOBUS_SUCCESS)
        {
            ok = false;
            goto no_delegatee_handle;
        }
        result = globus_gsi_proxy_handle_init(&delegator_handle, NULL);
        if (result != GLOBUS_SUCCESS)
        {
            ok = false;
            goto no_delegator_handle;
        }
        result = globus_gsi_proxy_handle_set_policy(
                delegatee_handle,
                NULL,
                0,
                pci_languages[i]);
        if (result != GLOBUS_SUCCESS)
        {
            ok = false;
        }

        result = globus_gsi_proxy_create_req(delegatee_handle, bio);
        if (result != GLOBUS_SUCCESS)
        {
            ok = false;
        }
        result = globus_gsi_proxy_inquire_req(delegator_handle, bio);
        if (result != GLOBUS_SUCCESS)
        {
            ok = false;
        }
        result = globus_gsi_proxy_handle_get_policy(delegator_handle, &data, &data_len, &lang);
        if (result != GLOBUS_SUCCESS)
        {
            ok = false;
        }
        if (lang != pci_languages[i])
        {
            ok = false;
        }
        globus_gsi_proxy_handle_destroy(delegator_handle);
no_delegator_handle:
        globus_gsi_proxy_handle_destroy(delegatee_handle);
no_delegatee_handle:
        BIO_free(bio);
    }

    return ok;
}

int
main(int argc, char *argv[])
{
    struct test_case                    test_cases[] =
    {
        TEST_CASE_INITIALIZER(create_req_null_test),
        TEST_CASE_INITIALIZER(inquire_req_null_test),
        TEST_CASE_INITIALIZER(create_inquire_req_test),
    };
    size_t                              num_test_cases = sizeof(test_cases)/sizeof(test_cases[0]);
    int                                 failed = 0;

    globus_module_activate(GLOBUS_GSI_PROXY_MODULE);

    printf("1..%zu\n", num_test_cases);

    for (size_t i = 0; i < num_test_cases; i++)
    {
        if (test_cases[i].test_func())
        {
            printf("ok %zu - %s\n", i+1, test_cases[i].test_name);
        }
        else
        {
            failed++;
            printf("not ok %zu - %s\n", i+1, test_cases[i].test_name);
        }
    }
    globus_module_deactivate(GLOBUS_GSI_PROXY_MODULE);

    return failed;
}