Skip to content

Commit 20e0683

Browse files
Not null the createdby on delete account (#6808)
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.
1 parent 8b9d58a commit 20e0683

4 files changed

Lines changed: 123 additions & 2 deletions

File tree

src/NuGetGallery/Areas/Admin/Services/SupportRequestService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class SupportRequestService
2020
private IAuditingService _auditingService;
2121
private readonly string _siteRoot;
2222
private const string _unassignedAdmin = "unassigned";
23+
private const string _deletedAccount = "_deletedaccount";
24+
private const string _NuGetDSRAccount = "_NuGetDSR";
2325

2426
public SupportRequestService(
2527
ISupportRequestDbContext supportRequestDbContext,
@@ -302,7 +304,11 @@ public async Task DeleteSupportRequestsAsync(User user)
302304
foreach (var accountDeletedIssue in userIssues.Where(i => string.Equals(i.IssueTitle, Strings.AccountDelete_SupportRequestTitle)))
303305
{
304306
accountDeletedIssue.OwnerEmail = "deletedaccount";
305-
accountDeletedIssue.CreatedBy = null;
307+
if(!accountDeletedIssue.CreatedBy.Equals(_NuGetDSRAccount, StringComparison.OrdinalIgnoreCase))
308+
{
309+
accountDeletedIssue.CreatedBy = _deletedAccount;
310+
}
311+
accountDeletedIssue.IssueStatusId = IssueStatusKeys.Resolved;
306312
accountDeletedIssue.Details = "This support request has been redacted as the customer's account has been deleted.";
307313
foreach (var historyEntry in accountDeletedIssue.HistoryEntries)
308314
{

tests/NuGetGallery.Facts/NuGetGallery.Facts.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="Controllers\AccountsControllerFacts.cs" />
8282
<Compile Include="Controllers\OrganizationsControllerFacts.cs" />
8383
<Compile Include="Controllers\SupportControllerFacts.cs" />
84+
<Compile Include="UsernameValidationRegex.cs" />
8485
<Compile Include="Extensions\NumberExtensionsFacts.cs" />
8586
<Compile Include="Extensions\RouteExtensionsFacts.cs" />
8687
<Compile Include="Filters\UIAuthorizeAttributeFacts.cs" />

tests/NuGetGallery.Facts/Services/SupportRequestServiceFacts.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public async Task DeleteRequestsNormalPath()
102102
Assert.False(supportRequestContext.Issues.Any(issue => string.Equals(issue.IssueTitle, "Joe's OldIssue")));
103103
var deleteRequestIssue = supportRequestContext.Issues.Where(issue => issue.Key == 1).FirstOrDefault();
104104
Assert.NotNull(deleteRequestIssue);
105-
Assert.Null(deleteRequestIssue.CreatedBy);
105+
Assert.Equal(deleteRequestIssue.CreatedBy, "_deletedaccount");
106+
Assert.Equal(deleteRequestIssue.IssueStatusId, IssueStatusKeys.Resolved);
106107
Assert.Null(deleteRequestIssue.HistoryEntries.ElementAt(0).EditedBy);
107108
}
108109

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text.RegularExpressions;
7+
using Xunit;
8+
9+
namespace NuGetGallery
10+
{
11+
public class UsernameValidationRegex
12+
{
13+
private const int TestCharSetSize = 256;
14+
15+
[Theory]
16+
[MemberData(nameof(GetAllowedShortUsername))]
17+
public void AllowedUsernames(string username)
18+
{
19+
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
20+
Assert.True(match);
21+
}
22+
23+
[Theory]
24+
[MemberData(nameof(GetNotAllowedSuffixPrefixCharacters))]
25+
public void NotAllowedUsernamesPrefix(char incorrectPrefixChar)
26+
{
27+
string username = new string(new char[] { incorrectPrefixChar, 'a' });
28+
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
29+
Assert.False(match);
30+
}
31+
32+
[Theory]
33+
[MemberData(nameof(GetNotAllowedSuffixPrefixCharacters))]
34+
public void NotAllowedUsernamesSuffix(char incorrectSuffixChar)
35+
{
36+
string username = new string(new char[] { 'a', incorrectSuffixChar });
37+
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
38+
Assert.False(match);
39+
}
40+
41+
[Theory]
42+
[MemberData(nameof(GetNotAllowedMiddleCharacters))]
43+
public void NotAllowedUsernamesMiddle(char incorrectMiddleChar)
44+
{
45+
string username = new string(new char[] { 'a', incorrectMiddleChar, 'b' });
46+
var match = new Regex(GalleryConstants.UsernameValidationRegex).IsMatch(username);
47+
Assert.False(match);
48+
}
49+
50+
public static IEnumerable<object[]> GetNotAllowedSuffixPrefixCharacters()
51+
{
52+
return Enumerable.Range(0, TestCharSetSize)
53+
.Select(i => (char)i)
54+
.Where(c => !GetAllowedSuffixPrefixCharacters().Contains(c))
55+
.Select(c => new object[] { c });
56+
}
57+
58+
public static IEnumerable<object[]> GetNotAllowedMiddleCharacters()
59+
{
60+
return Enumerable.Range(0, TestCharSetSize)
61+
.Select(i => (char)i)
62+
.Where(c => !GetAllowedMiddleCharacters().Contains(c))
63+
.Select(c => new object[] { c }); ;
64+
}
65+
66+
public static IEnumerable<object[]> GetAllowedShortUsername()
67+
{
68+
char[] shortAllowedPrefixSuffixList = new char[] { 'a', 'Z', '1' };
69+
char[] shortAllowedMiddleCharList = new char[] { '.', '_', '-' };
70+
71+
foreach (var prefix in shortAllowedPrefixSuffixList)
72+
{
73+
foreach (var middle in shortAllowedMiddleCharList)
74+
{
75+
foreach (var suffix in shortAllowedPrefixSuffixList)
76+
{
77+
var v = new string(new char[] { prefix, middle, suffix });
78+
yield return new object[] { new string(new char[] { prefix, middle, suffix }) };
79+
}
80+
}
81+
}
82+
}
83+
84+
public static IEnumerable<char> GetAllowedSuffixPrefixCharacters()
85+
{
86+
foreach (var index in Enumerable.Range('a', 'z' - 'a' + 1))
87+
{
88+
yield return (char)index;
89+
}
90+
foreach (var index in Enumerable.Range('A', 'Z' - 'A' + 1))
91+
{
92+
yield return (char)index;
93+
}
94+
foreach (var index in Enumerable.Range(0, 10))
95+
{
96+
yield return (char)('0' + index);
97+
}
98+
}
99+
100+
public static IEnumerable<char> GetAllowedMiddleCharacters()
101+
{
102+
foreach (var allowedPrefixOrSuffix in GetAllowedSuffixPrefixCharacters())
103+
{
104+
yield return allowedPrefixOrSuffix;
105+
}
106+
foreach (var otherAllowed in new char[] {'.', '_', '-'})
107+
{
108+
yield return otherAllowed;
109+
}
110+
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)