ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/http/parser/TesterHttpWgStructuredField.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/http/parser/TesterHttpWgStructuredField.java
Status
scanned
Type
file
Name
TesterHttpWgStructuredField.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4617 (4.5 KB)
MD5
c0c005b0b22218f1f856000598bbab74
SHA1
654c4d38bd855b16649673316a72afb8d4254130
SHA256
7d3386e5ecdeb70ba67011b234f0ea17a13c39205a79aa2bd150a0f7c091017b
SHA512

      
    
SHA1_git
00ba1eebcf819148d975d3a576ce378f0845a187
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterHttpWgStructuredField.java | 4.5 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.util.http.parser; import java.io.File; import java.io.FileInputStream; import java.io.Reader; import java.io.StringReader; import java.util.List; import java.util.Map; import org.junit.Assert; import org.junit.Test; import org.apache.tomcat.util.buf.StringUtils; import org.apache.tomcat.util.json.JSONParser; /* * Not run automatically (due to name) as it requires a local git clone of * https://github.com/httpwg/structured-field-tests */ public class TesterHttpWgStructuredField { private static final String testsPath = System.getProperty("user.home") + "/repos/httpwg-sf-tests"; @Test public void test() throws Exception { File testDir = new File(testsPath); doTestDirectory(testDir); } private void doTestDirectory(File directory) throws Exception { for (File file : directory.listFiles()) { if (file.isDirectory()) { if (!file.getName().equals("serialisation-tests")) { doTestDirectory(file); } } else if (file.isFile()) { if (file.getName().endsWith(".json")) { doTestFile(file); } } } } private void doTestFile(File file) throws Exception { System.out.println(file.getAbsolutePath()); try (FileInputStream fis = new FileInputStream(file)) { JSONParser parser = new JSONParser(fis); List<Object> array = parser.parseArray(); for (Object obj : array) { if (obj instanceof Map) { doTestMap((Map<?,?>) obj); } else { Assert.fail(); } } } } private void doTestMap(Map<?,?> map) throws Exception { String name = (String) map.get("name"); @SuppressWarnings("unchecked") List<String> rawLines = (List<String>) map.get("raw"); String headerType = (String) map.get("header_type"); Boolean mustFail = ((Boolean) map.get("must_fail")); if (mustFail == null) { mustFail = Boolean.FALSE; } Boolean canFail = ((Boolean) map.get("can_fail")); if (canFail == null) { canFail = Boolean.FALSE; } String raw = StringUtils.join(rawLines); /* * The simple JSON parser may not be handling escape sequences * correctly. */ String unescaped = raw.replace("\\\"", "\""); unescaped = unescaped.replace("\\b", "\u0008"); unescaped = unescaped.replace("\ ", " "); unescaped = unescaped.replace("\ ", " "); unescaped = unescaped.replace("\\f", "\u000c"); unescaped = unescaped.replace("\ ", " "); unescaped = unescaped.replace("\\\\", "\\"); Reader input = new StringReader(unescaped); try { switch (headerType) { case "item": { StructuredField.parseSfItem(input); break; } case "list": { StructuredField.parseSfList(input); break; } case "dictionary": { StructuredField.parseSfDictionary(input); break; } default: System.out.println("Type unsupported " + headerType); } } catch (Exception e) { Assert.assertTrue(name + ": raw [" + unescaped + "]", mustFail.booleanValue() || canFail.booleanValue()); return; } Assert.assertFalse(name + ": raw [" + unescaped + "]", mustFail.booleanValue()); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
26.62
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9
https://github.com/httpwg/structured-field-tests 34 34