Skip to content

Commit

Permalink
Merge branch 'dev' into master (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
joelverhagen committed Mar 21, 2019
2 parents e5d8ee2 + 6366df2 commit c2cac1d
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 53 deletions.
7 changes: 3 additions & 4 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ param (
[string]$SemanticVersion = '1.0.0-zlocal',
[string]$Branch,
[string]$CommitSHA,
[string]$BuildBranch = 'ed30a6392ef7c342ca46b20f7b9c964ab9ad5881'
[string]$BuildBranch = '2d8feecabe3aeaed7f5b4d50b9be78c94faf39ec'
)

$msBuildVersion = 15;
Expand Down Expand Up @@ -91,9 +91,8 @@ Invoke-BuildStep 'Creating artifacts' {
} `
-ev +BuildErrors

Invoke-BuildStep 'Signing the packages' {
$ProjectPath = Join-Path $PSScriptRoot "build\sign.proj"
Build-Solution $Configuration $BuildNumber -MSBuildVersion "$msBuildVersion" $ProjectPath `
Invoke-BuildStep 'Signing the packages' {
Sign-Packages -Configuration $Configuration -BuildNumber $BuildNumber -MSBuildVersion $msBuildVersion `
} `
-ev +BuildErrors

Expand Down
24 changes: 0 additions & 24 deletions build/sign.proj

This file was deleted.

54 changes: 47 additions & 7 deletions src/NuGet.Server.V2/NuGetV2WebApiEnabler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Net.Http;
Expand All @@ -19,10 +20,46 @@ namespace NuGet.Server.V2
{
public static class NuGetV2WebApiEnabler
{
/// <summary>
/// Enables the NuGet V2 protocol routes on this <see cref="HttpConfiguration"/>. Note that this method does
/// not activate the legacy push URL, <code>api/v2/package</code>. To activate the legacy push route, use the
/// <see cref="UseNuGetV2WebApiFeed(HttpConfiguration, string, string, string, bool)"/> method overload.
/// </summary>
/// <param name="config">The HTTP configuration associated with your web app.</param>
/// <param name="routeName">The route name prefix, to allow multiple feeds per web app.</param>
/// <param name="routeUrlRoot">The base URL for the routes, to allow multiple feeds per web app.</param>
/// <param name="oDatacontrollerName">The name of the OData controller containing the actions.</param>
/// <returns>The <paramref name="config"/> provided, for chaining purposes.</returns>
public static HttpConfiguration UseNuGetV2WebApiFeed(this HttpConfiguration config,
string routeName,
string routeUrlRoot,
string routeUrlRoot,
string oDatacontrollerName)
{
return config.UseNuGetV2WebApiFeed(
routeName,
routeUrlRoot,
oDatacontrollerName,
enableLegacyPushRoute: false);
}

/// <summary>
/// Enables the NuGet V2 protocol routes on this <see cref="HttpConfiguration"/>.
/// </summary>
/// <param name="config">The HTTP configuration associated with your web app.</param>
/// <param name="routeName">The route name prefix, to allow multiple feeds per web app.</param>
/// <param name="routeUrlRoot">The base URL for the routes, to allow multiple feeds per web app.</param>
/// <param name="oDatacontrollerName">The name of the OData controller containing the actions.</param>
/// <param name="enableLegacyPushRoute">
/// Whether or not to enable the legacy push URL, <code>api/v2/package</code>. Note that this route does not
/// use the <paramref name="routeName"/> prefix or <paramref name="routeUrlRoot"/> and therefore should only
/// be enabled once (i.e. on a single controller).
/// </param>
/// <returns>The <paramref name="config"/> provided, for chaining purposes.</returns>
public static HttpConfiguration UseNuGetV2WebApiFeed(this HttpConfiguration config,
string routeName,
string routeUrlRoot,
string oDatacontrollerName,
bool enableLegacyPushRoute)
{
// Insert conventions to make NuGet-compatible OData feed possible
var conventions = ODataRoutingConventions.CreateDefault();
Expand Down Expand Up @@ -53,12 +90,15 @@ public static HttpConfiguration UseNuGetV2WebApiFeed(this HttpConfiguration conf
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Delete) }
);

config.Routes.MapHttpRoute(
name: "apiv2package_upload",
routeTemplate: "api/v2/package",
defaults: new { controller = oDatacontrollerName, action = "UploadPackage" },
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Put) }
);
if (enableLegacyPushRoute)
{
config.Routes.MapHttpRoute(
name: "apiv2package_upload",
routeTemplate: "api/v2/package",
defaults: new { controller = oDatacontrollerName, action = "UploadPackage" },
constraints: new { httpMethod = new HttpMethodConstraint(HttpMethod.Put) }
);
}

config.Routes.MapODataServiceRoute(routeName, routeUrlRoot, oDataModel, new CountODataPathHandler(), conventions);
return config;
Expand Down
7 changes: 6 additions & 1 deletion src/NuGet.Server/App_Start/NuGetODataConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ public static void Start()

public static void Initialize(HttpConfiguration config, string controllerName)
{
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", controllerName);
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(
config,
"NuGetDefault",
"nuget",
controllerName,
enableLegacyPushRoute: true);

config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());

Expand Down
11 changes: 8 additions & 3 deletions src/NuGet.Server/App_Start/NuGetODataConfig.cs.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
namespace $rootnamespace$.App_Start
{
public static class NuGetODataConfig
{
{
public static void Start()
{
{
ServiceResolver.SetServiceResolver(new DefaultServiceResolver());

var config = GlobalConfiguration.Configuration;

NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", "PackagesOData");
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(
config,
"NuGetDefault",
"nuget",
"PackagesOData",
enableLegacyPushRoute: true);

config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());

Expand Down
71 changes: 57 additions & 14 deletions test/NuGet.Server.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using NuGet.Server.Core.Logging;
using NuGet.Server.Core.Tests;
using NuGet.Server.Core.Tests.Infrastructure;
using NuGet.Server.V2;
using Xunit;
using Xunit.Abstractions;
using ISystemDependencyResolver = System.Web.Http.Dependencies.IDependencyResolver;
Expand Down Expand Up @@ -162,6 +163,51 @@ public async Task PushPackageThenReadPackages()
}
}

[Fact]
public async Task CanSupportMultipleSetsOfRoutes()
{
// Arrange
using (var tc = new TestContext(_output))
{
// Enable another set of routes.
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(
tc.Config,
"NuGetDefault2",
"nuget2",
TestablePackagesODataController.Name);

string apiKey = "foobar";
tc.SetApiKey(apiKey);

var packagePath = Path.Combine(tc.TemporaryDirectory, "package.nupkg");
TestData.CopyResourceToPath(TestData.PackageResource, packagePath);

// Act & Assert
// 1. Push to the legacy route.
await tc.PushPackageAsync(apiKey, packagePath, "/api/v2/package");

// 2. Make a request to the first set of routes.
using (var request = new HttpRequestMessage(HttpMethod.Get, "/nuget/Packages()"))
using (var response = await tc.Client.SendAsync(request))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var content = await response.Content.ReadAsStringAsync();

Assert.Contains(TestData.PackageId, content);
}

// 3. Make a request to the second set of routes.
using (var request = new HttpRequestMessage(HttpMethod.Get, "/nuget2/Packages()"))
using (var response = await tc.Client.SendAsync(request))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var content = await response.Content.ReadAsStringAsync();

Assert.Contains(TestData.PackageId, content);
}
}
}

/// <summary>
/// Added due to https://github.com/NuGet/NuGetGallery/issues/6960. There was a concurrency issue when pushing
/// packages that could lead to unnecessary cache rebuilds.
Expand Down Expand Up @@ -354,7 +400,6 @@ public static IEnumerable<object[]> EndpointsSupportingProjection
private sealed class TestContext : IDisposable
{
private readonly HttpServer _server;
private readonly HttpConfiguration _config;

public TestContext(ITestOutputHelper output)
{
Expand All @@ -371,13 +416,13 @@ public TestContext(ITestOutputHelper output)

ServiceResolver = new DefaultServiceResolver(PackagesDirectory, Settings, Logger);

_config = new HttpConfiguration();
_config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
_config.DependencyResolver = new DependencyResolverAdapter(ServiceResolver);
Config = new HttpConfiguration();
Config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
Config.DependencyResolver = new DependencyResolverAdapter(ServiceResolver);

NuGetODataConfig.Initialize(_config, "TestablePackagesOData");
NuGetODataConfig.Initialize(Config, TestablePackagesODataController.Name);

_server = new HttpServer(_config);
_server = new HttpServer(Config);
Client = new SystemHttpClient(_server);
Client.BaseAddress = new Uri("http://localhost/");
}
Expand All @@ -388,6 +433,7 @@ public TestContext(ITestOutputHelper output)
public TemporaryDirectory TemporaryDirectory { get; }
public TemporaryDirectory PackagesDirectory { get; }
public NameValueCollection Settings { get; }
public HttpConfiguration Config { get; }
public SystemHttpClient Client { get; }

public void SetApiKey(string apiKey)
Expand Down Expand Up @@ -416,30 +462,27 @@ public MultipartContent GetFileUploadContent(params string[] paths)
return content;
}

public async Task PushPackageAsync(string apiKey, string packagePath)
public async Task PushPackageAsync(string apiKey, string packagePath, string pushUrl = "/nuget")
{
using (var request = new HttpRequestMessage(HttpMethod.Put, "/nuget")
using (var request = new HttpRequestMessage(HttpMethod.Put, pushUrl)
{
Headers =
{
{ "X-NUGET-APIKEY", apiKey }
},
Content = GetFileUploadContent(packagePath)
})
using (var response = await Client.SendAsync(request))
{
using (request)
using (var response = await Client.SendAsync(request))
{
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
}
Assert.Equal(HttpStatusCode.Created, response.StatusCode);
}
}

public void Dispose()
{
Client.Dispose();
_server.Dispose();
_config.Dispose();
Config.Dispose();
ServiceResolver.Dispose();
PackagesDirectory.Dispose();
TemporaryDirectory.Dispose();
Expand Down
3 changes: 3 additions & 0 deletions test/NuGet.Server.Tests/TestablePackagesODataController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace NuGet.Server.Tests
{
public class TestablePackagesODataController : PackagesODataController
{
public static readonly string Name = nameof(TestablePackagesODataController)
.Substring(0, nameof(TestablePackagesODataController).Length - "Controller".Length);

public TestablePackagesODataController(IServiceResolver serviceResolver)
: base(serviceResolver)
{
Expand Down

0 comments on commit c2cac1d

Please sign in to comment.