Skip to content

Commit 70b2bd6

Browse files
committed
add test_cfg base
Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 91b2bd2 commit 70b2bd6

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

test/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
/test_util
1515
/Makefile
1616
/Makefile.in
17+
/test_cfg

test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ test_util_CFLAGS = @CHECK_CFLAGS@ ${AM_CFLAGS}
5252
test_util_LDADD = @CHECK_LIBS@ ${LDADD}
5353
test_util_SOURCES = test_util.c helper.c stub.c
5454

55+
TESTS += test_cfg
56+
test_cfg_CFLAGS = @CHECK_CFLAGS@ ${AM_CFLAGS}
57+
test_cfg_LDADD = @CHECK_LIBS@ ${LDADD}
58+
test_cfg_SOURCES = test_cfg.c helper.c stub.c
59+
5560
endif
5661

5762
check_PROGRAMS = $(TESTS)

test/helper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ static request_rec *oidc_test_request_init(apr_pool_t *pool) {
102102
ap_set_module_config(request->server->module_config, &auth_openidc_module, cfg);
103103
ap_set_module_config(request->per_dir_config, &auth_openidc_module, d_cfg);
104104

105+
// TODO:
106+
cfg->public_keys = apr_array_make(pool, 1, sizeof(const char *));
107+
cfg->private_keys = apr_array_make(pool, 1, sizeof(const char *));
108+
105109
cfg->crypto_passphrase.secret1 = "12345678901234567890123456789012";
106110
cfg->cache.impl = &oidc_cache_shm;
107111
cfg->cache.cfg = NULL;

test/test_cfg.c

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/***************************************************************************
21+
* Copyright (C) 2017-2025 ZmartZone Holding BV
22+
* All rights reserved.
23+
*
24+
* DISCLAIMER OF WARRANTIES:
25+
*
26+
* THE SOFTWARE PROVIDED HEREUNDER IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
27+
* ANY WARRANTIES OR REPRESENTATIONS EXPRESS, IMPLIED OR STATUTORY; INCLUDING,
28+
* WITHOUT LIMITATION, WARRANTIES OF QUALITY, PERFORMANCE, NONINFRINGEMENT,
29+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NOR ARE THERE ANY
30+
* WARRANTIES CREATED BY A COURSE OR DEALING, COURSE OF PERFORMANCE OR TRADE
31+
* USAGE. FURTHERMORE, THERE ARE NO WARRANTIES THAT THE SOFTWARE WILL MEET
32+
* YOUR NEEDS OR BE FREE FROM ERRORS, OR THAT THE OPERATION OF THE SOFTWARE
33+
* WILL BE UNINTERRUPTED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
34+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF
36+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39+
*
40+
* @Author: Hans Zandbelt - [email protected]
41+
*
42+
**************************************************************************/
43+
44+
#include "cfg/provider.h"
45+
#include "helper.h"
46+
47+
#include <http_config.h>
48+
49+
static cmd_parms cmd = {};
50+
51+
// provider
52+
53+
START_TEST(test_cmd_provider_token_endpoint_auth_set) {
54+
void *ptr = NULL;
55+
const char *arg = NULL;
56+
const char *rv = NULL;
57+
58+
cmd.server = oidc_test_request_get()->server;
59+
cmd.pool = oidc_test_request_get()->pool;
60+
cmd.directive = apr_pcalloc(cmd.pool, sizeof(ap_directive_t));
61+
cmd.directive->directive = OIDCProviderTokenEndpointAuth;
62+
63+
arg = "private_key_jwt";
64+
rv = oidc_cmd_provider_token_endpoint_auth_set(&cmd, ptr, arg);
65+
ck_assert_msg(rv == NULL, "failed: %s", rv);
66+
67+
arg = "private_key_jws";
68+
rv = oidc_cmd_provider_token_endpoint_auth_set(&cmd, ptr, arg);
69+
ck_assert_msg(rv != NULL, "should have failed");
70+
71+
arg = "private_key_jwt:RS256";
72+
rv = oidc_cmd_provider_token_endpoint_auth_set(&cmd, ptr, arg);
73+
ck_assert_msg(rv == NULL, "failed: %s", rv);
74+
75+
arg = "private_key_jwt:RA256";
76+
rv = oidc_cmd_provider_token_endpoint_auth_set(&cmd, ptr, arg);
77+
ck_assert_msg(rv != NULL, "should have failed");
78+
}
79+
END_TEST
80+
81+
int main(void) {
82+
TCase *core = tcase_create("core");
83+
tcase_add_checked_fixture(core, oidc_test_setup, oidc_test_teardown);
84+
85+
tcase_add_test(core, test_cmd_provider_token_endpoint_auth_set);
86+
87+
Suite *s = suite_create("cfg");
88+
suite_add_tcase(s, core);
89+
90+
return oidc_test_suite_run(s);
91+
}

0 commit comments

Comments
 (0)