public void SendsBytesThroughDocumentBundleProcessors()
            {
                //Arrange
                var clientConfiguration = new Klientkonfigurasjon(Miljø.FunksjoneltTestmiljø)
                {
                    Dokumentpakkeprosessorer = new List <IDokumentpakkeProsessor>
                    {
                        new SimpleDocumentBundleProcessor(),
                        new SimpleDocumentBundleProcessor()
                    }
                };

                var forsendelse = DomainUtility.GetForsendelseSimple();
                var asiceAttachableProcessors = clientConfiguration.Dokumentpakkeprosessorer.Select(p => new AsiceAttachableProcessor(forsendelse, p));
                var asiceAttachables          = new IAsiceAttachable[] { DomainUtility.GetHoveddokumentSimple() };

                //Act
                var asiceArchive = new AsiceArchive(DomainUtility.GetMottakerCertificate(), new GuidUtility(), asiceAttachableProcessors, asiceAttachables);
                var bytes        = asiceArchive.Bytes;

                //Assert
                foreach (var simpleProcessor in clientConfiguration.Dokumentpakkeprosessorer.Cast <SimpleDocumentBundleProcessor>())
                {
                    Assert.True(simpleProcessor.StreamLength > 1000);
                    Assert.True(simpleProcessor.CouldReadBytesStream);
                    Assert.Equal(0, simpleProcessor.Initialposition);
                }
            }
        public SmokeTestsHelper Create_digital_forsendelse_with_different_sender()
        {
            _forsendelse          = DomainUtility.GetForsendelseSimple();
            _forsendelse.Avsender = new Avsender(new Organisasjonsnummer("984661185"))
            {
                Avsenderidentifikator = "digipost"
            };

            return(this);
        }
            public void ProcessesCorrectly()
            {
                //Arrange
                var message = DomainUtility.GetForsendelseSimple();
                var documentBundleProcessor = new MockAttachableProcessor();
                var stream = new MemoryStream(new byte[] { 0x42, 0x32 });
                var asiceAttachableProcessor = new AsiceAttachableProcessor(message, documentBundleProcessor);

                //Act
                asiceAttachableProcessor.Process(stream);

                //Assert
            }
            public async Task Throws_exception_on_response_not_matching_request()
            {
                //Arrange
                var sikkerDigitalPostKlient       = DomainUtility.GetSikkerDigitalPostKlientQaOffentlig();
                var fakeHttpClientHandlerResponse = new FakeResponseHandler()
                {
                    HttpContent = new StringContent(XmlResource.Response.GetTransportOk().OuterXml),
                };

                sikkerDigitalPostKlient.RequestHelper.HttpClient = new HttpClient(fakeHttpClientHandlerResponse);

                //Act
                var forsendelse = DomainUtility.GetForsendelseSimple();
                await Assert.ThrowsAsync <SecurityException>(async() => await sikkerDigitalPostKlient.SendAsync(forsendelse)).ConfigureAwait(false);
            }
            public void PersistsFileToDisk()
            {
                //Arrange
                var tmpDirectory = Path.GetTempPath();
                var processor    = new LagreDokumentpakkeTilDiskProsessor(tmpDirectory);
                var message      = DomainUtility.GetForsendelseSimple();
                var asiceBytes   = DomainUtility.GetAsiceArchive(message).Bytes;
                var asiceStream  = new MemoryStream(asiceBytes);

                //Act
                processor.Prosesser(message, asiceStream);
                var processedFileName = processor.LastFileProcessed;
                var tempFile          = Path.Combine(tmpDirectory, processedFileName);

                //Assert
                Assert.Equal(asiceBytes.Length, new FileInfo(tempFile).Length);
            }
            public async Task Returns_transport_error_receipt()
            {
                //Arrange
                var sikkerDigitalPostKlient       = DomainUtility.GetSikkerDigitalPostKlientIPLocalHost();
                var fakeHttpClientHandlerResponse = new FakeResponseHandler()
                {
                    HttpContent = new StringContent("Ikke gyldig json eller resopnse fra integrasjonspunkt medfører TransportFeiletKvittering"),
                    StatusCode  = HttpStatusCode.BadRequest
                };

                sikkerDigitalPostKlient.RequestHelper.HttpClient = new HttpClient(fakeHttpClientHandlerResponse);

                //Act
                var forsendelse         = DomainUtility.GetForsendelseSimple();
                var transportkvittering = await sikkerDigitalPostKlient.SendAsync(forsendelse).ConfigureAwait(false);

                //Assert
                Assert.IsType <TransportFeiletKvittering>(transportkvittering);
            }
            public async Task Calls_all_dokumentpakke_prosessors()
            {
                //Arrange
                var klientkonfigurasjon = new Klientkonfigurasjon(Miljø.FunksjoneltTestmiljø)
                {
                    Dokumentpakkeprosessorer = new List <IDokumentpakkeProsessor>
                    {
                        new SimpleDocumentBundleProcessor(),
                        new SimpleDocumentBundleProcessor()
                    }
                };

                var sikkerDigitalPostKlient = new SikkerDigitalPostKlient(DomainUtility.GetDatabehandler(), klientkonfigurasjon);

                DomainUtility.GetSikkerDigitalPostKlientQaOffentlig();
                var fakeHttpClientHandlerResponse = new FakeResponseHandler()
                {
                    HttpContent = new StringContent(XmlResource.Response.GetTransportOk().OuterXml),
                };

                sikkerDigitalPostKlient.RequestHelper.HttpClient = new HttpClient(fakeHttpClientHandlerResponse);

                //Act
                var forsendelse = DomainUtility.GetForsendelseSimple();

                try
                {
                    await sikkerDigitalPostKlient.SendAsync(forsendelse).ConfigureAwait(false);
                }
                catch (SecurityException)
                {
                    /*
                     *  We do not care about the results. Just do sending. Nasty hack as we are unable to mock validation
                     *  in SikkerDigitalPostKlient, which results in invalid timestamp since response is out of date.
                     */
                }

                //Assert
                foreach (var dokumentpakkeProsessor in klientkonfigurasjon.Dokumentpakkeprosessorer.Cast <SimpleDocumentBundleProcessor>())
                {
                    Assert.True(dokumentpakkeProsessor.CouldReadBytesStream);
                }
            }
            public async Task Returns_transport_error_receipt()
            {
                //Arrange
                var sikkerDigitalPostKlient       = DomainUtility.GetSikkerDigitalPostKlientQaOffentlig();
                var fakeHttpClientHandlerResponse = new FakeResponseHandler()
                {
                    HttpContent = new StringContent(XmlResource.Response.GetTransportError().OuterXml),
                    StatusCode  = HttpStatusCode.BadRequest
                };

                sikkerDigitalPostKlient.RequestHelper.HttpClient = new HttpClient(fakeHttpClientHandlerResponse);

                //Act
                var forsendelse         = DomainUtility.GetForsendelseSimple();
                var transportkvittering = await sikkerDigitalPostKlient.SendAsync(forsendelse).ConfigureAwait(false);

                //Assert
                Assert.IsType <TransportFeiletKvittering>(transportkvittering);
            }
Пример #9
0
            public async Task Returns_receipt_successfully()
            {
                //Arrange
                var forretningsmeldingEnvelope = DomainUtility.GetForretningsmeldingEnvelope();

                var documentBundle = AsiceGenerator.Create(DomainUtility.GetForsendelseSimple(), new GuidUtility(), DomainUtility.GetAvsenderCertificate(), DomainUtility.GetKlientkonfigurasjon());

                var requestHelper = new RequestHelper(new Klientkonfigurasjon(Miljø.FunksjoneltTestmiljø));
                var fakeHttpClientHandlerResponse = new FakeResponseHandler()
                {
                    HttpContent = new StringContent(XmlResource.Response.GetTransportOk().OuterXml),
                    StatusCode  = HttpStatusCode.OK
                };

                requestHelper.HttpClient = new HttpClient(fakeHttpClientHandlerResponse);

                //Act
                var kvittering = await requestHelper.SendMessage(forretningsmeldingEnvelope, documentBundle).ConfigureAwait(false);

                Assert.IsType <TransportOkKvittering>(kvittering);
            }
            public void FileNameContainsEssentialData()
            {
                //Arrange
                var tmpDirectory = Path.GetTempPath();
                var fileEnding   = "asice.zip";

                var processor   = new LagreDokumentpakkeTilDiskProsessor(tmpDirectory);
                var message     = DomainUtility.GetForsendelseSimple();
                var asiceBytes  = DomainUtility.GetAsiceArchive(message).Bytes;
                var asiceStream = new MemoryStream(asiceBytes);

                //Act
                processor.Prosesser(message, asiceStream);
                var processedFileName = processor.LastFileProcessed;
                var tempFileName      = Path.Combine(tmpDirectory, processedFileName);

                //Assert
                Assert.True(tempFileName.Contains(tmpDirectory));
                Assert.True(tempFileName.Contains(fileEnding));
                Assert.True(tempFileName.Contains(message.KonversasjonsId.ToString()));
                Assert.True(tempFileName.Contains(DateTime.Now.Year.ToString()));
            }
Пример #11
0
            public async Task Adds_user_agent()
            {
                //Arrange
                var forretningsmeldingEnvelope = DomainUtility.GetForretningsmeldingEnvelope();
                var documentBundle             = AsiceGenerator.Create(DomainUtility.GetForsendelseSimple(), new GuidUtility(), DomainUtility.GetAvsenderCertificate(), DomainUtility.GetKlientkonfigurasjon());

                Action <HttpRequestMessage> testingAction = message =>
                {
                    Assert.Contains("sikker-digital-post", message.Headers.UserAgent.ToString());
                };

                var requestHelper = new RequestHelper(
                    new Klientkonfigurasjon(Miljø.FunksjoneltTestmiljø),
                    new FakeResponseHandler()
                {
                    TestingAction = testingAction,
                    HttpContent   = new StringContent(XmlResource.Response.GetTransportOk().OuterXml)
                }
                    );

                //Act
                await requestHelper.SendMessage(forretningsmeldingEnvelope, documentBundle).ConfigureAwait(false);
            }