Beispiel #1
0
        public async Task <TlsRptInfoResponse> GetTlsRptForDomain(string requestDomain)
        {
            TlsRptInfoResponse response = await _dao.GetTlsRptForDomain(requestDomain);

            if (response is null)
            {
                await _messagePublisher.Publish(new DomainMissing(requestDomain), _config.MicroserviceOutputSnsTopicArn);
            }

            return(response);
        }
Beispiel #2
0
        public async Task ItShouldReturnTheFirstResultWhenTheTlsRptStateExists()
        {
            TlsRptInfoResponse state = new TlsRptInfoResponse("ncsc.gov.uk", TlsRptState.Created);

            A.CallTo(() => _TlsRptService.GetTlsRptForDomain(A <string> ._))
            .Returns(Task.FromResult(state));

            ObjectResult response = (ObjectResult)await _sut.GetTlsRpt(new TlsRptDomainRequest { Domain = "ncsc.gov.uk" });

            Assert.AreSame(response.Value, state);
        }
        public async Task PublishesDomainMissingMessageWhenDomainDoesNotExist()
        {
            A.CallTo(() => _dao.GetTlsRptForDomain("testDomain"))
            .Returns(Task.FromResult <TlsRptInfoResponse>(null));

            TlsRptInfoResponse result = await _tlsRptService.GetTlsRptForDomain("testDomain");

            A.CallTo(() => _messagePublisher.Publish(A <DomainMissing> ._, A <string> ._))
            .MustHaveHappenedOnceExactly();
            Assert.AreEqual(null, result);
        }
        public async Task DoesNotPublishDomainMissingMessageWhenDomainExists()
        {
            TlsRptInfoResponse tlsRptInfoResponse = new TlsRptInfoResponse("", TlsRptState.Created);

            A.CallTo(() => _dao.GetTlsRptForDomain("testDomain"))
            .Returns(Task.FromResult(tlsRptInfoResponse));

            TlsRptInfoResponse result = await _tlsRptService.GetTlsRptForDomain("testDomain");

            A.CallTo(() => _messagePublisher.Publish(A <DomainMissing> ._, A <string> ._))
            .MustNotHaveHappened();
            Assert.AreSame(tlsRptInfoResponse, result);
        }
        public async Task <IActionResult> GetTlsRpt(TlsRptDomainRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ErrorResponse(ModelState.Values)));
            }

            TlsRptInfoResponse response = await _tlsRptService.GetTlsRptForDomain(request.Domain);

            if (response == null)
            {
                return(new NotFoundObjectResult(new ErrorResponse($"No TLS/RPT found for {request.Domain}",
                                                                  ErrorStatus.Information)));
            }

            return(new ObjectResult(response));
        }