Skip to content

Commit

Permalink
redirect to external privacy link (#9347)
Browse files Browse the repository at this point in the history
* Redirect privacy to external Microsoft privacy
  • Loading branch information
lyndaidaii authored Feb 2, 2023
1 parent 83f98b7 commit 9602e0a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/NuGetGallery/Controllers/PagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ public virtual async Task<ActionResult> Terms()
[HttpGet]
public virtual async Task<ActionResult> Privacy()
{
if (!String.IsNullOrEmpty(Url.ExternalPrivacyUrl()))
{
return Redirect(Url.ExternalPrivacyUrl());
}

if (_contentService != null)
{
ViewBag.Content = await _contentService.GetContentItemAsync(
Expand Down
5 changes: 5 additions & 0 deletions src/NuGetGallery/UrlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,11 @@ public static string Privacy(this UrlHelper url, bool relativeUrl = true)
return GetActionLink(url, "Privacy", "Pages", relativeUrl);
}

public static string ExternalPrivacyUrl(this UrlHelper url)
{
return _configuration.Current.ExternalPrivacyPolicyUrl;
}

public static string About(this UrlHelper url, bool relativeUrl = true)
{
if (!String.IsNullOrEmpty(_configuration.Current.ExternalAboutUrl))
Expand Down
37 changes: 37 additions & 0 deletions tests/NuGetGallery.Facts/Controllers/PagesControllerFacts.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// 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.Threading.Tasks;
using System.Web;
using Moq;
using NuGet.Services.Entities;
using NuGet.Services.Messaging.Email;
using NuGetGallery.Areas.Admin;
using NuGetGallery.Configuration;
using NuGetGallery.Framework;
using NuGetGallery.Infrastructure.Mail.Messages;
using NuGetGallery.ViewModels;
Expand Down Expand Up @@ -88,6 +90,41 @@ public async Task HtmlEncodesTheSupportRequest()
It.IsAny<User>(),
It.IsAny<Package>()));
}

[Fact]
public async Task WithExternalPrivacyUrlConfigured()
{
var externalPrivacyUrl = "https://privacy.microsoft.com";
var configuration = GetConfigurationService();
var pagesController = GetController<PagesController>();

configuration.Current.ExternalPrivacyPolicyUrl = externalPrivacyUrl;

var result = await pagesController.Privacy();

GetMock<IContentService>()
.Verify(m => m.GetContentItemAsync(
It.IsAny<string>(),
It.IsAny<TimeSpan>()), Times.Never);

}

[Fact]
public async Task WithoutExternalPrivacyUrlConfigured()
{
var externalPrivacyUrl = "";
var configuration = GetConfigurationService();
var pagesController = GetController<PagesController>();

configuration.Current.ExternalPrivacyPolicyUrl = externalPrivacyUrl;

var result = await pagesController.Privacy();

GetMock<IContentService>()
.Verify(m => m.GetContentItemAsync(
It.IsAny<string>(),
It.IsAny<TimeSpan>()), Times.Once);
}
}
}
}
17 changes: 17 additions & 0 deletions tests/NuGetGallery.Facts/UrlHelperExtensionsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ public void UsesConfiguredSiteRootInAbsoluteUri(
}
}

public class GetExternalPrivacyUrlMethod : TestContainer
{
[Theory]
[InlineData("")]
[InlineData("https://privacy.microsoft.com")]
public void VerifyExternalPrivacyUrlMethod(string expectedUrl) {
var configurationService = GetConfigurationService();
configurationService.Current.ExternalPrivacyPolicyUrl = expectedUrl;

var urlHelper = TestUtility.MockUrlHelper(expectedUrl);

var result = UrlHelperExtensions.ExternalPrivacyUrl(TestUtility.MockUrlHelper());

Assert.Equal(expectedUrl, result);
}
}

public class TheGetActionLinkMethod : TestContainer
{
public static IEnumerable<object[]> GeneratesTheCorrectActionLink_Data
Expand Down

0 comments on commit 9602e0a

Please sign in to comment.