Skip to content
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

Update Web Pub Sub test recordings #35848

Merged
merged 18 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/webpubsub/azure-messaging-webpubsub/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/webpubsub/azure-messaging-webpubsub",
"Tag": "java/webpubsub/azure-messaging-webpubsub_2c7e99b063"
}
7 changes: 0 additions & 7 deletions sdk/webpubsub/azure-messaging-webpubsub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
<tag>HEAD</tag>
</scm>

<properties>
<!-- Once full testing is added this should either be removed or increased -->
<jacoco.min.linecoverage>0.10</jacoco.min.linecoverage>
<jacoco.min.branchcoverage>0.10</jacoco.min.branchcoverage>
</properties>

<dependencies>
<dependency>
<groupId>com.azure</groupId>
Expand Down Expand Up @@ -135,7 +129,6 @@
<rules>
<bannedDependencies>
<includes>
<include>com.azure:*</include>
<include>com.nimbusds:nimbus-jose-jwt:[9.31]</include> <!-- {x-include-update;com.nimbusds:nimbus-jose-jwt;external_dependency} -->
</includes>
</bannedDependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ Mono<Response<BinaryData>> generateClientTokenWithResponse(RequestOptions reques
return this.serviceClient.generateClientTokenWithResponseAsync(hub, requestOptions);
}


/**
* Broadcast content inside request body to all the connected client connections.
* @param message The payload body.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.messaging.webpubsub;

import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.FixedDelayOptions;
import com.azure.core.http.policy.RetryOptions;
import com.azure.core.test.http.AssertingHttpClientBuilder;
import com.azure.core.util.Configuration;

import java.time.Duration;

/**
* Common properties used in testing.
*/
final class TestUtils {
static final String HUB_NAME = "Hub";

static String getEndpoint() {
return Configuration.getGlobalConfiguration()
.get("WEB_PUB_SUB_ENDPOINT", "http://testendpoint.webpubsubdev.azure.com");
}

static String getConnectionString() {
return Configuration.getGlobalConfiguration()
.get("WEB_PUB_SUB_CONNECTION_STRING", "Endpoint=https://testendpoint.webpubsubdev.azure.com;AccessKey=LoremIpsumDolorSitAmetConsectetur;Version=1.0;");
}

static RetryOptions getRetryOptions() {
return new RetryOptions(new FixedDelayOptions(0, Duration.ofSeconds(20)));
}

static HttpClient buildAsyncAssertingClient(HttpClient httpClient) {
return new AssertingHttpClientBuilder(httpClient)
.assertAsync()
.skipRequest((httpRequest, context) -> false)
.build();
}

private TestUtils() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import com.azure.core.http.HttpClient;
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.http.policy.HttpLogOptions;
import com.azure.core.test.TestBase;
import com.azure.core.test.TestProxyTestBase;
import com.azure.core.test.annotation.DoNotRecord;
import com.azure.core.util.Configuration;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.messaging.webpubsub.models.GetClientAccessTokenOptions;
import com.azure.messaging.webpubsub.models.WebPubSubClientAccessToken;
Expand All @@ -33,16 +32,32 @@
* Unit tests for {@link WebPubSubServiceAsyncClient#getClientAccessToken(GetClientAccessTokenOptions)
* getAuthenticationToken} method.
*/
public class TokenGenerationTest extends TestBase {
public class TokenGenerationTest extends TestProxyTestBase {

private WebPubSubServiceClientBuilder builder;

@Override
protected void beforeTest() {
builder = new WebPubSubServiceClientBuilder()
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.retryOptions(TestUtils.getRetryOptions())
.hub(TestUtils.HUB_NAME);
}

/**
* Testing token generation with connection string.
*/
@ParameterizedTest
@MethodSource("getTokenOptions")
@DoNotRecord
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we ad @DonotRecord here?

Copy link
Member Author

@conniey conniey Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, The recording is always empty because no network calls are made when using a connection string. Seemed wasteful to have 7 recordings that are empty being uploaded. ;/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this class isn't recording anything we should make this a normal unit tests and remove the extends TestProxyTestBase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other tests in this class do make network calls. :/

public void testTokenGeneration(GetClientAccessTokenOptions tokenOptions, String connectionString,
String expectedUrlPrefix, String expectedSubject,
List<String> expectedRoles, List<String> expectedGroups) throws ParseException {
WebPubSubServiceClient client = new WebPubSubServiceClientBuilder()
.hub("test")

WebPubSubServiceClient client = builder
.connectionString(connectionString)
.buildClient();

WebPubSubClientAccessToken authenticationToken = client.getClientAccessToken(tokenOptions);

assertNotNull(authenticationToken.getToken());
Expand All @@ -53,23 +68,22 @@ public void testTokenGeneration(GetClientAccessTokenOptions tokenOptions, String
assertEquals(expectedSubject, jwtClaimsSet.getSubject());
assertEquals(expectedRoles, jwtClaimsSet.getClaim("role"));
assertEquals(expectedGroups, jwtClaimsSet.getClaim("webpubsub.group"));

}

@ParameterizedTest
@MethodSource("getTokenOptions")
@DoNotRecord(skipInPlayback = true)
public void testTokenGenerationFromAadCredential(GetClientAccessTokenOptions tokenOptions, String connectionString,
String expectedUrlPrefix, String expectedSubject,
List<String> expectedRoles, List<String> expectedGroups) throws ParseException {
String endpoint = Configuration.getGlobalConfiguration()
.get("WEB_PUB_SUB_ENDPOINT", "http://testendpoint.webpubsubdev.azure.com");
String expectedUrlPrefix, String expectedSubject, List<String> expectedRoles, List<String> expectedGroups)
throws ParseException {

String endpoint = TestUtils.getEndpoint();

WebPubSubServiceClientBuilder webPubSubServiceClientBuilder = new WebPubSubServiceClientBuilder()
.endpoint(endpoint)
.httpClient(HttpClient.createDefault())
.httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
.credential(new DefaultAzureCredentialBuilder().build())
.hub("test");
.hub(TestUtils.HUB_NAME);

WebPubSubServiceClient client = webPubSubServiceClientBuilder.buildClient();
WebPubSubClientAccessToken authenticationToken = client.getClientAccessToken(tokenOptions);
Expand Down
Loading