test/jdk/sun/security/util/ManifestDigester/FindSection.java
author weijun
Thu, 18 Jul 2019 08:53:06 +0800
changeset 57488 94691d8e746f
permissions -rw-r--r--
8217375: jarsigner breaks old signature with long lines in manifest Reviewed-by: jjiang, weijun Contributed-by: Philipp Kunz <philipp.kunz@paratix.ch>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57488
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     1
/*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     4
 *
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     8
 *
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    13
 * accompanied this code).
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    14
 *
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    18
 *
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    21
 * questions.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    22
 */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    23
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    24
import java.lang.reflect.Constructor;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    25
import java.lang.reflect.Field;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    26
import java.lang.reflect.Method;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    27
import java.util.Arrays;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    28
import java.util.concurrent.Callable;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    29
import java.util.function.Consumer;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    30
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    31
import sun.security.util.ManifestDigester;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    32
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    33
import org.testng.annotations.Test;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    34
import org.testng.annotations.BeforeClass;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    35
import org.testng.annotations.BeforeMethod;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    36
import org.testng.annotations.DataProvider;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    37
import org.testng.annotations.Factory;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    38
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    39
import static java.nio.charset.StandardCharsets.UTF_8;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    40
import static org.testng.Assert.*;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    41
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    42
/**
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    43
 * @test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    44
 * @bug 8217375
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    45
 * @modules java.base/sun.security.util:+open
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    46
 * @compile ../../tools/jarsigner/Utils.java
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    47
 * @run testng/othervm FindSection
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    48
 * @summary Check {@link ManifestDigester#findSection}.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    49
 */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    50
public class FindSection {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    51
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    52
    /*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    53
     * TODO:
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    54
     * FIXED_8217375 is not intended to keep. it is intended to show what
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    55
     * exactly has changed with respect to the previous version for which no
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    56
     * such test existed.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    57
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    58
    static final boolean FIXED_8217375 = true;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    59
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    60
    /**
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    61
     * {@link ManifestDigester.Entry#digestWorkaround} should not feed the
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    62
     * trailing blank line into the digester. Before resolution of 8217375 it
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    63
     * fed the trailing blank line into the digest if the second line break
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    64
     * was at the end of the file due to <pre>
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    65
     * if (allBlank || (i == len-1)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    66
     *     if (i == len-1)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    67
     *         pos.endOfSection = i;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    68
     *     else
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    69
     *         pos.endOfSection = last;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    70
     * </pre> in {@link ManifestDigester#findSection}. In that case at the end
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    71
     * of the manifest file, {@link ManifestDigester.Entry#digestWorkaround}
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    72
     * would have produced the same digest as
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    73
     * {@link ManifestDigester.Entry#digest} which was wrong and without effect
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    74
     * at best.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    75
     * <p>
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    76
     * Once this fix is accepted, this flag can be removed along with
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    77
     * {@link #actualEndOfSection8217375}.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    78
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    79
    static final boolean FIXED_8217375_EOF_ENDOFSECTION = FIXED_8217375;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    80
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    81
    /**
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    82
     * {@link ManifestDigester.Position.endOfSection} usually points to the
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    83
     * start position of the blank line trailing a section minus one.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    84
     * If a {@link ManifestDigester.Position} returned by
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    85
     * {@link ManifestDigester#findSection} is based on a portion that starts
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    86
     * with a blank line, above statement is (or was) not true, because of the
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    87
     * initialization of {@code last} in {@link ManifestDigester#findSection}
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    88
     * <pre>
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    89
     * int last = offset;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    90
     * </pre>
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    91
     * which would point after incrementing it in {@code pos.endOfSection + 1}
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    92
     * on line 128 (line number before this change) or {@code int sectionLen =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    93
     * pos.endOfSection-start+1;} on line 133 (line number before this change)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    94
     * at one byte after the first line break character of usually two and
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    95
     * possibly (assuming "{@code \r\n}" default line break normally) in between
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    96
     * the two characters of a line break. After subtracting again the index of
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    97
     * the section start position on former line 133, the last byte would be
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    98
     * missed to be digested by {@link ManifestDigester.Entry#digestWorkaround}.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
    99
     * <p>
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   100
     * All this, however could possibly matter (or have mattered) only when
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   101
     * {@link ManifestDigester#findSection} was invoked with an offset position
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   102
     * pointing straight to a line break which happens if a manifest starts
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   103
     * with an empty line or if there are superfluous blank lines between
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   104
     * sections in both cases no useful manifest portion is identified.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   105
     * Superfluous blank lines are not identified as sections (because they
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   106
     * don't have a name and specifically don't meet {@code if (len > 6) {} on
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   107
     * former line 136. Manifests starting with a line break are not any more
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   108
     * useful either.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   109
     * <p>
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   110
     * Once this fix is accepted, this flag can be removed along with
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   111
     * {@link #actualEndOfSection8217375}.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   112
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   113
    static final boolean FIXED_8217375_STARTWITHBLANKLINE_ENDOFSECTION =
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   114
            FIXED_8217375;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   115
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   116
    static Constructor<?> PositionConstructor;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   117
    static Method findSection;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   118
    static Field rawBytes;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   119
    static Field endOfFirstLine;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   120
    static Field endOfSection;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   121
    static Field startOfNext;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   122
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   123
    @BeforeClass
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   124
    public static void setFindSectionAccessible() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   125
        Class<?> Position = Arrays.stream(ManifestDigester.class.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   126
                getDeclaredClasses()).filter(c -> c.getSimpleName().
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   127
                        equals("Position")).findFirst().get();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   128
        PositionConstructor = Position.getDeclaredConstructor();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   129
        PositionConstructor.setAccessible(true);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   130
        findSection = ManifestDigester.class.getDeclaredMethod("findSection",
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   131
            int.class, Position);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   132
        findSection.setAccessible(true);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   133
        rawBytes = ManifestDigester.class.getDeclaredField("rawBytes");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   134
        rawBytes.setAccessible(true);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   135
        endOfFirstLine = Position.getDeclaredField("endOfFirstLine");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   136
        endOfFirstLine.setAccessible(true);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   137
        endOfSection = Position.getDeclaredField("endOfSection");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   138
        endOfSection.setAccessible(true);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   139
        startOfNext = Position.getDeclaredField("startOfNext");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   140
        startOfNext.setAccessible(true);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   141
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   142
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   143
    static class Position {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   144
        final int endOfFirstLine; // not including newline character
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   145
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   146
        final int endOfSection; // end of section, not including the blank line
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   147
                                // between sections
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   148
        final int startOfNext;  // the start of the next section
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   149
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   150
        Position(Object pos) throws ReflectiveOperationException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   151
            endOfFirstLine = FindSection.endOfFirstLine.getInt(pos);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   152
            endOfSection = FindSection.endOfSection.getInt(pos);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   153
            startOfNext = FindSection.startOfNext.getInt(pos);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   154
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   155
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   156
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   157
    Position findSection(byte[] manifestBytes)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   158
            throws ReflectiveOperationException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   159
        ManifestDigester manDig = new ManifestDigester("\n\n".getBytes(UTF_8));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   160
        FindSection.rawBytes.set(manDig, manifestBytes);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   161
        Object pos = PositionConstructor.newInstance();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   162
        Object result = findSection.invoke(manDig, offset, pos);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   163
        if (Boolean.FALSE.equals(result)) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   164
            return null; // indicates findSection having returned false
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   165
        } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   166
            return new Position(pos);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   167
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   168
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   169
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   170
    @DataProvider(name = "parameters")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   171
    public static Object[][] parameters() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   172
        return new Object[][] { { 0 }, { 42 } };
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   173
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   174
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   175
    @Factory(dataProvider = "parameters")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   176
    public static Object[] createTests(int offset) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   177
        return new Object[]{ new FindSection(offset) };
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   178
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   179
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   180
    final int offset;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   181
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   182
    FindSection(int offset) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   183
        this.offset = offset;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   184
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   185
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   186
    @BeforeMethod
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   187
    public void verbose() {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   188
        System.out.println("offset = " + offset);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   189
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   190
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   191
    Position findSection(String manifestString)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   192
            throws ReflectiveOperationException {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   193
        byte[] manifestBytes = manifestString.getBytes(UTF_8);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   194
        byte[] manifestWithOffset = new byte[manifestBytes.length + offset];
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   195
        System.arraycopy(manifestBytes, 0, manifestWithOffset, offset,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   196
                manifestBytes.length);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   197
        return findSection(manifestWithOffset);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   198
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   199
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   200
    /**
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   201
     * Surprising, but the offset actually makes a difference in
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   202
     * {@link ManifestDigester#findSection} return value.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   203
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   204
    @SuppressWarnings("unused")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   205
    int actualEndOfFirstLine8217375(int correctPosition) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   206
        // if the parsed portion of the manifest starts with a blank line,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   207
        // and offset is 0, "pos.endOfFirstLine = -1;" probably denoting a
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   208
        // yet uninitialized value coincides with the assignment by
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   209
        // "pos.endOfFirstLine = i-1;" if i == 0 and
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   210
        // "if (pos.endOfFirstLine == -1)" after "case '\n':" happens to
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   211
        // become true even though already assigned.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   212
        if (offset == 0 && correctPosition == -1 && !FIXED_8217375) return 0;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   213
        return correctPosition;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   214
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   215
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   216
    @SuppressWarnings("unused")
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   217
    int actualEndOfSection8217375(int correctPosition, boolean eof, int lbl) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   218
        // if the parsed portion of the manifest ends with a blank line and
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   219
        // just before eof, the blank line is included in Position.endOfSection/
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   220
        // Section.length (the one usually without blank line as well as in
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   221
        // Position.startOfNext/Section.lengthWithBlankLine) which is used
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   222
        // in digestWorkaround (independent of the digest without workaround)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   223
        if (eof && !FIXED_8217375_EOF_ENDOFSECTION) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   224
            return correctPosition + lbl;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   225
        } else if (correctPosition == -1
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   226
                && !FIXED_8217375_STARTWITHBLANKLINE_ENDOFSECTION) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   227
            return 0;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   228
        } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   229
            return correctPosition;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   230
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   231
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   232
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   233
    AssertionError collectErrors(AssertionError a, Runnable run) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   234
        try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   235
            run.run();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   236
        } catch (AssertionError e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   237
            if (a == null) a = new AssertionError();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   238
            a.addSuppressed(e);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   239
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   240
        return a;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   241
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   242
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   243
    void assertPosition(Position pos,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   244
            int endOfFirstLine, int endOfSection, int startOfNext) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   245
        AssertionError a = null;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   246
        a = collectErrors(a, () -> assertEquals(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   247
                pos.endOfFirstLine, endOfFirstLine + offset, "endOfFirstLine"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   248
        a = collectErrors(a, () -> assertEquals(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   249
                pos.endOfSection, endOfSection + offset, "endOfSection"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   250
        a = collectErrors(a, () -> assertEquals(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   251
                pos.startOfNext, startOfNext + offset, "startOfNext"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   252
        if (a != null) throw a;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   253
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   254
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   255
    void catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   256
            Callable<Position> test, Consumer<Position> asserts) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   257
        try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   258
            Position x = test.call();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   259
            if (!FIXED_8217375) fail();
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   260
            asserts.accept(x);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   261
        } catch (Exception e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   262
            if (e instanceof IndexOutOfBoundsException ||
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   263
                e.getCause() instanceof IndexOutOfBoundsException) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   264
                if (FIXED_8217375) throw new AssertionError(e);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   265
            } else {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   266
                throw new AssertionError(e);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   267
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   268
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   269
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   270
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   271
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   272
    public void testEmpty() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   273
        assertNull(findSection(""));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   274
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   275
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   276
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   277
    public void testOneLineBreakCr() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   278
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   279
                () -> findSection("\r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   280
                p -> assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   281
                        -1, actualEndOfSection8217375(-1, false, 1), 1)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   282
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   283
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   284
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   285
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   286
    public void testOneLineBreakLf() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   287
        assertPosition(findSection("\n"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   288
                -1, actualEndOfSection8217375(-1, false, 1), 1);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   289
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   290
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   291
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   292
    public void testOneLineBreakCrLf() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   293
        assertPosition(findSection("\r\n"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   294
                actualEndOfFirstLine8217375(-1),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   295
                actualEndOfSection8217375(-1, true, 2),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   296
                2);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   297
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   298
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   299
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   300
    public void testSpaceAndLineBreakCr() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   301
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   302
                () -> findSection("   \r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   303
                p -> assertPosition(p, 2, 3, 4)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   304
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   305
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   306
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   307
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   308
    public void testSpaceAndOneLineBreakLf() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   309
        assertPosition(findSection("   \n"), 2, 3, 4);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   310
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   311
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   312
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   313
    public void testSpaceAndOneLineBreakCrLf() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   314
        assertPosition(findSection("   \r\n"), 2, 4, 5);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   315
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   316
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   317
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   318
    public void testOneLineBreakCrAndSpace() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   319
        assertPosition(findSection("\r   "),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   320
                -1, actualEndOfSection8217375(-1, false, 1), 1);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   321
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   322
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   323
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   324
    public void testOneLineBreakLfAndSpace() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   325
        assertPosition(findSection("\n   "),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   326
                -1, actualEndOfSection8217375(-1, false, 1), 1);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   327
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   328
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   329
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   330
    public void testOneLineBreakCrLfAndSpace() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   331
        assertPosition(findSection("\r\n   "),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   332
                actualEndOfFirstLine8217375(-1),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   333
                actualEndOfSection8217375(-1, false, 1),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   334
                2);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   335
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   336
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   337
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   338
    public void testCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   339
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   340
                () -> findSection("abc\r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   341
                p -> assertPosition(p, 2, 3, 4)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   342
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   343
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   344
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   345
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   346
    public void testLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   347
        assertPosition(findSection("abc\n"), 2, 3, 4);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   348
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   349
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   350
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   351
    public void testCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   352
        assertPosition(findSection("abc\r\n"), 2, 4, 5);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   353
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   354
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   355
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   356
    public void testCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   357
        assertPosition(findSection("abc\rxyz\r\n\r\n   "), 2, 8, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   358
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   359
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   360
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   361
    public void testLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   362
        assertPosition(findSection("abc\nxyz\r\n\r\n   "), 2, 8, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   363
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   364
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   365
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   366
    public void testCrLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   367
        assertPosition(findSection("abc\r\nxyz\r\n\r\n   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   368
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   369
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   370
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   371
    public void testCrCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   372
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   373
                () -> findSection("abc\r\nxyz\r\r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   374
                p -> assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   375
                        2, actualEndOfSection8217375(8, true, 1), 10)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   376
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   377
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   378
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   379
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   380
    public void testCrCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   381
        assertPosition(findSection("abc\r\nxyz\r\r   "), 2, 8, 10);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   382
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   383
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   384
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   385
    public void testLfLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   386
        assertPosition(findSection("abc\r\nxyz\n\n"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   387
                2, actualEndOfSection8217375(8, true, 1), 10);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   388
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   389
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   390
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   391
    public void testLfLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   392
        assertPosition(findSection("abc\r\nxyz\n\n   "), 2, 8, 10);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   393
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   394
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   395
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   396
    public void testCrLfEof2() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   397
        assertPosition(findSection("abc\r\nxyz\r\n"), 2, 9, 10);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   398
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   399
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   400
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   401
    public void testMainSectionNotTerminatedWithLineBreak() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   402
        assertNull(findSection("abc\r\nxyz\r\n   "));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   403
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   404
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   405
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   406
    public void testLfCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   407
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   408
                () -> findSection("abc\r\nxyz\n\r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   409
                p -> assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   410
                        2, actualEndOfSection8217375(8, true, 1), 10)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   411
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   412
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   413
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   414
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   415
    public void testLfCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   416
        assertPosition(findSection("abc\r\nxyz\n\r   "), 2, 8, 10);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   417
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   418
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   419
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   420
    public void testCrLfCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   421
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   422
                () -> findSection("abc\r\nxyz\r\n\r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   423
                p -> assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   424
                        2, actualEndOfSection8217375(9, true, 2), 11)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   425
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   426
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   427
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   428
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   429
    public void testCrLfCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   430
        assertPosition(findSection("abc\r\nxyz\r\n\r   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   431
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   432
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   433
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   434
    public void testCrLfLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   435
        assertPosition(findSection("abc\r\nxyz\r\n\n"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   436
                2, actualEndOfSection8217375(9, true, 1), 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   437
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   438
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   439
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   440
    public void testCrLfLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   441
        assertPosition(findSection("abc\r\nxyz\r\n\n   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   442
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   443
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   444
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   445
    public void testCrLfCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   446
        assertPosition(findSection("abc\r\nxyz\r\n\r\n"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   447
                2, actualEndOfSection8217375(9, true, 2), 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   448
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   449
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   450
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   451
    public void testCrLfCfLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   452
        assertPosition(findSection("abc\r\nxyz\r\n\r\n   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   453
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   454
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   455
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   456
    public void testCrLfCrCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   457
        assertPosition(findSection("abc\r\nxyz\r\n\r\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   458
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   459
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   460
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   461
    public void testCrLfCrCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   462
        assertPosition(findSection("abc\r\nxyz\r\n\r\r   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   463
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   464
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   465
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   466
    public void testCrLfLfCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   467
        assertPosition(findSection("abc\r\nxyz\r\n\n\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   468
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   469
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   470
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   471
    public void testCrLfLfCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   472
        assertPosition(findSection("abc\r\nxyz\r\n\n\r   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   473
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   474
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   475
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   476
    public void testCrLfCrLfCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   477
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r"), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   478
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   479
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   480
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   481
    public void testCrLfCfLfCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   482
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   483
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   484
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   485
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   486
    public void testCrLfCrLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   487
        assertPosition(findSection("abc\r\nxyz\r\n\r\n   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   488
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   489
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   490
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   491
    public void testCrLfLfLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   492
        assertPosition(findSection("abc\r\nxyz\r\n\n\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   493
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   494
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   495
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   496
    public void testCrLfLfLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   497
        assertPosition(findSection("abc\r\nxyz\r\n\n\n   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   498
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   499
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   500
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   501
    public void testCrLfCrLfLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   502
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\n   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   503
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   504
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   505
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   506
    public void testCrLfCrCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   507
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   508
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   509
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   510
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   511
    public void testCrLfCrCrLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   512
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\n   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   513
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   514
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   515
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   516
    public void testCrLfLfCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   517
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   518
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   519
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   520
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   521
    public void testCrLfLfCrLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   522
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\n   "), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   523
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   524
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   525
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   526
    public void testCrLfCrLfCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   527
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r\n"), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   528
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   529
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   530
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   531
    public void testCrLfCfLfCrLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   532
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r\n   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   533
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   534
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   535
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   536
    public void testCrLfLfCrCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   537
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   538
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   539
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   540
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   541
    public void testCrLfCrLfCrCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   542
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r\r"), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   543
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   544
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   545
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   546
    public void testCrLfCrLfCrContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   547
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   548
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   549
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   550
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   551
    public void testCrLfLfLfCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   552
        assertPosition(findSection("abc\r\nxyz\r\n\n\n\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   553
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   554
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   555
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   556
    public void testCrLfLfCrLfCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   557
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\n\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   558
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   559
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   560
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   561
    public void testCrLfLfLfLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   562
        assertPosition(findSection("abc\r\nxyz\r\n\n\n\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   563
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   564
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   565
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   566
    public void testCrLfLfCrLfLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   567
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\n\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   568
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   569
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   570
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   571
    public void testCrLfLfCrCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   572
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   573
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   574
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   575
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   576
    public void testCrLfCrLfCrCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   577
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r\r\n"), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   578
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   579
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   580
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   581
    public void testCrLfCrLfCrLfContinued() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   582
        assertPosition(findSection("abc\r\nxyz\r\n\r\n\r\n   "), 2, 9, 12);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   583
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   584
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   585
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   586
    public void testCrLfLfLfCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   587
        assertPosition(findSection("abc\r\nxyz\r\n\n\n\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   588
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   589
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   590
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   591
    public void testCrLfLfCrLfCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   592
        assertPosition(findSection("abc\r\nxyz\r\n\n\r\n\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   593
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   594
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   595
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   596
    public void testCrLfCrCrLfCrCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   597
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\n\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   598
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   599
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   600
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   601
    public void testCrLfCrCrCrCrEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   602
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\r"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   603
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   604
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   605
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   606
    public void testCrLfCrCrLfLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   607
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\n\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   608
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   609
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   610
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   611
    public void testCrLfCrCrLfCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   612
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\n\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   613
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   614
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   615
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   616
    public void testCrLfCrCrCrLfEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   617
        assertPosition(findSection("abc\r\nxyz\r\n\r\r\r\n"), 2, 9, 11);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   618
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   619
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   620
    /*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   621
     * endOfFirstLine is the same regardless of the line break delimiter
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   622
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   623
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   624
    public void testEndOfFirstLineVsLineBreak() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   625
        for (String lb : new String[] { "\r", "\n", "\r\n" }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   626
            Position p = findSection("abc" + lb + "xyz" + lb + lb + " ");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   627
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   628
            // main assertion showing endOfFirstLine independent of line break
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   629
            assertEquals(p.endOfFirstLine, 2 + offset);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   630
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   631
            // assert remaining positions as well just for completeness
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   632
            assertPosition(p, 2, 5 + 2 * lb.length(), 6 + 3 * lb.length());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   633
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   634
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   635
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   636
    /*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   637
     * '\r' at the end of the bytes causes index out of bounds exception
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   638
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   639
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   640
    public void testCrLastCausesIndexOutOfBounds() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   641
        catchCrCausesIndexOutOfBoundsException(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   642
                () -> findSection("\r"),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   643
                p -> assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   644
                        -1, actualEndOfSection8217375(-1, true, 1), 1)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   645
        );
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   646
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   647
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   648
    /*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   649
     * endOfSection includes second line break if at end of bytes only
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   650
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   651
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   652
    public void testEndOfSectionWithLineBreakVsEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   653
        AssertionError errors = new AssertionError("offset = " + offset);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   654
        for (String lb : new String[] { "\r", "\n", "\r\n" }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   655
            for (boolean eof : new boolean[] { false, true }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   656
                Position p;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   657
                try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   658
                    p = findSection("abc" + lb + lb + (eof ? "" : "xyz"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   659
                } catch (RuntimeException | ReflectiveOperationException e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   660
                    if ((e instanceof IndexOutOfBoundsException ||
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   661
                         e.getCause() instanceof IndexOutOfBoundsException)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   662
                          && eof && "\r".equals(lb) && !FIXED_8217375) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   663
                    throw e;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   664
                }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   665
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   666
                AssertionError a = new AssertionError("offset = " + offset
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   667
                        + ", lb = " + Utils.escapeStringWithNumbers(lb) + ", "
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   668
                        + "eof = " + eof);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   669
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   670
                // main assertion showing endOfSection including second line
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   671
                // break when at end of file
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   672
                a = collectErrors(a, () -> assertEquals(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   673
                        p.endOfSection,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   674
                        actualEndOfSection8217375(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   675
                                2 + lb.length() + offset, eof, lb.length()) ));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   676
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   677
                // assert remaining positions as well just for completeness
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   678
                a = collectErrors(a, () -> assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   679
                        2,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   680
                        actualEndOfSection8217375(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   681
                                2 + lb.length(), eof, lb.length()),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   682
                        3 + lb.length() * 2));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   683
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   684
                if (a.getSuppressed().length > 0) errors.addSuppressed(a);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   685
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   686
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   687
        if (errors.getSuppressed().length > 0) throw errors;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   688
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   689
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   690
    /*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   691
     * returns position even if only one line break before end of bytes.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   692
     * because no name will be found the result will be skipped and no entry
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   693
     * will be created.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   694
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   695
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   696
    public void testReturnPosVsEof() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   697
        for (String lb : new String[] { "\r", "\n", "\r\n" }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   698
            for (boolean eof : new boolean[] { false, true }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   699
                try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   700
                    Position p = findSection("abc" + lb + (eof ? "" : "xyz"));
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   701
                    assertTrue(p != null == eof);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   702
                } catch (RuntimeException | ReflectiveOperationException e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   703
                    if ((e instanceof IndexOutOfBoundsException ||
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   704
                         e.getCause() instanceof IndexOutOfBoundsException)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   705
                          && eof && "\r".equals(lb) && !FIXED_8217375) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   706
                    throw e;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   707
                }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   708
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   709
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   710
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   711
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   712
    /*
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   713
     * it could be normally be expected that startOfNext would point to the
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   714
     * start of the next section after a blank line but that is not the case
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   715
     * if a section ends with only one line break and no blank line immediately
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   716
     * before eof of the manifest.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   717
     * such an entry will be digested without the trailing blank line which is
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   718
     * only fine until another section should be added afterwards.
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   719
     */
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   720
    @Test
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   721
    public void testStartOfNextPointsToEofWithNoBlankLine() throws Exception {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   722
        for (String lb : new String[] { "\r", "\n", "\r\n" }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   723
            for (boolean blank : new boolean[] { false, true }) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   724
                String manifest = "abc" + lb + "xyz" + lb + (blank ? lb : "");
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   725
                try {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   726
                    Position p = findSection(manifest);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   727
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   728
                    // assert that startOfNext points to eof in all cases
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   729
                    // whether with or without a blank line before eof
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   730
                    assertEquals(p.startOfNext, manifest.length() + offset);
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   731
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   732
                    // assert remaining positions as well just for completeness
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   733
                    assertPosition(p,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   734
                            2,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   735
                            actualEndOfSection8217375(
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   736
                                    5 + lb.length() * 2,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   737
                                    true,
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   738
                                    blank ? lb.length() : 0),
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   739
                            manifest.length());
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   740
                } catch (RuntimeException | ReflectiveOperationException e) {
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   741
                    if ((e instanceof IndexOutOfBoundsException ||
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   742
                         e.getCause() instanceof IndexOutOfBoundsException)
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   743
                          && "\r".equals(lb) && !FIXED_8217375) continue;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   744
                    throw e;
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   745
                }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   746
            }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   747
        }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   748
    }
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   749
94691d8e746f 8217375: jarsigner breaks old signature with long lines in manifest
weijun
parents:
diff changeset
   750
}