Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ReleasePrep][2017.05.19]RI of dev into master #3997

Merged
merged 28 commits into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
acee6f7
Fix migration issue #3865 (#3872)
chenriksson May 4, 2017
ba13855
Front page V3 feed compatibility should mention NuGet 4.x/VS 2017 (#3…
anangaur May 8, 2017
36d594f
Support MinClientVersion <= 4.1.0.0 (#3860)
maartenba May 8, 2017
b84d965
Improved the Gallery's Screen Reader Accessibility (#3902)
loic-sharma May 9, 2017
def1907
Added index on ([SemVerLevelKey], [IsLatest], [Deleted]) on Packages …
agr May 10, 2017
c4297a9
Revert "Added index on ([SemVerLevelKey], [IsLatest], [Deleted]) on P…
agr May 11, 2017
cdcb6a8
pressing edit or undo on the verify package page does not reset focus…
May 11, 2017
b2c49c8
Adding recommended index to the Packages table (#3950)
agr May 11, 2017
b9d3484
Improved NuGet Gallery's Accessibility (#3936)
loic-sharma May 11, 2017
d944bb3
Use HTTPS clone in README.md instead of SSH (#3955)
joelverhagen May 12, 2017
61368c3
Only use the certificate, since `netsh http add sslcert` only accepts…
joelverhagen May 12, 2017
98fdbf5
Fix SecurityPoliciesFix migration rollback (#3944)
chenriksson May 12, 2017
ce1bf4e
Update CSS to show focused elements.
ryuyu May 12, 2017
319bc79
Make PackageDownloadsDetail and PackageDownloadsByVersion graphs upda…
May 12, 2017
74cd45a
Scoped API keys UI - disabled elements are accessible using tab (#3963)
skofman1 May 15, 2017
6a7b75c
Fix: "Example glob patterns" button and "close" button are not access…
skofman1 May 16, 2017
9ea3066
Key creation telemetry (#3855)
chenriksson May 3, 2017
a1bc005
Temp keys policy onboarding (#3854)
chenriksson May 8, 2017
b6e424f
Enable security policy functional tests (#3965)
chenriksson May 15, 2017
cdc08cb
Temp keys telemetry and auditing (#3945)
chenriksson May 16, 2017
e9a92cb
Merge fix
chenriksson May 16, 2017
d1203e8
fix for 3828 (#3972)
cristinamanum May 17, 2017
01d0a4a
Avoid separate context from policy service (#3982)
chenriksson May 17, 2017
3f25393
Allow auto outlining. Fix issue with outline on click. (#3983)
ryuyu May 17, 2017
eddf514
Parse tags list before comparing on package validation completion (#3…
skofman1 May 19, 2017
d0bc5c0
Update Report Abuse Page (#3985)
ryuyu May 19, 2017
a1c1d56
Path too long fix for policy test (#3995)
chenriksson May 19, 2017
3ac8517
Merge pull request #3996 from NuGet/master
ryuyu May 20, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
2. PowerShell 4.0
2. Clone it!

```PS C:\Code> git clone git@github.com:NuGet/NuGetGallery.git```
```PS C:\Code> git clone https://github.com/NuGet/NuGetGallery.git```
3. Build it!

```
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.

namespace NuGetGallery.Auditing.AuditedEntities
{
/// <summary>
/// Auditing details for UserSecurityPolicy entity.
/// </summary>
public class AuditedUserSecurityPolicy
{
public string Name { get; }
public string Subscription { get; }
public string Value { get; }

public AuditedUserSecurityPolicy(UserSecurityPolicy policy)
{
Name = policy.Name;
Subscription = policy.Subscription;
Value = policy.Value;
}
}
}
3 changes: 1 addition & 2 deletions src/NuGetGallery.Core/Auditing/AuditedPackageAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public enum AuditedPackageAction
Unlist,
Edit,
UndoEdit,


Verify
}
}
11 changes: 11 additions & 0 deletions src/NuGetGallery.Core/Auditing/AuditedSecurityPolicyAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// 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.

namespace NuGetGallery.Auditing
{
public enum AuditedSecurityPolicyAction
{
Create,
Verify
}
}
4 changes: 3 additions & 1 deletion src/NuGetGallery.Core/Auditing/AuditedUserAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public enum AuditedUserAction
ChangeEmail,
CancelChangeEmail,
ConfirmEmail,
Login
Login,
SubscribeToPolicies,
UnsubscribeFromPolicies
}
}
16 changes: 0 additions & 16 deletions src/NuGetGallery.Core/Auditing/UserAuditAction.cs

This file was deleted.

19 changes: 18 additions & 1 deletion src/NuGetGallery.Core/Auditing/UserAuditRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NuGetGallery.Auditing.AuditedEntities;

namespace NuGetGallery.Auditing
{
Expand All @@ -17,6 +18,11 @@ public class UserAuditRecord : AuditRecord<AuditedUserAction>
public CredentialAuditRecord[] AffectedCredential { get; }
public string AffectedEmailAddress { get; }

/// <summary>
/// Subset of user policies affected by the action (subscription / unsubscription).
/// </summary>
public AuditedUserSecurityPolicy[] AffectedPolicies { get; }

public UserAuditRecord(User user, AuditedUserAction action)
: this(user, action, Enumerable.Empty<Credential>())
{
Expand Down Expand Up @@ -55,7 +61,18 @@ public UserAuditRecord(User user, AuditedUserAction action, string affectedEmail
{
AffectedEmailAddress = affectedEmailAddress;
}


public UserAuditRecord(User user, AuditedUserAction action, IEnumerable<UserSecurityPolicy> affectedPolicies)
: this(user, action, Enumerable.Empty<Credential>())
{
if (affectedPolicies == null || affectedPolicies.Count() == 0)
{
throw new ArgumentException(nameof(affectedPolicies));
}

AffectedPolicies = affectedPolicies.Select(p => new AuditedUserSecurityPolicy(p)).ToArray();
}

public override string GetPath()
{
return Username.ToLowerInvariant();
Expand Down
50 changes: 50 additions & 0 deletions src/NuGetGallery.Core/Auditing/UserSecurityPolicyAuditRecord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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.Collections.Generic;
using System.Linq;
using NuGetGallery.Auditing.AuditedEntities;

namespace NuGetGallery.Auditing
{
/// <summary>
/// Audit record for user security policy evaluations.
/// </summary>
public class UserSecurityPolicyAuditRecord : AuditRecord<AuditedSecurityPolicyAction>
{
public string Username { get; }

public AuditedUserSecurityPolicy[] AffectedPolicies { get; }

public bool Success { get; set; }

public string ErrorMessage { get; }

public UserSecurityPolicyAuditRecord(string username,
AuditedSecurityPolicyAction action,
IEnumerable<UserSecurityPolicy> affectedPolicies,
bool success, string errorMessage = null)
:base(action)
{
if (string.IsNullOrEmpty(username))
{
throw new ArgumentNullException(nameof(username));
}
if (affectedPolicies == null || affectedPolicies.Count() == 0)
{
throw new ArgumentException(nameof(affectedPolicies));
}

Username = username;
AffectedPolicies = affectedPolicies.Select(p => new AuditedUserSecurityPolicy(p)).ToArray();
Success = success;
ErrorMessage = errorMessage;
}

public override string GetPath()
{
return Username.ToLowerInvariant();
}
}
}
1 change: 1 addition & 0 deletions src/NuGetGallery.Core/Entities/EntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public EntitiesContext(string connectionString, bool readOnly)
public IDbSet<Credential> Credentials { get; set; }
public IDbSet<Scope> Scopes { get; set; }
public IDbSet<User> Users { get; set; }
public IDbSet<UserSecurityPolicy> UserSecurityPolicies { get; set; }

IDbSet<T> IEntitiesContext.Set<T>()
{
Expand Down
3 changes: 2 additions & 1 deletion src/NuGetGallery.Core/Entities/IEntitiesContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public interface IEntitiesContext
IDbSet<PackageRegistration> PackageRegistrations { get; set; }
IDbSet<Credential> Credentials { get; set; }
IDbSet<Scope> Scopes { get; set; }

IDbSet<User> Users { get; set; }
IDbSet<UserSecurityPolicy> UserSecurityPolicies { get; set; }

Task<int> SaveChangesAsync();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Set", Justification="This is to match the EF terminology.")]
IDbSet<T> Set<T>() where T : class;
Expand Down
43 changes: 40 additions & 3 deletions src/NuGetGallery.Core/Entities/UserSecurityPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
// 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.ComponentModel.DataAnnotations;

namespace NuGetGallery
{
/// <summary>
/// User-subscribed security policy.
/// </summary>
public class UserSecurityPolicy : IEntity
public class UserSecurityPolicy : IEntity, IEquatable<UserSecurityPolicy>
{
public UserSecurityPolicy()
{
}

public UserSecurityPolicy(string name)
public UserSecurityPolicy(UserSecurityPolicy policy)
: this(policy.Name, policy.Subscription, policy.Value)
{
Name = name;
}

public UserSecurityPolicy(string name, string subscription, string value = null)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Subscription = subscription ?? throw new ArgumentNullException(nameof(subscription));
Value = value;
}

/// <summary>
Expand All @@ -38,11 +46,40 @@ public UserSecurityPolicy(string name)
/// Type name for the policy handler that provides policy behavior.
/// </summary>
[Required]
[StringLength(256)]
public string Name { get; set; }

/// <summary>
/// Name of subscription that added this policy.
/// </summary>
[Required]
[StringLength(256)]
public string Subscription { get; set; }

/// <summary>
/// Support for JSON-serialized properties for specific policies.
/// </summary>
public string Value { get; set; }

/// <summary>
/// Determine if two policies are equal.
/// </summary>
public bool Equals(UserSecurityPolicy other)
{
return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase) &&
Subscription.Equals(other.Subscription, StringComparison.OrdinalIgnoreCase) &&
(
(string.IsNullOrEmpty(Value) && string.IsNullOrEmpty(other.Value)) ||
(Value.Equals(other.Value, StringComparison.OrdinalIgnoreCase))
);
}

private static readonly Func<object, long, long> _hash = (i, hash) => ((hash << 5) + hash) ^ (i?.GetHashCode() ?? 0);
private const long _seed = 0x1505L;

public override int GetHashCode()
{
return _hash(Value, _hash(Subscription, _hash(Name, _seed))).GetHashCode();
}
}
}
4 changes: 3 additions & 1 deletion src/NuGetGallery.Core/NuGetGallery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,14 @@
<Compile Include="Auditing\AuditedEntities\AuditedPackage.cs" />
<Compile Include="Auditing\AuditedEntities\AuditedPackageIdentifier.cs" />
<Compile Include="Auditing\AuditedAuthenticatedOperationAction.cs" />
<Compile Include="Auditing\AuditedEntities\AuditedUserSecurityPolicy.cs" />
<Compile Include="Auditing\AuditedSecurityPolicyAction.cs" />
<Compile Include="Auditing\AuditEntry.cs" />
<Compile Include="Auditing\AuditActor.cs" />
<Compile Include="Auditing\AuditingService.cs" />
<Compile Include="Auditing\AuditRecord.cs" />
<Compile Include="Auditing\FailedAuthenticatedOperationAuditRecord.cs" />
<Compile Include="Auditing\UserSecurityPolicyAuditRecord.cs" />
<Compile Include="Auditing\FileSystemAuditingService.cs" />
<Compile Include="Auditing\CloudAuditingService.cs" />
<Compile Include="Auditing\CredentialAuditRecord.cs" />
Expand All @@ -139,7 +142,6 @@
<Compile Include="Auditing\AuditedUserAction.cs" />
<Compile Include="Auditing\PackageAuditRecord.cs" />
<Compile Include="Auditing\ScopeAuditRecord.cs" />
<Compile Include="Auditing\UserAuditAction.cs" />
<Compile Include="Auditing\UserAuditRecord.cs" />
<Compile Include="CoreConstants.cs" />
<Compile Include="CredentialTypes.cs" />
Expand Down
3 changes: 3 additions & 0 deletions src/NuGetGallery/App_Start/DefaultDependenciesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ protected override void Load(ContainerBuilder builder)
.As<ISecurityPolicyService>()
.InstancePerLifetimeScope();

builder.RegisterType<SecurePushSubscription>()
.SingleInstance();

var mailSenderThunk = new Lazy<IMailSender>(
() =>
{
Expand Down
10 changes: 10 additions & 0 deletions src/NuGetGallery/App_Start/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,21 @@ public static void RegisterUIRoutes(RouteCollection routes)
"stats/packages/{id}/{version}",
new { controller = "Statistics", action = "PackageDownloadsDetail" });

routes.MapRoute(
RouteName.StatisticsPackageDownloadsDetailReport,
"stats/reports/packages/{id}/{version}",
new { controller = "Statistics", action = "PackageDownloadsDetailReport" });

routes.MapRoute(
RouteName.StatisticsPackageDownloadsByVersion,
"stats/packages/{id}",
new { controller = "Statistics", action = "PackageDownloadsByVersion" });

routes.MapRoute(
RouteName.StatisticsPackageDownloadsByVersionReport,
"stats/reports/packages/{id}",
new { controller = "Statistics", action = "PackageDownloadsByVersionReport" });

routes.MapRoute(
RouteName.JsonApi,
"json/{action}",
Expand Down
Loading