public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName           = "B3nCr Identity Server",
                    IssuerUri          = "https://b3ncr.auth/embedded",
                    SigningCertificate = LoadCertificate(),

                    Factory = InMemoryFactory.Create(
                        users: Users.Get(),
                        clients: Clients.Get(),
                        scopes: Scopes.Get())
                });
            });
        }
Beispiel #2
0
        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp =>
            {
                idsrvApp.UseIdentityServer(new IdentityServerOptions
                {
                    SiteName           = "Embedded IdentityServer",
                    IssuerUri          = ExpenseTrackerConstants.IdSrvIssuerUri,
                    SigningCertificate = LoadCertificate(),

                    Factory = InMemoryFactory.Create(
                        users: Users.Get(),
                        clients: Clients.Get(),
                        scopes: Scopes.Get())
                });
            });
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RingMasterInstance"/> class.
        /// </summary>
        /// <param name="id">Unique Id of the instance</param>
        /// <param name="isPrimary">If <c>true</c> this instance is the primary</param>
        public RingMasterInstance(int id, bool isPrimary)
        {
            this.Id = id;
            Trace.TraceInformation($"RingMasterInstance id={this.Id}");

            this.persistedDataFactory = new InMemoryFactory(isPrimary, null, CancellationToken.None);
            this.backend = new RingMasterBackendCore(this.persistedDataFactory);
            this.persistedDataFactory.SetBackend(this.backend);

            this.backend.StartService = this.OnStartService;
            this.persistedDataFactory.OnFatalError = (message, exception) =>
            {
                Assert.Fail($"RingMasterInstance.FatalError: instanceId={id} message={message}, exception={exception}");
            };

            this.persistedDataFactory.OnChangeListCommitted = this.OnChangeListCommitted;
        }
Beispiel #4
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    clients: Clients.Get(),
                    scopes: Scopes.Get());

                // different examples of custom user services
                var userService = new RegisterFirstExternalRegistrationUserService();
                //var userService = new ExternalRegistrationUserService();
                //var userService = new EulaAtLoginUserService();
                //var userService = new LocalRegistrationUserService();

                factory.UserService = Registration.RegisterFactory <IUserService>(() => userService);

                var options = new IdentityServerOptions
                {
                    IssuerUri  = "https://idsrv3.com",
                    SiteName   = "Thinktecture IdentityServer v3 - CustomUserService",
                    RequireSsl = false,

                    SigningCertificate = Certificate.Get(),
                    Factory            = factory,
                    CorsPolicy         = CorsPolicy.AllowAll,

                    AdditionalIdentityProviderConfiguration = ConfigureAdditionalIdentityProviders,

                    AuthenticationOptions = new AuthenticationOptions
                    {
                        LoginPageLinks = new LoginPageLink[] {
                            new LoginPageLink {
                                Text = "Register",
                                //Href = "~/localregistration"
                                Href = "localregistration"
                            }
                        }
                    }
                };

                coreApp.UseIdentityServer(options);
            });
        }
Beispiel #5
0
        public async Task GetUserPageItems_ShouldReturnAllUsersOnPage()
        {
            // Arange
            List <ApplicationUser> usersData = new() { Users.User1Employee, Users.User2Employee };


            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(usersData);

            var service = new UserService(context);

            // Act
            var users = await service.GetUserPageItems <UserDataViewModel>(1, 2);

            // Assert
            Assert.NotNull(users);
            Assert.AreEqual(usersData.Count, users.Count());
        }
Beispiel #6
0
        public async Task CreateClient_ShouldCreateClient()
        {
            // Arange
            List <ClientData> clientsData = new() { Users.Client1User, Users.Client2User };


            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(clientsData);

            var service      = new UserService(context);
            var initialCount = context.ClientData.Count();

            // Act
            await service.CreateClient(Users.searchParam, Users.searchParam, true);

            // Assert
            Assert.AreEqual(initialCount + 1, context.ClientData.Count());
        }
        public async Task GetRoom_ShouldGetARoomById()
        {
            //Arrange
            List <Room> rooms = new() { Rooms.Room1 };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(rooms);

            var roomService = new RoomServices(context);

            //Act
            var resultRoom = await roomService.GetRoom <RoomViewModel>(Rooms.Room1.Id);

            //Assert
            Assert.IsNotNull(resultRoom);
            Assert.AreEqual(Rooms.Room1.Id, resultRoom.Id);
            Assert.AreEqual(Rooms.Room1.Capacity, resultRoom.Capacity);
        }
Beispiel #8
0
        public async Task GetEmployeePageItems_ShouldReturnAllEmployeesOnPage()
        {
            // Arange
            List <EmployeeData> employeesData = new() { Users.EmployeeUser1, Users.EmployeeUser2 };


            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(employeesData);

            var service = new UserService(context);

            // Act
            var employees = await service.GetEmployeePageItems <EmployeeDataViewModel>(1, 2);

            // Assert
            Assert.NotNull(employees);
            Assert.AreEqual(employeesData.Count, employees.Count());
        }
        public void Configuration(IAppBuilder appBuilder)
        {
            var factory = InMemoryFactory.Create(
                users:   Users.Get(),
                clients: Clients.Get(),
                scopes:  Scopes.Get());

            var options = new IdentityServerOptions
            {
                IssuerUri = "https://idsrv3.com",
                SiteName  = "Thinktecture IdentityServer v3 (self host)",

                SigningCertificate = Certificate.Get(),
                Factory            = factory,
            };

            appBuilder.UseIdentityServer(options);
        }
        public static void Configure(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());

            var factory      = InMemoryFactory.Create(users: GetUsers(), scopes: GetScopes(), clients: GetClients());
            var idsrvOptions = new IdentityServerOptions
            {
                SiteName           = "IdentityAdmin",
                SigningCertificate = Cert.Load(),
                Endpoints          = new EndpointOptions {
                    EnableCspReportEndpoint = true
                },
                Factory    = factory,
                CorsPolicy = CorsPolicy.AllowAll,
            };

            app.UseIdentityServer(idsrvOptions);
        }
Beispiel #11
0
        public async Task IsAlreadyAdded_ShouldFindAddeUser()
        {
            // Arange
            List <ApplicationUser> usersData = new()
            {
                Users.UserForSearch
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(usersData);

            var service = new UserService(context);

            // Act
            var result = service.IsAlreadyAdded(Users.searchParam);

            // Assert
            Assert.IsTrue(result);
        }
Beispiel #12
0
        public async Task DeleteClient_ShouldRemoveClient()
        {
            // Arange
            List <ClientData>      clientsData = new() { Users.Client1User, Users.Client2User };
            List <ApplicationUser> usersData   = new() { Users.User1Employee, Users.User2Employee };


            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(clientsData)
                                           .SeedAsync(usersData);

            var service      = new UserService(context);
            var initialCount = context.ClientData.Count();
            // Act
            await service.DeleteClient(clientsData.First().Id);

            // Assert
            Assert.AreEqual(initialCount - 1, context.ClientData.Count());
        }
        public async Task DeleteRoom_ShouldRemoveARoom()
        {
            //Arrange
            List <Room> rooms = new()
            {
                Rooms.Room2
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(rooms);

            var roomService = new RoomServices(context);

            //Act
            await roomService.DeleteRoom(Rooms.Room2.Id);

            //Assert
            Assert.AreEqual(0, context.Rooms.Count());
        }
        public async Task GetAllByCapacity_ShouldGetAllRoomsByCapacity()
        {
            //Arange
            List <Room> rooms = new()
            {
                Rooms.Room1,
                Rooms.Room2
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(rooms);

            var roomService = new RoomServices(context);
            //Act
            var result = await roomService.GetAllByCapacity <RoomViewModel>(4);

            //Arrange
            Assert.AreEqual(1, result.Count());
        }
        public static void Configure(IAppBuilder app)
        {
            var factory      = InMemoryFactory.Create(users: GetUsers(), scopes: GetScopes(), clients: GetClients());
            var idsrvOptions = new IdentityServerOptions
            {
                IssuerUri          = "https://idsrv3.com",
                SiteName           = "Thinktecture IdentityServer v3",
                SigningCertificate = Cert.Load(),
                CspOptions         = new CspOptions {
                    ReportEndpoint = EndpointSettings.Enabled,
                },
                PublicHostName = "http://localhost:17457",
                RequireSsl     = false,
                Factory        = factory,
                CorsPolicy     = CorsPolicy.AllowAll,
            };

            app.UseIdentityServer(idsrvOptions);
        }
Beispiel #16
0
        public async Task UpdateAsync_ShouldAddEmployeeData()
        {
            // Arange
            List <EmployeeData> employeeData = new()
            {
                Users.EmployeeUser1
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(employeeData);

            var service = new UserService(context);

            // Act
            await service.UpdateAsync(Users.EmployeeUser2);

            // Assert
            Assert.AreEqual(employeeData.Count() + 1, context.EmployeeData.Count());
        }
Beispiel #17
0
        public async Task UpdateClient_ShouldUpdateClient()
        {
            // Arange
            List <ClientData> clientsData = new() { Users.ClientForSearch };


            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(clientsData);

            await context.SaveChangesAsync();

            var service = new UserService(context);
            // Act
            var updatedClient = await service.UpdateClient(Users.ClientForSearch.Id, Users.searchParam2, Users.searchParam2, true);

            // Assert
            Assert.AreEqual(Users.searchParam2, updatedClient.Email);
            Assert.AreEqual(Users.searchParam2, updatedClient.FullName);
        }
Beispiel #18
0
        /// <summary>
        /// Gets the descendants of the given node from a snapshot of the current state of this instance.
        /// </summary>
        /// <param name="path">Path to the node</param>
        /// <returns>A <see cref="Task"/> that resolves to the list of descendant node paths</returns>
        public async Task <IList <string> > GetDescendantsFromSnapshot(string path)
        {
            Trace.TraceInformation($"RingMasterInstance.GetDescendantsFromSnapshot instanceId={this.Id}, path={path}");

            byte[] snapshot = this.GetSnapshot();
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            var nodes = new List <string>();

            using (var factory = new InMemoryFactory())
            {
                factory.LoadState = () =>
                {
                    using (var stream = new MemoryStream(snapshot))
                    {
                        factory.LoadFrom(stream);
                    }
                };

                factory.OnFatalError = (message, exception) =>
                {
                    Assert.Fail($"FatalError: message={message}, exception={exception}");
                };

                using (var backend = CreateBackend(factory))
                {
                    using (var ringMaster = new CoreRequestHandler(backend))
                    {
                        await ringMaster.ForEachDescendant(
                            path,
                            RingMasterInstance.MaxGetChildrenEnumerationCount,
                            descendantPath => nodes.Add(descendantPath));
                    }
                }
            }

            Trace.TraceInformation($"RingMasterInstance.GetDescendantsFromSnapshot-Completed instanceId={this.Id}, path={path}, descendantsCount={nodes.Count}");
            return(nodes);
        }
Beispiel #19
0
        public async Task AddReservation_ShouldAddReservation()
        {
            // Arange
            List <Setting> settings = new()
            {
                Settings.AllInclusive,
                Settings.Breakfast
            };

            List <Room> rooms = new()
            {
                Rooms.Room1
            };

            List <ApplicationUser> users = new()
            {
                Users.User3NotEmployee
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(settings)
                                           .SeedAsync(users)
                                           .SeedAsync(rooms);

            SettingService settingService = new(context);

            var service = new ReservationsService(context, settingService);

            // Act
            var reservation = await service.AddReservation(Reservations.Reservation1User3Room1NoClient.Room.Id,
                                                           Reservations.Reservation1User3Room1NoClient.AccommodationDate,
                                                           Reservations.Reservation1User3Room1NoClient.ReleaseDate,
                                                           Reservations.AllInClusive1,
                                                           Reservations.Breakfast1,
                                                           Reservations.Reservation1User3Room1NoClient.Clients,
                                                           Reservations.Reservation1User3Room1NoClient.User
                                                           );

            // Assert
            Assert.NotNull(reservation);
            Assert.AreEqual(1, context.Reservations.Count());
        }
Beispiel #20
0
        public async Task GetAllEmployees_ShouldReturnAllEmployees()
        {
            // Arange
            List <EmployeeData> employeeData = new()
            {
                Users.EmployeeUser1
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(employeeData);

            var service = new UserService(context);

            // Act
            var result = await service.GetAllEmployees <EmployeeDataViewModel>();

            // Assert
            Assert.AreEqual(employeeData.Count(), result.Count());
            Assert.AreEqual(employeeData.First().UCN, context.EmployeeData.First().UCN);
        }
Beispiel #21
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var factory = InMemoryFactory.Create(
                users:   Users.Get(),
                clients: Clients.Get(),
                scopes:  Scopes.Get());

            factory.CustomGrantValidator = Registration.RegisterType <ICustomGrantValidator>(typeof(CustomGrantValidator));

            var options = new IdentityServerOptions
            {
                IssuerUri = "https://idsrv3.com",
                SiteName  = "Thinktecture IdentityServer v3 - beta 2 (SelfHost)",

                SigningCertificate = Certificate.Get(),
                Factory            = factory,
            };

            appBuilder.UseIdentityServer(options);
        }
        public async Task CountAllRooms_ShouldCountAllRoomsInDb()
        {
            //Arange
            List <Room> rooms = new()
            {
                Rooms.Room1,
                Rooms.Room2
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(rooms);

            var roomService = new RoomServices(context);

            //Act
            var count = roomService.CountAllRooms();

            //Arrange
            Assert.AreEqual(rooms.Count(), count);
        }
Beispiel #23
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var factory = InMemoryFactory.Create(
                users:   Users.Get(),
                clients: Clients.Get(),
                scopes:  Scopes.Get());

            var options = new IdentityServerOptions
            {
                IssuerUri  = "https://idsrv3.com",
                SiteName   = "Thinktecture IdentityServer v3 - beta 2 (SelfHost)",
                RequireSsl = false,

                SigningCertificate            = Certificate.Get(),
                Factory                       = factory,
                AccessTokenValidationEndpoint = EndpointSettings.Enabled
            };

            appBuilder.UseIdentityServer(options);
        }
        public void Configuration(IAppBuilder appBuilder)
        {
            var factory = InMemoryFactory.Create(
                users:   Users.Get(),
                clients: Clients.Get(),
                scopes:  Scopes.Get());

            var options = new IdentityServerOptions
            {
                IssuerUri      = "https://idsrv3.com",
                SiteName       = "Thinktecture IdentityServer v3 - beta 1-1 (SelfHost)",
                PublicHostName = "http://localhost:3333",

                SigningCertificate  = Certificate.Get(),
                Factory             = factory,
                PluginConfiguration = ConfigurePlugins
            };

            appBuilder.UseIdentityServer(options);
        }
        public async Task GetMaxPrice_ShouldReturnTheHighestAdultPrice()
        {
            //Arange
            List <Room> rooms = new()
            {
                Rooms.Room1,
                Rooms.Room2
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(rooms);

            var roomService = new RoomServices(context);

            //Act
            var maxPrice = roomService.GetMaxPrice();

            //Arrange
            Assert.AreEqual(rooms[1].AdultPrice, maxPrice.Result);
        }
        public async Task GetMaxCapacity_ShouldReturnTheMaxCapacity()
        {
            //Arange
            List <Room> rooms = new()
            {
                Rooms.Room1,
                Rooms.Room2
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(rooms);

            var roomService = new RoomServices(context);

            //Act
            var maxCapacity = roomService.GetMaxCapacity();

            //Arrange
            Assert.AreEqual(Rooms.Room2.Capacity, maxCapacity.Result);
        }
Beispiel #27
0
        public async Task GetUsersSearchResults_ShouldFindExistingSearchedResult()
        {
            // Arange
            List <ApplicationUser> userData = new()
            {
                Users.UserForSearch
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(userData);

            var service = new UserService(context);

            // Act
            var result = await service.GetUsersSearchResults <UserDataViewModel>(Users.searchParam);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count());
        }
Beispiel #28
0
        public async Task CountAllUsers_ShouldCountAllUsers()
        {
            // Arange
            List <ApplicationUser> usersData = new()
            {
                Users.User3NotEmployee,
                Users.User4NotEmployee
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(usersData);

            var service = new UserService(context);

            // Act
            var result = service.CountAllUsers();

            // Assert
            Assert.AreEqual(usersData.Count(), result);
        }
Beispiel #29
0
        public async Task CountAllEmployees_ShouldCountAllemployees()
        {
            // Arange
            List <EmployeeData> employeeData = new()
            {
                Users.EmployeeUser1,
                Users.EmployeeUser2
            };

            ApplicationDbContext context = await InMemoryFactory.InitializeContext()
                                           .SeedAsync(employeeData);

            var service = new UserService(context);

            // Act
            var result = service.CountAllEmployees();

            // Assert
            Assert.AreEqual(employeeData.Count(), result);
        }
Beispiel #30
0
        public void Configuration(IAppBuilder app)
        {
            LogProvider.SetCurrentLogProvider(new DiagnosticsTraceLogProvider());
            //LogProvider.SetCurrentLogProvider(new TraceSourceLogProvider());

            // uncomment to enable HSTS headers for the host
            // see: https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security
            //app.UseHsts();

            app.Map("/core", coreApp =>
            {
                var factory = InMemoryFactory.Create(
                    users:   Users.Get(),
                    clients: Clients.Get(),
                    scopes:  Scopes.Get());

                var idsrvOptions = new IdentityServerOptions
                {
                    IssuerUri          = "https://idsrv3.com",
                    SiteName           = "Thinktecture IdentityServer v3 - beta 3",
                    Factory            = factory,
                    SigningCertificate = Cert.Load(),

                    CorsPolicy = CorsPolicy.AllowAll,
                    CspOptions = new CspOptions
                    {
                        ReportEndpoint = EndpointSettings.Enabled,
                    },

                    AuthenticationOptions = new AuthenticationOptions
                    {
                        IdentityProviders = ConfigureIdentityProviders,
                    }
                };

                coreApp.UseIdentityServer(idsrvOptions);
            });

            // only for showing the getting started index page
            app.UseStaticFiles();
        }