Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CommunicationIdentityClientOptions(ServiceVersion version = LatestVersion
ServiceVersion.V2021_03_07 => "2021-03-07",
ServiceVersion.V2022_06_01 => "2022-06-01",
ServiceVersion.V2022_10_01 => "2022-10-01",
_ => throw new ArgumentOutOfRangeException(nameof(version)),
_ => throw new ArgumentOutOfRangeException(nameof(version))
};
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Azure.Communication.Identity
{
[CodeGenModel("CommunicationIdentityAccessTokenResult")]
[CodeGenSuppress("CommunicationUserIdentifierAndToken", typeof(CommunicationIdentity))]
public partial class CommunicationUserIdentifierAndToken
{
private readonly AccessToken? _accessToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Azure.Core;
using Azure.Core.TestFramework;
using NUnit.Framework;
using static Azure.Communication.Identity.CommunicationIdentityClientOptions;

namespace Azure.Communication.Identity.Tests
{
Expand Down Expand Up @@ -215,7 +216,7 @@ public async Task GetTokenWithValidCustomExpiration(string expiresIn)

CommunicationIdentityClient client = CreateClient();
CommunicationUserIdentifier userIdentifier = await client.CreateUserAsync();
Response<AccessToken> accessToken = await client.GetTokenAsync(communicationUser: userIdentifier, scopes: new[] { CommunicationTokenScope.Chat }, tokenExpiresIn: tokenExpiresIn);
Response<AccessToken> accessToken = await client.GetTokenAsync(communicationUser: userIdentifier, scopes: new[] { CommunicationTokenScope.VoIP }, tokenExpiresIn: tokenExpiresIn);

Assert.IsNotNull(accessToken.Value);
Assert.IsFalse(string.IsNullOrWhiteSpace(accessToken.Value.Token));
Expand All @@ -240,7 +241,7 @@ public async Task GetTokenWithInvalidCustomExpirationShouldThrow(string expiresI
TimeSpan tokenExpiresIn = TokenCustomExpirationTimes[expiresIn];
CommunicationIdentityClient client = CreateClient();
CommunicationUserIdentifier userIdentifier = await client.CreateUserAsync();
Response<AccessToken> accessToken = await client.GetTokenAsync(communicationUser: userIdentifier, scopes: new[] { CommunicationTokenScope.Chat }, tokenExpiresIn: tokenExpiresIn);
Response<AccessToken> accessToken = await client.GetTokenAsync(communicationUser: userIdentifier, scopes: new[] { CommunicationTokenScope.VoIP }, tokenExpiresIn: tokenExpiresIn);
}
catch (RequestFailedException ex)
{
Expand All @@ -260,7 +261,7 @@ public async Task GetTokenWithOverflownExpirationShouldThrow()
TimeSpan tokenExpiresIn = new TimeSpan(int.MaxValue / 20, 0, 0);
CommunicationIdentityClient client = CreateClient();
CommunicationUserIdentifier userIdentifier = await client.CreateUserAsync();
Response<AccessToken> accessToken = await client.GetTokenAsync(communicationUser: userIdentifier, scopes: new[] { CommunicationTokenScope.Chat }, tokenExpiresIn: tokenExpiresIn);
Response<AccessToken> accessToken = await client.GetTokenAsync(communicationUser: userIdentifier, scopes: new[] { CommunicationTokenScope.VoIP }, tokenExpiresIn: tokenExpiresIn);
}
catch (ArgumentOutOfRangeException ex)
{
Expand Down Expand Up @@ -477,6 +478,40 @@ public async Task GetTokenForTeamsUserWithWrongUserObjectIdShouldThrow()
Assert.Fail("An exception should have been thrown.");
}

[Test]
[TestCase(ServiceVersion.V2021_03_07, TestName = "CreateIdentityWithServiceVersion_V2021_03_07")]
[TestCase(ServiceVersion.V2022_06_01, TestName = "CreateIdentityWithServiceVersion_V2022_06_01")]
[TestCase(ServiceVersion.V2022_10_01, TestName = "CreateIdentityWithServiceVersion_V2022_10_01")]
public async Task CreateIdentityWithDifferentServiceVersions(ServiceVersion version)
{
try
{
CommunicationIdentityClient client = CreateClient(default, version);
CommunicationUserIdentifier userResponse = await client.CreateUserAsync();
Assert.IsNotNull(userResponse);
}
catch (Exception ex)
{
Assert.Fail($"Unexpected error: {ex}");
}
}

[Test]
public void CreateClientWithIncorrectServiceVersionShouldThrow()
{
try
{
ServiceVersion invalidVersion = (ServiceVersion)(-1);
CommunicationIdentityClient client = CreateClient(default, invalidVersion);
}
catch (ArgumentOutOfRangeException ex)
{
Assert.NotNull(ex.Message);
return;
}
Assert.Fail("An exception should have been thrown.");
}

private bool TokenExpirationWithinAllowedDeviation(TimeSpan expectedTokenExpiration, DateTimeOffset tokenExpiresIn, double allowedDeviation, out TimeSpan tokenTimeSpan)
{
tokenTimeSpan = tokenExpiresIn - DateTimeOffset.UtcNow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Azure.Core.TestFramework.Models;
using System;
using Azure.Communication.Tests;
using static Azure.Communication.Identity.CommunicationIdentityClientOptions;
using NUnit.Framework.Constraints;

namespace Azure.Communication.Identity.Tests
{
Expand All @@ -34,39 +36,40 @@ public CommunicationIdentityClientLiveTestBase(bool isAsync) : base(isAsync)
/// variables and instruments it to make use of the Azure Core Test Framework functionalities.
/// </summary>
/// <returns>The instrumented <see cref="CommunicationIdentityClient" />.</returns>
private CommunicationIdentityClient CreateClientWithConnectionString()
private CommunicationIdentityClient CreateClientWithConnectionString(ServiceVersion? version)
=> InstrumentClient(
new CommunicationIdentityClient(
TestEnvironment.LiveTestDynamicConnectionString,
CreateIdentityClientOptionsWithCorrelationVectorLogs()));
CreateIdentityClientOptionsWithCorrelationVectorLogs(version)));

private CommunicationIdentityClient CreateClientWithAzureKeyCredential()
private CommunicationIdentityClient CreateClientWithAzureKeyCredential(ServiceVersion? version)
=> InstrumentClient(
new CommunicationIdentityClient(
TestEnvironment.LiveTestDynamicEndpoint,
new AzureKeyCredential(TestEnvironment.LiveTestDynamicAccessKey),
CreateIdentityClientOptionsWithCorrelationVectorLogs()));
CreateIdentityClientOptionsWithCorrelationVectorLogs(version)));

private CommunicationIdentityClient CreateClientWithTokenCredential()
private CommunicationIdentityClient CreateClientWithTokenCredential(ServiceVersion? version)
=> InstrumentClient(
new CommunicationIdentityClient(
TestEnvironment.LiveTestDynamicEndpoint,
(Mode == RecordedTestMode.Playback) ? new MockCredential() : new DefaultAzureCredential(),
CreateIdentityClientOptionsWithCorrelationVectorLogs()));
CreateIdentityClientOptionsWithCorrelationVectorLogs(version)));

private CommunicationIdentityClientOptions CreateIdentityClientOptionsWithCorrelationVectorLogs()
private CommunicationIdentityClientOptions CreateIdentityClientOptionsWithCorrelationVectorLogs(ServiceVersion? version)
{
CommunicationIdentityClientOptions communicationIdentityClientOptions = new CommunicationIdentityClientOptions();
CommunicationIdentityClientOptions communicationIdentityClientOptions = (version == null) ? new CommunicationIdentityClientOptions()
: new CommunicationIdentityClientOptions((ServiceVersion)version);
communicationIdentityClientOptions.Diagnostics.LoggedHeaderNames.Add("MS-CV");
return InstrumentClientOptions(communicationIdentityClientOptions);
}

protected CommunicationIdentityClient CreateClient(AuthMethod authMethod = AuthMethod.ConnectionString)
protected CommunicationIdentityClient CreateClient(AuthMethod authMethod = AuthMethod.ConnectionString, ServiceVersion? version = default)
=> authMethod switch
{
AuthMethod.ConnectionString => CreateClientWithConnectionString(),
AuthMethod.KeyCredential => CreateClientWithAzureKeyCredential(),
AuthMethod.TokenCredential => CreateClientWithTokenCredential(),
AuthMethod.ConnectionString => CreateClientWithConnectionString(version),
AuthMethod.KeyCredential => CreateClientWithAzureKeyCredential(version),
AuthMethod.TokenCredential => CreateClientWithTokenCredential(version),
_ => throw new ArgumentOutOfRangeException(nameof(authMethod)),
};

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading