Skip to content

Commit a98e3bc

Browse files
committed
Allow skipping tests tha require browser auth
Some UAA do not return a Location header.
1 parent f5ecb4a commit a98e3bc

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Name | Description
298298
`TEST_PROXY_USERNAME` | _(Optional)_ The username for a proxy to route all requests through
299299
`TEST_SKIPSSLVALIDATION` | _(Optional)_ Whether to skip SSL validation when connecting to the Cloud Foundry instance. Defaults to `false`.
300300
`UAA_API_REQUEST_LIMIT` | _(Optional)_ If your UAA server does rate limiting and returns 429 errors, set this variable to the smallest limit configured there. Whether your server limits UAA calls is shown in the log, together with the location of the configuration file on the server. Defaults to `0` (no limit).
301+
`SKIP_BROWSER_AUTH_TESTS` | _(Optional)_ Set to `true` to skip integration tests that require browser-based authentication (e.g., SSO tests). Useful when the Cloud Foundry instance does not support browser-based authentication or when running tests in a non-interactive environment. Defaults to `false`.
301302
`SKIP_TCP_ROUTING_TESTS` | _(Optional)_ Set to `true` to skip TCP routing integration tests (TcpRoutesTest, RouterGroupsTest). Useful when the Cloud Foundry instance does not have TCP routing configured (i.e., no `routing_endpoint` in the info payload). Defaults to `false`.
302303
`SKIP_V2_TESTS` | _(Optional)_ Set to `true` to skip all V2 API integration tests. Useful when the Cloud Foundry V2 API is rate-limited or unavailable. When enabled, tests annotated with `@RequiresV2Api` will be skipped, including V3 tests that depend on V2 API calls (e.g., service broker creation). Defaults to `false`.
303304

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2026 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+
* http://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+
17+
package org.cloudfoundry;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Inherited;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
26+
import org.junit.jupiter.api.extension.ExecutionCondition;
27+
import org.junit.jupiter.api.extension.ExtendWith;
28+
import org.junit.jupiter.api.extension.ExtensionContext;
29+
30+
/**
31+
* Annotation to mark tests that require browser-based authentication (e.g., OAuth
32+
* authorization code grants, implicit grants). Tests annotated with this will be skipped
33+
* if the environment variable {@code SKIP_BROWSER_AUTH_TESTS} is set to "true".
34+
*
35+
* <p>Usage:
36+
* <pre>
37+
* &#64;RequiresBrowserAuth
38+
* public class MyAuthTest extends AbstractIntegrationTest {
39+
* // ...
40+
* }
41+
* </pre>
42+
*
43+
* <p>To skip browser auth tests, set the environment variable:
44+
* <pre>
45+
* export SKIP_BROWSER_AUTH_TESTS=true
46+
* </pre>
47+
*/
48+
@Target({ElementType.METHOD, ElementType.TYPE})
49+
@Retention(RetentionPolicy.RUNTIME)
50+
@Documented
51+
@Inherited
52+
@ExtendWith(RequiresBrowserAuth.BrowserAuthCondition.class)
53+
public @interface RequiresBrowserAuth {
54+
55+
/**
56+
* JUnit 5 ExecutionCondition that checks if Browser Auth tests should be skipped.
57+
*/
58+
class BrowserAuthCondition implements ExecutionCondition {
59+
60+
private static final String SKIP_BROWSER_AUTH_ENV = "SKIP_BROWSER_AUTH_TESTS";
61+
62+
@Override
63+
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
64+
if ("true".equalsIgnoreCase(System.getenv(SKIP_BROWSER_AUTH_ENV))) {
65+
return ConditionEvaluationResult.disabled(
66+
"Tests requiring Browser Authentication are disabled via "
67+
+ SKIP_BROWSER_AUTH_ENV
68+
+ " environment variable");
69+
}
70+
71+
return ConditionEvaluationResult.enabled("Browser authentication tests are enabled");
72+
}
73+
}
74+
}

integration-test/src/test/java/org/cloudfoundry/uaa/AuthorizationsTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.Duration;
2222
import java.util.function.Consumer;
2323
import org.cloudfoundry.AbstractIntegrationTest;
24+
import org.cloudfoundry.RequiresBrowserAuth;
2425
import org.cloudfoundry.uaa.authorizations.AuthorizeByAuthorizationCodeGrantApiRequest;
2526
import org.cloudfoundry.uaa.authorizations.AuthorizeByAuthorizationCodeGrantBrowserRequest;
2627
import org.cloudfoundry.uaa.authorizations.AuthorizeByAuthorizationCodeGrantHybridRequest;
@@ -55,6 +56,7 @@ public void authorizeByAuthorizationCodeGrantApi() {
5556
}
5657

5758
@Test
59+
@RequiresBrowserAuth
5860
public void authorizeByAuthorizationCodeGrantBrowser() {
5961
this.uaaClient
6062
.authorizations()
@@ -70,6 +72,7 @@ public void authorizeByAuthorizationCodeGrantBrowser() {
7072
}
7173

7274
@Test
75+
@RequiresBrowserAuth
7376
public void authorizeByAuthorizationCodeGrantHybrid() {
7477
this.uaaClient
7578
.authorizations()
@@ -85,6 +88,7 @@ public void authorizeByAuthorizationCodeGrantHybrid() {
8588
}
8689

8790
@Test
91+
@RequiresBrowserAuth
8892
public void authorizeByImplicitGrantBrowser() {
8993
this.uaaClient
9094
.authorizations()
@@ -100,6 +104,7 @@ public void authorizeByImplicitGrantBrowser() {
100104
}
101105

102106
@Test
107+
@RequiresBrowserAuth
103108
public void authorizeByOpenIdWithAuthorizationCodeGrant() {
104109
this.uaaClient
105110
.authorizations()
@@ -116,6 +121,7 @@ public void authorizeByOpenIdWithAuthorizationCodeGrant() {
116121
}
117122

118123
@Test
124+
@RequiresBrowserAuth
119125
public void authorizeByOpenIdWithIdToken() {
120126
this.uaaClient
121127
.authorizations()
@@ -132,6 +138,7 @@ public void authorizeByOpenIdWithIdToken() {
132138
}
133139

134140
@Test
141+
@RequiresBrowserAuth
135142
public void authorizeByOpenIdWithImplicitGrant() {
136143
this.uaaClient
137144
.authorizations()

0 commit comments

Comments
 (0)