public void ThenAddsCohortIdToContext()
        {
            //Act
            var context = _contextProvider.GetAuthorizationContext();

            //Assert
            Assert.IsTrue(context.TryGet <long>("CohortId", out var actualCohortId));
            Assert.AreEqual(CohortId, actualCohortId);
        }
        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 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);
        }
        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));
        }
Esempio n. 5
0
 public IAuthorizationContext GetAuthorizationContext()
 {
     return(AuthorizationContextProvider.GetAuthorizationContext());
 }