public void TestFailbackToLocalHost(string username, string computerName)
        {
            IUser     user      = directory.GetUser(username);
            IComputer computer  = directory.GetComputer(computerName);
            string    dnsDomain = this.discoveryServices.GetDomainNameDns(user.Sid);

            var options = new AuthorizationOptions
            {
                AuthorizationServerMapping = new List <AuthorizationServerMapping>
                {
                    new AuthorizationServerMapping
                    {
                        Domain = dnsDomain,
                        DisableLocalFallback = false,
                        Servers = new List <AuthorizationServer>
                        {
                            new AuthorizationServer
                            {
                                Name = "madeup.local",
                                Type = AuthorizationServerType.Default
                            }
                        }
                    }
                }
            };

            var authorizationContextProvider = new AuthorizationContextProvider(this.SetupOptions(options), logger, discoveryServices);
            var c = authorizationContextProvider.GetAuthorizationContext(user, computer.Sid);

            Assert.AreEqual(c.Server, null);
        }
        public void Arrange()
        {
            _httpContextAccessor = new Mock <IHttpContextAccessor>();
            _encodingService     = new Mock <IEncodingService>();
            _routingFeature      = new Mock <IRoutingFeature>();
            _routeData           = new RouteData();
            _routeData.Values.Add("ukprn", UkPrn);

            _contextProvider = new AuthorizationContextProvider(_httpContextAccessor.Object, _encodingService.Object);

            _encodingService
            .Setup(x => x.TryDecode(It.IsAny <string>(), EncodingType.CohortReference, out It.Ref <long> .IsAny))
            .Callback(new TryGetCallback((string cohortRef, EncodingType encodingType, ref long val) => val = CohortId))
            .Returns(new TryGetReturns((string cohortRef, EncodingType encodingType, ref long val) => true));

            _routingFeature.Setup(f => f.RouteData).Returns(_routeData);

            _httpContextAccessor.Setup(c => c.HttpContext.Features[typeof(IRoutingFeature)])
            .Returns(_routingFeature.Object);

            var queryParams = new Dictionary <string, StringValues>
            {
                { "cohortRef", new StringValues(CohortId.ToString()) }
            };

            _httpContextAccessor.Setup(c => c.HttpContext.Request.Query).Returns(new QueryCollection(queryParams));
        }
        public AuthorizationContextProviderTestsFixture()
        {
            HttpContext           = new Mock <HttpContextBase>();
            HashingService        = new Mock <IHashingService>();
            AuthenticationService = new Mock <IAuthenticationService>();

            HttpContext.Setup(c => c.Request.RequestContext.RouteData).Returns(new RouteData());

            AuthorizationContextProvider = new AuthorizationContextProvider(HttpContext.Object, HashingService.Object, AuthenticationService.Object);
        }
Beispiel #4
0
        public AuthorizationContextProviderTestsFixture()
        {
            HttpContextAccessor   = new Mock <IHttpContextAccessor>();
            RoutingFeature        = new Mock <IRoutingFeature>();
            HashingService        = new Mock <IHashingService>();
            AuthenticationService = new Mock <IAuthenticationService>();

            HttpContextAccessor.Setup(c => c.HttpContext.Features[typeof(IRoutingFeature)]).Returns(RoutingFeature.Object);
            RoutingFeature.Setup(f => f.RouteData).Returns(new RouteData());

            AuthorizationContextProvider = new AuthorizationContextProvider(HttpContextAccessor.Object, HashingService.Object, AuthenticationService.Object);
        }
        public AuthorizationContextProviderTestsFixture()
        {
            RouteData = new RouteData();
            Params    = new NameValueCollection();

            HttpContext = new Mock <HttpContextBase>();
            HttpContext.Setup(c => c.Request.RequestContext.RouteData).Returns(RouteData);
            HttpContext.Setup(c => c.Request.Params).Returns(Params);
            HttpContext.Setup(c => c.User).Returns(new GenericPrincipal(new Mock <IIdentity>().Object, new string[0]));

            AccountLegalEntityPublicHashingService = new Mock <IAccountLegalEntityPublicHashingService>();
            AuthorizationContextProvider           = new AuthorizationContextProvider(HttpContext.Object, AccountLegalEntityPublicHashingService.Object, Mock.Of <ILog>());
        }
        public AuthorizationContextProviderTestsFixture()
        {
            RouteData                    = new RouteData();
            RoutingFeature               = new Mock <IRoutingFeature>();
            HttpContextAccessor          = new Mock <IHttpContextAccessor>();
            EncodingService              = new Mock <IEncodingService>();
            AuthenticationService        = new Mock <IAuthenticationService>();
            AuthorizationContextProvider = new AuthorizationContextProvider(HttpContextAccessor.Object, EncodingService.Object, AuthenticationService.Object);

            RoutingFeature.Setup(f => f.RouteData).Returns(RouteData);
            HttpContextAccessor.Setup(c => c.HttpContext.Features[typeof(IRoutingFeature)]).Returns(RoutingFeature.Object);
            HttpContextAccessor.Setup(c => c.HttpContext.Request.Query).Returns(new QueryCollection());
            HttpContextAccessor.Setup(c => c.HttpContext.Request.Form).Returns(new FormCollection(new Dictionary <string, StringValues>()));
        }
        public void ExceptionThrownWhenHostListRecycles(string username, string computerName)
        {
            IUser     user      = directory.GetUser(username);
            IComputer computer  = directory.GetComputer(computerName);
            string    dnsDomain = this.discoveryServices.GetDomainNameDns(user.Sid);

            var options = new AuthorizationOptions
            {
                AuthorizationServerMapping = new List <AuthorizationServerMapping>
                {
                    new AuthorizationServerMapping
                    {
                        Domain = dnsDomain,
                        DisableLocalFallback = true,
                        Servers = new List <AuthorizationServer>
                        {
                            new AuthorizationServer
                            {
                                Name = "madeup.local",
                                Type = AuthorizationServerType.Default
                            },
                            new AuthorizationServer
                            {
                                Name = "madeup2.local",
                                Type = AuthorizationServerType.Default
                            },
                            new AuthorizationServer
                            {
                                Name = "madeup3.local",
                                Type = AuthorizationServerType.Default
                            },
                        }
                    }
                }
            };

            var authorizationContextProvider = new AuthorizationContextProvider(this.SetupOptions(options), logger, discoveryServices);

            Assert.Throws <AuthorizationContextException>(() => authorizationContextProvider.GetAuthorizationContext(user, computer.Sid));
        }
        public void TestFailoverToNextHost(string username, string computerName)
        {
            IUser     user      = directory.GetUser(username);
            IComputer computer  = directory.GetComputer(computerName);
            string    dnsDomain = this.directory.GetDomainNameDnsFromSid(user.Sid);
            string    dc        = this.directory.GetDomainControllerForDomain(dnsDomain);

            var options = new BuiltInProviderOptions
            {
                AuthorizationServerMapping = new List <AuthorizationServerMapping>
                {
                    new AuthorizationServerMapping
                    {
                        Domain = dnsDomain,
                        DisableLocalFallback = true,
                        Servers = new List <AuthorizationServer>
                        {
                            new AuthorizationServer
                            {
                                Name = "madeup.local",
                                Type = AuthorizationServerType.Default
                            },
                            new AuthorizationServer
                            {
                                Name = dc,
                                Type = AuthorizationServerType.Default
                            }
                        }
                    }
                }
            };

            var authorizationContextProvider = new AuthorizationContextProvider(this.SetupOptions(options), directory, logger);
            var c = authorizationContextProvider.GetAuthorizationContext(user, computer);

            c = authorizationContextProvider.GetAuthorizationContext(user, computer);

            Assert.AreEqual(c.Server, dc);
        }
Beispiel #9
0
        public AuthorizationContextProviderTestsFixture()
        {
            UserService         = new Mock <IAuthenticationService>();
            HttpContextAccessor = new Mock <IHttpContextAccessor>();
            RoutingFeature      = new Mock <IRoutingFeature>();
            EncodingService     = new Mock <IEncodingService>();
            RouteData           = new RouteData();
            RoutingFeature.Setup(f => f.RouteData).Returns(RouteData);
            UserRef = Guid.NewGuid();

            var featureCollection = new Mock <IFeatureCollection>();

            featureCollection.Setup(f => f.Get <IRoutingFeature>()).Returns(RoutingFeature.Object);

            var context = new Mock <HttpContext>();

            context.Setup(c => c.Features).Returns(featureCollection.Object);
            context.Setup(c => c.Request.Query).Returns(new QueryCollection());
            context.Setup(c => c.Request.Form).Returns(new FormCollection(new Dictionary <string, StringValues>()));

            HttpContextAccessor.Setup(c => c.HttpContext).Returns(context.Object);

            AuthorizationContextProvider = new AuthorizationContextProvider(HttpContextAccessor.Object, EncodingService.Object, UserService.Object);
        }
Beispiel #10
0
 public IAuthorizationContext GetAuthorizationContext()
 {
     return(AuthorizationContextProvider.GetAuthorizationContext());
 }