|
| 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