Skip to content

Commit

Permalink
Not null the createdby on delete account (#6808)
Browse files Browse the repository at this point in the history
A support issue for a deleted account will have createdby field not null bu obfuscated. With this the issue will still be in the support issues view. Also the issue is automatically resolved.
  • Loading branch information
cristinamanum authored Jan 10, 2019
1 parent 8b9d58a commit 20e0683
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class SupportRequestService
private IAuditingService _auditingService;
private readonly string _siteRoot;
private const string _unassignedAdmin = "unassigned";
private const string _deletedAccount = "_deletedaccount";
private const string _NuGetDSRAccount = "_NuGetDSR";

public SupportRequestService(
ISupportRequestDbContext supportRequestDbContext,
Expand Down Expand Up @@ -302,7 +304,11 @@ public async Task DeleteSupportRequestsAsync(User user)
foreach (var accountDeletedIssue in userIssues.Where(i => string.Equals(i.IssueTitle, Strings.AccountDelete_SupportRequestTitle)))
{
accountDeletedIssue.OwnerEmail = "deletedaccount";
accountDeletedIssue.CreatedBy = null;
if(!accountDeletedIssue.CreatedBy.Equals(_NuGetDSRAccount, StringComparison.OrdinalIgnoreCase))
{
accountDeletedIssue.CreatedBy = _deletedAccount;
}
accountDeletedIssue.IssueStatusId = IssueStatusKeys.Resolved;
accountDeletedIssue.Details = "This support request has been redacted as the customer's account has been deleted.";
foreach (var historyEntry in accountDeletedIssue.HistoryEntries)
{
Expand Down
1 change: 1 addition & 0 deletions tests/NuGetGallery.Facts/NuGetGallery.Facts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="Controllers\AccountsControllerFacts.cs" />
<Compile Include="Controllers\OrganizationsControllerFacts.cs" />
<Compile Include="Controllers\SupportControllerFacts.cs" />
<Compile Include="UsernameValidationRegex.cs" />
<Compile Include="Extensions\NumberExtensionsFacts.cs" />
<Compile Include="Extensions\RouteExtensionsFacts.cs" />
<Compile Include="Filters\UIAuthorizeAttributeFacts.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public async Task DeleteRequestsNormalPath()
Assert.False(supportRequestContext.Issues.Any(issue => string.Equals(issue.IssueTitle, "Joe's OldIssue")));
var deleteRequestIssue = supportRequestContext.Issues.Where(issue => issue.Key == 1).FirstOrDefault();
Assert.NotNull(deleteRequestIssue);
Assert.Null(deleteRequestIssue.CreatedBy);
Assert.Equal(deleteRequestIssue.CreatedBy, "_deletedaccount");
Assert.Equal(deleteRequestIssue.IssueStatusId, IssueStatusKeys.Resolved);
Assert.Null(deleteRequestIssue.HistoryEntries.ElementAt(0).EditedBy);
}

Expand Down
113 changes: 113 additions & 0 deletions tests/NuGetGallery.Facts/UsernameValidationRegex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// 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.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Xunit;

namespace NuGetGallery
{
public class UsernameValidationRegex
{
private const int TestCharSetSize = 256;

[Theory]
[MemberData(nameof(GetAllowedShortUsername))]
public void AllowedUsernames(string username)
{
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
Assert.True(match);
}

[Theory]
[MemberData(nameof(GetNotAllowedSuffixPrefixCharacters))]
public void NotAllowedUsernamesPrefix(char incorrectPrefixChar)
{
string username = new string(new char[] { incorrectPrefixChar, 'a' });
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
Assert.False(match);
}

[Theory]
[MemberData(nameof(GetNotAllowedSuffixPrefixCharacters))]
public void NotAllowedUsernamesSuffix(char incorrectSuffixChar)
{
string username = new string(new char[] { 'a', incorrectSuffixChar });
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
Assert.False(match);
}

[Theory]
[MemberData(nameof(GetNotAllowedMiddleCharacters))]
public void NotAllowedUsernamesMiddle(char incorrectMiddleChar)
{
string username = new string(new char[] { 'a', incorrectMiddleChar, 'b' });
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
Assert.False(match);
}

public static IEnumerable<object[]> GetNotAllowedSuffixPrefixCharacters()
{
return Enumerable.Range(0, TestCharSetSize)
.Select(i => (char)i)
.Where(c => !GetAllowedSuffixPrefixCharacters().Contains(c))
.Select(c => new object[] { c });
}

public static IEnumerable<object[]> GetNotAllowedMiddleCharacters()
{
return Enumerable.Range(0, TestCharSetSize)
.Select(i => (char)i)
.Where(c => !GetAllowedMiddleCharacters().Contains(c))
.Select(c => new object[] { c }); ;
}

public static IEnumerable<object[]> GetAllowedShortUsername()
{
char[] shortAllowedPrefixSuffixList = new char[] { 'a', 'Z', '1' };
char[] shortAllowedMiddleCharList = new char[] { '.', '_', '-' };

foreach (var prefix in shortAllowedPrefixSuffixList)
{
foreach (var middle in shortAllowedMiddleCharList)
{
foreach (var suffix in shortAllowedPrefixSuffixList)
{
var v = new string(new char[] { prefix, middle, suffix });
yield return new object[] { new string(new char[] { prefix, middle, suffix }) };
}
}
}
}

public static IEnumerable<char> GetAllowedSuffixPrefixCharacters()
{
foreach (var index in Enumerable.Range('a', 'z' - 'a' + 1))
{
yield return (char)index;
}
foreach (var index in Enumerable.Range('A', 'Z' - 'A' + 1))
{
yield return (char)index;
}
foreach (var index in Enumerable.Range(0, 10))
{
yield return (char)('0' + index);
}
}

public static IEnumerable<char> GetAllowedMiddleCharacters()
{
foreach (var allowedPrefixOrSuffix in GetAllowedSuffixPrefixCharacters())
{
yield return allowedPrefixOrSuffix;
}
foreach (var otherAllowed in new char[] {'.', '_', '-'})
{
yield return otherAllowed;
}

}
}
}

0 comments on commit 20e0683

Please sign in to comment.