-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test: accessTokenScopesIT (#18322)
- Loading branch information
1 parent
251938c
commit 9ec1f54
Showing
8 changed files
with
111 additions
and
69 deletions.
There are no files selected for viewing
54 changes: 0 additions & 54 deletions
54
...test-aad/src/test/java/com/azure/test/aad/converter/AADWebAppRefreshTokenConverterIT.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
...spring-boot-test-aad/src/test/java/com/azure/test/aad/converter/RefreshTokenScopesIT.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,88 @@ | ||
|
||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.test.aad.converter; | ||
|
||
import com.azure.test.oauth.SeleniumTestUtils; | ||
import com.azure.test.utils.AppRunner; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; | ||
import org.springframework.security.oauth2.client.annotation.RegisteredOAuth2AuthorizedClient; | ||
import org.springframework.security.oauth2.core.OAuth2AccessToken; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.*; | ||
|
||
public class RefreshTokenScopesIT { | ||
|
||
@Test | ||
public void testRefreshTokenConverter() { | ||
try (AppRunner app = new AppRunner(DumbApp.class)) { | ||
SeleniumTestUtils.addProperty(app); | ||
app.property("azure.activedirectory.authorization.office.scopes", "https://manage.office.com/ActivityFeed.Read"); | ||
app.property("azure.activedirectory.authorization.graph.scopes", "https://graph.microsoft.com/User.Read"); | ||
List<String> endPoints = new ArrayList<>(); | ||
endPoints.add("api/office"); | ||
endPoints.add("api/azure"); | ||
endPoints.add("api/graph"); | ||
endPoints.add("api/arm"); | ||
Map<String, String> result = SeleniumTestUtils.get(app, endPoints); | ||
|
||
Assert.assertFalse(result.get("api/office").contains("profile")); | ||
Assert.assertTrue(result.get("api/office").contains("https://manage.office.com/ActivityFeed.Read")); | ||
|
||
Assert.assertTrue(result.get("api/azure").contains("profile")); | ||
Assert.assertTrue(result.get("api/azure").contains("https://graph.microsoft.com/User.Read")); | ||
|
||
Assert.assertTrue(result.get("api/graph").contains("profile")); | ||
Assert.assertTrue(result.get("api/graph").contains("https://graph.microsoft.com/User.Read")); | ||
|
||
Assert.assertNotEquals("error", result.get("api/arm")); | ||
} | ||
} | ||
|
||
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) | ||
@SpringBootApplication | ||
@RestController | ||
public static class DumbApp { | ||
|
||
@GetMapping(value = "api/office") | ||
public Set<String> office( | ||
@RegisteredOAuth2AuthorizedClient("office") OAuth2AuthorizedClient authorizedClient) { | ||
return Optional.of(authorizedClient) | ||
.map(OAuth2AuthorizedClient::getAccessToken) | ||
.map(OAuth2AccessToken::getScopes) | ||
.orElse(null); | ||
} | ||
|
||
@GetMapping(value = "api/azure") | ||
public Set<String> azure( | ||
@RegisteredOAuth2AuthorizedClient("azure") OAuth2AuthorizedClient authorizedClient) { | ||
return Optional.of(authorizedClient) | ||
.map(OAuth2AuthorizedClient::getAccessToken) | ||
.map(OAuth2AccessToken::getScopes) | ||
.orElse(null); | ||
} | ||
|
||
@GetMapping(value = "api/graph") | ||
public Set<String> graph( | ||
@RegisteredOAuth2AuthorizedClient("graph") OAuth2AuthorizedClient authorizedClient) { | ||
return Optional.of(authorizedClient) | ||
.map(OAuth2AuthorizedClient::getAccessToken) | ||
.map(OAuth2AccessToken::getScopes) | ||
.orElse(null); | ||
} | ||
|
||
@GetMapping(value = "api/arm") | ||
public String arm( | ||
@RegisteredOAuth2AuthorizedClient("arm") OAuth2AuthorizedClient authorizedClient) { | ||
return "error"; | ||
} | ||
} | ||
|
||
} |
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
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