1 /*
2  * Copyright (c) 2013 Tim Ruehsen
3  * Copyright (c) 2015-2021 Free Software Foundation, Inc.
4  *
5  * This file is part of Wget
6  *
7  * Wget is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * Wget is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Wget  If not, see <https://www.gnu.org/licenses/>.
19  *
20  *
21  * Testing Wget
22  *
23  * Changelog
24  * 15.07.2013  Tim Ruehsen  created
25  *
26  */
27 
28 #include <config.h>
29 
30 #include <stdlib.h> // exit()
31 #include "libtest.h"
32 
main(void)33 int main(void)
34 {
35 	wget_test_url_t urls[]={
36 		{	.name = "/index.html",
37 			.code = "200 Dontcare",
38 			.body =
39 				"<html><head><title>Main Page</title>" \
40 				"<style> html { background: url(htTp://localhost:{{port}}/second.html); }</style>" \
41 				"<style> div { background: url(htTp://localhost:{{port}}/second.html); }</style>" \
42 				"</head><body><p>A link to a" \
43 				" <a href=\"second.html\">second page</a>." \
44 				" <a href=\"htTp://localhost:{{port}}/second.html\">second page</a>." \
45 				" <a href=\"subdir/third.html\">third page</a>." \
46 				" <a href=\"htTp://localhost:{{port}}/subdir/third.html\">third page</a>." \
47 				" <SCRIPT LANGUAGE=\"JavaScript\">document.write(\"<img src=\\\"rw1\\\"\");</SCRIPT>" \
48 				"</p></body></html>",
49 			.headers = {
50 				"Content-Type: text/html",
51 			}
52 		},
53 		{	.name = "/second.html",
54 			.code = "200 Dontcare",
55 			.body = "<html><head><title>Site</title></head><body>Some Text</body></html>",
56 			.headers = {
57 				"Content-Type: text/html",
58 			}
59 		},
60 		{	.name = "/subdir/third.html",
61 			.code = "200 Dontcare",
62 			.body = "<html><head><title>Site</title></head><body>Some Text</body></html>",
63 			.headers = {
64 				"Content-Type: text/html",
65 			}
66 		},
67 	};
68 
69 	const char *converted =
70 		"<html><head><title>Main Page</title>" \
71 		"<style> html { background: url(second.html); }</style>" \
72 		"<style> div { background: url(second.html); }</style>" \
73 		"</head><body><p>A link to a" \
74 		" <a href=\"second.html\">second page</a>." \
75 		" <a href=\"second.html\">second page</a>." \
76 		" <a href=\"subdir/third.html\">third page</a>." \
77 		" <a href=\"subdir/third.html\">third page</a>." \
78 		" <SCRIPT LANGUAGE=\"JavaScript\">document.write(\"<img src=\\\"rw1\\\"\");</SCRIPT>" \
79 		"</p></body></html>";
80 
81 	// functions won't come back if an error occurs
82 	wget_test_start_server(
83 		WGET_TEST_RESPONSE_URLS, &urls, countof(urls),
84 		WGET_TEST_FEATURE_MHD,
85 		0);
86 
87 	// test-k, links in <script> shouldn't be converted
88 	wget_test(
89 		// WGET_TEST_KEEP_TMPFILES, 1,
90 		WGET_TEST_OPTIONS, "-k -r -nH",
91 		WGET_TEST_REQUEST_URL, "index.html",
92 		WGET_TEST_EXPECTED_ERROR_CODE, 0,
93 		WGET_TEST_EXPECTED_FILES, &(wget_test_file_t []) {
94 			{ urls[0].name + 1, converted },
95 			{ urls[1].name + 1, urls[1].body },
96 			{ urls[2].name + 1, urls[2].body },
97 			{	NULL } },
98 		0);
99 
100 	exit(EXIT_SUCCESS);
101 }
102