Skip to content

Commit 511b388

Browse files
committed
test: add test/test_http.c and migrate http accept tests there
from deprecated test.c Signed-off-by: Hans Zandbelt <[email protected]>
1 parent 3277f28 commit 511b388

File tree

4 files changed

+126
-55
lines changed

4 files changed

+126
-55
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
11/11/2025
2+
- test: add test/test_http.c and migrate http accept tests there from test.c
3+
14
11/07/2025
25
- support individual SameSite cookie settings on the session cookie, state cookie and Discovery CSRF
36
cookie by adding 2 more arguments to OIDCCookieSameSite

test/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ test_cfg_CFLAGS = @CHECK_CFLAGS@ ${AM_CFLAGS}
5757
test_cfg_LDADD = @CHECK_LIBS@ ${LDADD}
5858
test_cfg_SOURCES = test_cfg.c helper.c stub.c
5959

60+
TESTS += test_http
61+
test_http_CFLAGS = @CHECK_CFLAGS@ ${AM_CFLAGS}
62+
test_http_LDADD = @CHECK_LIBS@ ${LDADD}
63+
test_http_SOURCES = test_http.c helper.c stub.c
64+
6065
endif
6166

6267
check_PROGRAMS = $(TESTS)

test/test.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,59 +1192,6 @@ static char *test_proto_validate_jwt(request_rec *r) {
11921192
return 0;
11931193
}
11941194

1195-
static char *test_accept(request_rec *r) {
1196-
1197-
// ie 9/10/11
1198-
apr_table_set(r->headers_in, "Accept", "text/html, application/xhtml+xml, */*");
1199-
TST_ASSERT("Accept: text/html (ie 9/10/11)", oidc_http_hdr_in_accept_contains(r, "text/html") != 0);
1200-
TST_ASSERT("Accept: application/json (ie 9/10/11)",
1201-
oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1202-
1203-
// firefox
1204-
apr_table_set(r->headers_in, "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
1205-
TST_ASSERT("Accept: text/html (firefox)", oidc_http_hdr_in_accept_contains(r, "text/html") != 0);
1206-
TST_ASSERT("Accept: application/json (firefox)", oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1207-
1208-
// chrome/safari
1209-
apr_table_set(r->headers_in, "Accept",
1210-
"application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5");
1211-
TST_ASSERT("Accept: text/html (chrome/safari)", oidc_http_hdr_in_accept_contains(r, "text/html") != 0);
1212-
TST_ASSERT("Accept: application/json (chrome/safari)",
1213-
oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1214-
1215-
// safari 5
1216-
apr_table_set(r->headers_in, "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
1217-
TST_ASSERT("Accept: text/html (safari 5)", oidc_http_hdr_in_accept_contains(r, "text/html") != 0);
1218-
TST_ASSERT("Accept: application/json (safari 5)", oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1219-
1220-
// ie 8
1221-
apr_table_set(r->headers_in, "Accept",
1222-
"image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, "
1223-
"application/x-ms-xbap, application/x-shockwave-flash, application/msword, */*");
1224-
TST_ASSERT("Accept: text/html (ie 8)", oidc_http_hdr_in_accept_contains(r, "text/html") == 0);
1225-
TST_ASSERT("Accept: */* (ie 8)", oidc_http_hdr_in_accept_contains(r, "*/*") != 0);
1226-
TST_ASSERT("Accept: application/json (ie 8)", oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1227-
1228-
// edge
1229-
apr_table_set(r->headers_in, "Accept", "text/html, application/xhtml+xml, image/jxr, */*");
1230-
TST_ASSERT("Accept: text/html (edge)", oidc_http_hdr_in_accept_contains(r, "text/html") != 0);
1231-
TST_ASSERT("Accept: application/json (edge)", oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1232-
1233-
// opera
1234-
apr_table_set(r->headers_in, "Accept",
1235-
"text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, "
1236-
"image/gif, image/x-xbitmap, */*;q=0.1");
1237-
TST_ASSERT("Accept: text/html (opera)", oidc_http_hdr_in_accept_contains(r, "text/html") != 0);
1238-
TST_ASSERT("Accept: application/json (opera)", oidc_http_hdr_in_accept_contains(r, "application/json") == 0);
1239-
1240-
// xmlhttprequest
1241-
apr_table_set(r->headers_in, "Accept", "application/json");
1242-
TST_ASSERT("Accept: text/html (opera)", oidc_http_hdr_in_accept_contains(r, "text/html") == 0);
1243-
TST_ASSERT("Accept: application/json (opera)", oidc_http_hdr_in_accept_contains(r, "application/json") != 0);
1244-
1245-
return 0;
1246-
}
1247-
12481195
#if HAVE_APACHE_24
12491196

12501197
static char *test_authz_worker(request_rec *r) {
@@ -1698,8 +1645,6 @@ static char *all_tests(apr_pool_t *pool, request_rec *r) {
16981645
TST_RUN(test_proto_validate_nonce, r);
16991646
TST_RUN(test_proto_validate_jwt, r);
17001647

1701-
TST_RUN(test_accept, r);
1702-
17031648
TST_RUN(test_decode_json_object, r);
17041649

17051650
TST_RUN(test_remote_user, r);

test/test_http.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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/cache.h"
45+
#include "cfg/cfg_int.h"
46+
#include "cfg/provider.h"
47+
#include "helper.h"
48+
49+
START_TEST(test_http_accept) {
50+
request_rec *r = oidc_test_request_get();
51+
52+
// ie 9/10/11
53+
apr_table_set(r->headers_in, "Accept", "text/html, application/xhtml+xml, */*");
54+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == TRUE, "Accept: text/html (ie 9/10/11)");
55+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
56+
"Accept: application/json (ie 9/10/11)");
57+
58+
// firefox
59+
apr_table_set(r->headers_in, "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
60+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == TRUE, "Accept: text/html (firefox)");
61+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
62+
"Accept: application/json (firefox)");
63+
64+
// chrome/safari
65+
apr_table_set(r->headers_in, "Accept",
66+
"application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5");
67+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == TRUE, "Accept: text/html (chrome/safari)");
68+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
69+
"Accept: application/json (chrome/safari)");
70+
71+
// safari 5
72+
apr_table_set(r->headers_in, "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
73+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == TRUE, "Accept: text/html (safari 5)");
74+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
75+
"Accept: application/json (safari 5)");
76+
77+
// ie 8
78+
apr_table_set(r->headers_in, "Accept",
79+
"image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, "
80+
"application/x-ms-xbap, application/x-shockwave-flash, application/msword, */*");
81+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == FALSE, "Accept: text/html (ie 8)");
82+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "*/*") == TRUE, "Accept: */* (ie 8)");
83+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
84+
"Accept: application/json (ie 8)");
85+
86+
// edge
87+
apr_table_set(r->headers_in, "Accept", "text/html, application/xhtml+xml, image/jxr, */*");
88+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == TRUE, "Accept: text/html (edge)");
89+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
90+
"Accept: application/json (edge)");
91+
92+
// opera
93+
apr_table_set(r->headers_in, "Accept",
94+
"text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, "
95+
"image/gif, image/x-xbitmap, */*;q=0.1");
96+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == TRUE, "Accept: text/html (opera)");
97+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == FALSE,
98+
"Accept: application/json (opera)");
99+
100+
// xmlhttprequest
101+
apr_table_set(r->headers_in, "Accept", "application/json");
102+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "text/html") == FALSE, "Accept: text/html (opera)");
103+
ck_assert_msg(oidc_http_hdr_in_accept_contains(r, "application/json") == TRUE,
104+
"Accept: application/json (opera)");
105+
}
106+
END_TEST
107+
108+
int main(void) {
109+
TCase *accept = tcase_create("accept");
110+
tcase_add_checked_fixture(accept, oidc_test_setup, oidc_test_teardown);
111+
112+
tcase_add_test(accept, test_http_accept);
113+
114+
Suite *s = suite_create("http");
115+
suite_add_tcase(s, accept);
116+
117+
return oidc_test_suite_run(s);
118+
}

0 commit comments

Comments
 (0)