public Task <IActionResult> GetSubdomains(DomainsRequest request) { Func <DomainsSecurityResponse, List <DomainSecurityInfo>, DomainsSecurityResponse> responseFactory = (response, items) => new DomainsSecurityResponse(items, 0); return(GetDomainSecurityInfoInternal(request, GetSubdomainsResponse, responseFactory)); }
public Task <IActionResult> GetDomainsSecurityInfoByUserId(DomainsRequest request) { Func <MyDomainsResponse, List <DomainSecurityInfo>, MyDomainsResponse> responseFactory = (response, items) => new MyDomainsResponse(items, response.DomainCount, response.UserDomainCount); return(GetDomainSecurityInfoInternal(request, GetDomainsSecurityInfoResponseByUserId, responseFactory)); }
public Domain GetDomain(string domainName) { if (string.IsNullOrWhiteSpace(domainName)) { throw new ArgumentNullException("domainName"); } return(httpCacheClient.GetCacheData(() => { Logger.Write("Call API:DomainsRequest"); DomainsRequest request = new DomainsRequest(); request.Email = email; request.Password = password; var response = request.Execute(); if (response.Domains == null) { throw new DNSPodException(9, "没有任何域名"); } if (response.Domains.Count(t => domainName.Equals(t.Name, StringComparison.OrdinalIgnoreCase)) == 0) { throw new DNSPodException(6, "域名不存在"); } Logger.Write("API Complete:DomainsRequest"); return response.Domains.Single(t => domainName.Equals(t.Name, StringComparison.OrdinalIgnoreCase)); }, string.Format("domain_{0}", domainName), TimeSpan.FromDays(1))); }
private async Task <DomainsSecurityResponse> GetSubdomainsResponse(DomainsRequest request) { List <DomainSecurityInfo> subdomains = await _domainStatusListDao.GetSubdomains(request.Search, request.Page.Value, request.PageSize.Value); List <DomainSecurityInfo> resultsWithCertificateStatus = await _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus(subdomains); return(new DomainsSecurityResponse(resultsWithCertificateStatus, 0)); }
public async Task <IActionResult> GetWelcomeSearchResult(DomainsRequest request) { if (!_domainValidator.IsValidDomain(request.Search)) { return(BadRequest(new ErrorResponse("Please enter a valid domain."))); } WelcomeSearchResult result = await _domainStatusListDao.GetWelcomeSearchResult(request.Search); bool isPublicSectorOrg = _publicDomainValidator.IsValidPublicDomain(request.Search); return(new ObjectResult(new WelcomeSearchResponse(result, isPublicSectorOrg))); }
public async Task GetDomainSecurityInfoByUserIdWhenDomainDoesntHaveDmarcButOrgDomainDoesReturnsOrgDomainResult() { SetSid("1", _domainStatusListController); A.CallTo(() => _domainRequestValidator.ValidateAsync(A <DomainsRequest> ._, CancellationToken.None)) .Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()))); var domainSecurityInfos = new List <DomainSecurityInfo>() { CreateDomainSecurityInfo(DomainId1, SubDomain1, false, Error), CreateDomainSecurityInfo(DomainId2, SubDomain2, true, Warning) }; A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByUserId(A <int> ._, A <int> ._, A <int> ._, A <string> ._)).Returns(domainSecurityInfos); A.CallTo(() => _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus(A <List <DomainSecurityInfo> > ._)).Returns(domainSecurityInfos); A.CallTo(() => _organisationDomainProvider.GetOrganisationalDomain(SubDomain1)) .Returns(Task.FromResult(new OrganisationalDomain(OrgDomain1, SubDomain1))); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByDomainNames(A <List <string> > ._)).Returns( Task.FromResult(new List <DomainSecurityInfo> { CreateDomainSecurityInfo(DomainId3, OrgDomain1, true, Success), })); DomainsRequest request = new DomainsRequest(); IActionResult result = await _domainStatusListController.GetDomainsSecurityInfoByUserId(request); Assert.That(result, Is.TypeOf <ObjectResult>()); ObjectResult objectResult = result as ObjectResult; Assert.That(objectResult.Value, Is.TypeOf <MyDomainsResponse>()); DomainsSecurityResponse response = objectResult.Value as DomainsSecurityResponse; Assert.That(response.DomainSecurityInfos[0].Domain.Id, Is.EqualTo(DomainId1)); Assert.That(response.DomainSecurityInfos[0].Domain.Name, Is.EqualTo(SubDomain1)); Assert.That(response.DomainSecurityInfos[0].DmarcStatus, Is.EqualTo(Success)); Assert.That(response.DomainSecurityInfos[1].Domain.Id, Is.EqualTo(DomainId2)); Assert.That(response.DomainSecurityInfos[1].Domain.Name, Is.EqualTo(SubDomain2)); Assert.That(response.DomainSecurityInfos[1].DmarcStatus, Is.EqualTo(Warning)); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByUserId(A <int> ._, A <int> ._, A <int> ._, A <string> ._)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus(A <List <DomainSecurityInfo> > ._)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _domainStatusListDao.GetDomainsCountByUserId(A <int> ._, A <string> ._)).MustHaveHappened(Repeated.Exactly.Twice); A.CallTo(() => _organisationDomainProvider.GetOrganisationalDomain(A <string> ._)).MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByDomainNames(A <List <string> > ._)).MustHaveHappened(Repeated.Exactly.Once); }
private async Task <DomainsSecurityResponse> GetDomainsSecurityInfoResponse(DomainsRequest request) { Task <List <DomainSecurityInfo> > getDomainSecurityInfoTask = _domainStatusListDao.GetDomainsSecurityInfo(request.Page.Value, request.PageSize.Value, request.Search); Task <long> getDomainCountTask = _domainStatusListDao.GetDomainsCount(request.Search); await Task.WhenAll(getDomainSecurityInfoTask, getDomainCountTask); List <DomainSecurityInfo> resultsWithCertificateStatus = await _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus( getDomainSecurityInfoTask.Result); return(new DomainsSecurityResponse(resultsWithCertificateStatus, getDomainCountTask.Result)); }
public async Task GetDomainSecurityInfoInvalidRequestReturnsBadRequest() { ValidationResult validationResult = new ValidationResult(new List <ValidationFailure> { new ValidationFailure(string.Empty, string.Empty) }); A.CallTo(() => _domainRequestValidator.ValidateAsync(A <DomainsRequest> ._, CancellationToken.None)) .Returns(Task.FromResult(validationResult)); DomainsRequest request = new DomainsRequest(); IActionResult result = await _domainStatusListController.GetDomainsSecurityInfo(request); Assert.That(result, Is.TypeOf <BadRequestObjectResult>()); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfo(A <int> ._, A <int> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus(A <List <DomainSecurityInfo> > ._)).MustNotHaveHappened(); A.CallTo(() => _domainStatusListDao.GetDomainsCount(A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _organisationDomainProvider.GetOrganisationalDomain(A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByDomainNames(A <List <string> > ._)).MustNotHaveHappened(); }
private async Task <IActionResult> GetDomainSecurityInfoInternal <T>(DomainsRequest request, Func <DomainsRequest, Task <T> > getDomainSecurityInfoResponse, Func <T, List <DomainSecurityInfo>, T> updateResponseFactory) where T : DomainsSecurityResponse { ValidationResult validationResult = await _domainsRequestValidator.ValidateAsync(request); if (!validationResult.IsValid) { string errorString = validationResult.GetErrorString(); _log.LogWarning($"Bad request: {errorString}"); return(BadRequest(new ErrorResponse(errorString))); } T domainsSecurityResponse = await getDomainSecurityInfoResponse(request); List <DomainSecurityInfo> domainSecurityInfoWithoutDmarcRecord = domainsSecurityResponse.DomainSecurityInfos.Where(_ => !_.HasDmarc).ToList(); if (!domainSecurityInfoWithoutDmarcRecord.Any()) { return(new ObjectResult(domainsSecurityResponse)); } Dictionary <string, string> nonOrgDomainsWithoutDmarcRecordForOrgDomains = await GetOrganisationalDomains(domainSecurityInfoWithoutDmarcRecord); if (!nonOrgDomainsWithoutDmarcRecordForOrgDomains.Any()) { return(new ObjectResult(domainsSecurityResponse)); } List <string> organisationalDomains = nonOrgDomainsWithoutDmarcRecordForOrgDomains.Values.Distinct().ToList(); List <DomainSecurityInfo> orgDomainSecurityInfos = await _domainStatusListDao .GetDomainsSecurityInfoByDomainNames(organisationalDomains); List <DomainSecurityInfo> updatedDomainSecurityInfos = Merge(domainsSecurityResponse.DomainSecurityInfos, orgDomainSecurityInfos, nonOrgDomainsWithoutDmarcRecordForOrgDomains); return(new ObjectResult(updateResponseFactory(domainsSecurityResponse, updatedDomainSecurityInfos))); }
public async Task GetDomainSecurityInfoByUserIdNoUserIdEmptyResult() { A.CallTo(() => _domainRequestValidator.ValidateAsync(A <DomainsRequest> ._, CancellationToken.None)) .Returns(Task.FromResult(new ValidationResult(new List <ValidationFailure>()))); DomainsRequest request = new DomainsRequest(); IActionResult result = await _domainStatusListController.GetDomainsSecurityInfoByUserId(request); Assert.That(result, Is.TypeOf <ObjectResult>()); ObjectResult objectResult = result as ObjectResult; Assert.That(objectResult.Value, Is.TypeOf <MyDomainsResponse>()); DomainsSecurityResponse response = objectResult.Value as DomainsSecurityResponse; Assert.That(response.DomainSecurityInfos, Is.Empty); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByUserId(A <int> ._, A <int> ._, A <int> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus(A <List <DomainSecurityInfo> > ._)).MustNotHaveHappened(); A.CallTo(() => _domainStatusListDao.GetDomainsCountByUserId(A <int> ._, A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _organisationDomainProvider.GetOrganisationalDomain(A <string> ._)).MustNotHaveHappened(); A.CallTo(() => _domainStatusListDao.GetDomainsSecurityInfoByDomainNames(A <List <string> > ._)).MustNotHaveHappened(); }
private async Task <MyDomainsResponse> GetDomainsSecurityInfoResponseByUserId(DomainsRequest request) { int?userId = User.GetId(); if (!userId.HasValue) { return(new MyDomainsResponse(new List <DomainSecurityInfo>(), 0, 0)); } Task <List <DomainSecurityInfo> > getDomainSecurityInfoTask = _domainStatusListDao.GetDomainsSecurityInfoByUserId(userId.Value, request.Page.Value, request.PageSize.Value, request.Search); Task <long> getDomainCountTask = _domainStatusListDao.GetDomainsCountByUserId(userId.Value, request.Search); Task <long> getUserDomainCountTask = _domainStatusListDao.GetDomainsCountByUserId(userId.Value, string.Empty); await Task.WhenAll(getDomainSecurityInfoTask, getDomainCountTask, getUserDomainCountTask); List <DomainSecurityInfo> resultsWithCertificateStatus = await _certificateEvaluatorApi.UpdateTlsWithCertificateEvaluatorStatus( getDomainSecurityInfoTask.Result); return(new MyDomainsResponse(resultsWithCertificateStatus, getDomainCountTask.Result, getUserDomainCountTask.Result)); }
public void Test(DomainsRequest request, bool valid) { ValidationResult result = _domainsRequestValidator.Validate(request); Assert.That(result.IsValid, Is.EqualTo(valid)); }