Skip to content

Commit 797bfc2

Browse files
msJinLeiCopilotNoriZC
authored
Collect Authentication Telemetry (#27560)
Co-authored-by: Copilot <[email protected]> Co-authored-by: NoriZC <[email protected]>
1 parent c674667 commit 797bfc2

File tree

50 files changed

+733
-116
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+733
-116
lines changed

src/Accounts/Accounts.Test/AccessTokenCmdletTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
17+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions.Interfaces;
1718
using Microsoft.Azure.Commands.Common.Authentication.Models;
1819
using Microsoft.Azure.Commands.Profile;
1920
using Microsoft.Azure.Commands.Profile.Models;
@@ -28,6 +29,7 @@
2829
using Moq;
2930

3031
using System;
32+
using System.Collections.Generic;
3133
using System.Linq;
3234
using System.Security;
3335

@@ -49,7 +51,7 @@ public AccessTokenCmdletTests(ITestOutputHelper output)
4951
{
5052
TestExecutionHelpers.SetUpSessionAndProfile();
5153
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
52-
54+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
5355
var defaultContext = new AzureContext(
5456
new AzureSubscription()
5557
{
@@ -97,8 +99,7 @@ public void TestGetAccessTokenAsPlainText()
9799
It.IsAny<SecureString>(),
98100
It.IsAny<string>(),
99101
It.IsAny<Action<string>>(),
100-
It.IsAny<IAzureTokenCache>(),
101-
It.IsAny<string>())).Returns(new MockAccessToken
102+
It.IsAny<IDictionary<string, object>>())).Returns(new MockAccessToken
102103
{
103104
UserId = expected.UserId,
104105
LoginType = LoginType.OrgId,
@@ -146,8 +147,7 @@ public void TestGetAccessTokenAsSecureString()
146147
It.IsAny<SecureString>(),
147148
It.IsAny<string>(),
148149
It.IsAny<Action<string>>(),
149-
It.IsAny<IAzureTokenCache>(),
150-
It.IsAny<string>())).Returns(new MockAccessToken
150+
It.IsAny<IDictionary<string, object>>())).Returns(new MockAccessToken
151151
{
152152
UserId = expected.UserId,
153153
LoginType = LoginType.OrgId,

src/Accounts/Accounts.Test/AutosaveTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
using Xunit.Abstractions;
2323
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
2424
using System;
25-
using System.Security;
2625
using Microsoft.Azure.Commands.Profile.Context;
2726
using Microsoft.Azure.Commands.ScenarioTest;
2827
using Microsoft.Azure.Commands.ResourceManager.Common;
@@ -57,7 +56,6 @@ private AzKeyStore SetMockedAzKeyStore()
5756

5857
void ResetState()
5958
{
60-
6159
TestExecutionHelpers.SetUpSessionAndProfile();
6260
ResourceManagerProfileProvider.InitializeResourceManagerProfile(true);
6361
// prevent token acquisition
@@ -69,6 +67,7 @@ void ResetState()
6967
PowerShellTokenCacheProvider tokenProvider = new InMemoryTokenCacheProvider();
7068
AzureSession.Instance.RegisterComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenProvider, true);
7169
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => keyStore, true);
70+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
7271
}
7372

7473
[Fact]

src/Accounts/Accounts.Test/AzureRMProfileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
using System.Management.Automation;
4242
using System.Net.Http;
4343
using System.Runtime.InteropServices;
44-
using System.Runtime.Serialization.Formatters.Binary;
4544
using System.Text.Json;
4645
using System.Threading;
4746
using System.Threading.Tasks;
@@ -176,6 +175,7 @@ public AzureRMProfileTests(ITestOutputHelper output)
176175
{
177176
TestExecutionHelpers.SetUpSessionAndProfile();
178177
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
178+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
179179
}
180180

181181
[Fact]

src/Accounts/Accounts.Test/AzureSessionTestInitializer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static void Initialize()
3333
AzureSession.Instance.RegisterComponent(AuthenticatorBuilder.AuthenticatorBuilderKey, () => builder);
3434
AzureSession.Instance.RegisterComponent(nameof(AzureCredentialFactory), () => new AzureCredentialFactory());
3535
AzureSession.Instance.RegisterComponent(nameof(MsalAccessTokenAcquirerFactory), () => new MsalAccessTokenAcquirerFactory());
36+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
3637
}
3738

3839
}

src/Accounts/Accounts.Test/ContextCmdletTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public ContextCmdletTests(ITestOutputHelper output)
6666
string profilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Resources.AzureDirectoryName);
6767
azKeyStore = new AzKeyStore(profilePath, AzureSession.Instance.KeyStoreFile, true, storageMocker.Object);
6868
AzureSession.Instance.RegisterComponent(AzKeyStore.Name, () => azKeyStore, true);
69+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
6970
}
7071

7172
[Fact]

src/Accounts/Accounts.Test/EnvironmentCmdletTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ public EnvironmentCmdletTests(ITestOutputHelper output)
5050
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
5151
dataStore = new MemoryDataStore();
5252
AzureSession.Instance.DataStore = dataStore;
53+
if (!AzureSession.Instance.TryGetComponent(nameof(AuthenticationTelemetry), out AuthenticationTelemetry authenticationTelemetry))
54+
{
55+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(nameof(AuthenticationTelemetry), () => new AuthenticationTelemetry());
56+
}
5357
}
5458

5559
private void Cleanup()

src/Accounts/Accounts.Test/ErrorResolutionTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Hyak.Common;
16+
17+
using Microsoft.Azure.Commands.Common.Authentication;
18+
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
1619
using Microsoft.Azure.Commands.Profile.Errors;
1720
using Microsoft.Azure.Commands.ScenarioTest;
1821
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
@@ -43,6 +46,7 @@ public TestHyakException(string message, CloudHttpRequestErrorInfo request, Clou
4346
public void DoesNotThrowWithNullError()
4447
{
4548
TestExecutionHelpers.SetUpSessionAndProfile();
49+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
4650
var cmdlet = new ResolveError();
4751
var output = cmdlet.ExecuteCmdletInPipeline<AzureErrorRecord>("Resolve-Error");
4852
Assert.True(output == null || output.Count == 0);
@@ -168,6 +172,7 @@ public void HandlesNullValuesInArmExceptions()
168172
public void LastParameterFindsLastError()
169173
{
170174
TestExecutionHelpers.SetUpSessionAndProfile();
175+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
171176
var mock = new MockCommandRuntime();
172177
var cmdlet = new ResolveError { CommandRuntime = mock };
173178
var message = "RuntimeErrorMessage";

src/Accounts/Accounts.Test/ProfileCmdletTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public ProfileCmdletTests(ITestOutputHelper output)
5555
AzureSession.Instance.DataStore = dataStore;
5656
commandRuntimeMock = new MockCommandRuntime();
5757
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
58+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
5859
keyStore = SetMockedAzKeyStore();
5960
}
6061

src/Accounts/Accounts.Test/SilentReAuthByTenantCmdletTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
using System.Threading.Tasks;
3737
using Xunit;
3838
using Xunit.Abstractions;
39-
using Microsoft.CodeAnalysis.CSharp.Syntax;
40-
using Microsoft.Azure.Commands.Common.Authentication.Factories;
4139

4240
namespace Microsoft.Azure.Commands.ResourceManager.Common.Test
4341
{
@@ -326,6 +324,8 @@ private void InitializeSession()
326324
DefaultContext = defaultContext
327325
};
328326
cmdlet.profileClient = new RMProfileClient(profile);
327+
328+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
329329
}
330330

331331
~SilentReAuthByTenantCmdletTest()

src/Accounts/Accounts.Test/TenantCmdletMockTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using Microsoft.Azure.Commands.ScenarioTest;
2121
using Microsoft.Azure.Commands.TestFx.Mocks;
2222
using Microsoft.Azure.ServiceManagement.Common.Models;
23-
using Microsoft.WindowsAzure.Commands.Common.Test.Mocks;
2423
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2524
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2625
using Moq;
@@ -55,7 +54,7 @@ public TenantCmdletMockTests(ITestOutputHelper output)
5554
{
5655
TestExecutionHelpers.SetUpSessionAndProfile();
5756
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
58-
57+
AzureSession.Instance.RegisterComponent<AuthenticationTelemetry>(AuthenticationTelemetry.Name, () => new AuthenticationTelemetry());
5958
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
6059
((MockTokenAuthenticationFactory)AzureSession.Instance.AuthenticationFactory).TokenProvider = (account, environment, tenant) =>
6160
new MockAccessToken

0 commit comments

Comments
 (0)