diff --git a/Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj b/Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj index 4a0291c85..2e69aebec 100644 --- a/Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj +++ b/Bonobo.Git.Server.Test/Bonobo.Git.Server.Test.csproj @@ -1,5 +1,6 @@  + Debug @@ -48,6 +49,9 @@ MinimumRecommendedRules.ruleset + + ..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll True @@ -56,6 +60,15 @@ ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll True + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll + + + ..\packages\MSTest.TestFramework.2.1.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll + + + ..\packages\Moq.4.15.2\lib\net45\Moq.dll + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -90,30 +103,30 @@ True + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll - - ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - True + + ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll - ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - True + ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll ..\packages\Selenium.WebDriver.3.3.0\lib\net40\WebDriver.dll @@ -130,13 +143,7 @@ - - - - False - - - + @@ -159,16 +166,17 @@ - - - - + + + + - - - - + + + + + @@ -208,6 +216,8 @@ + + @@ -217,6 +227,7 @@ + diff --git a/Bonobo.Git.Server.Test/UnitTests/CustomHtmlHelperTest.cs b/Bonobo.Git.Server.Test/Unit/CustomHtmlHelperTest.cs similarity index 96% rename from Bonobo.Git.Server.Test/UnitTests/CustomHtmlHelperTest.cs rename to Bonobo.Git.Server.Test/Unit/CustomHtmlHelperTest.cs index 95f2984a4..a6bf2c104 100644 --- a/Bonobo.Git.Server.Test/UnitTests/CustomHtmlHelperTest.cs +++ b/Bonobo.Git.Server.Test/Unit/CustomHtmlHelperTest.cs @@ -4,7 +4,7 @@ using Bonobo.Git.Server.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace Bonobo.Git.Server.Test.UnitTests +namespace Bonobo.Git.Server.Test.Unit { [TestClass] public class CustomHtmlHelperTest diff --git a/Bonobo.Git.Server.Test/UnitTests/DatabaseUpdateTestsSqlServer.cs b/Bonobo.Git.Server.Test/Unit/DatabaseUpdateTestsSqlServer.cs similarity index 99% rename from Bonobo.Git.Server.Test/UnitTests/DatabaseUpdateTestsSqlServer.cs rename to Bonobo.Git.Server.Test/Unit/DatabaseUpdateTestsSqlServer.cs index d7c399558..34a9ec082 100644 --- a/Bonobo.Git.Server.Test/UnitTests/DatabaseUpdateTestsSqlServer.cs +++ b/Bonobo.Git.Server.Test/Unit/DatabaseUpdateTestsSqlServer.cs @@ -4,7 +4,7 @@ using Bonobo.Git.Server.Data.Update; using Bonobo.Git.Server.Data; -namespace Bonobo.Git.Server.Test.UnitTests +namespace Bonobo.Git.Server.Test.Unit { [TestClass] public class DatabaseUpdateTestsSqlServer diff --git a/Bonobo.Git.Server.Test/UnitTests/DatabaseUpdateTestsSqlite.cs b/Bonobo.Git.Server.Test/Unit/DatabaseUpdateTestsSqlite.cs similarity index 99% rename from Bonobo.Git.Server.Test/UnitTests/DatabaseUpdateTestsSqlite.cs rename to Bonobo.Git.Server.Test/Unit/DatabaseUpdateTestsSqlite.cs index 1067bf137..ee958c166 100644 --- a/Bonobo.Git.Server.Test/UnitTests/DatabaseUpdateTestsSqlite.cs +++ b/Bonobo.Git.Server.Test/Unit/DatabaseUpdateTestsSqlite.cs @@ -4,7 +4,7 @@ using Bonobo.Git.Server.Data.Update; using Bonobo.Git.Server.Data; -namespace Bonobo.Git.Server.Test.UnitTests +namespace Bonobo.Git.Server.Test.Unit { [TestClass] public class DatabaseUpdateTestsSqlite diff --git a/Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs b/Bonobo.Git.Server.Test/Unit/GitAuthorizeAttributeTest.cs similarity index 100% rename from Bonobo.Git.Server.Test/UnitTests/GitAuthorizeAttributeTest.cs rename to Bonobo.Git.Server.Test/Unit/GitAuthorizeAttributeTest.cs diff --git a/Bonobo.Git.Server.Test/UnitTests/PasswordServiceTest.cs b/Bonobo.Git.Server.Test/Unit/PasswordServiceTest.cs similarity index 100% rename from Bonobo.Git.Server.Test/UnitTests/PasswordServiceTest.cs rename to Bonobo.Git.Server.Test/Unit/PasswordServiceTest.cs diff --git a/Bonobo.Git.Server.Test/UnitTests/PathEncoderTest.cs b/Bonobo.Git.Server.Test/Unit/PathEncoderTest.cs similarity index 100% rename from Bonobo.Git.Server.Test/UnitTests/PathEncoderTest.cs rename to Bonobo.Git.Server.Test/Unit/PathEncoderTest.cs diff --git a/Bonobo.Git.Server.Test/Unit/UserConfigurationTests.cs b/Bonobo.Git.Server.Test/Unit/UserConfigurationTests.cs new file mode 100644 index 000000000..b2b991b4c --- /dev/null +++ b/Bonobo.Git.Server.Test/Unit/UserConfigurationTests.cs @@ -0,0 +1,20 @@ +using Bonobo.Git.Server.Configuration; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; + +namespace Bonobo.Git.Server.Test.Unit +{ + [TestClass] + public class UserConfigurationTests + { + [TestMethod] + public void UserConfiguration_Current_Can_Be_Used_After_Preparing_PathResolver() + { + Mock pathResolverMock = new Mock(); + pathResolverMock.Setup(pr => pr.ResolveWithConfiguration(It.IsAny())) + .Returns("BonoboTestConfig.config"); + UserConfiguration.PathResolver = pathResolverMock.Object; + Assert.IsNotNull(UserConfiguration.Current); + } + } +} diff --git a/Bonobo.Git.Server.Test/UnitTests/UserExtensionsTests.cs b/Bonobo.Git.Server.Test/Unit/UserExtensionsTests.cs similarity index 99% rename from Bonobo.Git.Server.Test/UnitTests/UserExtensionsTests.cs rename to Bonobo.Git.Server.Test/Unit/UserExtensionsTests.cs index c0a435de4..196fe0e7c 100644 --- a/Bonobo.Git.Server.Test/UnitTests/UserExtensionsTests.cs +++ b/Bonobo.Git.Server.Test/Unit/UserExtensionsTests.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; -namespace Bonobo.Git.Server.Test.UnitTests +namespace Bonobo.Git.Server.Test.Unit { [TestClass] public class UserExtensionsTests diff --git a/Bonobo.Git.Server.Test/UnitTests/UserModelTest.cs b/Bonobo.Git.Server.Test/Unit/UserModelTest.cs similarity index 97% rename from Bonobo.Git.Server.Test/UnitTests/UserModelTest.cs rename to Bonobo.Git.Server.Test/Unit/UserModelTest.cs index e845bb073..cbcdd314b 100644 --- a/Bonobo.Git.Server.Test/UnitTests/UserModelTest.cs +++ b/Bonobo.Git.Server.Test/Unit/UserModelTest.cs @@ -1,7 +1,7 @@ using Bonobo.Git.Server.Models; using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace Bonobo.Git.Server.Test.UnitTests +namespace Bonobo.Git.Server.Test.Unit { [TestClass] public sealed class UserModelTest diff --git a/Bonobo.Git.Server.Test/app.config b/Bonobo.Git.Server.Test/app.config index 7cd250804..2c5642f0d 100644 --- a/Bonobo.Git.Server.Test/app.config +++ b/Bonobo.Git.Server.Test/app.config @@ -32,7 +32,7 @@ - + @@ -54,6 +54,18 @@ + + + + + + + + + + + + diff --git a/Bonobo.Git.Server.Test/packages.config b/Bonobo.Git.Server.Test/packages.config index ba78b3b29..e12b1e08c 100644 --- a/Bonobo.Git.Server.Test/packages.config +++ b/Bonobo.Git.Server.Test/packages.config @@ -1,12 +1,16 @@  + - + - - + + + + + @@ -17,4 +21,6 @@ + + \ No newline at end of file diff --git a/Bonobo.Git.Server/App_Start/UnityConfig.cs b/Bonobo.Git.Server/App_Start/UnityConfig.cs new file mode 100644 index 000000000..54136e2fc --- /dev/null +++ b/Bonobo.Git.Server/App_Start/UnityConfig.cs @@ -0,0 +1,47 @@ +using System; + +using Unity; + +namespace Bonobo.Git.Server +{ + /// + /// Specifies the Unity configuration for the main container. + /// + public static class UnityConfig + { + #region Unity Container + private static Lazy container = + new Lazy(() => + { + var container = new UnityContainer(); + RegisterTypes(container); + return container; + }); + + /// + /// Configured Unity Container. + /// + public static IUnityContainer Container => container.Value; + #endregion + + /// + /// Registers the type mappings with the Unity container. + /// + /// The unity container to configure. + /// + /// There is no need to register concrete types such as controllers or + /// API controllers (unless you want to change the defaults), as Unity + /// allows resolving a concrete type even if it was not previously + /// registered. + /// + public static void RegisterTypes(IUnityContainer container) + { + // NOTE: To load from web.config uncomment the line below. + // Make sure to add a Unity.Configuration to the using statements. + // container.LoadConfiguration(); + + // TODO: Register your type's mappings here. + // container.RegisterType(); + } + } +} \ No newline at end of file diff --git a/Bonobo.Git.Server/App_Start/UnityMvcActivator.cs b/Bonobo.Git.Server/App_Start/UnityMvcActivator.cs new file mode 100644 index 000000000..c0143d4b9 --- /dev/null +++ b/Bonobo.Git.Server/App_Start/UnityMvcActivator.cs @@ -0,0 +1,38 @@ +using System.Linq; +using System.Web.Mvc; + +using Unity.AspNet.Mvc; + +[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Bonobo.Git.Server.UnityMvcActivator), nameof(Bonobo.Git.Server.UnityMvcActivator.Start))] +[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(Bonobo.Git.Server.UnityMvcActivator), nameof(Bonobo.Git.Server.UnityMvcActivator.Shutdown))] + +namespace Bonobo.Git.Server +{ + /// + /// Provides the bootstrapping for integrating Unity with ASP.NET MVC. + /// + public static class UnityMvcActivator + { + /// + /// Integrates Unity when the application starts. + /// + public static void Start() + { + FilterProviders.Providers.Remove(FilterProviders.Providers.OfType().First()); + FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(UnityConfig.Container)); + + DependencyResolver.SetResolver(new UnityDependencyResolver(UnityConfig.Container)); + + // TODO: Uncomment if you want to use PerRequestLifetimeManager + // Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule)); + } + + /// + /// Disposes the Unity container when the application is shut down. + /// + public static void Shutdown() + { + UnityConfig.Container.Dispose(); + } + } +} \ No newline at end of file diff --git a/Bonobo.Git.Server/Attributes/AllViewsAttribute.cs b/Bonobo.Git.Server/Attributes/AllViewsAttribute.cs index 63477e8d6..632e9aabc 100644 --- a/Bonobo.Git.Server/Attributes/AllViewsAttribute.cs +++ b/Bonobo.Git.Server/Attributes/AllViewsAttribute.cs @@ -1,11 +1,11 @@ using Bonobo.Git.Server.App_GlobalResources; using Bonobo.Git.Server.Models; using Bonobo.Git.Server.Security; -using Microsoft.Practices.Unity; using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server.Attributes { diff --git a/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs b/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs index f0b547206..190006ff9 100644 --- a/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs +++ b/Bonobo.Git.Server/Attributes/GitAuthorizeAttribute.cs @@ -1,14 +1,14 @@ -using System; +using Bonobo.Git.Server.Data; +using Bonobo.Git.Server.Helpers; +using Bonobo.Git.Server.Security; +using Serilog; +using System; using System.Net; using System.Security.Claims; using System.Text; using System.Web; using System.Web.Mvc; -using Bonobo.Git.Server.Data; -using Bonobo.Git.Server.Security; -using Microsoft.Practices.Unity; -using Bonobo.Git.Server.Helpers; -using Serilog; +using Unity; namespace Bonobo.Git.Server { @@ -28,7 +28,7 @@ public class GitAuthorizeAttribute : AuthorizeAttribute public static string GetRepoPath(string path, string applicationPath) { - var repo = path.Replace(applicationPath, "").Replace("/",""); + var repo = path.Replace(applicationPath, "").Replace("/", ""); return repo.Substring(0, repo.IndexOf(".git")); } diff --git a/Bonobo.Git.Server/Attributes/IsValidRegexAttribute.cs b/Bonobo.Git.Server/Attributes/IsValidRegexAttribute.cs index 3bbbd6b56..69d222ccc 100644 --- a/Bonobo.Git.Server/Attributes/IsValidRegexAttribute.cs +++ b/Bonobo.Git.Server/Attributes/IsValidRegexAttribute.cs @@ -1,14 +1,6 @@ -using Bonobo.Git.Server.Data; -using Bonobo.Git.Server.App_GlobalResources; -using Microsoft.Practices.Unity; +using Bonobo.Git.Server.App_GlobalResources; using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Web; -using System.Web.Mvc; - -using Bonobo.Git.Server.Models; using System.Text.RegularExpressions; namespace Bonobo.Git.Server.Attributes @@ -22,10 +14,13 @@ protected override ValidationResult IsValid(object value, ValidationContext cont return ValidationResult.Success; } - try{ + try + { new Regex((string)value); return ValidationResult.Success; - }catch(ArgumentException e){ + } + catch (ArgumentException e) + { return new ValidationResult(string.Format(Resources.Validation_Invalid_Regex, e.Message)); } } diff --git a/Bonobo.Git.Server/Attributes/RepositoryNameNormalizerAttribute.cs b/Bonobo.Git.Server/Attributes/RepositoryNameNormalizerAttribute.cs index f79b4a884..226b00b57 100644 --- a/Bonobo.Git.Server/Attributes/RepositoryNameNormalizerAttribute.cs +++ b/Bonobo.Git.Server/Attributes/RepositoryNameNormalizerAttribute.cs @@ -1,6 +1,6 @@ -using System.Web.Mvc; using Bonobo.Git.Server.Data; -using Microsoft.Practices.Unity; +using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server { @@ -26,7 +26,7 @@ public RepositoryNameNormalizerAttribute(string repositoryNameParameterName) public override void OnActionExecuting(ActionExecutingContext filterContext) { object incomingRepositoryNameParameter; - if(filterContext.ActionParameters.TryGetValue(_repositoryNameParameterName, out incomingRepositoryNameParameter)) + if (filterContext.ActionParameters.TryGetValue(_repositoryNameParameterName, out incomingRepositoryNameParameter)) { var incomingRepositoryName = (string)incomingRepositoryNameParameter; var normalizedName = Repository.NormalizeRepositoryName(incomingRepositoryName, RepositoryRepository); diff --git a/Bonobo.Git.Server/Attributes/UniqueRepoNameAttribute.cs b/Bonobo.Git.Server/Attributes/UniqueRepoNameAttribute.cs index 2b642ba26..9b3a159cd 100644 --- a/Bonobo.Git.Server/Attributes/UniqueRepoNameAttribute.cs +++ b/Bonobo.Git.Server/Attributes/UniqueRepoNameAttribute.cs @@ -1,15 +1,9 @@ -using Bonobo.Git.Server.Data; -using Bonobo.Git.Server.App_GlobalResources; -using Microsoft.Practices.Unity; -using System; -using System.Collections.Generic; +using Bonobo.Git.Server.App_GlobalResources; +using Bonobo.Git.Server.Data; +using Bonobo.Git.Server.Models; using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Web; using System.Web.Mvc; -using Bonobo.Git.Server.Models; - namespace Bonobo.Git.Server.Attributes { public class UniqueRepoNameAttribute : ValidationAttribute diff --git a/Bonobo.Git.Server/Attributes/WebAuthorizeRepositoryAttribute.cs b/Bonobo.Git.Server/Attributes/WebAuthorizeRepositoryAttribute.cs index 687a6b72f..4cf7768d7 100644 --- a/Bonobo.Git.Server/Attributes/WebAuthorizeRepositoryAttribute.cs +++ b/Bonobo.Git.Server/Attributes/WebAuthorizeRepositoryAttribute.cs @@ -1,10 +1,7 @@ -using System.Web.Mvc; -using System.Web.Routing; -using Bonobo.Git.Server.Data; -using Bonobo.Git.Server.Security; - -using Microsoft.Practices.Unity; +using Bonobo.Git.Server.Security; using System; +using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server { diff --git a/Bonobo.Git.Server/Bonobo.Git.Server.csproj b/Bonobo.Git.Server/Bonobo.Git.Server.csproj index 32725905f..ad78e8525 100644 --- a/Bonobo.Git.Server/Bonobo.Git.Server.csproj +++ b/Bonobo.Git.Server/Bonobo.Git.Server.csproj @@ -126,22 +126,6 @@ ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll True - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.dll - True - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.Configuration.dll - True - - - ..\packages\Unity.Mvc.4.0.1\lib\net45\Microsoft.Practices.Unity.Mvc.dll - True - - - ..\packages\Unity.4.0.1\lib\net45\Microsoft.Practices.Unity.RegistrationByConvention.dll - True - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll @@ -209,11 +193,17 @@ + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll + @@ -222,35 +212,29 @@ False - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.Helpers.dll - - ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll - True + + ..\packages\Microsoft.AspNet.Mvc.5.2.7\lib\net45\System.Web.Mvc.dll ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll True - ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll - True + ..\packages\Microsoft.AspNet.Razor.3.2.7\lib\net45\System.Web.Razor.dll False - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.dll - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Deployment.dll - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll - True + ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll @@ -261,6 +245,15 @@ ..\packages\UDE.CSharp.1.1.0\lib\Ude.dll True + + ..\packages\Unity.5.11.7\lib\net46\Unity.Abstractions.dll + + + ..\packages\Unity.5.11.7\lib\net46\Unity.Container.dll + + + ..\packages\Unity.Mvc.5.11.1\lib\net46\Unity.Mvc.dll + ..\packages\WebActivatorEx.2.2.0\lib\net40\WebActivatorEx.dll True @@ -272,6 +265,8 @@ + + @@ -281,6 +276,8 @@ + + diff --git a/Bonobo.Git.Server/Configuration/ConfigurationEntry.cs b/Bonobo.Git.Server/Configuration/ConfigurationEntry.cs index e8843e324..01af32069 100644 --- a/Bonobo.Git.Server/Configuration/ConfigurationEntry.cs +++ b/Bonobo.Git.Server/Configuration/ConfigurationEntry.cs @@ -1,7 +1,4 @@ -using System.Configuration; -using System.IO; -using System.Web; -using System.Web.Hosting; +using System.IO; using System.Xml.Serialization; namespace Bonobo.Git.Server.Configuration @@ -9,11 +6,11 @@ namespace Bonobo.Git.Server.Configuration public abstract class ConfigurationEntry where Entry : ConfigurationEntry, new() { private static Entry _current = null; + private static IPathResolver pathResolver = new HostingEnvironmentPathResolver(); private static readonly object _sync = new object(); private static readonly XmlSerializer _serializer = new XmlSerializer(typeof(Entry)); - private static readonly string _configPath = Path.IsPathRooted(ConfigurationManager.AppSettings["UserConfiguration"]) - ? ConfigurationManager.AppSettings["UserConfiguration"] - : HostingEnvironment.MapPath(ConfigurationManager.AppSettings["UserConfiguration"]); + public static IPathResolver PathResolver { get => pathResolver; set => pathResolver = value; } + private static string ConfigPath { get => PathResolver.ResolveWithConfiguration("UserConfiguration"); } public static Entry Current { get { return _current ?? Load(); } } @@ -27,7 +24,7 @@ private static Entry Load() { try { - using (var stream = File.Open(_configPath, FileMode.Open)) + using (var stream = File.Open(ConfigPath, FileMode.Open)) { _current = _serializer.Deserialize(stream) as Entry; } @@ -48,7 +45,7 @@ public void Save() { if (_current != null) { - using (var stream = File.Open(_configPath, FileMode.Create)) + using (var stream = File.Open(ConfigPath, FileMode.Create)) { _serializer.Serialize(stream, _current); } diff --git a/Bonobo.Git.Server/Configuration/HostingEnvironmentPathResolver.cs b/Bonobo.Git.Server/Configuration/HostingEnvironmentPathResolver.cs new file mode 100644 index 000000000..d78784809 --- /dev/null +++ b/Bonobo.Git.Server/Configuration/HostingEnvironmentPathResolver.cs @@ -0,0 +1,13 @@ +using System.Configuration; +using System.IO; +using System.Web.Hosting; + +namespace Bonobo.Git.Server.Configuration +{ + internal class HostingEnvironmentPathResolver : IPathResolver + { + public string Resolve(string path) => Path.IsPathRooted(path) ? path : HostingEnvironment.MapPath(path); + + public string ResolveWithConfiguration(string configKey) => Resolve(ConfigurationManager.AppSettings[configKey]); + } +} \ No newline at end of file diff --git a/Bonobo.Git.Server/Configuration/IPathResolver.cs b/Bonobo.Git.Server/Configuration/IPathResolver.cs new file mode 100644 index 000000000..70c56c431 --- /dev/null +++ b/Bonobo.Git.Server/Configuration/IPathResolver.cs @@ -0,0 +1,8 @@ +namespace Bonobo.Git.Server.Configuration +{ + public interface IPathResolver + { + string ResolveWithConfiguration(string configKey); + string Resolve(string path); + } +} \ No newline at end of file diff --git a/Bonobo.Git.Server/Configuration/UserConfiguration.cs b/Bonobo.Git.Server/Configuration/UserConfiguration.cs index f6db21795..655607539 100644 --- a/Bonobo.Git.Server/Configuration/UserConfiguration.cs +++ b/Bonobo.Git.Server/Configuration/UserConfiguration.cs @@ -1,19 +1,16 @@ -using System; +using Bonobo.Git.Server.App_GlobalResources; +using System; using System.Configuration; -using System.IO; -using System.Web; using System.Xml.Serialization; namespace Bonobo.Git.Server.Configuration { - using Bonobo.Git.Server.App_GlobalResources; - using System.Web.Hosting; - [XmlRootAttribute(ElementName = "Configuration", IsNullable = false)] + [XmlRoot(ElementName = "Configuration", IsNullable = false)] public class UserConfiguration : ConfigurationEntry { public bool AllowAnonymousPush { get; set; } - [XmlElementAttribute(ElementName = "Repositories")] + [XmlElement(ElementName = "Repositories")] public string RepositoryPath { get; set; } public bool AllowUserRepositoryCreation { get; set; } public bool AllowPushToCreate { get; set; } @@ -27,63 +24,29 @@ public class UserConfiguration : ConfigurationEntry public string LinksRegex { get; set; } public string LinksUrl { get; set; } - public string Repositories - { - get - { - return Path.IsPathRooted(RepositoryPath) - ? RepositoryPath - : HostingEnvironment.MapPath(RepositoryPath); - } - } + public string Repositories => PathResolver.Resolve(RepositoryPath); - public bool HasSiteFooterMessage - { - get - { - return !string.IsNullOrWhiteSpace(this.SiteFooterMessage); - } - } + public bool HasSiteFooterMessage => !string.IsNullOrWhiteSpace(this.SiteFooterMessage); - public bool HasCustomSiteLogo - { - get - { - return !string.IsNullOrWhiteSpace(this.SiteLogoUrl); - } - } + public bool HasCustomSiteLogo => !string.IsNullOrWhiteSpace(this.SiteLogoUrl); - public bool HasCustomSiteCss - { - get { return !string.IsNullOrWhiteSpace(SiteCssUrl); } - } + public bool HasCustomSiteCss => !string.IsNullOrWhiteSpace(SiteCssUrl); - public bool HasLinks - { - get - { - return !string.IsNullOrWhiteSpace(this.LinksRegex); - } - } + public bool HasLinks => !string.IsNullOrWhiteSpace(this.LinksRegex); - public string GetSiteTitle() - { - return !string.IsNullOrWhiteSpace(this.SiteTitle) ? this.SiteTitle : Resources.Layout_Title; - } + public string GetSiteTitle() => !string.IsNullOrWhiteSpace(this.SiteTitle) ? this.SiteTitle : Resources.Layout_Title; public static void Initialize() { - if (IsInitialized()) + if (IsInitialized) + { return; + } Current.RepositoryPath = ConfigurationManager.AppSettings["DefaultRepositoriesDirectory"]; Current.Save(); } - - private static bool IsInitialized() - { - return !String.IsNullOrEmpty(Current.RepositoryPath); - } + private static bool IsInitialized => !String.IsNullOrEmpty(Current.RepositoryPath); } } \ No newline at end of file diff --git a/Bonobo.Git.Server/Controllers/AccountController.cs b/Bonobo.Git.Server/Controllers/AccountController.cs index 72b1d847d..73486f07f 100644 --- a/Bonobo.Git.Server/Controllers/AccountController.cs +++ b/Bonobo.Git.Server/Controllers/AccountController.cs @@ -1,24 +1,16 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Security.Claims; -using System.Web; -using System.Web.Mvc; -using System.Web.Security; - -using Bonobo.Git.Server.App_GlobalResources; +using Bonobo.Git.Server.App_GlobalResources; using Bonobo.Git.Server.Configuration; -using Bonobo.Git.Server.Extensions; +using Bonobo.Git.Server.Helpers; using Bonobo.Git.Server.Models; using Bonobo.Git.Server.Security; - -using Bonobo.Git.Server.Helpers; -using System.DirectoryServices.AccountManagement; - -using Microsoft.Practices.Unity; -using Serilog; using Microsoft.Owin.Security; +using Serilog; +using System; +using System.Linq; +using System.Security.Claims; +using System.Web; +using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server.Controllers { @@ -187,10 +179,10 @@ public ActionResult Edit(UserEditModel model) public ActionResult CreateADUser() { var efms = MembershipService as EFMembershipService; - + if ((!Request.IsAuthenticated) || efms == null) { - Log.Warning("CreateADUser: can't run IsAuth: {IsAuth}, MemServ {MemServ}", + Log.Warning("CreateADUser: can't run IsAuth: {IsAuth}, MemServ {MemServ}", Request.IsAuthenticated, MembershipService.GetType()); return RedirectToAction("Unauthorized", "Home"); @@ -209,7 +201,7 @@ public ActionResult CreateADUser() Log.Information("Making AD user {User} into an admin", credentials); var id = MembershipService.GetUserModel(credentials).Id; - RoleProvider.AddUserToRoles(id, new[] {Definitions.Roles.Administrator}); + RoleProvider.AddUserToRoles(id, new[] { Definitions.Roles.Administrator }); // Add the administrator role to the Identity/cookie var Identity = (ClaimsIdentity)User.Identity; diff --git a/Bonobo.Git.Server/Controllers/GitController.cs b/Bonobo.Git.Server/Controllers/GitController.cs index 91bd95566..c541b1c12 100644 --- a/Bonobo.Git.Server/Controllers/GitController.cs +++ b/Bonobo.Git.Server/Controllers/GitController.cs @@ -1,16 +1,15 @@ -using System; -using System.IO; -using System.Net; -using System.Web.Mvc; -using Bonobo.Git.Server.Configuration; +using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Data; using Bonobo.Git.Server.Git; using Bonobo.Git.Server.Git.GitService; using Bonobo.Git.Server.Models; using Bonobo.Git.Server.Security; using Ionic.Zlib; -using Microsoft.Practices.Unity; using Serilog; +using System; +using System.IO; +using System.Web.Mvc; +using Unity; using Repository = LibGit2Sharp.Repository; namespace Bonobo.Git.Server.Controllers @@ -63,7 +62,7 @@ public ActionResult SecureGetInfoRefs(String repositoryName, String service) } else { - Log.Warning("GitC: SecureGetInfoRefs unauth because User {UserId} doesn't have permission {Permission} on repo {RepositoryName}", + Log.Warning("GitC: SecureGetInfoRefs unauth because User {UserId} doesn't have permission {Permission} on repo {RepositoryName}", User.Id(), requiredLevel, repositoryName); @@ -127,7 +126,7 @@ private bool TryCreateOnPush(string repositoryName) var user = MembershipService.GetUserModel(User.Id()); repository.Description = "Auto-created by push for " + user.DisplayName; repository.AnonymousAccess = false; - repository.Administrators = new[] {user}; + repository.Administrators = new[] { user }; if (!RepositoryRepository.Create(repository)) { // We can't add this to the repo store @@ -147,7 +146,7 @@ private bool TryCreateOnPush(string repositoryName) /// public ActionResult GitUrl(string repositoryName) { - return RedirectPermanent(Url.Action("Detail", "Repository", new { id = repositoryName})); + return RedirectPermanent(Url.Action("Detail", "Repository", new { id = repositoryName })); } private ActionResult ExecuteReceivePack(string repositoryName) @@ -192,13 +191,13 @@ private ActionResult GetInfoRefs(String repositoryName, String service) { GitService.ExecuteServiceByName( Guid.NewGuid().ToString("N"), - repositoryName, - serviceName, + repositoryName, + serviceName, new ExecutionOptions() { AdvertiseRefs = true }, GetInputStream(), outStream ); - }, + }, advertiseRefsContent); } @@ -206,7 +205,7 @@ private ActionResult UnauthorizedResult() { Response.Clear(); Response.AddHeader("WWW-Authenticate", "Basic realm=\"Bonobo Git\""); - + return new HttpStatusCodeResult(401); } diff --git a/Bonobo.Git.Server/Controllers/HomeController.cs b/Bonobo.Git.Server/Controllers/HomeController.cs index ae02c5a8b..5ec113430 100644 --- a/Bonobo.Git.Server/Controllers/HomeController.cs +++ b/Bonobo.Git.Server/Controllers/HomeController.cs @@ -1,25 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Security.Claims; -using System.Text; -using System.Web; -using System.Web.Caching; -using System.Web.Mvc; - -using Bonobo.Git.Server.App_GlobalResources; +using Bonobo.Git.Server.App_GlobalResources; using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Data; using Bonobo.Git.Server.Helpers; using Bonobo.Git.Server.Models; +using Bonobo.Git.Server.Owin.Windows; using Bonobo.Git.Server.Security; - using Microsoft.Owin.Security; -using Microsoft.Owin.Security.Cookies; -using Microsoft.Practices.Unity; -using Bonobo.Git.Server.Owin.Windows; +using System; using System.Configuration; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Web; +using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server.Controllers { @@ -68,7 +62,7 @@ private string CheckForPasswordResetUsername(string digest) public ActionResult ResetPassword(string digest) { string username = CheckForPasswordResetUsername(digest); - if (username != null ) + if (username != null) { using (var db = new BonoboGitServerContext()) { @@ -77,7 +71,7 @@ public ActionResult ResetPassword(string digest) { throw new UnauthorizedAccessException("Unknown user " + username); } - return View(new ResetPasswordModel { Username = username, Digest = digest}); + return View(new ResetPasswordModel { Username = username, Digest = digest }); } } else @@ -139,7 +133,7 @@ public ActionResult ForgotPassword(ForgotPasswordModel model) MvcApplication.Cache.Add(token, model.Username, DateTimeOffset.Now.AddHours(1)); // Passing Requust.Url.Scheme to Url.Action forces it to generate a full URL - var resetUrl = Url.Action("ResetPassword", "Home", new {digest = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes(token))},Request.Url.Scheme); + var resetUrl = Url.Action("ResetPassword", "Home", new { digest = HttpUtility.UrlEncode(Encoding.UTF8.GetBytes(token)) }, Request.Url.Scheme); TempData["SendSuccess"] = MembershipHelper.SendForgotPasswordEmail(user, resetUrl); } @@ -187,7 +181,7 @@ public ActionResult LogOn(LogOnModel model) case ValidationResult.Success: AuthenticationProvider.SignIn(model.Username, Url.IsLocalUrl(model.ReturnUrl) ? model.ReturnUrl : Url.Action("Index", "Home"), model.RememberMe); Response.AppendToLog("SUCCESS"); - if (Request.IsLocal && model.DatabaseResetCode > 0 && model.Username == "admin" && ConfigurationManager.AppSettings["AllowDBReset"] == "true" ) + if (Request.IsLocal && model.DatabaseResetCode > 0 && model.Username == "admin" && ConfigurationManager.AppSettings["AllowDBReset"] == "true") { ResetManager.DoReset(model.DatabaseResetCode); } @@ -198,7 +192,7 @@ public ActionResult LogOn(LogOnModel model) ModelState.AddModelError("", Resources.Home_LogOn_UsernamePasswordIncorrect); Response.AppendToLog("FAILURE"); break; - } + } } return View(model); diff --git a/Bonobo.Git.Server/Controllers/RepositoryController.cs b/Bonobo.Git.Server/Controllers/RepositoryController.cs index a4d52ee3b..dd39565b3 100644 --- a/Bonobo.Git.Server/Controllers/RepositoryController.cs +++ b/Bonobo.Git.Server/Controllers/RepositoryController.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Web.Mvc; -using Bonobo.Git.Server.App_GlobalResources; +using Bonobo.Git.Server.App_GlobalResources; using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Data; using Bonobo.Git.Server.Data.Update; @@ -13,9 +6,16 @@ using Bonobo.Git.Server.Models; using Bonobo.Git.Server.Security; using Ionic.Zip; -using Microsoft.Practices.Unity; using MimeTypes; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Security.Principal; +using System.Text; +using System.Text.RegularExpressions; +using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server.Controllers { @@ -49,7 +49,8 @@ public ActionResult Index(string sortGroup = null, string searchString = null) .AsEnumerable(); } - foreach(var item in firstList){ + foreach (var item in firstList) + { SetGitUrls(item); } var list = firstList @@ -439,7 +440,8 @@ public ActionResult Tags(Guid id, string encodedName, int page = 1) var commits = browser.GetTags(name, page, 10, out referenceName, out totalCount); PopulateBranchesData(browser, referenceName); ViewBag.TotalCount = totalCount; - return View(new RepositoryCommitsModel { + return View(new RepositoryCommitsModel + { Commits = commits, Name = repo.Name, Logo = new RepositoryLogoDetailModel(repo.Logo) @@ -500,7 +502,8 @@ public ActionResult Commits(Guid id, string encodedName, int? page = null) } commit.Links = links; } - return View(new RepositoryCommitsModel { + return View(new RepositoryCommitsModel + { Commits = commits, Name = repo.Name, Logo = new RepositoryLogoDetailModel(repo.Logo) @@ -570,10 +573,10 @@ public ActionResult Clone(Guid id, RepositoryDetailModel model) string sourceRepositoryPath = Path.Combine(UserConfiguration.Current.Repositories, source_repo.Name); LibGit2Sharp.CloneOptions options = new LibGit2Sharp.CloneOptions() - { - IsBare = true, - Checkout = false - }; + { + IsBare = true, + Checkout = false + }; LibGit2Sharp.Repository.Clone(sourceRepositoryPath, targetRepositoryPath, options); @@ -617,7 +620,8 @@ public ActionResult History(Guid id, string encodedPath, string encodedName) var name = PathEncoder.Decode(encodedName); string referenceName; var commits = browser.GetHistory(path, name, out referenceName); - return View(new RepositoryCommitsModel { + return View(new RepositoryCommitsModel + { Commits = commits, Name = repo.Name, Logo = new RepositoryLogoDetailModel(repo.Logo) @@ -643,7 +647,7 @@ private void PopulateCheckboxListData(ref RepositoryDetailModel model) { model.Administrators = model.PostedSelectedAdministrators.Select(x => MembershipService.GetUserModel(x)).ToArray(); } - model.PostedSelectedAdministrators = new Guid[0]; + model.PostedSelectedAdministrators = new Guid[0]; model.PostedSelectedUsers = new Guid[0]; model.PostedSelectedTeams = new Guid[0]; } diff --git a/Bonobo.Git.Server/Controllers/TeamController.cs b/Bonobo.Git.Server/Controllers/TeamController.cs index 057303feb..ad3e6bfa1 100644 --- a/Bonobo.Git.Server/Controllers/TeamController.cs +++ b/Bonobo.Git.Server/Controllers/TeamController.cs @@ -1,14 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web.Mvc; - +using Bonobo.Git.Server.App_GlobalResources; using Bonobo.Git.Server.Data; using Bonobo.Git.Server.Models; using Bonobo.Git.Server.Security; -using Bonobo.Git.Server.App_GlobalResources; - -using Microsoft.Practices.Unity; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web.Mvc; +using Unity; namespace Bonobo.Git.Server.Controllers { @@ -40,7 +38,7 @@ public ActionResult Edit(Guid id) [ValidateAntiForgeryToken] [WebAuthorize(Roles = Definitions.Roles.Administrator)] public ActionResult Edit(TeamEditModel model) - { + { if (ModelState.IsValid) { TeamRepository.Update(ConvertTeamDetailModel(model)); @@ -53,7 +51,7 @@ public ActionResult Edit(TeamEditModel model) [WebAuthorize(Roles = Definitions.Roles.Administrator)] public ActionResult Create() { - var model = new TeamEditModel + var model = new TeamEditModel { AllUsers = MembershipService.GetAllUsers().ToArray(), SelectedUsers = new UserModel[] { } diff --git a/Bonobo.Git.Server/Controllers/ValidationController.cs b/Bonobo.Git.Server/Controllers/ValidationController.cs index 569003fce..aaf74bc44 100644 --- a/Bonobo.Git.Server/Controllers/ValidationController.cs +++ b/Bonobo.Git.Server/Controllers/ValidationController.cs @@ -1,11 +1,11 @@ using Bonobo.Git.Server.Attributes; using Bonobo.Git.Server.Data; using Bonobo.Git.Server.Security; -using Microsoft.Practices.Unity; using System; using System.ComponentModel.DataAnnotations; using System.Web.Mvc; using System.Web.UI; +using Unity; namespace Bonobo.Git.Server.Controllers { diff --git a/Bonobo.Git.Server/Data/ADBackend.cs b/Bonobo.Git.Server/Data/ADBackend.cs index c9c6589ea..c83506bce 100644 --- a/Bonobo.Git.Server/Data/ADBackend.cs +++ b/Bonobo.Git.Server/Data/ADBackend.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; - +using Bonobo.Git.Server.Configuration; +using Bonobo.Git.Server.Helpers; using Bonobo.Git.Server.Models; -using System.DirectoryServices.AccountManagement; -using System.Threading.Tasks; -using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Security; -using System.Threading; -using Microsoft.Practices.Unity; -using Bonobo.Git.Server.Helpers; using Serilog; +using System; +using System.DirectoryServices.AccountManagement; +using System.Linq; +using System.Threading; +using Unity; namespace Bonobo.Git.Server.Data { @@ -107,7 +103,7 @@ private void Update(object state) UpdateRoles(); UpdateRepositories(); } - catch(Exception ex) + catch (Exception ex) { Log.Error(ex, "Failed to update data from AD"); } @@ -146,7 +142,7 @@ private UserModel GetUserModelFromPrincipal(UserPrincipal user) private void UpdateRepositories() { - foreach(RepositoryModel repository in Repositories) + foreach (RepositoryModel repository in Repositories) { UserModel[] usersToRemove = repository.Users.Where(repoUser => !Users.Select(u => u.Id).Contains(repoUser.Id)).ToArray(); TeamModel[] teamsToRemove = repository.Teams.Where(repoTeam => !Teams.Select(team => team.Id).Contains(repoTeam.Id)).ToArray(); @@ -163,7 +159,7 @@ private void UpdateUsers() { try { - GroupPrincipal group; + GroupPrincipal group; PrincipalContext pc = ADHelper.GetMembersGroup(out group); foreach (Guid Id in Users.Select(x => x.Id).Where(x => ADHelper.GetUserPrincipal(x) == null)) @@ -194,7 +190,7 @@ private void UpdateTeams() Teams.Remove(team.Id); } - if(MembershipService == null) + if (MembershipService == null) MembershipService = new ADMembershipService(); foreach (string teamName in ActiveDirectorySettings.TeamNameToGroupNameMapping.Keys) @@ -229,7 +225,7 @@ private void UpdateRoles() { Roles.Remove(role.Id); } - + foreach (string roleName in ActiveDirectorySettings.RoleNameToGroupNameMapping.Keys) { string groupName = ActiveDirectorySettings.RoleNameToGroupNameMapping[roleName]; diff --git a/Bonobo.Git.Server/Data/BonoboGitServerContext.cs b/Bonobo.Git.Server/Data/BonoboGitServerContext.cs index d01e0d8c6..d05ce0eb6 100644 --- a/Bonobo.Git.Server/Data/BonoboGitServerContext.cs +++ b/Bonobo.Git.Server/Data/BonoboGitServerContext.cs @@ -1,7 +1,6 @@ using System.Data.Common; using Bonobo.Git.Server.Data.Mapping; using System.Data.Entity; -using Microsoft.Practices.Unity; namespace Bonobo.Git.Server.Data { diff --git a/Bonobo.Git.Server/Data/DatabaseResetManager.cs b/Bonobo.Git.Server/Data/DatabaseResetManager.cs index 3684bc1c9..894f81c16 100644 --- a/Bonobo.Git.Server/Data/DatabaseResetManager.cs +++ b/Bonobo.Git.Server/Data/DatabaseResetManager.cs @@ -1,9 +1,8 @@ -using System; -using System.Runtime.Remoting.Messaging; -using Bonobo.Git.Server.Security; -using Microsoft.Practices.Unity; -using System.Configuration; +using Bonobo.Git.Server.Security; using Serilog; +using System; +using System.Configuration; +using Unity; namespace Bonobo.Git.Server.Data { diff --git a/Bonobo.Git.Server/Data/EFRepositoryRepository.cs b/Bonobo.Git.Server/Data/EFRepositoryRepository.cs index a9ed1ce48..3c9816b8b 100644 --- a/Bonobo.Git.Server/Data/EFRepositoryRepository.cs +++ b/Bonobo.Git.Server/Data/EFRepositoryRepository.cs @@ -1,11 +1,11 @@ -using System; +using Bonobo.Git.Server.Models; +using Serilog; +using System; using System.Collections.Generic; -using System.Linq; -using Bonobo.Git.Server.Models; using System.Data.Entity.Core; using System.Data.Entity.Infrastructure; -using Microsoft.Practices.Unity; -using Serilog; +using System.Linq; +using Unity; namespace Bonobo.Git.Server.Data { @@ -120,7 +120,7 @@ public bool Create(RepositoryModel model) AuditPushUser = model.AuditPushUser, LinksUseGlobal = model.LinksUseGlobal, LinksUrl = model.LinksUrl, - LinksRegex = model.LinksRegex + LinksRegex = model.LinksRegex }; database.Repositories.Add(repository); AddMembers(model.Users.Select(x => x.Id), model.Administrators.Select(x => x.Id), model.Teams.Select(x => x.Id), repository, database); diff --git a/Bonobo.Git.Server/Data/EFTeamRepository.cs b/Bonobo.Git.Server/Data/EFTeamRepository.cs index b6d0a4852..2a459f503 100644 --- a/Bonobo.Git.Server/Data/EFTeamRepository.cs +++ b/Bonobo.Git.Server/Data/EFTeamRepository.cs @@ -1,10 +1,10 @@ -using System; +using Bonobo.Git.Server.Models; +using System; using System.Collections.Generic; -using System.Linq; -using Bonobo.Git.Server.Models; using System.Data.Entity.Core; using System.Data.Entity.Infrastructure; -using Microsoft.Practices.Unity; +using System.Linq; +using Unity; namespace Bonobo.Git.Server.Data { @@ -43,13 +43,13 @@ public IList GetTeams(Guid UserId) private TeamModel GetTeamModel(Team team) { - return team == null ? null : new TeamModel - { - Id = team.Id, - Name = team.Name, - Description = team.Description, - Members = team.Users.Select(user => user.ToModel()).ToArray(), - }; + return team == null ? null : new TeamModel + { + Id = team.Id, + Name = team.Name, + Description = team.Description, + Members = team.Users.Select(user => user.ToModel()).ToArray(), + }; } public TeamModel GetTeam(Guid id) diff --git a/Bonobo.Git.Server/FilterProviders/UnityFilterAttributeFilterProvider.cs b/Bonobo.Git.Server/FilterProviders/UnityFilterAttributeFilterProvider.cs index 0bec6818f..9b0f7e2d8 100644 --- a/Bonobo.Git.Server/FilterProviders/UnityFilterAttributeFilterProvider.cs +++ b/Bonobo.Git.Server/FilterProviders/UnityFilterAttributeFilterProvider.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Web.Mvc; -using Microsoft.Practices.Unity; +using Unity; public class UnityFilterAttributeFilterProvider : FilterAttributeFilterProvider { diff --git a/Bonobo.Git.Server/Global.asax.cs b/Bonobo.Git.Server/Global.asax.cs index 025442966..fbdf2c0fa 100644 --- a/Bonobo.Git.Server/Global.asax.cs +++ b/Bonobo.Git.Server/Global.asax.cs @@ -1,16 +1,5 @@ -using System; -using System.Configuration; -using System.Globalization; -using System.IO; -using System.Linq; -using System.Security.Principal; -using System.Threading; -using System.Web; -using System.Web.Mvc; -using System.Web.Optimization; -using System.Web.Routing; -using System.Web.Security; -using Bonobo.Git.Server.App_Start; +using Bonobo.Git.Server.App_Start; +using Bonobo.Git.Server.Attributes; using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Controllers; using Bonobo.Git.Server.Data; @@ -21,21 +10,32 @@ using Bonobo.Git.Server.Git.GitService.ReceivePackHook.Durability; using Bonobo.Git.Server.Git.GitService.ReceivePackHook.Hooks; using Bonobo.Git.Server.Security; -using Microsoft.Practices.Unity; +using Serilog; +using System; +using System.Configuration; +using System.Globalization; +using System.IO; +using System.Linq; using System.Runtime.Caching; -using Bonobo.Git.Server.Attributes; -using Microsoft.Practices.Unity.Mvc; -using System.Web.Configuration; using System.Security.Claims; +using System.Threading; +using System.Web; +using System.Web.Configuration; using System.Web.Helpers; using System.Web.Hosting; -using Serilog; +using System.Web.Mvc; +using System.Web.Optimization; +using System.Web.Routing; +using Unity; +using Unity.AspNet.Mvc; +using Unity.Injection; +using Unity.Resolution; namespace Bonobo.Git.Server { public class MvcApplication : HttpApplication { - public static ObjectCache Cache = MemoryCache.Default; + public static ObjectCache Cache = MemoryCache.Default; protected void Application_AcquireRequestState(object sender, EventArgs e) { @@ -86,7 +86,7 @@ protected void Application_Start() var connectionstring = WebConfigurationManager.ConnectionStrings["BonoboGitServerContext"]; if (connectionstring.ProviderName.ToLowerInvariant() == "system.data.sqlite") { - if(!connectionstring.ConnectionString.ToLowerInvariant().Contains("binaryguid=false")) + if (!connectionstring.ConnectionString.ToLowerInvariant().Contains("binaryguid=false")) { Log.Error("Please ensure that the sqlite connection string contains 'BinaryGUID=false;'."); throw new ConfigurationErrorsException("Please ensure that the sqlite connection string contains 'BinaryGUID=false;'."); @@ -174,12 +174,8 @@ private static void RegisterDependencyResolver() throw new ArgumentException("Missing declaration in web.config", "AuthenticationProvider"); } - container.RegisterType( - new InjectionFactory((ctr, type, name) => { - return new ConfigurationBasedRepositoryLocator(UserConfiguration.Current.Repositories); - }) - ); - + container.RegisterFactory((ctr, type, name) => new ConfigurationBasedRepositoryLocator(UserConfiguration.Current.Repositories)); + container.RegisterInstance( new GitServiceExecutorParams() { @@ -201,7 +197,7 @@ private static void RegisterDependencyResolver() var oldProvider = FilterProviders.Providers.Single(f => f is FilterAttributeFilterProvider); FilterProviders.Providers.Remove(oldProvider); - + var provider = new UnityFilterAttributeFilterProvider(container); FilterProviders.Providers.Add(provider); } @@ -218,7 +214,7 @@ private static void EnablePushAuditAnalysis(IUnityContainer container) container.RegisterType(); container.RegisterType(); container.RegisterInstance(new NamedArguments.FailedPackWaitTimeBeforeExecution(TimeSpan.FromSeconds(5 * 60))); - + container.RegisterInstance(new NamedArguments.ReceivePackRecoveryDirectory( Path.IsPathRooted(ConfigurationManager.AppSettings["RecoveryDataPath"]) ? ConfigurationManager.AppSettings["RecoveryDataPath"] : @@ -251,10 +247,6 @@ private static void EnablePushAuditAnalysis(IUnityContainer container) } finally { - if (recoveryProcess != null) - { - container.Teardown(recoveryProcess); - } } } } diff --git a/Bonobo.Git.Server/Security/AuthenticationProvider.cs b/Bonobo.Git.Server/Security/AuthenticationProvider.cs index ca273bc4e..bd41fd3b8 100644 --- a/Bonobo.Git.Server/Security/AuthenticationProvider.cs +++ b/Bonobo.Git.Server/Security/AuthenticationProvider.cs @@ -1,13 +1,9 @@ -using System; +using Bonobo.Git.Server.Models; +using Owin; using System.Collections.Generic; -using System.Security.Claims; using System.Linq; - -using Bonobo.Git.Server.Models; - -using Microsoft.Practices.Unity; - -using Owin; +using System.Security.Claims; +using Unity; namespace Bonobo.Git.Server.Security { diff --git a/Bonobo.Git.Server/Security/CookieAuthenticationProvider.cs b/Bonobo.Git.Server/Security/CookieAuthenticationProvider.cs index 801041612..d98419b45 100644 --- a/Bonobo.Git.Server/Security/CookieAuthenticationProvider.cs +++ b/Bonobo.Git.Server/Security/CookieAuthenticationProvider.cs @@ -1,17 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Web; - -using Bonobo.Git.Server.Models; - -using Microsoft.Owin; +using Microsoft.Owin; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Cookies; -using Microsoft.Practices.Unity; - using Owin; +using System; +using System.Security.Claims; +using System.Web; namespace Bonobo.Git.Server.Security { diff --git a/Bonobo.Git.Server/Security/EFMembershipService.cs b/Bonobo.Git.Server/Security/EFMembershipService.cs index 5e197703e..44b8a25e5 100644 --- a/Bonobo.Git.Server/Security/EFMembershipService.cs +++ b/Bonobo.Git.Server/Security/EFMembershipService.cs @@ -1,12 +1,12 @@ -using System; +using Bonobo.Git.Server.Data; +using Bonobo.Git.Server.Models; +using Serilog; +using System; using System.Collections.Generic; +using System.Data.Entity.Core; using System.Linq; -using Bonobo.Git.Server.Data; -using Bonobo.Git.Server.Models; using System.Security.Cryptography; -using System.Data.Entity.Core; -using Microsoft.Practices.Unity; -using Serilog; +using Unity; namespace Bonobo.Git.Server.Security { @@ -139,7 +139,7 @@ private UserModel GetUserModel(User user) GivenName = user.GivenName, Surname = user.Surname, Email = user.Email, - }; + }; } public UserModel GetUserModel(Guid id) @@ -197,7 +197,7 @@ public void DeleteUser(Guid id) db.SaveChanges(); } } - } + } private void SetPassword(User user, string password) { @@ -226,6 +226,6 @@ public string GenerateResetToken(string username) Buffer.BlockCopy(salt, 0, outputBytes, 1, SaltSize); Buffer.BlockCopy(subkey, 0, outputBytes, 1 + SaltSize, PBKDF2SubkeyLength); return Convert.ToBase64String(outputBytes); - } + } } } \ No newline at end of file diff --git a/Bonobo.Git.Server/Security/EFRoleProvider.cs b/Bonobo.Git.Server/Security/EFRoleProvider.cs index 9b0fba330..ec0f111c6 100644 --- a/Bonobo.Git.Server/Security/EFRoleProvider.cs +++ b/Bonobo.Git.Server/Security/EFRoleProvider.cs @@ -1,7 +1,7 @@ -using System; +using Bonobo.Git.Server.Data; +using System; using System.Linq; -using Bonobo.Git.Server.Data; -using Microsoft.Practices.Unity; +using Unity; namespace Bonobo.Git.Server.Security { diff --git a/Bonobo.Git.Server/Security/RepositoryPermissionService.cs b/Bonobo.Git.Server/Security/RepositoryPermissionService.cs index 5989708a9..40437cfe7 100644 --- a/Bonobo.Git.Server/Security/RepositoryPermissionService.cs +++ b/Bonobo.Git.Server/Security/RepositoryPermissionService.cs @@ -1,11 +1,11 @@ -using System.Linq; +using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Data; -using System; -using System.Collections.Generic; -using Bonobo.Git.Server.Configuration; using Bonobo.Git.Server.Models; -using Microsoft.Practices.Unity; using Serilog; +using System; +using System.Collections.Generic; +using System.Linq; +using Unity; namespace Bonobo.Git.Server.Security { @@ -19,7 +19,7 @@ public class RepositoryPermissionService : IRepositoryPermissionService [Dependency] public ITeamRepository TeamRepository { get; set; } - + public bool HasPermission(Guid userId, string repositoryName, RepositoryAccessLevel requiredLevel) { var repository = Repository.GetRepository(repositoryName); @@ -109,8 +109,8 @@ private bool CheckNamedUserPermission(Guid userId, IList userTeams, b { case RepositoryAccessLevel.Push: case RepositoryAccessLevel.Pull: - return userIsAnAdministrator || - UserIsARepoUser(userId, repository) || + return userIsAnAdministrator || + UserIsARepoUser(userId, repository) || UserIsATeamMember(userTeams, repository); case RepositoryAccessLevel.Administer: diff --git a/Bonobo.Git.Server/Security/WindowsAuthenticationProvider.cs b/Bonobo.Git.Server/Security/WindowsAuthenticationProvider.cs index ec8cc6317..29f393300 100644 --- a/Bonobo.Git.Server/Security/WindowsAuthenticationProvider.cs +++ b/Bonobo.Git.Server/Security/WindowsAuthenticationProvider.cs @@ -1,19 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Web; - -using Bonobo.Git.Server.Models; - +using Bonobo.Git.Server.Owin.Windows; using Microsoft.Owin; using Microsoft.Owin.Security; using Microsoft.Owin.Security.Cookies; -using Microsoft.Practices.Unity; - using Owin; -using Bonobo.Git.Server.Owin.Windows; -using Microsoft.Owin.Extensions; +using System; +using System.Security.Claims; +using System.Web; namespace Bonobo.Git.Server.Security { diff --git a/Bonobo.Git.Server/packages.config b/Bonobo.Git.Server/packages.config index 3fb6f6e4b..03ed7230a 100644 --- a/Bonobo.Git.Server/packages.config +++ b/Bonobo.Git.Server/packages.config @@ -9,10 +9,10 @@ - - + + - + @@ -36,9 +36,13 @@ + + - - + + + + \ No newline at end of file diff --git a/Bonobo.Git.Server/web.config b/Bonobo.Git.Server/web.config index c41892d6a..7272fea61 100644 --- a/Bonobo.Git.Server/web.config +++ b/Bonobo.Git.Server/web.config @@ -80,6 +80,14 @@ + + + + + + + + @@ -98,7 +106,7 @@ - + @@ -116,6 +124,14 @@ + + + + + + + + @@ -141,4 +157,4 @@ - \ No newline at end of file +