Skip to content

Commit 0ff8293

Browse files
committed
Disable AppId tests on Vault 1.12 and newer.
Closes gh-798
1 parent 02e4e0c commit 0ff8293

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

spring-vault-core/src/test/java/org/springframework/vault/authentication/AppIdAuthenticationIntegrationTestBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
import org.junit.jupiter.api.BeforeEach;
2222

23+
import org.springframework.vault.util.DisabledOnVaultVersion;
2324
import org.springframework.vault.util.IntegrationTestSupport;
2425

2526
/**
2627
* Integration test base class for {@link AppIdAuthentication} tests.
2728
*
2829
* @author Mark Paluch
2930
*/
31+
@DisabledOnVaultVersion("1.12")
3032
public abstract class AppIdAuthenticationIntegrationTestBase extends IntegrationTestSupport {
3133

3234
@BeforeEach
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2019-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.vault.util;
17+
18+
import java.lang.annotation.Documented;
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Inherited;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
import org.junit.jupiter.api.extension.ExtendWith;
26+
27+
/**
28+
* Annotation to guard a {@code @Test} to skip on or after the specified Vault version.
29+
* <p>
30+
* When applied at the class level, all test methods within that class are automatically
31+
* disabled as well.
32+
*
33+
* <p>
34+
* When applied at the method level, the presence of this annotation does not prevent the
35+
* test class from being instantiated. Rather, it prevents the execution of the test
36+
* method and method-level lifecycle callbacks such as {@code @BeforeEach} methods,
37+
* {@code @AfterEach} methods, and corresponding extension APIs.
38+
*
39+
* @author Mark Paluch
40+
* @see VaultVersionExtension
41+
*/
42+
@Target({ ElementType.TYPE, ElementType.METHOD })
43+
@Retention(RetentionPolicy.RUNTIME)
44+
@Documented
45+
@Inherited
46+
@ExtendWith(VaultVersionExtension.class)
47+
public @interface DisabledOnVaultVersion {
48+
49+
/**
50+
* Minimum version to skip a test.
51+
*/
52+
String value();
53+
54+
}

spring-vault-core/src/test/java/org/springframework/vault/util/VaultVersionExtension.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
/**
2626
* This is an {@link org.junit.jupiter.api.extension.ExecutionCondition} that supports the
27-
* {@link RequiresVaultVersion @RequiresVaultVersion} annotation.
27+
* {@link RequiresVaultVersion @RequiresVaultVersion} and
28+
* {@link DisabledOnVaultVersion @DisabledOnVaultVersion} annotations.
2829
*
2930
* @author Mark Paluch
3031
* @see RequiresVaultVersion
@@ -35,15 +36,18 @@ class VaultVersionExtension implements ExecutionCondition {
3536
private static final ExtensionContext.Namespace VAULT = ExtensionContext.Namespace.create("vault.version");
3637

3738
private static final ConditionEvaluationResult ENABLED_BY_DEFAULT = ConditionEvaluationResult
38-
.enabled("@VaultVersion is not present");
39+
.enabled("@VaultVersion is not present");
3940

4041
@Override
4142
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
4243

43-
Optional<RequiresVaultVersion> optional = AnnotationUtils.findAnnotation(context.getElement(),
44+
Optional<RequiresVaultVersion> required = AnnotationUtils.findAnnotation(context.getElement(),
4445
RequiresVaultVersion.class);
4546

46-
if (!optional.isPresent()) {
47+
Optional<DisabledOnVaultVersion> disabled = AnnotationUtils.findAnnotation(context.getElement(),
48+
DisabledOnVaultVersion.class);
49+
50+
if (required.isEmpty() && disabled.isEmpty()) {
4751
return ENABLED_BY_DEFAULT;
4852
}
4953

@@ -56,17 +60,37 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
5660
return initializer.prepare().getVersion();
5761
}, Version.class);
5862

59-
RequiresVaultVersion requiredVersion = optional.get();
63+
if (required.isPresent()) {
64+
65+
Version requiredVersion = Version.parse(required.get().value());
6066

61-
Version required = Version.parse(requiredVersion.value());
67+
if (runningVersion.isGreaterThanOrEqualTo(requiredVersion)) {
68+
return ConditionEvaluationResult
69+
.enabled(String.format("Test is enabled, @VaultVersion(%s) is met with Vault running version %s",
70+
requiredVersion, runningVersion));
71+
}
6272

63-
if (runningVersion.isGreaterThanOrEqualTo(required)) {
6473
return ConditionEvaluationResult
65-
.enabled(String.format("@VaultVersion check passed current Vault version is %s", runningVersion));
74+
.disabled(String.format("Test is disabled, @VaultVersion(%s) is not met with Vault running version %s",
75+
requiredVersion, runningVersion));
76+
}
77+
78+
if (disabled.isPresent()) {
79+
80+
Version disabledVersion = Version.parse(disabled.get().value());
81+
82+
if (runningVersion.isGreaterThanOrEqualTo(disabledVersion)) {
83+
return ConditionEvaluationResult.disabled(String.format(
84+
"Test is disabled, @DisabledOnVaultVersion(%s) is met with Vault running version %s",
85+
disabledVersion, runningVersion));
86+
}
87+
88+
return ConditionEvaluationResult.enabled(String.format(String.format(
89+
"Test is enabled, @DisabledOnVaultVersion(%s) is not met with Vault running version %s",
90+
disabledVersion, runningVersion)));
6691
}
6792

68-
return ConditionEvaluationResult.disabled(String
69-
.format("@VaultVersion requires since version %s, current Vault version is %s", required, runningVersion));
93+
return ENABLED_BY_DEFAULT;
7094
}
7195

7296
}

0 commit comments

Comments
 (0)