-
Notifications
You must be signed in to change notification settings - Fork 869
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mask URL with credentials on publish telemetry
- Loading branch information
1 parent
42229c7
commit d24d8fe
Showing
3 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -12,6 +12,8 @@ | |
using Xunit; | ||
using System.Threading; | ||
using Pipelines = Microsoft.TeamFoundation.DistributedTask.Pipelines; | ||
using Microsoft.VisualStudio.Services.Agent.Worker.Telemetry; | ||
using Microsoft.VisualStudio.Services.WebPlatform; | ||
|
||
namespace Microsoft.VisualStudio.Services.Agent.Tests.Worker | ||
{ | ||
|
@@ -61,6 +63,8 @@ public override void InitializeJobExtension(IExecutionContext context, IList<Pip | |
private Mock<IPagingLogger> _logger; | ||
private Mock<IExpressionManager> _express; | ||
private Mock<IContainerOperationProvider> _containerProvider; | ||
private Mock<ICustomerIntelligenceServer> _mockCiService; | ||
private Mock<IAsyncCommandContext> _asyncCommandContext; | ||
private TestHostContext CreateTestContext(CancellationTokenSource _tokenSource, [CallerMemberName] String testName = "") | ||
{ | ||
var hc = new TestHostContext(this, testName); | ||
|
@@ -291,6 +295,9 @@ private TestHostContext CreateMSITestContext(CancellationTokenSource _tokenSourc | |
_express = new Mock<IExpressionManager>(); | ||
_containerProvider = new Mock<IContainerOperationProvider>(); | ||
_logPlugin = new Mock<IAgentLogPlugin>(); | ||
_mockCiService = new Mock<ICustomerIntelligenceServer>(); | ||
_asyncCommandContext = new Mock<IAsyncCommandContext>(); | ||
|
||
|
||
TaskRunner step1 = new TaskRunner(); | ||
TaskRunner step2 = new TaskRunner(); | ||
|
@@ -333,7 +340,7 @@ private TestHostContext CreateMSITestContext(CancellationTokenSource _tokenSourc | |
Url = new Uri("https://test.visualstudio.com"), | ||
Authorization = new EndpointAuthorization() | ||
{ | ||
Scheme = "ManagedServiceIdentity", | ||
Scheme = "OAuth", | ||
} | ||
}; | ||
environment.SystemConnection.Authorization.Parameters["AccessToken"] = "token"; | ||
|
@@ -462,6 +469,7 @@ private TestHostContext CreateMSITestContext(CancellationTokenSource _tokenSourc | |
hc.SetSingleton(_express.Object); | ||
hc.SetSingleton(_containerProvider.Object); | ||
hc.SetSingleton(_logPlugin.Object); | ||
hc.SetSingleton(_mockCiService.Object); | ||
hc.EnqueueInstance<IPagingLogger>(_logger.Object); // jobcontext logger | ||
hc.EnqueueInstance<IPagingLogger>(_logger.Object); // init step logger | ||
hc.EnqueueInstance<IPagingLogger>(_logger.Object); // step 1 | ||
|
@@ -762,5 +770,55 @@ public async Task JobExtensionManagementScriptStepMSI() | |
Environment.SetEnvironmentVariable("VSTS_AGENT_CLEANUP_INTERNAL_TEMP_HACK", ""); | ||
} | ||
} | ||
[Fact] | ||
[Trait("Level", "L0")] | ||
[Trait("Category", "Worker")] | ||
[Trait("SkipOn", "darwin")] | ||
[Trait("SkipOn", "linux")] | ||
public async Task JobExtensionTelemetryPublisherSecretValue() | ||
{ | ||
using CancellationTokenSource tokenSource = new CancellationTokenSource(); | ||
using TestHostContext hc = CreateMSITestContext(tokenSource); | ||
|
||
hc.EnqueueInstance<IAsyncCommandContext>(_asyncCommandContext.Object); | ||
hc.EnqueueInstance<IAsyncCommandContext>(_asyncCommandContext.Object); | ||
hc.EnqueueInstance<IAsyncCommandContext>(_asyncCommandContext.Object); | ||
|
||
hc.SetSingleton(new TaskRestrictionsChecker() as ITaskRestrictionsChecker); | ||
|
||
Environment.SetEnvironmentVariable("http_proxy", "http://admin:[email protected]"); | ||
Environment.SetEnvironmentVariable("AGENT_DISABLE_NODE6_TASKS", "true"); | ||
|
||
var expectedEvents = new List<Dictionary<string, object>>() | ||
{ | ||
new Dictionary<string, object>() { { "JobId", "" }, { "ImageVersion", null } }, | ||
new Dictionary<string, object>() { | ||
{ "JobId", null }, | ||
{ "ProxyAddress-${http_proxy}", "http://admin:***@localhost.com"}, | ||
{ "DisableNode6Tasks-${AGENT_DISABLE_NODE6_TASKS}","true"} | ||
} | ||
}; | ||
|
||
var actualEvents = new List<CustomerIntelligenceEvent[]>(); | ||
|
||
_mockCiService.Setup(s => s.PublishEventsAsync(It.IsAny<CustomerIntelligenceEvent[]>())) | ||
.Callback<CustomerIntelligenceEvent[]>(actualEvents.Add) | ||
.Returns(Task.CompletedTask); | ||
|
||
|
||
TestJobExtension testExtension = new TestJobExtension(); | ||
testExtension.Initialize(hc); | ||
List<IStep> result = await testExtension.InitializeJob(_jobEc, _message); | ||
|
||
Assert.Equal(expectedEvents.Count, actualEvents.Count); | ||
for (int i = 0; i < expectedEvents.Count; i++) | ||
{ | ||
Assert.True( | ||
expectedEvents[i].Count == actualEvents[i][0].Properties.Count && | ||
!expectedEvents[i].Except(actualEvents[i][0].Properties).Any(), | ||
$"Event at index {i} does not match. " | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} |