View Javadoc
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.htmlunit.junit.BrowserRunner;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  
28  /**
29   * Tests for issues reported by Google OSS-Fuzz
30   * (https://github.com/google/oss-fuzz).
31   *
32   * @author Ronald Brill
33   */
34  @RunWith(BrowserRunner.class)
35  public class FuzzerTest extends WebTestCase {
36  
37      /**
38       * @throws Exception if the test fails
39       */
40      @Test
41      public void case54522() throws Exception {
42          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54522
43          test("test-54522.html");
44      }
45  
46      /**
47       * @throws Exception if the test fails
48       */
49      @Test
50      public void case54523() throws Exception {
51          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54523
52          test("test-54523.html");
53      }
54  
55      /**
56       * @throws Exception if the test fails
57       */
58      @Test
59      public void case54524() throws Exception {
60          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54524
61          test("test-54524.html");
62      }
63  
64      /**
65       * @throws Exception if the test fails
66       */
67      @Test
68      public void case54526() throws Exception {
69          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54526
70          test("test-54526.html");
71      }
72  
73      /**
74       * @throws Exception if the test fails
75       */
76      @Test
77      public void case54527() throws Exception {
78          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54527
79          test("test-54527.html");
80      }
81  
82      /**
83       * @throws Exception if the test fails
84       */
85      @Test
86      public void case54528() throws Exception {
87          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54528
88          test("test-54528.html");
89      }
90  
91      /**
92       * @throws Exception if the test fails
93       */
94      @Test
95      public void case54535() throws Exception {
96          // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54535
97          test("test-54535.html");
98      }
99  
100     /**
101      * @throws Exception if the test fails
102      */
103     @Test
104     public void case54613() throws Exception {
105         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54613
106         test("test-54613.html");
107     }
108 
109     /**
110      * @throws Exception if the test fails
111      */
112     @Test
113     public void case54965() throws Exception {
114         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54965
115         test("test-54965.html");
116     }
117 
118     /**
119      * @throws Exception if the test fails
120      */
121     @Test
122     public void case55628() throws Exception {
123         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55628
124         test("test-55628.html");
125     }
126 
127     /**
128      * @throws Exception if the test fails
129      */
130     @Test
131     public void case55747() throws Exception {
132         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=55747
133         test("test-55747.html");
134     }
135 
136     /**
137      * @throws Exception if the test fails
138      */
139     @Test
140     public void case56702() throws Exception {
141         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=56702
142         test("test-56702.html");
143     }
144 
145     /**
146      * @throws Exception if the test fails
147      */
148     @Test
149     public void case58943() throws Exception {
150         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=58943
151         test("test-58943.html");
152     }
153 
154     /**
155      * @throws Exception if the test fails
156      */
157     @Test
158     public void case67067() throws Exception {
159         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67067
160         test("test-67067.html");
161     }
162 
163     /**
164      * @throws Exception if the test fails
165      */
166     @Test
167     public void case67493() throws Exception {
168         // https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67493
169         test("test-67493.html");
170     }
171 
172     private void test(final String inputFileName) throws Exception {
173         final InputStream file = getClass().getClassLoader()
174                 .getResourceAsStream("org/htmlunit/fuzzer/" + inputFileName);
175         final String input = IOUtils.toString(file, StandardCharsets.UTF_8);
176 
177         try (WebClient webClient = new WebClient(getBrowserVersion())) {
178             // org.htmlunit.corejs.javascript.EvaluatorException seems to be fatal
179             webClient.getOptions().setThrowExceptionOnScriptError(false);
180             // no exception if linked resources are not available
181             webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
182 
183             webClient.loadHtmlCodeIntoCurrentWindow(input);
184         }
185         catch (final IllegalArgumentException e) {
186         }
187         catch (final IOException e) {
188         }
189     }
190 }