Skip to content

Commit 8788d9e

Browse files
committed
test: use helper.c/libtest.la for all test and test-cmd as well
Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 1d5c7d6 commit 8788d9e

File tree

3 files changed

+18
-96
lines changed

3 files changed

+18
-96
lines changed

test/Makefile.am

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,6 @@ endif
2929

3030
noinst_HEADERS = helper.h
3131

32-
LDADD = ${top_builddir}/src/libauth_openidc.la ${LIBADD}
33-
34-
noinst_PROGRAMS = test-cmd
35-
test_cmd_SOURCES = test-cmd.c stub.c
36-
test_cmd_CFLAGS = ${AM_CFLAGS} -fPIC
37-
38-
TESTS = test
39-
40-
test_SOURCES = test.c stub.c
41-
test_CFLAGS = ${AM_CFLAGS} -fPIC
42-
43-
if HAVE_CHECK
44-
4532
noinst_LTLIBRARIES = libtest.la
4633

4734
libtest_la_CFLAGS = ${AM_CFLAGS} -fPIC
@@ -50,8 +37,16 @@ libtest_la_SOURCES = \
5037
helper.c \
5138
stub.c
5239

40+
LDADD = ${top_builddir}/src/libauth_openidc.la libtest.la ${LIBADD}
41+
42+
noinst_PROGRAMS = test-cmd
43+
44+
TESTS = test
45+
46+
if HAVE_CHECK
47+
5348
AM_CFLAGS += @CHECK_CFLAGS@
54-
LDADD += libtest.la @CHECK_LIBS@
49+
LDADD += @CHECK_LIBS@
5550

5651
TESTS += \
5752
test_cfg \

test/helper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@
5555
void oidc_test_setup(void);
5656
void oidc_test_teardown(void);
5757
int oidc_test_suite_run(Suite *s);
58-
apr_pool_t *oidc_test_pool_get();
59-
request_rec *oidc_test_request_get();
60-
oidc_cfg_t *oidc_test_cfg_get();
58+
apr_pool_t *oidc_test_pool_get(void);
59+
request_rec *oidc_test_request_get(void);
60+
oidc_cfg_t *oidc_test_cfg_get(void);
6161
cmd_parms *oidc_test_cmd_get(const char *primitive);
6262

6363
#ifndef _ck_assert_ptr_null

test/test.c

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include <openssl/evp.h>
5353
#include <openssl/hmac.h>
5454

55+
#include "helper.h"
56+
5557
static int test_nr_run = 0;
5658
static char TST_ERR_MSG[4096];
5759
static int TST_RC;
@@ -1419,95 +1421,20 @@ static char *all_tests(apr_pool_t *pool, request_rec *r) {
14191421
return 0;
14201422
}
14211423

1422-
static request_rec *test_setup(apr_pool_t *pool) {
1423-
const unsigned int kIdx = 0;
1424-
const unsigned int kEls = kIdx + 1;
1425-
request_rec *request = (request_rec *)apr_pcalloc(pool, sizeof(request_rec));
1426-
1427-
apr_pool_create(&request->pool, pool);
1428-
request->subprocess_env = apr_table_make(request->pool, 0);
1429-
1430-
request->headers_in = apr_table_make(request->pool, 0);
1431-
request->headers_out = apr_table_make(request->pool, 0);
1432-
request->err_headers_out = apr_table_make(request->pool, 0);
1433-
1434-
apr_table_set(request->headers_in, "Host", "www.example.com");
1435-
apr_table_set(request->headers_in, "OIDC_foo", "some-value");
1436-
apr_table_set(request->headers_in, "Cookie",
1437-
"foo=bar; "
1438-
"mod_auth_openidc_session"
1439-
"=0123456789abcdef; baz=zot");
1440-
1441-
request->server = apr_pcalloc(request->pool, sizeof(struct server_rec));
1442-
request->server->process = apr_pcalloc(request->pool, sizeof(struct process_rec));
1443-
apr_pool_create(&request->server->process->pool, pool);
1444-
apr_pool_create(&request->server->process->pconf, pool);
1445-
request->connection = apr_pcalloc(request->pool, sizeof(struct conn_rec));
1446-
request->connection->bucket_alloc = apr_bucket_alloc_create(request->pool);
1447-
request->connection->local_addr = apr_pcalloc(request->pool, sizeof(apr_sockaddr_t));
1448-
1449-
apr_pool_userdata_set("https", "scheme", NULL, request->pool);
1450-
request->server->server_hostname = "www.example.com";
1451-
request->connection->local_addr->port = 443;
1452-
request->unparsed_uri = "/bla?foo=bar&param1=value1";
1453-
request->args = "foo=bar&param1=value1";
1454-
apr_uri_parse(request->pool, "https://www.example.com/bla?foo=bar&param1=value1", &request->parsed_uri);
1455-
1456-
auth_openidc_module.module_index = kIdx;
1457-
oidc_cfg_t *cfg = oidc_cfg_server_create(request->server->process->pconf, request->server);
1458-
1459-
oidc_cfg_provider_issuer_set(request->server->process->pconf, oidc_cfg_provider_get(cfg),
1460-
"https://idp.example.com");
1461-
oidc_cfg_provider_authorization_endpoint_url_set(request->server->process->pconf, oidc_cfg_provider_get(cfg),
1462-
"https://idp.example.com/authorize");
1463-
oidc_cfg_provider_client_id_set(request->server->process->pconf, oidc_cfg_provider_get(cfg), "client_id");
1464-
1465-
cfg->redirect_uri = "https://www.example.com/protected/";
1466-
1467-
oidc_dir_cfg_t *d_cfg = oidc_cfg_dir_config_create(request->server->process->pconf, NULL);
1468-
1469-
// coverity[suspicious_sizeof]
1470-
request->server->module_config = apr_pcalloc(request->server->process->pconf, sizeof(void *) * kEls);
1471-
// coverity[suspicious_sizeof]
1472-
request->per_dir_config = apr_pcalloc(request->server->process->pconf, sizeof(void *) * kEls);
1473-
ap_set_module_config(request->server->module_config, &auth_openidc_module, cfg);
1474-
ap_set_module_config(request->per_dir_config, &auth_openidc_module, d_cfg);
1475-
1476-
cfg->crypto_passphrase.secret1 = "12345678901234567890123456789012";
1477-
cfg->cache.impl = &oidc_cache_shm;
1478-
cfg->cache.cfg = NULL;
1479-
cfg->cache.shm_size_max = 500;
1480-
cfg->cache.shm_entry_size_max = 16384 + 255 + 17;
1481-
cfg->cache.encrypt = 1;
1482-
if (oidc_cfg_post_config(request->server->process->pconf, cfg, request->server) != OK) {
1483-
printf("cfg->cache.impl->post_config failed!\n");
1484-
exit(-1);
1485-
}
1486-
1487-
return request;
1488-
}
1489-
14901424
int main(int argc, char **argv, char **env) {
1491-
if (apr_app_initialize(&argc, (const char *const **)argv, (const char *const **)env) != APR_SUCCESS) {
1492-
printf("apr_app_initialize failed\n");
1493-
return -1;
1494-
}
14951425

1496-
oidc_pre_config_init();
1426+
oidc_test_setup();
14971427

1498-
apr_pool_t *pool = NULL;
1499-
apr_pool_create(&pool, NULL);
1500-
request_rec *r = test_setup(pool);
1428+
request_rec *r = oidc_test_request_get();
15011429

1502-
char *result = all_tests(pool, r);
1430+
char *result = all_tests(oidc_test_pool_get(), r);
15031431
if (result != 0) {
15041432
printf("Failed: %s\n", result);
15051433
} else {
15061434
printf("All %d tests passed!\n", test_nr_run);
15071435
}
15081436

1509-
EVP_cleanup();
1510-
apr_terminate();
1437+
oidc_test_teardown();
15111438

15121439
return result != 0;
15131440
}

0 commit comments

Comments
 (0)