Skip to content

Commit 31565f5

Browse files
authored
Add features to support application as a test controller. (#576)
1 parent 50a5aac commit 31565f5

61 files changed

Lines changed: 3230 additions & 485 deletions

File tree

Some content is hidden

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

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.29
1+
2.1.30

src/VirtualClient/VirtualClient.Actions/GeekBench/GeekbenchExecutor.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,6 @@ private Task ExecuteWorkloadAsync(string pathToExe, string commandLineArguments,
275275
await this.LogProcessDetailsAsync(process, telemetryContext, this.PackageName, logToFile: true);
276276
process.ThrowIfWorkloadFailed();
277277

278-
if (process.StandardError.Length > 0)
279-
{
280-
process.ThrowOnStandardError<WorkloadException>(errorReason: ErrorReason.WorkloadFailed);
281-
}
282-
283278
string standardOutput = process.StandardOutput.ToString();
284279
this.CaptureMetrics(process, standardOutput, commandLineArguments, telemetryContext, cancellationToken);
285280
}

src/VirtualClient/VirtualClient.Common.UnitTests/SensitiveDataTests.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,6 @@ public void ObscureSecretsObfuscatesSasUriSignatures_Scenario1()
151151
Assert.AreEqual(dataContainingSecrets.Item2, obscuredString);
152152
}
153153

154-
[Test]
155-
public void ObscureSecretsObfuscatesSasUriSignatures_Scenario2()
156-
{
157-
Tuple<string, string> dataContainingSecrets = SensitiveDataTests.GetSasUriPairScenario2();
158-
string obscuredString = SensitiveData.ObscureSecrets(dataContainingSecrets.Item1);
159-
160-
Assert.AreEqual(dataContainingSecrets.Item2, obscuredString);
161-
}
162-
163154
[Test]
164155
[TestCase("Password=AnySecretHereae09g34YT112", "Password=...")]
165156
[TestCase("Password AnySecretHereae09g34YT112", "Password ...")]
@@ -216,6 +207,18 @@ public void ObscureSecretsHandlesCasesWhereThePasswordTermIsASubstringThatIsPart
216207
Assert.AreEqual(expectedString, obscuredString);
217208
}
218209

210+
[Test]
211+
[TestCase("user@10.2.3.5;pass_;wor;d", "user@10.2.3.5;...")]
212+
[TestCase("user@10.2.3.5;pass__w@rd", "user@10.2.3.5;...")]
213+
[TestCase("user@machine@somewhere;pass", "user@machine@somewhere;...")]
214+
[TestCase("user@machine@somewhere;pass;_w@rd", "user@machine@somewhere;...")]
215+
[TestCase("user@2001:db8:85a3:0:0:8a2e:370:7334;pass;_w@rd", "user@2001:db8:85a3:0:0:8a2e:370:7334;...")]
216+
public void ObscureSecretsObfuscatesPasswordsInAgentSshConnections(string originalString, string expectedString)
217+
{
218+
string obscuredString = SensitiveData.ObscureSecrets(originalString);
219+
Assert.AreEqual(expectedString, obscuredString);
220+
}
221+
219222
[Test]
220223
public void ObscureSecretsObfuscatesSecretsThatMatchAGivenRegularExpression_Scenario1()
221224
{

src/VirtualClient/VirtualClient.Common/SensitiveData.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public static class SensitiveData
3030
// of expressions to allow the handling of special cases (e.g. delimited key/value pair groups (e.g. Password=s@me,val;ue,,,Property1=Value1).
3131
new Regex("(?<=Password[=\x20]+\"*)(?:,{0,2}[\x21\x23-\x2B\x2D-\x7E]+,{0,2}[\x21\x23-\x2B\x2D-\x7E]+)+\"*", RegexOptions.IgnoreCase),
3232
new Regex("(?<=Pwd[=\x20]+\"*)(?:,{0,2}[\x21\x23-\x2B\x2D-\x7E]+,{0,2}[\x21\x23-\x2B\x2D-\x7E]+)+\"*", RegexOptions.IgnoreCase),
33+
34+
// Agent SSH connections allow for passwords
35+
// (e.g. user@10.2.3.5;pass_;wor;d).
36+
new Regex(@"[0-9a-z_\-\. ]+@[^;]+;([\x20-\x7E]+)", RegexOptions.IgnoreCase)
3337
};
3438

3539
/// <summary>

src/VirtualClient/VirtualClient.Contracts/AliasAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace VirtualClient.Contracts
1010
/// <summary>
1111
/// Defines one or more aliases for a given class for reflection support.
1212
/// </summary>
13-
[AttributeUsage(validOn: AttributeTargets.Class)]
13+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
1414
public class AliasAttribute : Attribute
1515
{
1616
/// <summary>

src/VirtualClient/VirtualClient.Contracts/ComponentTypeCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace VirtualClient.Contracts
88
using System.Diagnostics.CodeAnalysis;
99
using System.IO;
1010
using System.Linq;
11+
using System.Net;
1112
using System.Reflection;
1213
using Microsoft.Extensions.Logging;
1314
using VirtualClient.Common.Extensions;

src/VirtualClient/VirtualClient.Contracts/Constants.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,6 @@ public static class EnvironmentVariable
150150
/// </summary>
151151
public const string PATH = nameof(PATH);
152152

153-
/// <summary>
154-
/// Name = SDK_EVENTHUB_CONNECTION
155-
/// </summary>
156-
public const string SDK_EVENTHUB_CONNECTION = nameof(SDK_EVENTHUB_CONNECTION);
157-
158-
/// <summary>
159-
/// Name = SDK_PACKAGES_CONNECTION
160-
/// </summary>
161-
public const string SDK_PACKAGES_CONNECTION = nameof(SDK_PACKAGES_CONNECTION);
162-
163-
/// <summary>
164-
/// Name = SDK_PACKAGES_DIR
165-
/// </summary>
166-
public const string SDK_PACKAGES_DIR = nameof(SDK_PACKAGES_DIR);
167-
168153
/// <summary>
169154
/// Name = SUDO_USER
170155
/// </summary>

src/VirtualClient/VirtualClient.Contracts/PlatformSpecifics.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public PlatformSpecifics(PlatformID platform, Architecture architecture, string
149149
public string StateDirectory { get; set; }
150150

151151
/// <summary>
152-
/// The directory where scripts related to workloads exist.
152+
/// The directory where temp files can be saved.
153153
/// </summary>
154154
public string TempDirectory { get; set; }
155155

@@ -280,8 +280,8 @@ public static string ResolveRelativePaths(string text)
280280
{
281281
// Ensure that relative working directory paths are fully expanded. Preserve case-sensitivity
282282
// to avoid anomalies on Linux.
283-
string relativeDirectory = match.Value;
284-
resolved = resolved.Replace(relativeDirectory, Path.GetFullPath(relativeDirectory), StringComparison.Ordinal);
283+
string relativePath = match.Value;
284+
resolved = resolved.Replace(relativePath, Path.GetFullPath(relativePath), StringComparison.Ordinal);
285285
}
286286
}
287287
}

src/VirtualClient/VirtualClient.Contracts/VirtualClientComponent.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ protected set
377377
/// placeholders and well-known terms to be replaced in the values of the parameters before
378378
/// execution of workloads, monitors or dependencies.
379379
/// </summary>
380-
public bool ParametersEvaluated { get; internal set; }
380+
public bool ParametersEvaluated { get; protected set; }
381381

382382
/// <summary>
383383
/// The OS/system platform (e.g. Windows, Unix).
@@ -659,6 +659,28 @@ public static bool IsSupported(VirtualClientComponent component)
659659
return platformSupported && component.IsSupported();
660660
}
661661

662+
/// <summary>
663+
/// Evaluates each of the parameters provided to the component to replace
664+
/// supported placeholder expressions (e.g. {PackagePath:anytool} -> replace with path to 'anytool' package).
665+
/// </summary>
666+
/// <param name="cancellationToken">A token that can be used to cancel the operations.</param>
667+
/// <param name="force">Forces the evaluation of the parameters for scenarios where re-evaluation is necessary after an initial pass. Default = false.</param>
668+
public async Task EvaluateParametersAsync(CancellationToken cancellationToken, bool force = false)
669+
{
670+
if (!this.ParametersEvaluated || force)
671+
{
672+
if (this.Parameters?.Any() == true)
673+
{
674+
if (this.Dependencies.TryGetService<IExpressionEvaluator>(out IExpressionEvaluator evaluator))
675+
{
676+
await evaluator.EvaluateAsync(this.Dependencies, this.Parameters, cancellationToken);
677+
}
678+
}
679+
680+
this.ParametersEvaluated = true;
681+
}
682+
}
683+
662684
/// <summary>
663685
/// When overriden in a derived class, executes the component logic.
664686
/// </summary>

src/VirtualClient/VirtualClient.Contracts/VirtualClientComponentExtensions.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,31 +220,6 @@ public static IEnumerable<FileUploadDescriptor> CreateFileUploadDescriptors(this
220220
return descriptors;
221221
}
222222

223-
/// <summary>
224-
/// Evaluates each of the parameters provided to the component to replace
225-
/// supported placeholder expressions (e.g. {PackagePath:anytool} -> replace with path to 'anytool' package).
226-
/// </summary>
227-
/// <param name="component">The component whose parameters to evaluate.</param>
228-
/// <param name="cancellationToken">A token that can be used to cancel the operations.</param>
229-
/// <param name="force">Forces the evaluation of the parameters for scenarios where re-evaluation is necessary after an initial pass. Default = false.</param>
230-
public static async Task EvaluateParametersAsync(this VirtualClientComponent component, CancellationToken cancellationToken, bool force = false)
231-
{
232-
component.ThrowIfNull(nameof(component));
233-
234-
if (!component.ParametersEvaluated || force)
235-
{
236-
if (component.Parameters?.Any() == true)
237-
{
238-
if (component.Dependencies.TryGetService<IExpressionEvaluator>(out IExpressionEvaluator evaluator))
239-
{
240-
await evaluator.EvaluateAsync(component.Dependencies, component.Parameters, cancellationToken);
241-
}
242-
}
243-
244-
component.ParametersEvaluated = true;
245-
}
246-
}
247-
248223
/// <summary>
249224
/// Returns the client instance defined in the environment layout provided to the Virtual Client
250225
/// whose ID matches.

0 commit comments

Comments
 (0)