Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add degraded mode tests for token operations
[#151024202] https://www.pivotaltracker.com/story/show/151024202
- Loading branch information
Showing
10 changed files
with
285 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...a/org/cloudfoundry/identity/uaa/mock/degraded/DegradedModeJwtBearerGrantMockMvcTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* **************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.mock.degraded; | ||
|
||
import org.cloudfoundry.identity.uaa.mock.token.JwtBearerGrantMockMvcTests; | ||
import org.cloudfoundry.identity.uaa.web.DegradedModeUaaFilter; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
public class DegradedModeJwtBearerGrantMockMvcTests extends JwtBearerGrantMockMvcTests { | ||
private boolean original; | ||
|
||
@Before | ||
public void setup () throws Exception { | ||
DegradedModeUaaFilter bean = getWebApplicationContext().getBean(DegradedModeUaaFilter.class); | ||
original = bean.isEnabled(); | ||
bean.setEnabled(true); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception { | ||
getWebApplicationContext().getBean(DegradedModeUaaFilter.class).setEnabled(original); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
.../test/java/org/cloudfoundry/identity/uaa/mock/degraded/DegradedModeTokenMockMvcTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* **************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.mock.degraded; | ||
|
||
import org.cloudfoundry.identity.uaa.mock.token.TokenMvcMockTests; | ||
import org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils; | ||
import org.cloudfoundry.identity.uaa.web.DegradedModeUaaFilter; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.springframework.security.crypto.codec.Base64; | ||
import org.springframework.security.oauth2.provider.client.BaseClientDetails; | ||
|
||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
import static org.springframework.http.HttpHeaders.AUTHORIZATION; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
public class DegradedModeTokenMockMvcTests extends TokenMvcMockTests { | ||
|
||
private boolean original; | ||
|
||
@Before | ||
@Override | ||
public void setup () throws Exception { | ||
super.setup(); | ||
DegradedModeUaaFilter bean = getWebApplicationContext().getBean(DegradedModeUaaFilter.class); | ||
original = bean.isEnabled(); | ||
bean.setEnabled(true); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception { | ||
getWebApplicationContext().getBean(DegradedModeUaaFilter.class).setEnabled(original); | ||
} | ||
|
||
@Test | ||
public void check_token_while_degraded() throws Exception { | ||
BaseClientDetails client = setUpClients(generator.generate().toLowerCase(), | ||
"uaa.resource,clients.read", | ||
"", | ||
"client_credentials", | ||
true); | ||
String token = MockMvcUtils.getClientCredentialsOAuthAccessToken(getMockMvc(), client.getClientId(), SECRET, null, null, true); | ||
getMockMvc().perform( | ||
post("/check_token") | ||
.param("token", token) | ||
.header(AUTHORIZATION, | ||
"Basic " + new String(Base64.encode((client.getClientId() + ":" + SECRET).getBytes()))) | ||
) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.scope").value(containsInAnyOrder("clients.read", "uaa.resource"))) | ||
.andExpect(jsonPath("$.client_id").value(client.getClientId())) | ||
.andExpect(jsonPath("$.jti").value(token)); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...t/java/org/cloudfoundry/identity/uaa/mock/degraded/DegradedModeUserTokenMockMvcTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* **************************************************************************** | ||
* Cloud Foundry | ||
* Copyright (c) [2009-2017] Pivotal Software, Inc. All Rights Reserved. | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product includes a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of these | ||
* subcomponents is subject to the terms and conditions of the | ||
* subcomponent's license, as noted in the LICENSE file. | ||
* **************************************************************************** | ||
*/ | ||
|
||
package org.cloudfoundry.identity.uaa.mock.degraded; | ||
|
||
import org.cloudfoundry.identity.uaa.mock.token.UserTokenMockMvcTests; | ||
import org.cloudfoundry.identity.uaa.web.DegradedModeUaaFilter; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Ignore; | ||
import org.junit.Test; | ||
|
||
public class DegradedModeUserTokenMockMvcTests extends UserTokenMockMvcTests { | ||
private boolean original; | ||
|
||
@Before | ||
public void setup () throws Exception { | ||
DegradedModeUaaFilter bean = getWebApplicationContext().getBean(DegradedModeUaaFilter.class); | ||
original = bean.isEnabled(); | ||
bean.setEnabled(true); | ||
} | ||
|
||
@After | ||
public void teardown() throws Exception { | ||
getWebApplicationContext().getBean(DegradedModeUaaFilter.class).setEnabled(original); | ||
} | ||
|
||
@Test | ||
@Ignore("super method uses disabled endpoints") | ||
@Override | ||
public void test_create_client_with_user_token_grant() throws Exception { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.