-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test: accessTokenScopesIT #18322
Changes from all commits
7672337
7d11fd9
9a67388
7f3cdc1
8af1ac1
671b413
8b43650
e1cca06
f6bcb17
74b7e21
5179ff0
08c59c2
20d5d03
efa9f79
3c765cc
bc73f25
a44207e
0c613ce
74a5aab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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"; | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
|
@@ -14,14 +15,15 @@ | |
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
import static com.azure.test.oauth.OAuthUtils.*; | ||
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated; | ||
|
||
public class OAuthLoginUtils { | ||
public class SeleniumTestUtils { | ||
|
||
static { | ||
final String directory = "src/test/resources/driver/"; | ||
|
@@ -56,9 +58,9 @@ public class OAuthLoginUtils { | |
} | ||
} | ||
|
||
public static List<String> get(AppRunner app, List<String> endPoints) { | ||
public static Map<String, String> get(AppRunner app, List<String> endPoints) { | ||
|
||
List<String> result = new ArrayList<>(); | ||
Map<String , String> result = new HashMap<>(); | ||
ChromeOptions options = new ChromeOptions(); | ||
options.addArguments("--incognito"); | ||
options.addArguments("--headless"); | ||
|
@@ -77,12 +79,12 @@ public static List<String> get(AppRunner app, List<String> endPoints) { | |
Thread.sleep(10000); | ||
driver.findElement(By.cssSelector("input[type='submit']")).click(); | ||
Thread.sleep(10000); | ||
result.add(driver.findElement(By.tagName("body")).getText()); | ||
result.put(endPoints.get(0) , driver.findElement(By.tagName("body")).getText()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we put |
||
endPoints.remove(0); | ||
for(String endPoint : endPoints) { | ||
driver.get(app.root() + endPoint); | ||
Thread.sleep(1000); | ||
result.add(driver.findElement(By.tagName("body")).getText()); | ||
result.put(endPoint ,driver.findElement(By.tagName("body")).getText()); | ||
} | ||
return result; | ||
} catch (InterruptedException e) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessTokenScopesIT