Esempio n. 1
0
        public void Arrange()
        {
            SetUp();
            EmployerAccountsConfiguration = new EmployerAccountsConfiguration()
            {
                ApplicationId = "eas-acc",
                DefaultCacheExpirationInMinutes = 1
            };
            ContentBanner           = "<p>find out how you can pause your apprenticeships<p>";
            MockCacheStorageService = new Mock <ICacheStorageService>();
            _contentType            = "banner";
            _clientId             = "eas-acc";
            _logger               = new Mock <ILog>();
            _contentBannerService = new Mock <IContentApiClient>();
            _contentBannerService
            .Setup(cbs => cbs.Get(_contentType, _clientId))
            .ReturnsAsync(ContentBanner);

            Query = new GetContentRequest
            {
                ContentType = "banner"
            };

            RequestHandler = new GetContentRequestHandler(RequestValidator.Object, _logger.Object, _contentBannerService.Object, EmployerAccountsConfiguration);
        }
        public void Arrange()
        {
            _mediator      = new Mock <IMediator>();
            _logger        = new Mock <ILog>();
            _cookieService = new Mock <ICookieStorageService <EmployerAccountData> >();
            _configuration = new EmployerAccountsConfiguration();

            _employerAccountOrchestrator = new EmployerAccountOrchestrator(
                _mediator.Object,
                _logger.Object,
                _cookieService.Object,
                _configuration);

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetUserAccountsQuery>()))
            .ReturnsAsync(new GetUserAccountsQueryResponse()
            {
                Accounts = new Accounts <Account>()
            });


            _mediator.Setup(x => x.SendAsync(It.IsAny <CreateUserAccountCommand>()))
            .ReturnsAsync(new CreateUserAccountCommandResponse()
            {
                HashedAccountId = "ABS10"
            });
        }
Esempio n. 3
0
 public EmployerAccountOrchestrator(IMediator mediator, ILog logger, ICookieStorageService <EmployerAccountData> cookieService,
                                    EmployerAccountsConfiguration configuration)
     : base(mediator, cookieService, configuration)
 {
     _mediator = mediator;
     _logger   = logger;
 }
Esempio n. 4
0
 private static OidcMiddlewareOptions GetOidcMiddlewareOptions(EmployerAccountsConfiguration config,
                                                               ICookieStorageService <EmployerAccountData> accountDataCookieStorageService,
                                                               ICookieStorageService <HashedAccountIdModel> hashedAccountIdCookieStorageService,
                                                               Constants constants)
 {
     return(new OidcMiddlewareOptions
     {
         AuthenticationType = CookieAuthenticationDefaults.AuthenticationType,
         BaseUrl = config.Identity.BaseAddress,
         ClientId = config.Identity.ClientId,
         ClientSecret = config.Identity.ClientSecret,
         Scopes = config.Identity.Scopes,
         AuthorizeEndpoint = constants.AuthorizeEndpoint(),
         TokenEndpoint = constants.TokenEndpoint(),
         UserInfoEndpoint = constants.UserInfoEndpoint(),
         TokenSigningCertificateLoader = GetSigningCertificate(config.Identity.UseCertificate),
         TokenValidationMethod = config.Identity.UseCertificate ? TokenValidationMethod.SigningKey : TokenValidationMethod.BinarySecret,
         AuthenticatedCallback = identity =>
         {
             PostAuthentiationAction(
                 identity,
                 constants,
                 accountDataCookieStorageService,
                 hashedAccountIdCookieStorageService);
         }
     });
 }
 public ResendInvitationCommandHandler(IInvitationRepository invitationRepository, IMembershipRepository membershipRepository, IMediator mediator, EmployerAccountsConfiguration employerApprenticeshipsServiceConfiguration, IUserAccountRepository userRepository)
 {
     if (invitationRepository == null)
     {
         throw new ArgumentNullException(nameof(invitationRepository));
     }
     if (membershipRepository == null)
     {
         throw new ArgumentNullException(nameof(membershipRepository));
     }
     if (mediator == null)
     {
         throw new ArgumentNullException(nameof(mediator));
     }
     if (employerApprenticeshipsServiceConfiguration == null)
     {
         throw new ArgumentNullException(nameof(employerApprenticeshipsServiceConfiguration));
     }
     _invitationRepository = invitationRepository;
     _membershipRepository = membershipRepository;
     _mediator             = mediator;
     _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration;
     _userRepository = userRepository;
     _validator      = new ResendInvitationCommandValidator();
 }
Esempio n. 6
0
        public HmrcService(
            EmployerAccountsConfiguration configuration,
            IHttpClientWrapper httpClientWrapper,
            IApprenticeshipLevyApiClient apprenticeshipLevyApiClient,
            ITokenServiceApiClient tokenServiceApiClient,
            [RequiredPolicy(HmrcExecutionPolicy.Name)] ExecutionPolicy executionPolicy,
            IInProcessCache inProcessCache,
            IAzureAdAuthenticationService azureAdAuthenticationService,
            ILog log)
        {
            _configuration                = configuration;
            _httpClientWrapper            = httpClientWrapper;
            _apprenticeshipLevyApiClient  = apprenticeshipLevyApiClient;
            _tokenServiceApiClient        = tokenServiceApiClient;
            _executionPolicy              = executionPolicy;
            _inProcessCache               = inProcessCache;
            _azureAdAuthenticationService = azureAdAuthenticationService;
            _log = log;

            _httpClientWrapper.BaseUrl    = _configuration.Hmrc.BaseUrl;
            _httpClientWrapper.AuthScheme = "Bearer";
            _httpClientWrapper.MediaTypeWithQualityHeaderValueList = new List <MediaTypeWithQualityHeaderValue> {
                new MediaTypeWithQualityHeaderValue("application/vnd.hmrc.1.0+json")
            };
        }
Esempio n. 7
0
        public void Arrange()
        {
            _configuration = new EmployerAccountsConfiguration
            {
                SupportConsoleUsers = SupportConsoleUsers
            };
            _mockAuthenticationService           = new Mock <IAuthenticationService>();
            AuthorizationContextTestsFixture     = new AuthorizationContextTestsFixture();
            MockIAuthorisationResourceRepository = new Mock <IAuthorisationResourceRepository>();
            Options      = new List <string>();
            _userContext = new UserContext(_mockAuthenticationService.Object, _configuration);
            SutDefaultAuthorizationHandler = new DefaultAuthorizationHandler(MockIAuthorisationResourceRepository.Object, _userContext);
            _testAuthorizationResource     = new AuthorizationResource
            {
                Name  = "Test",
                Value = Guid.NewGuid().ToString()
            };
            ResourceList = new List <AuthorizationResource>
            {
                _testAuthorizationResource
            };

            MockIAuthorisationResourceRepository.Setup(x => x.Get(It.IsAny <ClaimsIdentity>())).Returns(ResourceList);
            AuthorizationContext = new AuthorizationContext();
        }
        public void Arrange()
        {
            _cookieService = new Mock <ICookieStorageService <EmployerAccountData> >();
            _logger        = new Mock <ILog>();
            _mediator      = new Mock <IMediator>();
            _configuration = new EmployerAccountsConfiguration();

            _account = new Account
            {
                Id       = 123,
                HashedId = "ABC123",
                Name     = "Test Account"
            };

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetEmployerAccountHashedQuery>()))
            .ReturnsAsync(new GetEmployerAccountResponse {
                Account = _account
            });

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetUserAccountRoleQuery>()))
            .ReturnsAsync(new GetUserAccountRoleResponse {
                UserRole = Role.Owner
            });

            _orchestrator = new EmployerAccountOrchestrator(_mediator.Object, _logger.Object, _cookieService.Object, _configuration, Mock.Of <IHashingService>());
        }
 protected EmployerVerificationOrchestratorBase(IMediator mediator, ILog logger, ICookieStorageService <EmployerAccountData> cookieService, EmployerAccountsConfiguration configuration)
 {
     Mediator      = mediator;
     Logger        = logger;
     CookieService = cookieService;
     Configuration = configuration;
 }
        public void Arrange()
        {
            _mockAuthenticationService = new Mock <IAuthenticationService>();
            MockActionDescriptor       = new Mock <ActionDescriptor>();
            ActionExecutingContext     = new ActionExecutingContext {
                ActionDescriptor = MockActionDescriptor.Object
            };
            MockAuthorizationService = new Mock <IAuthorizationService>();
            ActionOptions            = new string[0];
            ControllerOptions        = new string[0];
            _config = new EmployerAccountsConfiguration()
            {
                SupportConsoleUsers = _supportConsoleUsers
            };
            MockActionDescriptor.Setup(d => d.ControllerDescriptor.ControllerName).Returns(Guid.NewGuid().ToString());
            MockActionDescriptor.Setup(d => d.ControllerDescriptor.GetCustomAttributes(typeof(DasAuthorizeAttribute), true)).Returns(new object[] { });
            MockActionDescriptor.Setup(d => d.ActionName).Returns(Guid.NewGuid().ToString());
            MockActionDescriptor.Setup(d => d.GetCustomAttributes(typeof(DasAuthorizeAttribute), true)).Returns(new object[] { });

            AuthorizationFilter = new AuthorizationFilter(() => MockAuthorizationService.Object);
            ActionOptions       = new[] { "Action.Option" };
            MockActionDescriptor.Setup(d => d.GetCustomAttributes(typeof(DasAuthorizeAttribute), true)).Returns(new object[] { new DasAuthorizeAttribute(ActionOptions) });
            mockContext.Setup(htx => htx.Request).Returns(mockRequest.Object);
            mockContext.Setup(htx => htx.Response).Returns(mockResponse.Object);
        }
        public void Setup()
        {
            _command = new ResendInvitationCommand
            {
                Email          = "*****@*****.**",
                AccountId      = ExpectedHashedId,
                ExternalUserId = Guid.NewGuid().ToString(),
            };

            var owner = new MembershipView
            {
                AccountId       = ExpectedAccountId,
                UserId          = 2,
                Role            = Role.Owner,
                HashedAccountId = ExpectedHashedId
            };

            _userRepository = new Mock <IUserAccountRepository>();
            _userRepository.Setup(x => x.Get(ExpectedExistingUserEmail)).ReturnsAsync(new User {
                Email = ExpectedExistingUserEmail, UserRef = Guid.NewGuid().ToString()
            });

            _membershipRepository = new Mock <IMembershipRepository>();
            _membershipRepository.Setup(x => x.GetCaller(owner.HashedAccountId, _command.ExternalUserId)).ReturnsAsync(owner);
            _invitationRepository = new Mock <IInvitationRepository>();
            _mediator             = new Mock <IMediator>();

            _config = new EmployerAccountsConfiguration();

            _handler = new ResendInvitationCommandHandler(_invitationRepository.Object, _membershipRepository.Object, _mediator.Object, _config, _userRepository.Object);
        }
Esempio n. 12
0
        public void Setup()
        {
            _configuration = new EmployerAccountsConfiguration {
                Hmrc = new HmrcConfiguration()
            };
            _logger        = new Mock <ILog>();
            _cookieService = new Mock <ICookieStorageService <EmployerAccountData> >();
            _mediator      = new Mock <IMediator>();

            _payeScheme = new PayeSchemeView
            {
                Ref       = EmpRef,
                Name      = SchemeName,
                AddedDate = DateTime.Now
            };

            _mediator
            .Setup(x => x.SendAsync(It.IsAny <GetEmployerEnglishFractionQuery>()))
            .ReturnsAsync(new GetEmployerEnglishFractionResponse {
                Fractions = new List <DasEnglishFraction>()
            });

            _mediator.Setup(x => x.SendAsync(It.IsAny <GetPayeSchemeByRefQuery>()))
            .ReturnsAsync(new GetPayeSchemeByRefResponse
            {
                PayeScheme = _payeScheme
            });

            _orchestrator = new EmployerAccountPayeOrchestrator(_mediator.Object, _logger.Object, _cookieService.Object, _configuration);
        }
Esempio n. 13
0
        public async Task Arrange()
        {
            _owinWrapper      = new Mock <IAuthenticationService>();
            _configuration    = new EmployerAccountsConfiguration();
            _homeOrchestrator = new Mock <HomeOrchestrator>();
            _returnUrlCookieStorageService = new Mock <ICookieStorageService <ReturnUrlModel> >();

            _homeController = new HomeController(
                _owinWrapper.Object,
                _homeOrchestrator.Object,
                _configuration,
                Mock.Of <IMultiVariantTestingService>(),
                Mock.Of <ICookieStorageService <FlashMessageViewModel> >(),
                _returnUrlCookieStorageService.Object,
                Mock.Of <ILog>());


            _expectedEmail     = "*****@*****.**";
            _expectedId        = "123456";
            _expectedFirstName = "Test";
            _expectedLastName  = "tester";
            _expectedReturnUrl = "campaign page";
            _owinWrapper.Setup(x => x.GetClaimValue("sub")).Returns(_expectedId);
            _owinWrapper.Setup(x => x.GetClaimValue("email")).Returns(_expectedEmail);
            _owinWrapper.Setup(x => x.GetClaimValue(DasClaimTypes.GivenName)).Returns(_expectedFirstName);
            _owinWrapper.Setup(x => x.GetClaimValue(DasClaimTypes.FamilyName)).Returns(_expectedLastName);

            _actualResult = await _homeController.SaveAndSearch(_expectedReturnUrl);
        }
Esempio n. 14
0
        public void Arrange()
        {
            _mediator      = new Mock <IMediator>();
            _logger        = new Mock <ILog>();
            _cookieService = new Mock <ICookieStorageService <EmployerAccountData> >();
            _configuration = new EmployerAccountsConfiguration();

            _employerAccountOrchestrator = new EmployerAccountOrchestrator(
                _mediator.Object,
                _logger.Object,
                _cookieService.Object,
                _configuration);


            _mediator.Setup(x => x.SendAsync(It.IsAny <GetUserAccountsQuery>()))
            .ReturnsAsync(new GetUserAccountsQueryResponse()
            {
                Accounts = new Accounts <Account> {
                    AccountsCount = 1, AccountList = new List <Account> {
                        new Account {
                            HashedId = _existingAccountHashedId
                        }
                    }
                }
            });
        }
        public void ItShouldReturnTheCorrectAornLockStatus([ValueSource("TestData")] TestData testData)
        {
            var userRef  = Guid.NewGuid();
            var logger   = Mock.Of <ILog>();
            var userRepo = new Mock <IUserRepository>();

            userRepo.Setup(x => x.GetAornPayeQueryAttempts(It.IsAny <string>())).ReturnsAsync(testData.Attempts.ToList());

            var config = new EmployerAccountsConfiguration
            {
                UserAornPayeLock = new UserAornPayeLockConfiguration
                {
                    NumberOfPermittedAttempts        = testData.NumberOfPermittedAttempts,
                    PermittedAttemptsTimeSpanMinutes = testData.PermittedAttemptsTimeSpanMinutes,
                    LockoutTimeSpanMinutes           = testData.LockoutTimeSpanMinutes
                }
            };

            var service = new UserAornPayeLockService(userRepo.Object, config, logger);
            var result  = service.UserAornPayeStatus(userRef.ToString()).Result;

            Assert.AreEqual(result.RemainingAttempts, testData.Expected.RemainingAttempts);
            Assert.AreEqual(result.IsLocked, testData.Expected.IsLocked);
            Assert.AreEqual(result.RemainingLock, testData.Expected.RemainingLock);
        }
 public HomeController(IAuthenticationService owinWrapper, HomeOrchestrator homeOrchestrator,
                       EmployerAccountsConfiguration configuration, IAuthorizationService authorization,
                       IMultiVariantTestingService multiVariantTestingService, ICookieStorageService <FlashMessageViewModel> flashMessage)
     : base(owinWrapper, multiVariantTestingService, flashMessage)
 {
     _homeOrchestrator = homeOrchestrator;
     _configuration    = configuration;
 }
 public AddressLookupService(
     IRestServiceFactory restServiceFactory,
     EmployerAccountsConfiguration configuration)
 {
     _configuration         = configuration.PostcodeAnywhere;
     _findByPostCodeService = restServiceFactory.Create(_configuration.FindPartsBaseUrl);
     _findByIdService       = restServiceFactory.Create(_configuration.RetrieveServiceBaseUrl);
 }
Esempio n. 18
0
        public void Arrange()
        {
            _owinWrapper   = new Mock <IAuthenticationService>();
            _configuration = new EmployerAccountsConfiguration();

            _homeController = new HomeController(
                _owinWrapper.Object, Mock.Of <HomeOrchestrator>(), _configuration, Mock.Of <IAuthorizationService>(),
                Mock.Of <IMultiVariantTestingService>(), Mock.Of <ICookieStorageService <FlashMessageViewModel> >());
        }
 public AccountRepository(
     EmployerAccountsConfiguration configuration,
     ILog logger, Lazy <EmployerAccountsDbContext> db,
     IAccountLegalEntityPublicHashingService accountLegalEntityHashingService)
     : base(configuration.DatabaseConnectionString, logger)
 {
     _db = db;
     _accountLegalEntityHashingService = accountLegalEntityHashingService;
 }
 public UserAornPayeLockService(
     IUserRepository userRepository,
     EmployerAccountsConfiguration configuration,
     ILog logger)
 {
     _logger         = logger;
     _userRepository = userRepository;
     _configuration  = configuration.UserAornPayeLock;
 }
 public ReportTrainingProviderCommandHandler(
     IMessageSession publisher,
     ILog logger,
     EmployerAccountsConfiguration configuration)
 {
     _publisher     = publisher;
     _logger        = logger;
     _configuration = configuration;
 }
Esempio n. 22
0
 public void Arrange()
 {
     _mockAuthenticationService     = new Mock <IAuthenticationService>();
     _employerAccountsConfiguration = new EmployerAccountsConfiguration()
     {
         SupportConsoleUsers = _supportConsoleUsers
     };
     _userContext = new UserContext(_mockAuthenticationService.Object, _employerAccountsConfiguration);
 }
Esempio n. 23
0
        public void Arrange()
        {
            _flashMessage = new Mock <ICookieStorageService <FlashMessageViewModel> >();

            _owinWrapper = new Mock <IAuthenticationService>();
            _owinWrapper.Setup(x => x.GetClaimValue(DasClaimTypes.RequiresVerification)).Returns("false");

            _homeOrchestrator = new Mock <HomeOrchestrator>();
            _homeOrchestrator.Setup(x => x.GetUsers()).ReturnsAsync(new SignInUserViewModel());
            _homeOrchestrator.Setup(x => x.GetUserAccounts(ExpectedUserId)).ReturnsAsync(
                new OrchestratorResponse <UserAccountsViewModel>
            {
                Data = new UserAccountsViewModel
                {
                    Accounts = new Accounts <Account>
                    {
                        AccountList = new List <Account> {
                            new Account()
                        }
                    }
                }
            });

            _configuration = new EmployerAccountsConfiguration
            {
                Identity = new IdentityServerConfiguration
                {
                    BaseAddress                  = "http://test",
                    ChangePasswordLink           = "123",
                    ChangeEmailLink              = "123",
                    ClaimIdentifierConfiguration = new ClaimIdentifierConfiguration {
                        ClaimsBaseUrl = "http://claims.test/"
                    }
                },
                EmployerPortalBaseUrl = "https://localhost"
            };

            _dependancyResolver = new Mock <IDependencyResolver>();
            _dependancyResolver.Setup(r => r.GetService(typeof(EmployerAccountsConfiguration))).Returns(_configuration);

            DependencyResolver.SetResolver(_dependancyResolver.Object);

            _userTestingService = new Mock <IMultiVariantTestingService>();

            _homeController = new HomeController(
                _owinWrapper.Object,
                _homeOrchestrator.Object,
                _configuration,
                _userTestingService.Object,
                _flashMessage.Object,
                Mock.Of <ICookieStorageService <ReturnUrlModel> >(),
                Mock.Of <ILog>())
            {
                Url = new UrlHelper()
            };
        }
Esempio n. 24
0
 public GetContentRequestHandler(
     IValidator <GetContentRequest> validator,
     ILog logger,
     IContentApiClient contentApiClient, EmployerAccountsConfiguration employerAccountsConfiguration)
 {
     _validator        = validator;
     _logger           = logger;
     _contentApiClient = contentApiClient;
     _employerAccountsConfiguration = employerAccountsConfiguration;
 }
Esempio n. 25
0
 public void SetUp()
 {
     _config = new EmployerAccountsConfiguration()
     {
         SupportConsoleUsers = SupportConsoleUsers
     };
     _mockAuthenticationService = new Mock <IAuthenticationService>();
     _userContext = new UserContext(_mockAuthenticationService.Object, _config);
     _authorisationResourceRepository = new AuthorisationResourceRepository(_userContext);
     _claimsIdentity = new ClaimsIdentity();
 }
 public ApprovedTransferConnectionRequestEventNotificationHandler(
     EmployerAccountsConfiguration config,
     ILog logger,
     INotificationsApi notificationsApi,
     Lazy <EmployerAccountsDbContext> db)
 {
     _config           = config;
     _logger           = logger;
     _notificationsApi = notificationsApi;
     _db = db;
 }
        public void Arrange()
        {
            _logger        = new Mock <ILog>();
            _mediator      = new Mock <IMediator>();
            _cookieService = new Mock <ICookieStorageService <EmployerAccountData> >();
            _configuration = new EmployerAccountsConfiguration
            {
                Hmrc = new HmrcConfiguration()
            };

            _employerAccountOrchestrator = new EmployerAccountOrchestrator(_mediator.Object, _logger.Object, _cookieService.Object, _configuration, Mock.Of <IHashingService>());
        }
 public CreateInvitationCommandHandler(IInvitationRepository invitationRepository, IMembershipRepository membershipRepository, IMediator mediator,
                                       EmployerAccountsConfiguration employerApprenticeshipsServiceConfiguration, IValidator <CreateInvitationCommand> validator,
                                       IUserAccountRepository userRepository, IEventPublisher eventPublisher)
 {
     _invitationRepository = invitationRepository;
     _membershipRepository = membershipRepository;
     _mediator             = mediator;
     _employerApprenticeshipsServiceConfiguration = employerApprenticeshipsServiceConfiguration;
     _validator      = validator;
     _userRepository = userRepository;
     _eventPublisher = eventPublisher;
 }
 public UnsubscribeProviderEmailQueryHandler(
     IHttpServiceFactory httpServiceFactory,
     EmployerAccountsConfiguration configuration)
 {
     _configuration = configuration;
     _httpService   = httpServiceFactory.Create(
         configuration.ProviderRegistrationsApi.ClientId,
         configuration.ProviderRegistrationsApi.ClientSecret,
         configuration.ProviderRegistrationsApi.IdentifierUri,
         configuration.ProviderRegistrationsApi.Tenant
         );
 }
 public PensionRegulatorService(
     IHttpServiceFactory httpServiceFactory,
     EmployerAccountsConfiguration configuration)
 {
     _configuration = configuration;
     _httpService   = httpServiceFactory.Create(
         configuration.PensionRegulatorApi.ClientId,
         configuration.PensionRegulatorApi.ClientSecret,
         configuration.PensionRegulatorApi.IdentifierUri,
         configuration.PensionRegulatorApi.Tenant
         );
 }