-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve sanitized secrets definition (#14284)
- Loading branch information
Showing
27 changed files
with
202 additions
and
223 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
28 changes: 0 additions & 28 deletions
28
sdk/appconfiguration/Azure.Data.AppConfiguration/tests/ConfigurationRecordedTestSanitizer.cs
This file was deleted.
Oops, something went wrong.
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
69 changes: 69 additions & 0 deletions
69
sdk/core/Azure.Core.TestFramework/src/RecordedVariableOptions.cs
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Azure.Core.TestFramework | ||
{ | ||
public class RecordedVariableOptions | ||
{ | ||
private readonly Dictionary<string, string> _secretConnectionStringParameters = new Dictionary<string, string>(); | ||
private string _sanitizedValue; | ||
|
||
public RecordedVariableOptions HasSecretConnectionStringParameter(string name, SanitizedValue sanitizedValue = default) | ||
{ | ||
_secretConnectionStringParameters[name] = GetStringValue(sanitizedValue); | ||
return this; | ||
} | ||
|
||
public RecordedVariableOptions HasSecretConnectionStringParameter(string name, string sanitizedValue) | ||
{ | ||
_secretConnectionStringParameters[name] = sanitizedValue; | ||
return this; | ||
} | ||
|
||
public RecordedVariableOptions IsSecret(SanitizedValue sanitizedValue = default) | ||
{ | ||
_sanitizedValue = GetStringValue(sanitizedValue); | ||
return this; | ||
} | ||
|
||
public RecordedVariableOptions IsSecret(string sanitizedValue) | ||
{ | ||
_sanitizedValue = sanitizedValue; | ||
return this; | ||
} | ||
|
||
private string GetStringValue(SanitizedValue sanitizedValue) | ||
{ | ||
return sanitizedValue switch | ||
{ | ||
SanitizedValue.Base64 => "Kg==", | ||
_ => RecordedTestSanitizer.SanitizeValue, | ||
}; | ||
} | ||
|
||
public string Apply(string value) | ||
{ | ||
if (_secretConnectionStringParameters.Any()) | ||
{ | ||
var parsed = ConnectionString.Parse(value, allowEmptyValues: true); | ||
|
||
foreach (var connectionStringParameter in _secretConnectionStringParameters) | ||
{ | ||
parsed.Replace(connectionStringParameter.Key, connectionStringParameter.Value); | ||
} | ||
|
||
value = parsed.ToString(); | ||
} | ||
|
||
if (_sanitizedValue != null) | ||
{ | ||
value = _sanitizedValue; | ||
} | ||
|
||
return value; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.Core.TestFramework | ||
{ | ||
public enum SanitizedValue | ||
{ | ||
Default, | ||
Base64 | ||
} | ||
} |
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
Oops, something went wrong.