1 /*
2 * Copyright (c) 2002-2025 Gargoyle Software Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 * https://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 package org.htmlunit.fuzzer;
16
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.nio.charset.StandardCharsets;
20
21 import org.apache.commons.io.IOUtils;
22 import org.htmlunit.WebClient;
23 import org.htmlunit.WebTestCase;
24 import org.junit.jupiter.api.Test;
25
26 /**
27 * Tests for issues reported by Google OSS-Fuzz
28 * (https://github.com/google/oss-fuzz).
29 *
30 * @author Ronald Brill
31 */
32 public class FuzzerTest extends WebTestCase {
33
34 /**
35 * @throws Exception if the test fails
36 */
37 @Test
38 public void case54522() throws Exception {
39 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54522
40 test("test-54522.html");
41 }
42
43 /**
44 * @throws Exception if the test fails
45 */
46 @Test
47 public void case54523() throws Exception {
48 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54523
49 test("test-54523.html");
50 }
51
52 /**
53 * @throws Exception if the test fails
54 */
55 @Test
56 public void case54524() throws Exception {
57 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54524
58 test("test-54524.html");
59 }
60
61 /**
62 * @throws Exception if the test fails
63 */
64 @Test
65 public void case54526() throws Exception {
66 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54526
67 test("test-54526.html");
68 }
69
70 /**
71 * @throws Exception if the test fails
72 */
73 @Test
74 public void case54527() throws Exception {
75 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54527
76 test("test-54527.html");
77 }
78
79 /**
80 * @throws Exception if the test fails
81 */
82 @Test
83 public void case54528() throws Exception {
84 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54528
85 test("test-54528.html");
86 }
87
88 /**
89 * @throws Exception if the test fails
90 */
91 @Test
92 public void case54535() throws Exception {
93 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54535
94 test("test-54535.html");
95 }
96
97 /**
98 * @throws Exception if the test fails
99 */
100 @Test
101 public void case54613() throws Exception {
102 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54613
103 test("test-54613.html");
104 }
105
106 /**
107 * @throws Exception if the test fails
108 */
109 @Test
110 public void case54965() throws Exception {
111 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54965
112 test("test-54965.html");
113 }
114
115 /**
116 * @throws Exception if the test fails
117 */
118 @Test
119 public void case55628() throws Exception {
120 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55628
121 test("test-55628.html");
122 }
123
124 /**
125 * @throws Exception if the test fails
126 */
127 @Test
128 public void case55747() throws Exception {
129 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55747
130 test("test-55747.html");
131 }
132
133 /**
134 * @throws Exception if the test fails
135 */
136 @Test
137 public void case56702() throws Exception {
138 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56702
139 test("test-56702.html");
140 }
141
142 /**
143 * @throws Exception if the test fails
144 */
145 @Test
146 public void case58943() throws Exception {
147 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58943
148 test("test-58943.html");
149 }
150
151 /**
152 * @throws Exception if the test fails
153 */
154 @Test
155 public void case67067() throws Exception {
156 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67067
157 test("test-67067.html");
158 }
159
160 /**
161 * @throws Exception if the test fails
162 */
163 @Test
164 public void case67493() throws Exception {
165 // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67493
166 test("test-67493.html");
167 }
168
169 private void test(final String inputFileName) throws Exception {
170 final InputStream file = getClass().getClassLoader()
171 .getResourceAsStream("org/htmlunit/fuzzer/" + inputFileName);
172 final String input = IOUtils.toString(file, StandardCharsets.UTF_8);
173
174 try (WebClient webClient = new WebClient(getBrowserVersion())) {
175 // org.htmlunit.corejs.javascript.EvaluatorException seems to be fatal
176 webClient.getOptions().setThrowExceptionOnScriptError(false);
177 // no exception if linked resources are not available
178 webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
179
180 webClient.loadHtmlCodeIntoCurrentWindow(input);
181 }
182 catch (final IllegalArgumentException e) {
183 }
184 catch (final IOException e) {
185 }
186 }
187 }