|
| 1 | +/* |
| 2 | + * Copyright (c) Kristaps Dzonsons <kristaps@bsd.lv> |
| 3 | + * |
| 4 | + * Permission to use, copy, modify, and distribute this software for any |
| 5 | + * purpose with or without fee is hereby granted, provided that the above |
| 6 | + * copyright notice and this permission notice appear in all copies. |
| 7 | + * |
| 8 | + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | + */ |
| 16 | +#include "../config.h" |
| 17 | + |
| 18 | +#include <stdarg.h> |
| 19 | +#include <stdint.h> |
| 20 | +#include <stdlib.h> |
| 21 | +#include <string.h> |
| 22 | +#include <unistd.h> |
| 23 | + |
| 24 | +#include <curl/curl.h> |
| 25 | + |
| 26 | +#include "../kcgi.h" |
| 27 | +#include "regress.h" |
| 28 | + |
| 29 | +static int |
| 30 | +parent(CURL *curl) |
| 31 | +{ |
| 32 | + struct curl_slist *slist; |
| 33 | + int ret; |
| 34 | + |
| 35 | + slist = NULL; |
| 36 | + slist = curl_slist_append(slist, "Sec-Fetch-Dest: www.example.com"); |
| 37 | + slist = curl_slist_append(slist, "Sec-Fetch-User: ?1"); |
| 38 | + slist = curl_slist_append(slist, "Sec-Fetch-Mode: navigate"); |
| 39 | + slist = curl_slist_append(slist, "Sec-Fetch-Site: same-origin"); |
| 40 | + curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:17123/"); |
| 41 | + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); |
| 42 | + ret = curl_easy_perform(curl); |
| 43 | + curl_slist_free_all(slist); |
| 44 | + return(CURLE_OK == ret); |
| 45 | +} |
| 46 | + |
| 47 | +static int |
| 48 | +child(void) |
| 49 | +{ |
| 50 | + struct kreq r; |
| 51 | + const char *page = "index"; |
| 52 | + |
| 53 | + if (khttp_parse(&r, NULL, 0, &page, 1, 0) != KCGI_OK) |
| 54 | + return 0; |
| 55 | + |
| 56 | + if (r.reqmap[KREQU_SEC_FETCH_DEST] == NULL || |
| 57 | + strcmp(r.reqmap[KREQU_SEC_FETCH_DEST]->val, "www.example.com") != 0) |
| 58 | + return 0; |
| 59 | + if (r.reqmap[KREQU_SEC_FETCH_USER] == NULL || |
| 60 | + strcmp(r.reqmap[KREQU_SEC_FETCH_USER]->val, "?1") != 0) |
| 61 | + return 0; |
| 62 | + if (r.reqmap[KREQU_SEC_FETCH_MODE] == NULL || |
| 63 | + strcmp(r.reqmap[KREQU_SEC_FETCH_MODE]->val, "navigate") != 0) |
| 64 | + return 0; |
| 65 | + if (r.reqmap[KREQU_SEC_FETCH_SITE] == NULL || |
| 66 | + strcmp(r.reqmap[KREQU_SEC_FETCH_SITE]->val, "same-origin") != 0) |
| 67 | + return 0; |
| 68 | + |
| 69 | + khttp_head(&r, kresps[KRESP_STATUS], |
| 70 | + "%s", khttps[KHTTP_200]); |
| 71 | + khttp_head(&r, kresps[KRESP_CONTENT_TYPE], |
| 72 | + "%s", kmimetypes[KMIME_TEXT_HTML]); |
| 73 | + khttp_body(&r); |
| 74 | + khttp_free(&r); |
| 75 | + return 1; |
| 76 | +} |
| 77 | + |
| 78 | +int |
| 79 | +main(int argc, char *argv[]) |
| 80 | +{ |
| 81 | + |
| 82 | + return(regress_cgi(parent, child) ? EXIT_SUCCESS : EXIT_FAILURE); |
| 83 | +} |
0 commit comments