Path: blob/master/test/jdk/sun/security/util/ManifestDigester/FindSections.java
41152 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import sun.security.util.ManifestDigester;24import org.testng.annotations.Test;2526import static java.nio.charset.StandardCharsets.UTF_8;27import static org.testng.Assert.*;282930/**31* @test32* @bug 821737533* @modules java.base/sun.security.util34* @run testng FindSections35* @summary Check {@link ManifestDigester#ManifestDigester} processing36* individual sections and particularly identifying their names correctly.37* Main attributes are not covered in this test.38* <p>39* See also {@link FindSection} for the {@link ManifestDigester#findSection}40* method specifically.41*/42public class FindSections {4344static final String DEFAULT_MANIFEST = "Manifest-Version: 1.0\r\n\r\n";4546void test(String manifest, String expectedSection) {47ManifestDigester md = new ManifestDigester(manifest.getBytes(UTF_8));48if (expectedSection != null) {49assertNotNull(md.get(expectedSection, false));50} else {51assertNull(md.get(expectedSection, false));52}53}5455@Test56public void testNameNoSpaceAfterColon() throws Exception {57test(DEFAULT_MANIFEST + "Name:section\r\n\r\n", null);58}5960@Test61public void testNameCase() throws Exception {62test(DEFAULT_MANIFEST + "nAME: section\r\n\r\n", "section");63}6465@Test66public void testEmptyName() throws Exception {67test(DEFAULT_MANIFEST + "Name: \r\n\r\n", "");68}6970@Test71public void testShortestInvalidSection() throws Exception {72test(DEFAULT_MANIFEST + "Name: ", null);73}7475@Test76public void testMinimalValidSection() throws Exception {77test(DEFAULT_MANIFEST + "Name: \r", "");78}7980@Test81public void testNameNotContinued() throws Exception {82test(DEFAULT_MANIFEST + "Name: FooBar\r\n", "FooBar");83}8485@Test86public void testImmediatelyContinuedCrName() throws Exception {87test(DEFAULT_MANIFEST + "Name: \r FooBar\r\n", "FooBar");88}8990@Test91public void testImmediatelyContinuedLfName() throws Exception {92test(DEFAULT_MANIFEST + "Name: \n FooBar\r\n", "FooBar");93}9495@Test96public void testImmediatelyContinuedCrLfName() throws Exception {97test(DEFAULT_MANIFEST + "Name: \r\n FooBar\r\n", "FooBar");98}99100@Test101public void testNameContinuedCr() throws Exception {102test(DEFAULT_MANIFEST + "Name: FooBar\r \r\n", "FooBar");103}104105@Test106public void testNameContinuedLf() throws Exception {107test(DEFAULT_MANIFEST + "Name: FooBar\n \r\n", "FooBar");108}109110@Test111public void testNameContinuedCrLf() throws Exception {112test(DEFAULT_MANIFEST + "Name: FooBar\r\n \r\n", "FooBar");113}114115@Test116public void testNameContinuedCrIgnoreNextChar() throws Exception {117test(DEFAULT_MANIFEST + "Name: Foo\r: Bar\r\n", "Foo");118}119120@Test121public void testNameContinuedCrIgnoreNextCharSpace() throws Exception {122test(DEFAULT_MANIFEST + "Name: Foo\r Bar\r\n", "Foo Bar");123}124125@Test126public void testNameContinuedContinuedCr() throws Exception {127test(DEFAULT_MANIFEST + "Name: Fo\r\n oB\r ar\r\n", "FooBar");128}129130@Test131public void testNameContinuedContinuedLf() throws Exception {132test(DEFAULT_MANIFEST + "Name: Fo\r\n oB\n ar\r\n", "FooBar");133}134135@Test136public void testNameContinuedContinuedCrLf() throws Exception {137test(DEFAULT_MANIFEST + "Name: Fo\r\n oB\r\n ar\r\n", "FooBar");138}139140@Test141public void testNameContinuedEndCr() throws Exception {142test(DEFAULT_MANIFEST + "Name: Foo\r\n Bar\r", "FooBar");143}144145@Test146public void testNameContinuedEndLf() throws Exception {147test(DEFAULT_MANIFEST + "Name: Foo\r\n Bar\n", "FooBar");148}149150@Test151public void testNameContinuedEndCrLf() throws Exception {152test(DEFAULT_MANIFEST + "Name: Foo\r\n Bar\r\n", "FooBar");153}154155}156157158