Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/add-delayed…
Browse files Browse the repository at this point in the history
…-response
  • Loading branch information
scbedd committed Feb 15, 2023
2 parents 6bed92f + 76afc9b commit c04e0f9
Show file tree
Hide file tree
Showing 29 changed files with 708 additions and 327 deletions.
4 changes: 2 additions & 2 deletions eng/common/scripts/Cadl-Project-Sync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ function GetGitRemoteValue([string]$repo) {
$gitRemotes = (git remote -v)
foreach ($remote in $gitRemotes) {
if ($remote.StartsWith("origin")) {
if ($remote -match 'https://github.com/\S+[\.git]') {
if ($remote -match 'https://github.com/\S+') {
$result = "https://github.com/$repo.git"
break
} elseif ($remote -match "[email protected]:\S+[\.git]"){
} elseif ($remote -match "[email protected]:\S+"){
$result = "[email protected]:$repo.git"
break
} else {
Expand Down
19 changes: 12 additions & 7 deletions eng/common/scripts/get-codeowners.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,18 @@ function TestGetCodeOwner([string]$targetDirectory, [string]$codeOwnerFileLocati
}

if($Test) {
$testFile = (Resolve-Path $PSScriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/simple_path_CODEOWNERS)
TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4")
TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4")
TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @()
TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk")
# These tests have been removed; now instead we should run tests from RetrieveCodeOwnersProgramTests, and in a way as explained in:
# https://github.com/Azure/azure-sdk-tools/issues/5434
# https://github.com/Azure/azure-sdk-tools/pull/5103#discussion_r1068680818
Write-Host "These tests have been removed. Please see https://github.com/Azure/azure-sdk-tools/issues/5434 for more."
#
# $testFile = (Resolve-Path $PSScriptRoot/../../../tools/code-owners-parser/Azure.Sdk.Tools.RetrieveCodeOwners.Tests/TestData/simple_path_CODEOWNERS)
# TestGetCodeOwner -targetDirectory "sdk" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
# TestGetCodeOwner -targetDirectory "sdk/noPath" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person1", "person2")
# TestGetCodeOwner -targetDirectory "/sdk/azconfig" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @("person3", "person4")
# TestGetCodeOwner -targetDirectory "/sdk/azconfig/package" -codeOwnerFileLocation $testFile -includeNonUserAliases $true $testFile -expectReturn @("person3", "person4")
# TestGetCodeOwner -targetDirectory "/sd" -codeOwnerFileLocation $testFile -includeNonUserAliases $true -expectReturn @()
# TestGetCodeOwner -targetDirectory "/sdk/testUser/" -codeOwnerFileLocation $testFile -expectReturn @("azure-sdk")
exit 0
}
else {
Expand Down
9 changes: 7 additions & 2 deletions eng/pipelines/templates/steps/install-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ steps:
retryCountOnTaskFailure: 3
inputs:
# We must install sdk, not just runtime, as it is required by some of our tools, like test-proxy.
# For additional context, see PR: https://github.com/Azure/azure-sdk-tools/pull/5405
# Specifically, test-proxy requires asp.net core runtime, which is installed only when sdk option
# is selected, per: https://github.com/microsoft/azure-pipelines-tasks/issues/14405
#
# For additional context, see:
# https://github.com/Azure/azure-sdk-tools/pull/5405#discussion_r1105006774
# https://github.com/Azure/azure-sdk-tools/pull/5405
packageType: sdk
version: 6.0.x
# performMultiLevelLookup comes into play when given .NET executable target runtime is different
# than the installed .NET SDK. Without this, such runtime would not be found.
performMultiLevelLookup: true

# Future work: add NuGet packages caching. See:
# https://github.com/Azure/azure-sdk-tools/issues/5086
# https://github.com/Azure/azure-sdk-tools/issues/5086
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<span class="small text-muted">Approves the current revision of the API</span>
<div class="d-grid gap-2">
<button type="button" class="btn btn-success" data-bs-toggle="modal" data-bs-target="#approveModel">
Approve With Modal
Approve
</button>
</div>
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static int Main(
bool excludeNonUserAliases = false,
string? targetDir = null,
string ignoredPathPrefixes = DefaultIgnoredPrefixes,
bool useRegexMatcher = false)
bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault)
{
try
{
Expand Down Expand Up @@ -109,7 +109,7 @@ private static Dictionary<string, CodeownersEntry> GetCodeownersForGlobPath(
string codeownersFilePathOrUrl,
bool excludeNonUserAliases,
string[]? ignoredPathPrefixes = null,
bool useRegexMatcher = false)
bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault)
{
ignoredPathPrefixes ??= Array.Empty<string>();

Expand All @@ -131,7 +131,7 @@ private static CodeownersEntry GetCodeownersForSimplePath(
string targetPath,
string codeownersFilePathOrUrl,
bool excludeNonUserAliases,
bool useRegexMatcher = false)
bool useRegexMatcher = CodeownersFile.UseRegexMatcherDefault)
{
CodeownersEntry codeownersEntry =
CodeownersFile.GetMatchingCodeownersEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Azure.Sdk.Tools.CodeOwnersParser
{
public static class CodeownersFile
{
private const bool UseRegexMatcherDefault = true;
public const bool UseRegexMatcherDefault = true;

public static List<CodeownersEntry> GetCodeownersEntriesFromFileOrUrl(
string codeownersFilePathOrUrl)
Expand Down
35 changes: 34 additions & 1 deletion tools/test-proxy/Azure.Sdk.Tools.TestProxy.Tests/InfoTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Azure.Sdk.Tools.TestProxy.Common;
using Azure.Sdk.Tools.TestProxy.Common;
using Azure.Sdk.Tools.TestProxy.Matchers;
using Azure.Sdk.Tools.TestProxy.Models;
using Azure.Sdk.Tools.TestProxy.Sanitizers;
using Azure.Sdk.Tools.TestProxy.Transforms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
Expand Down Expand Up @@ -58,5 +60,36 @@ public void TestReflectionModelWithAdvancedType()

var result = controller.Active();
}

[Fact]
public async Task TestReflectionModelWithTargetRecordSession()
{
RecordingHandler testRecordingHandler = new RecordingHandler(Directory.GetCurrentDirectory());
var httpContext = new DefaultHttpContext();

await testRecordingHandler.StartPlaybackAsync("Test.RecordEntries/multipart_request.json", httpContext.Response);
testRecordingHandler.Transforms.Clear();

var recordingId = httpContext.Response.Headers["x-recording-id"].ToString();

testRecordingHandler.AddSanitizerToRecording(recordingId, new UriRegexSanitizer(regex: "ABC123"));
testRecordingHandler.AddSanitizerToRecording(recordingId, new BodyRegexSanitizer(regex: ".+?"));
testRecordingHandler.SetMatcherForRecording(recordingId, new CustomDefaultMatcher(compareBodies: false, excludedHeaders: "an-excluded-header"));

var model = new ActiveMetadataModel(testRecordingHandler, recordingId);
var descriptions = model.Descriptions.ToList();

// we should have exactly 6 if we're counting all the customizations appropriately
Assert.True(descriptions.Count == 6);
Assert.True(model.Matchers.Count() == 1);
Assert.True(model.Sanitizers.Count() == 5);

// confirm that the overridden matcher is showing up
Assert.True(descriptions[3].ConstructorDetails.Arguments[1].Item2 == "\"ABC123\"");
Assert.True(descriptions[4].ConstructorDetails.Arguments[1].Item2 == "\".+?\"");

// and finally confirm our sanitizers are what we expect
Assert.True(descriptions[5].Name == "CustomDefaultMatcher");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
namespace Azure.Sdk.Tools.TestProxy.Common.Exceptions
{
public class SessionNotActiveException: Exception
{
public SessionNotActiveException()
{
}
public SessionNotActiveException(string message)
: base(message)
{
}
}
}
22 changes: 17 additions & 5 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/Info.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Azure.Sdk.Tools.TestProxy.Common.Exceptions;
using Azure.Sdk.Tools.TestProxy.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
Expand Down Expand Up @@ -33,15 +34,26 @@ public async Task<ContentResult> Available()
}

[HttpGet]
public async Task<ContentResult> Active()
public async Task<ContentResult> Active(string id="")
{
var dataModel = new ActiveMetadataModel(_recordingHandler);
var viewHtml = await RenderViewAsync(this, "ActiveExtensions", dataModel);
string content = string.Empty;

try
{
var dataModel = new ActiveMetadataModel(_recordingHandler, recordingId: id);
content = await RenderViewAsync(this, "ActiveExtensions", dataModel);
}
// if a SessionNotActiveException is thrown, we have passed in an invalid recordingId, otherwise it'll be an unhandled
// exception, which the exception middleware should surface just fine.
catch (SessionNotActiveException)
{
content = await RenderViewAsync(this, "Error", new ActiveMetadataModel(id));
}

return new ContentResult
{
ContentType = "text/html",
Content = viewHtml
Content = content
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,79 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.IO;
using Azure.Sdk.Tools.TestProxy.Common;
using System.Collections.Concurrent;
using Microsoft.CodeAnalysis.Operations;
using Azure.Sdk.Tools.TestProxy.Common.Exceptions;

namespace Azure.Sdk.Tools.TestProxy.Models
{
public class ActiveMetadataModel : RunTimeMetaDataModel
{
public ActiveMetadataModel(string recordingId)
{
RecordingId = recordingId;
}

public ActiveMetadataModel(RecordingHandler pageRecordingHandler)
{
Descriptions = _populateFromHandler(pageRecordingHandler);
Descriptions = _populateFromHandler(pageRecordingHandler, "");
}

private List<ActionDescription> _populateFromHandler(RecordingHandler handler)
public ActiveMetadataModel(RecordingHandler pageRecordingHandler, string recordingId)
{
RecordingId = recordingId;
Descriptions = _populateFromHandler(pageRecordingHandler, recordingId);
}

public string RecordingId { get; set; }

private List<ActionDescription> _populateFromHandler(RecordingHandler handler, string recordingId)
{
var sanitizers = (IEnumerable<RecordedTestSanitizer>) handler.Sanitizers;
var transforms = (IEnumerable<ResponseTransform>) handler.Transforms;
var matcher = handler.Matcher;

List<ConcurrentDictionary<string, ModifiableRecordSession>> searchCollections = new List<ConcurrentDictionary<string, ModifiableRecordSession>>()
{
handler.PlaybackSessions,
handler.RecordingSessions,
handler.InMemorySessions
};

var recordingFound = false;
if (!string.IsNullOrWhiteSpace(recordingId)){
foreach (var sessionDict in searchCollections)
{
if (sessionDict.TryGetValue(recordingId, out var session))
{
sanitizers = sanitizers.Concat(session.AdditionalSanitizers);
transforms = transforms.Concat(session.AdditionalTransforms);

if (session.CustomMatcher != null)
{
matcher = session.CustomMatcher;
}

recordingFound = true;
break;
}
}

if (!recordingFound)
{
throw new SessionNotActiveException($"{recordingId} is not found in any Playback, Recording, or In-Memory sessions.");
}
}

List<ActionDescription> descriptions = new List<ActionDescription>();
var docXML = GetDocCommentXML();

descriptions.AddRange(handler.Sanitizers.Select(x => new ActionDescription()
descriptions.AddRange(sanitizers.Select(x => new ActionDescription()
{
ActionType = MetaDataType.Sanitizer,
Name = x.GetType().Name,
Expand All @@ -39,9 +92,9 @@ private List<ActionDescription> _populateFromHandler(RecordingHandler handler)
descriptions.Add(new ActionDescription()
{
ActionType = MetaDataType.Matcher,
Name = handler.Matcher.GetType().Name,
ConstructorDetails = GetInstanceDetails(handler.Matcher),
Description = GetClassDocComment(handler.Matcher.GetType(), docXML)
Name = matcher.GetType().Name,
ConstructorDetails = GetInstanceDetails(matcher),
Description = GetClassDocComment(matcher.GetType(), docXML)
});

return descriptions;
Expand Down
Loading

0 comments on commit c04e0f9

Please sign in to comment.