Esempio n. 1
0
        public async Task <IIdentificationResult> IdentifyAsync(IIdentification identification)
        {
            _logger.LogDebug($"Outgoing identification request: {identification}");

            var uri = new Uri("identification", UriKind.Relative);

            var identifyResponse = RequestHelper.PostIdentification <identificationresult>(identification, uri);

            if (identifyResponse.IsFaulted)
            {
                var exception = identifyResponse.Exception?.InnerException;

                _logger.LogWarning($"Identification failed, {exception}");

                if (identifyResponse.Exception != null)
                {
                    throw identifyResponse.Exception.InnerException;
                }
            }

            var identificationResultDataTransferObject = await identifyResponse.ConfigureAwait(false);

            var identificationResult = DataTransferObjectConverter.FromDataTransferObject(identificationResultDataTransferObject);

            _logger.LogDebug($"Response received for identification to recipient, ResultType '{identificationResult.ResultType}', Data '{identificationResult.Data}'.");

            return(identificationResult);
        }
Esempio n. 2
0
        /// <summary>
        ///     Get the current status for the given <see cref="StatusReference" />, which references the status for a specific
        ///     job.
        ///     When processing of the status is complete (e.g. retrieving <see cref="GetPades(PadesReference)">PAdES</see> and/or
        ///     <see cref="GetXades(XadesReference)">XAdES</see> documents for a <see cref="JobStatus.CompletedSuccessfully" /> job
        ///     where all the signers have <see cref="SignatureStatus.Signed" /> their documents), the returned  status
        ///     must be confirmed via <see cref="Confirm(ConfirmationReference)" />.
        /// </summary>
        /// <param name="statusReference">The reference to the status of a specific job.</param>
        /// <returns>
        ///     the <see cref="JobStatusResponse" /> for the job referenced by the given <see cref="StatusReference" />,
        ///     never null.
        /// </returns>
        public async Task <JobStatusResponse> GetStatus(StatusReference statusReference)
        {
            var request = new HttpRequestMessage
            {
                RequestUri = statusReference.Url(),
                Method     = HttpMethod.Get
            };

            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));

            var requestResult = await HttpClient.SendAsync(request).ConfigureAwait(false);

            var requestContent = requestResult.Content.ReadAsStringAsync().Result;

            switch (requestResult.StatusCode)
            {
            case HttpStatusCode.OK:
                var nextPermittedPollTime = DateTime.Now;
                var jobStatusResponse     = DataTransferObjectConverter.FromDataTransferObject(SerializeUtility.Deserialize <directsignaturejobstatusresponse>(requestContent), nextPermittedPollTime);
                _logger.LogDebug($"Requested status for JobId: {jobStatusResponse.JobId}, status was: {jobStatusResponse.Status}.");
                return(jobStatusResponse);

            default:
                throw RequestHelper.HandleGeneralException(requestResult.StatusCode, requestContent);
            }
        }
        private static JobStatusChanged ParseResponseToPortalJobStatusChangeResponse(string requestContent, DateTime nextPermittedPollTime)
        {
            var deserialized = SerializeUtility.Deserialize <portalsignaturejobstatuschangeresponse>(requestContent);
            var portalJobStatusChangeResponse = DataTransferObjectConverter.FromDataTransferObject(deserialized, nextPermittedPollTime);

            return(portalJobStatusChangeResponse);
        }
Esempio n. 4
0
        public async Task <ISearchDetailsResult> SearchAsync(string search)
        {
            _logger.LogDebug($"Outgoing search request, term: '{search}'.");

            search = search.RemoveReservedUriCharacters();
            var uri = new Uri($"recipients/search/{Uri.EscapeUriString(search)}", UriKind.Relative);

            if (search.Length < MinimumSearchLength)
            {
                var emptyResult = new SearchDetailsResult {
                    PersonDetails = new List <SearchDetails>()
                };

                var taskSource = new TaskCompletionSource <ISearchDetailsResult>();
                taskSource.SetResult(emptyResult);
                return(await taskSource.Task.ConfigureAwait(false));
            }

            var searchDetailsResultDataTransferObject = await RequestHelper.Get <recipients>(uri).ConfigureAwait(false);

            var searchDetailsResult = DataTransferObjectConverter.FromDataTransferObject(searchDetailsResultDataTransferObject);

            _logger.LogDebug($"Response received for search with term '{search}' retrieved.");

            return(searchDetailsResult);
        }
Esempio n. 5
0
            public void Converts_error_successfully()
            {
                //Arrange
                var source = new error
                {
                    errorcode    = "errorcode",
                    errormessage = "errormessage",
                    errortype    = "errortype"
                };

                var expected = new Error
                {
                    Code    = source.errorcode,
                    Message = source.errormessage,
                    Type    = source.errortype
                };

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                var compartor = new Comparator();
                IEnumerable <IDifference> differences;

                compartor.AreEqual(expected, actual, out differences);
                Assert.Empty(differences);
            }
Esempio n. 6
0
        private void ThrowNotEmptyResponseError(string responseContent)
        {
            var errorDataTransferObject = SerializeUtil.Deserialize <error>(responseContent);
            var error = DataTransferObjectConverter.FromDataTransferObject(errorDataTransferObject);

            _logger.LogError("Error occured, check inner Error object for more information.", error);
            throw new ClientResponseException("Error occured, check inner Error object for more information.", error);
        }
            public void Converts_direct_job_status_with_multiple_signers_successfully()
            {
                //Arrange
                var now = DateTime.Now;

                var source = new directsignaturejobstatusresponse
                {
                    signaturejobid     = 77,
                    reference          = null,
                    signaturejobstatus = directsignaturejobstatus.FAILED,
                    status             = new[]
                    {
                        new signerstatus {
                            signer = "12345678910", Value = "REJECTED", since = now
                        },
                        new signerstatus {
                            signer = "10987654321", Value = "SIGNED", since = now
                        }
                    },
                    xadesurl = new[]
                    {
                        new signerspecificurl {
                            signer = "10987654321", Value = "https://example.com/xades-url"
                        }
                    },
                    confirmationurl = "https://example.com/confirmation-url"
                };

                var nextPermittedPollTime = DateTime.Now;

                var expected = new JobStatusResponse(
                    source.signaturejobid,
                    source.reference,
                    JobStatus.Failed,
                    new JobReferences(new Uri("https://example.com/confirmation-url"), null),
                    new List <Signature>
                {
                    new Signature("12345678910", null, SignatureStatus.Rejected, now),
                    new Signature("10987654321", new XadesReference(new Uri("https://example.com/xades-url")), SignatureStatus.Signed, now)
                },
                    nextPermittedPollTime
                    );

                //Act
                var result = DataTransferObjectConverter.FromDataTransferObject(source, nextPermittedPollTime);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, result, out differences);
                Assert.Empty(differences);
            }
            public void Converts_signed_direct_job_status_successfully()
            {
                //Arrange
                var now = DateTime.Now;

                var source = new directsignaturejobstatusresponse
                {
                    signaturejobid     = 77,
                    reference          = "senders-reference",
                    signaturejobstatus = directsignaturejobstatus.COMPLETED_SUCCESSFULLY,
                    status             = new[] { new signerstatus {
                                                     signer = "12345678910", Value = "SIGNED", since = now
                                                 } },
                    confirmationurl = "http://signatureRoot.digipost.no/confirmation",
                    xadesurl        = new[] { new signerspecificurl {
                                                  signer = "12345678910", Value = "http://signatureRoot.digipost.no/xades"
                                              } },
                    padesurl = "http://signatureRoot.digipost.no/pades"
                };

                var nextPermittedPollTime = DateTime.Now;

                var expected = new JobStatusResponse(
                    source.signaturejobid,
                    source.reference,
                    JobStatus.CompletedSuccessfully,
                    new JobReferences(new Uri(source.confirmationurl), new Uri(source.padesurl)),
                    new List <Signature> {
                    new Signature("12345678910", new XadesReference(new Uri("http://signatureRoot.digipost.no/xades")), SignatureStatus.Signed, now)
                },
                    nextPermittedPollTime
                    );

                //Act
                var result = DataTransferObjectConverter.FromDataTransferObject(source, nextPermittedPollTime);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, result, out differences);
                Assert.Empty(differences);
            }
Esempio n. 9
0
            public void IdentificationByPinReturnsDigipostResultWithNoneResultType()
            {
                //Arrange
                var source = new identificationresult
                {
                    result = identificationresultcode.DIGIPOST,
                    Items  = new object[] { null }
                    //ItemsElementName = new [] { },

                    //IdentificationResultCode = IdentificationResultCode.Digipost,
                    //IdentificationValue = null,
                    //IdentificationResultType = IdentificationResultType.None
                };

                var expected = new IdentificationResult(IdentificationResultType.DigipostAddress, string.Empty);

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }
Esempio n. 10
0
            public void Error()
            {
                //Arrange
                var source = new error
                {
                    errorcode    = "UNKNOWN_RECIPIENT",
                    errormessage = "The recipient does not have a Digipost account.",
                    errortype    = "CLIENT_DATA"
                };

                var expected = new Error
                {
                    Errorcode    = source.errorcode,
                    Errormessage = source.errormessage,
                    Errortype    = source.errortype
                };

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }
Esempio n. 11
0
            public void IdentificationByOrganizationNumberReturnsUnidentifiedResultWithUnidentifiedReason()
            {
                //Arrange
                var reason = unidentifiedreason.NOT_FOUND;
                var source = new identificationresult
                {
                    result           = identificationresultcode.UNIDENTIFIED,
                    Items            = new object[] { reason },
                    ItemsElementName = new[] { ItemsChoiceType.unidentifiedreason }

                    //IdentificationResultCode = IdentificationResultCode.Unidentified,
                    //IdentificationValue = reason,
                    //IdentificationResultType = IdentificationResultType.UnidentifiedReason
                };

                var expected = new IdentificationResult(IdentificationResultType.UnidentifiedReason, reason.ToString());

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }
Esempio n. 12
0
        internal SignatureException HandleGeneralException(HttpStatusCode statusCode, string requestContent = null)
        {
            Error error;

            try
            {
                error = DataTransferObjectConverter.FromDataTransferObject(SerializeUtility.Deserialize <error>(requestContent));
                _logger.LogWarning($"Error occured: {error}");
            }
            catch (Exception exception)
            {
                _logger.LogWarning($"Unexpected error occured. Content: `{requestContent}`, statusCode: {statusCode}, {exception}");
                return(new UnexpectedResponseException(requestContent, statusCode, exception));
            }

            if (error != null && error.Code == BrokerNotAuthorized)
            {
                return(new BrokerNotAuthorizedException(error, statusCode));
            }

            _logger.LogWarning($"Unexpected error occured. Content: `{requestContent}`, statusCode: {statusCode}");
            return(new UnexpectedResponseException(error, statusCode));
        }
Esempio n. 13
0
            public void IdentificationByPinReturnsInvalidResultWithInvalidReason()
            {
                //Arrange
                object invalidValue = invalidreason.INVALID_PERSONAL_IDENTIFICATION_NUMBER;
                var    source       = new identificationresult
                {
                    result           = identificationresultcode.INVALID,
                    Items            = new[] { invalidValue },
                    ItemsElementName = new[] { ItemsChoiceType.invalidreason }

                    //IdentificationResultCode = IdentificationResultCode.Invalid,
                    //IdentificationValue = invalidValue,
                    //IdentificationResultType = IdentificationResultType.InvalidReason
                };

                var expected = new IdentificationResult(IdentificationResultType.InvalidReason, invalidValue.ToString());

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }
Esempio n. 14
0
            public void IdentificationByAddressReturnsDigipostResultWithDigipostAddressResultType()
            {
                //Arrange
                const string digipostAddress = "ola.nordmann#1234";
                var          source          = new identificationresult
                {
                    result           = identificationresultcode.DIGIPOST,
                    Items            = new object[] { digipostAddress },
                    ItemsElementName = new[] { ItemsChoiceType.digipostaddress }

                    //IdentificationResultCode = IdentificationResultCode.Digipost,
                    //IdentificationValue = digipostAddress,
                    //IdentificationResultType = IdentificationResultType.DigipostAddress
                };

                var expected = new IdentificationResult(IdentificationResultType.DigipostAddress, digipostAddress);

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }
Esempio n. 15
0
            public void IdentificationByAddressReturnsIdentifiedResultWithPersonalAliasResultType()
            {
                //Arrange
                const string personAlias = "fewoinf23nio3255n32oi5n32oi5n#1234";
                var          source      = new identificationresult
                {
                    result           = identificationresultcode.IDENTIFIED,
                    Items            = new object[] { personAlias },
                    ItemsElementName = new[] { ItemsChoiceType.personalias }

                    //IdentificationResultCode = IdentificationResultCode.Identified,
                    //IdentificationValue = personAlias,
                    //IdentificationResultType = IdentificationResultType.Personalias
                };

                var expected = new IdentificationResult(IdentificationResultType.Personalias, personAlias);

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }
Esempio n. 16
0
            public void Converts_portal_job_response_successfully()
            {
                //Arrange
                var signaturejobid      = 12345678910;
                var jobReference        = "senders-reference";
                var httpCancellationurl = "http://cancellationurl.no";
                var source = new portalsignaturejobresponse
                {
                    signaturejobid  = signaturejobid,
                    reference       = jobReference,
                    cancellationurl = httpCancellationurl
                };
                var expected = new JobResponse(signaturejobid, jobReference, new Uri(httpCancellationurl));

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, actual, out differences);
                Assert.Empty(differences);
            }
Esempio n. 17
0
        private static JobStatusResponse ParseResponseToJobStatusResponse(string requestContent, DateTime nextPermittedPollTime)
        {
            var deserialized = SerializeUtility.Deserialize <directsignaturejobstatusresponse>(requestContent);

            return(DataTransferObjectConverter.FromDataTransferObject(deserialized, nextPermittedPollTime));
        }
Esempio n. 18
0
            public void Converts_portal_job_status_change_response_successfully()
            {
                //Todo: Husk å sjekke om vi skal ha type, ettersom man kan få et fødselsnummer eller en identifier tilbake. Nå er det bare en string

                //Arrange
                var now = DateTime.Now;

                var source = new portalsignaturejobstatuschangeresponse
                {
                    confirmationurl = "http://confirmationurl.no",
                    signaturejobid  = 12345678901011,
                    reference       = "senders-reference",
                    signatures      = new signatures
                    {
                        padesurl  = "http://padesurl.no",
                        signature = new[]
                        {
                            new signature
                            {
                                Item   = "01013300001",
                                status = new signaturestatus
                                {
                                    Value = SignatureStatus.Signed.Identifier,
                                    since = now
                                },
                                xadesurl = "http://xadesurl1.no"
                            },
                            new signature
                            {
                                Item   = "01013300002",
                                status = new signaturestatus
                                {
                                    Value = SignatureStatus.Waiting.Identifier,
                                    since = now
                                },
                                xadesurl = "http://xadesurl2.no"
                            }
                        }
                    },
                    status = portalsignaturejobstatus.IN_PROGRESS
                };

                var jobStatus             = source.status.ToJobStatus();
                var confirmationReference = new ConfirmationReference(new Uri(source.confirmationurl));
                var signature1            = source.signatures.signature[0];
                var signature2            = source.signatures.signature[1];
                var signatures            = new List <Signature>
                {
                    new Signature
                    {
                        SignatureStatus   = new SignatureStatus(signature1.status.Value),
                        Identifier        = new PersonalIdentificationNumber((string)signature1.Item),
                        XadesReference    = new XadesReference(new Uri(signature1.xadesurl)),
                        DateTimeForStatus = now
                    },
                    new Signature
                    {
                        SignatureStatus   = new SignatureStatus(signature2.status.Value),
                        Identifier        = new PersonalIdentificationNumber((string)signature2.Item),
                        XadesReference    = new XadesReference(new Uri(signature2.xadesurl)),
                        DateTimeForStatus = now
                    }
                };

                var nextPermittedPollTime = DateTime.Now;

                var expected = new JobStatusChanged(
                    source.signaturejobid,
                    source.reference,
                    jobStatus,
                    confirmationReference,
                    signatures,
                    nextPermittedPollTime
                    );

                var padesUrl = source.signatures.padesurl;

                if (padesUrl != null)
                {
                    expected.PadesReference = new PadesReference(new Uri(padesUrl));
                }

                //Act
                var actual = DataTransferObjectConverter.FromDataTransferObject(source, nextPermittedPollTime);

                //Assert
                var comparator = new Comparator();
                IEnumerable <IDifference> differences;

                comparator.AreEqual(expected, actual, out differences);
                Assert.Empty(differences);
            }
Esempio n. 19
0
            public void SearchResult()
            {
                //Arrange
                var source = new recipients
                {
                    recipient = new[]
                    {
                        new recipient
                        {
                            firstname          = "Stian Jarand",
                            middlename         = "Jani",
                            lastname           = "Larsen",
                            digipostaddress    = "Stian.Jani.Larsen#22DB",
                            mobilenumber       = "12345678",
                            organisationname   = "Organisatorisk Landsforbund",
                            organisationnumber = "1234567689",
                            address            = new[]
                            {
                                new address
                                {
                                    street                = "Bakkeveien",
                                    housenumber           = "3",
                                    houseletter           = "C",
                                    additionaladdressline = "Underetasjen",
                                    zipcode               = "3453",
                                    city = "Konjakken"
                                },
                                new address
                                {
                                    street      = "Komleveien",
                                    housenumber = "33",
                                    zipcode     = "3453",
                                    city        = "Konjakken"
                                }
                            }
                        },
                        new recipient
                        {
                            firstname       = "Bentoni Jarandsen",
                            lastname        = "Larsen",
                            mobilenumber    = "02345638",
                            digipostaddress = "Bentoni.Jarandsen.Larsen#KG33",
                            address         = new[]
                            {
                                new address
                                {
                                    street      = "Mudleveien",
                                    housenumber = "45",
                                    zipcode     = "4046",
                                    city        = "Hafrsfjell"
                                }
                            }
                        }
                    }
                };

                var recipient0 = source.recipient.ElementAt(0);
                var recipient1 = source.recipient.ElementAt(1);

                var expected = new SearchDetailsResult
                {
                    PersonDetails = new List <SearchDetails>
                    {
                        new SearchDetails
                        {
                            FirstName            = recipient0.firstname,
                            MiddleName           = recipient0.middlename,
                            LastName             = recipient0.lastname,
                            MobileNumber         = recipient0.mobilenumber,
                            OrganizationName     = recipient0.organisationname,
                            OrganizationNumber   = recipient0.organisationnumber,
                            DigipostAddress      = recipient0.digipostaddress,
                            SearchDetailsAddress = new List <SearchDetailsAddress>
                            {
                                new SearchDetailsAddress
                                {
                                    Street                = recipient0.address[0].street,
                                    HouseNumber           = recipient0.address[0].housenumber,
                                    HouseLetter           = recipient0.address[0].houseletter,
                                    AdditionalAddressLine = recipient0.address[0].additionaladdressline,
                                    PostalCode            = recipient0.address[0].zipcode,
                                    City = recipient0.address[0].city
                                },
                                new SearchDetailsAddress
                                {
                                    Street                = recipient0.address[1].street,
                                    HouseNumber           = recipient0.address[1].housenumber,
                                    HouseLetter           = recipient0.address[1].houseletter,
                                    AdditionalAddressLine = recipient0.address[1].additionaladdressline,
                                    PostalCode            = recipient0.address[1].zipcode,
                                    City = recipient0.address[1].city
                                }
                            }
                        },
                        new SearchDetails
                        {
                            FirstName            = recipient1.firstname,
                            MiddleName           = recipient1.middlename,
                            LastName             = recipient1.lastname,
                            MobileNumber         = recipient1.mobilenumber,
                            OrganizationName     = recipient1.organisationname,
                            OrganizationNumber   = recipient1.organisationnumber,
                            DigipostAddress      = recipient1.digipostaddress,
                            SearchDetailsAddress = new List <SearchDetailsAddress>
                            {
                                new SearchDetailsAddress
                                {
                                    Street                = recipient1.address[0].street,
                                    HouseNumber           = recipient1.address[0].housenumber,
                                    HouseLetter           = recipient1.address[0].houseletter,
                                    AdditionalAddressLine = recipient1.address[0].additionaladdressline,
                                    PostalCode            = recipient1.address[0].zipcode,
                                    City = recipient1.address[0].city
                                }
                            }
                        }
                    }
                };

                var actual = DataTransferObjectConverter.FromDataTransferObject(source);

                //Assert
                Comparator.AssertEqual(expected, actual);
            }