1 /* t-http-basic.c - Basic regression tests for http.c
2 * Copyright (C) 2018 g10 Code GmbH
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <https://gnu.org/licenses/>.
18 * SPDX-License-Identifier: GPL-3.0-or-later
24 #include "../common/util.h"
25 #include "t-support.h"
28 #define PGM "t-http-basic"
32 test_http_prepare_redirect (void)
37 const char *expect_url;
38 gpg_error_t expect_err;
41 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
47 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
53 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
59 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
60 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
61 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
65 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
66 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
67 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
71 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
72 "http://foo.gnupg.org:8080/.not-so-well-known/openpgpkey/hu/12345678",
73 "http://foo.gnupg.org:8080/.well-known/openpgpkey/hu/12345678",
77 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
78 "http:///.no-so-well-known/openpgpkey/hu/12345678",
79 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
83 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
84 "http://gnupg.org:8080/.not-so-well-known/openpgpkey/hu/12345678",
85 "http://gnupg.org:8080/.not-so-well-known/openpgpkey/hu/12345678",
89 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
90 "http://gnupg.org:8/.not-so-well-known/openpgpkey/hu/12345678",
91 "http://gnupg.org:8/.not-so-well-known/openpgpkey/hu/12345678",
95 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
96 "http://gnupg.org:/.no-so-well-known/openpgpkey/hu/12345678",
97 "http://gnupg.org:/.no-so-well-known/openpgpkey/hu/12345678",
101 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
107 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
109 "http://gnupg.net/.well-known/openpgpkey/hu/12345678",
120 "http://foo.gnupg.org",
121 "http://foo.gnupg.org",
126 "http://foo.gnupg.org",
127 "http://foo.gnupg.org/",
132 "http://foo.gnupg.org/",
133 "http://foo.gnupg.org",
137 "http://gnupg.org/.well-known/openpgpkey/hu/12345678",
138 "http://gnupg.org/something-else",
139 "http://gnupg.org/something-else",
144 http_redir_info_t ri;
148 err = http_prepare_redirect (NULL, 301, tests[0].location, &newurl);
149 if (gpg_err_code (err) != GPG_ERR_INV_ARG)
151 memset (&ri, 0, sizeof ri);
152 err = http_prepare_redirect (&ri, 301, tests[0].location, &newurl);
153 if (gpg_err_code (err) != GPG_ERR_INV_ARG)
155 memset (&ri, 0, sizeof ri);
157 ri.orig_url = "http://example.org";
158 err = http_prepare_redirect (&ri, 301, tests[0].location, &newurl);
159 if (gpg_err_code (err) != GPG_ERR_NO_DATA)
162 for (tidx = 0; tidx < DIM (tests); tidx++)
164 memset (&ri, 0, sizeof ri);
166 ri.redirects_left = 1;
167 ri.orig_url = tests[tidx].url;
168 ri.restrict_redir = 1; /* This is what we used to test here. */
170 err = http_prepare_redirect (&ri, 301, tests[tidx].location, &newurl);
173 if (err && gpg_err_code (err) != tests[tidx].expect_err)
179 if (strcmp (tests[tidx].expect_url, newurl))
181 fprintf (stderr, "want: '%s'\n", tests[tidx].expect_url);
182 fprintf (stderr, "got : '%s'\n", newurl);
192 main (int argc, char **argv)
197 test_http_prepare_redirect ();