-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Bearer Token Challenge Auth Policy performance test. #19360
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5abdbc6
update
fe005d0
add perf test
e3939d5
update
cbb069a
update
8eb200f
Merge remote-tracking branch 'upstream/master' into cae-performance-t…
585e502
perf test updates
4866c32
fix checkstyle
acfef18
fix changelog
4ec74b7
update
a08b6c5
fix pom
15e8d54
Merge remote-tracking branch 'upstream/master' into cae-performance-t…
924295d
update pom
8853ceb
update
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,34 @@ | ||
| # Azure Core Experimental Performance test client library for Java | ||
|
|
||
| Represents Performance tests for Azure Core SDK for Java. | ||
|
|
||
| ## Getting started | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Java Development Kit (JDK) with version 8 or above | ||
|
|
||
| ### Adding the package to your product | ||
|
|
||
|
|
||
| ## Key concepts | ||
|
|
||
|
|
||
| ## Examples | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ## Next steps | ||
|
|
||
| ## Contributing | ||
|
|
||
| If you would like to become an active contributor to this project please follow the instructions provided in [Microsoft | ||
| Azure Projects Contribution Guidelines](http://azure.github.io/guidelines.html). | ||
|
|
||
| 1. Fork it | ||
| 1. Create your feature branch (`git checkout -b my-new-feature`) | ||
| 1. Commit your changes (`git commit -am 'Add some feature'`) | ||
| 1. Push to the branch (`git push origin my-new-feature`) | ||
| 1. Create new Pull Request | ||
|
|
||
|  |
This file contains hidden or 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,64 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <groupId>com.azure</groupId> | ||
| <artifactId>azure-client-sdk-parent</artifactId> | ||
| <version>1.7.0</version> <!-- {x-version-update;com.azure:azure-client-sdk-parent;current} --> | ||
| <relativePath>../../parents/azure-client-sdk-parent</relativePath> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>azure-core-experimental-perf</artifactId> | ||
| <version>1.0.0-beta.1</version> | ||
|
|
||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.azure</groupId> | ||
| <artifactId>azure-core</artifactId> | ||
| <version>1.14.0-beta.1</version> <!-- {x-version-update;com.azure:azure-core;current} --> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.azure</groupId> | ||
| <artifactId>perf-test-core</artifactId> | ||
| <version>1.0.0-beta.1</version> <!-- {x-version-update;com.azure:perf-test-core;current} --> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.azure</groupId> | ||
| <artifactId>azure-core-experimental</artifactId> | ||
| <version>1.0.0-beta.11</version> <!-- {x-version-update;com.azure:azure-core-experimental-perf;current} --> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-assembly-plugin</artifactId> | ||
| <version>3.2.0</version> <!-- {x-version-update;org.apache.maven.plugins:maven-assembly-plugin;external_dependency} --> | ||
| <executions> | ||
| <execution> | ||
| <phase>package</phase> | ||
| <goals> | ||
| <goal>single</goal> | ||
| </goals> | ||
| <configuration> | ||
| <archive> | ||
| <manifest> | ||
| <mainClass> | ||
| com.azure.core.perf.App | ||
| </mainClass> | ||
| </manifest> | ||
| </archive> | ||
| <descriptorRefs> | ||
| <descriptorRef>jar-with-dependencies</descriptorRef> | ||
| </descriptorRefs> | ||
| </configuration> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
112 changes: 112 additions & 0 deletions
112
...rimental-perf/src/main/java/com/azure/core/perf/ARMChallengeAuthenticationPolicyTest.java
This file contains hidden or 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,112 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.perf; | ||
|
|
||
| import com.azure.core.credential.AccessToken; | ||
| import com.azure.core.credential.TokenCredential; | ||
| import com.azure.core.credential.TokenRequestContext; | ||
| import com.azure.core.experimental.http.policy.ARMChallengeAuthenticationPolicy; | ||
| import com.azure.core.experimental.http.policy.BearerTokenAuthenticationChallengePolicy; | ||
| import com.azure.core.experimental.implementation.AzureEnvironment; | ||
| import com.azure.core.http.HttpPipeline; | ||
| import com.azure.core.http.HttpPipelineBuilder; | ||
| import com.azure.core.http.HttpRequest; | ||
| import com.azure.core.http.HttpResponse; | ||
| import com.azure.core.http.HttpHeaders; | ||
| import com.azure.core.http.rest.RestProxy; | ||
| import com.azure.core.perf.core.MockHttpClient; | ||
| import com.azure.core.perf.core.MyRestProxyService; | ||
| import com.azure.core.perf.models.MockHttpResponse; | ||
| import com.azure.core.util.CoreUtils; | ||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.azure.perf.test.core.PerfStressOptions; | ||
| import com.azure.perf.test.core.PerfStressTest; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
| import java.util.HashMap; | ||
|
|
||
| /** | ||
| * The Performance Test class for Bearer Token Authentication Challenge Policy. | ||
| */ | ||
| public class ARMChallengeAuthenticationPolicyTest extends PerfStressTest<PerfStressOptions> { | ||
| private static final String CLAIMS_ACCESS_TOKEN = "CLAIMS-ACCESS-TOKEN"; | ||
| private static final String ACCESS_TOKEN = "ACCESS-TOKEN"; | ||
| private static final String AUTHORIZATION = "Authorization"; | ||
| private static final String APPLICATION_JSON = "application/json"; | ||
| private static final String CONTENT_TYPE = "Content-Type"; | ||
| private static final String MOCK_CHALLENGE = "Bearer authorization_uri=" | ||
| + "\"https://login.windows-ppe.net/\", error=\"invalid_token\"," | ||
| + " error_description=\"User session has been revoked\"," | ||
| + " claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTYwMzc0MjgwMCJ9fX0=\""; | ||
|
|
||
| private final ClientLogger logger = new ClientLogger(ARMChallengeAuthenticationPolicyTest.class); | ||
| private final MockHttpClient mockHTTPClient; | ||
| private final MyRestProxyService service; | ||
| private boolean trigger = false; | ||
|
|
||
| /** | ||
| * Creates an instance of the ARMChallengeAuthenticationPolicyTest class. | ||
| * @param options the command line options to run the performance test. | ||
| */ | ||
| public ARMChallengeAuthenticationPolicyTest(PerfStressOptions options) { | ||
| super(options); | ||
| mockHTTPClient = new MockHttpClient((httpRequest) -> { | ||
| String bearerToken = httpRequest.getHeaders().getValue(AUTHORIZATION); | ||
| if (bearerToken.contains(CLAIMS_ACCESS_TOKEN)) { | ||
| return createMockSuccessResponse(httpRequest, APPLICATION_JSON); | ||
| } else { | ||
| return createMockClaimsResponse(httpRequest, "application/json"); | ||
| } | ||
| }); | ||
| final HttpPipeline pipeline = new HttpPipelineBuilder() | ||
| .policies(new ARMChallengeAuthenticationPolicy(new TokenCredential() { | ||
| @Override | ||
| public Mono<AccessToken> getToken(TokenRequestContext request) { | ||
| return Mono.defer(() -> { | ||
| AccessToken token; | ||
| if (!CoreUtils.isNullOrEmpty(request.getClaims()) && request.getClaims().length() > 1) { | ||
| token = new AccessToken(CLAIMS_ACCESS_TOKEN, OffsetDateTime.now().plusDays(1)); | ||
| } else { | ||
| token = new AccessToken(ACCESS_TOKEN, OffsetDateTime.now().plusDays(1)); | ||
| } | ||
| return Mono.just(token); | ||
| }); | ||
| } | ||
| }, new AzureEnvironment(new HashMap<>()), "Dummy-Scope")) | ||
| .httpClient(mockHTTPClient) | ||
| .build(); | ||
|
|
||
| service = RestProxy.create(MyRestProxyService.class, pipeline); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { | ||
| throw logger.logExceptionAsError(new UnsupportedOperationException()); | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<Void> runAsync() { | ||
| if (!trigger) { | ||
| trigger = true; | ||
| return service.listSubscriptions().then(); | ||
| } else { | ||
| return Mono.empty(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| private HttpResponse createMockClaimsResponse(HttpRequest httpRequest, String contentType) { | ||
| HttpHeaders headers = new HttpHeaders().set(CONTENT_TYPE, contentType); | ||
| headers.set(BearerTokenAuthenticationChallengePolicy.WWW_AUTHENTICATE, MOCK_CHALLENGE); | ||
| HttpResponse res = new MockHttpResponse(httpRequest, 401, headers); | ||
| return res; | ||
| } | ||
|
|
||
| private HttpResponse createMockSuccessResponse(HttpRequest httpRequest, String contentType) { | ||
| HttpHeaders headers = new HttpHeaders().set(CONTENT_TYPE, contentType); | ||
| HttpResponse res = new MockHttpResponse(httpRequest, 200, headers); | ||
| return res; | ||
| } | ||
| } | ||
38 changes: 38 additions & 0 deletions
38
sdk/core/azure-core-experimental-perf/src/main/java/com/azure/core/perf/App.java
This file contains hidden or 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,38 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.perf; | ||
|
|
||
| import com.azure.perf.test.core.PerfStressProgram; | ||
|
|
||
| /** | ||
| * Runs the Storage performance test. | ||
| * | ||
| * <p>To run from command line. Package the project into a jar with dependencies via mvn clean package. | ||
| * Then run the program via java -jar 'compiled-jar-with-dependencies-path' </p> | ||
| * | ||
| * <p> To run from IDE, set all the required environment variables in IntelliJ via Run -> EditConfigurations | ||
| * section. | ||
| * Then run the App's main method via IDE.</p> | ||
| */ | ||
| public class App { | ||
|
|
||
| /** | ||
| * The main method for the performance testing package. | ||
| * @param args the command line arguments. | ||
| * @throws RuntimeException if the performance tests implementation classes cannot be found. | ||
| */ | ||
| public static void main(String[] args) { | ||
| Class<?>[] testClasses; | ||
|
|
||
| try { | ||
| testClasses = new Class<?>[]{ | ||
| Class.forName("com.azure.core.perf.ARMChallengeAuthenticationPolicyTest") | ||
| }; | ||
| } catch (ClassNotFoundException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
|
|
||
| PerfStressProgram.run(testClasses, args); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...e/azure-core-experimental-perf/src/main/java/com/azure/core/perf/core/MockHttpClient.java
This file contains hidden or 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,32 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.perf.core; | ||
|
|
||
| import com.azure.core.http.HttpClient; | ||
| import com.azure.core.http.HttpRequest; | ||
| import com.azure.core.http.HttpResponse; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.util.function.Function; | ||
|
|
||
| /** | ||
| * The Mock Http Client to send recorded responses back to the Http Pipeline. | ||
| */ | ||
| public class MockHttpClient implements HttpClient { | ||
| private final Function<HttpRequest, HttpResponse> responseSupplier; | ||
|
|
||
| /** | ||
| * Creates an instance of the {@link MockHttpClient} | ||
| * | ||
| * @param responseSupplier the supplier to supply the {@link HttpResponse} | ||
| */ | ||
| public MockHttpClient(Function<HttpRequest, HttpResponse> responseSupplier) { | ||
| this.responseSupplier = responseSupplier; | ||
| } | ||
|
|
||
| @Override | ||
| public Mono<HttpResponse> send(HttpRequest request) { | ||
| return Mono.just(responseSupplier.apply(request)); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
...ure-core-experimental-perf/src/main/java/com/azure/core/perf/core/MyRestProxyService.java
This file contains hidden or 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,26 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.core.perf.core; | ||
|
|
||
| import com.azure.core.annotation.Get; | ||
| import com.azure.core.annotation.Host; | ||
|
|
||
| import com.azure.core.annotation.ServiceInterface; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
|
|
||
| /** | ||
| * Mock Rest Proxy Service for Performance Testing. | ||
| */ | ||
| @Host("https://unused") | ||
| @ServiceInterface(name = "MyMockService") | ||
| public interface MyRestProxyService { | ||
|
|
||
| /** | ||
| * List all the subscriptions | ||
| * @return A {@link Mono} containing Void. | ||
| */ | ||
| @Get("ListSubscriptions") | ||
| Mono<Void> listSubscriptions(); | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ore/azure-core-experimental-perf/src/main/java/com/azure/core/perf/core/package-info.java
This file contains hidden or 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,7 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| /** | ||
| * Core package of azure-core-experimental-perf. | ||
| */ | ||
| package com.azure.core.perf.core; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is this named ARM? This isn't related to the management plane right?
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.
Yes, this policy is for ARM SDK.
We will work with ARM folks and move it there later on.