Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Commit a33b053

Browse files
Add test cases for OAuth feature validation (#1874)
* test: Add test cases for OAuth feature validation * remove old property and remove WithMockUser annotation as the logout url is public one --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 15465c9 commit a33b053

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

gate-web/gate-web.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ dependencies {
7474
testImplementation "org.apache.groovy:groovy-json"
7575
testImplementation "com.squareup.retrofit2:converter-jackson"
7676
testImplementation "com.squareup.retrofit2:retrofit-mock"
77+
testImplementation "org.springframework.security:spring-security-oauth2-client"
78+
7779

7880
// Add each included authz provider as a runtime dependency
7981
gradle.includedProviderProjects.each {

gate-web/src/test/java/com/netflix/spinnaker/gate/security/oauth/OAuth2Test.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package com.netflix.spinnaker.gate.security.oauth;
1818

1919
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oauth2Login;
2021
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
2122
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
23+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2224

2325
import org.junit.jupiter.api.Test;
2426
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,7 +34,6 @@
3234
@AutoConfigureMockMvc
3335
@SpringBootTest(
3436
properties = {
35-
"retrofit.enabled=true",
3637
"security.oauth2.client.clientId=Spinnaker-Client",
3738
"security.oauth2.resource.userInfoUri=http://localhost/userinfo"
3839
})
@@ -51,4 +52,22 @@ void shouldRedirectOnOauth2Authentication() throws Exception {
5152

5253
assertEquals(302, result.getResponse().getStatus());
5354
}
55+
56+
/** Test: Public endpoint should be accessible without authentication */
57+
@Test
58+
public void whenAccessingPublicEndpointThenSuccess() throws Exception {
59+
mockMvc.perform(get("/auth/user")).andExpect(status().isOk());
60+
}
61+
62+
/** Test: Secure endpoint should be accessible with OAuth2 authentication */
63+
@Test
64+
public void whenAuthenticatedWithOAuth2ThenAccessGranted() throws Exception {
65+
mockMvc.perform(get("/credentials").with(oauth2Login())).andExpect(status().isOk());
66+
}
67+
68+
/** Test: Logout should redirect to home */
69+
@Test
70+
public void whenLoggingOutThenRedirectToHome() throws Exception {
71+
mockMvc.perform(get("/auth/logout")).andExpect(status().is3xxRedirection());
72+
}
5473
}

0 commit comments

Comments
 (0)