diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-07-05 21:36:07 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-07-05 21:36:07 +0000 |
commit | a01600e60599ee23c9639cbef98ea70cdec90293 (patch) | |
tree | 5afe0e6c98b3acd34a1dcda98c76b3be8ac47555 | |
parent | 8848c65651ffbf01143d3de32f67a99d6e4b0e33 (diff) | |
download | poi-a01600e60599ee23c9639cbef98ea70cdec90293.tar.gz poi-a01600e60599ee23c9639cbef98ea70cdec90293.zip |
deactivate TestSignatureInfo on Jdk 1.8.0 PatchLevel 292
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1891289 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java | 7 | ||||
-rw-r--r-- | poi/src/test/java/org/apache/poi/util/ConditionalExecution.java | 89 |
2 files changed, 96 insertions, 0 deletions
diff --git a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java index 644aca19b1..77a709eb3b 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java +++ b/poi-ooxml/src/test/java/org/apache/poi/poifs/crypt/dsig/TestSignatureInfo.java @@ -102,6 +102,7 @@ import org.apache.poi.poifs.crypt.dsig.services.TimeStampService; import org.apache.poi.poifs.crypt.dsig.services.TimeStampServiceValidator; import org.apache.poi.poifs.storage.RawDataUtil; import org.apache.poi.ss.usermodel.WorkbookFactory; +import org.apache.poi.util.ConditionalExecution.DisabledOnJreEx; import org.apache.poi.util.IOUtils; import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.TempFile; @@ -444,6 +445,7 @@ class TestSignatureInfo { } @Test + @DisabledOnJreEx("1.8.0_292") void testSignSpreadsheetWithSignatureInfo() throws Exception { initKeyPair(); String testFile = "hello-world-unsigned.xlsx"; @@ -467,6 +469,7 @@ class TestSignatureInfo { } @Test + @DisabledOnJreEx("1.8.0_292") void testSignEnvelopingDocument() throws Exception { String testFile = "hello-world-unsigned.xlsx"; File sigCopy = testdata.getFile(testFile); @@ -716,6 +719,7 @@ class TestSignatureInfo { } @Test + @DisabledOnJreEx("1.8.0_292") void testNonSha1() throws Exception { String testFile = "hello-world-unsigned.xlsx"; initKeyPair(); @@ -745,6 +749,7 @@ class TestSignatureInfo { // Test signing of external references / hyperlinks @Test + @DisabledOnJreEx("1.8.0_292") void bug65214() throws Exception { initKeyPair(); @@ -783,6 +788,7 @@ class TestSignatureInfo { } @Test + @DisabledOnJreEx("1.8.0_292") void bug58630() throws Exception { // test deletion of sheet 0 and signing File tpl = copy(testdata.getFile("bug58630.xlsx")); @@ -915,6 +921,7 @@ class TestSignatureInfo { } @Test + @DisabledOnJreEx("1.8.0_292") void testSignatureImage() throws Exception { initKeyPair(); diff --git a/poi/src/test/java/org/apache/poi/util/ConditionalExecution.java b/poi/src/test/java/org/apache/poi/util/ConditionalExecution.java new file mode 100644 index 0000000000..9158d20577 --- /dev/null +++ b/poi/src/test/java/org/apache/poi/util/ConditionalExecution.java @@ -0,0 +1,89 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +/* ==================================================================== + This product contains an ASLv2 licensed version of the OOXML signer + package from the eID Applet project + http://code.google.com/p/eid-applet/source/browse/trunk/README.txt + Copyright (C) 2008-2014 FedICT. + ================================================================= */ +package org.apache.poi.util; + +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.disabled; +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.enabled; +import static org.junit.platform.commons.util.AnnotationUtils.findAnnotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Arrays; +import java.util.regex.Pattern; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.platform.commons.util.Preconditions; + +/** + * Collection of Junit annotations to control the executions of tests + */ +public class ConditionalExecution { + @Target({ ElementType.TYPE, ElementType.METHOD }) + @Retention(RetentionPolicy.RUNTIME) + @Documented + @ExtendWith(DisabledOnJreExCondition.class) + public @interface DisabledOnJreEx { + + /** + * Version-Strings as Regex + */ + String[] value(); + + /** + * Reason to provide if the test of container ends up being disabled. + */ + String disabledReason() default ""; + + } + + public static class DisabledOnJreExCondition implements ExecutionCondition { + + DisabledOnJreExCondition() { + } + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + String version = Runtime.class.getPackage().getImplementationVersion(); + return findAnnotation(context.getElement(), DisabledOnJreEx.class).filter(annotation -> !isEnabled(annotation)) + .map(annotation -> disabled("PatchLevel skipped", "JRE version " + version + " skipped")) + .orElseGet(() -> enabled("PatchLevel not matched")); + } + + + boolean isEnabled(DisabledOnJreEx annotation) { + String[] versions = annotation.value(); + Preconditions.condition(versions.length > 0, "You must declare at least one JRE version in @DisabledOnJreEx"); + String version = Runtime.class.getPackage().getImplementationVersion(); + return Arrays.stream(versions).noneMatch(p -> Pattern.matches(p, version)); + } + + } + +} |