Esempio n. 1
0
        public AuthenticationResultResponse GetAuthenticationResult(AuthenticationResultRequest authenticationResultRequest)
        {
            var jsonRequest  = JsonConvert.SerializeObject(authenticationResultRequest);
            var jsonResponse = _getAuthenticationResult.Request(jsonRequest);

            return(JsonConvert.DeserializeObject <AuthenticationResultResponse>(jsonResponse));
        }
Esempio n. 2
0
        public void GetAuthResult_sendRequestWithoutRelyingPartyId_success()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(REFERENCE);
            String authenticationResultResponseString = jsonService.SerializeToJson(authenticationResult);

            StartMockServer(authenticationResultRequest, (int)HttpStatusCode.OK, authenticationResultResponseString);

            AuthenticationResult response = authenticationClient.GetResult(authenticationResultRequest);

            Assert.AreEqual(REFERENCE, response.AuthRef);
        }
        public void TestAuthenticationResult3ds2Success()
        {
            var client  = CreateMockTestClientRequest("Mocks/authentication-result-success-3ds2.json");
            var payment = new Payment(client);
            var authenticationResultRequest  = new AuthenticationResultRequest();
            var authenticationResultResponse = payment.GetAuthenticationResult(authenticationResultRequest);

            Assert.IsNotNull(authenticationResultResponse);
            Assert.IsNull(authenticationResultResponse.ThreeDS1Result);
            Assert.IsNotNull(authenticationResultResponse.ThreeDS2Result);
        }
Esempio n. 4
0
        public void PollForResultRequestTimeout_expectTimeoutError()
        {
            IAuthenticationClient authenticationClient = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                                                         .SetHttpService(CommonTestData.HttpServiceMock.Object)
                                                         .SetTransactionContext(TransactionContext.PERSONAL).Build <AuthenticationClient>();
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(CommonTestData.REFERENCE);

            try
            {
                CommonTestData.HttpServiceMock.Setup(x => x.Send <AuthenticationResult>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <AuthenticationResultRequest>(), It.IsAny <string>())).Throws(new FrejaEidClientPollingException(POLLING_TIMEOUT_ERROR_MESSAGE));
                AuthenticationResult response = authenticationClient.PollForResult(authenticationResultRequest, WAITING_TIME_IN_SEC);
                Assert.Fail("Test should throw exception!");
            }
            catch (FrejaEidClientPollingException ex)
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResult>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_GET_RESULT), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, null));
                Assert.AreEqual(POLLING_TIMEOUT_ERROR_MESSAGE, ex.Message);
            }
        }
Esempio n. 5
0
        public void GetAuthenticationResultInvalidReference_expectInvalidReferenceError()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(CommonTestData.REFERENCE, CommonTestData.RELYING_PARTY_ID);
            IAuthenticationClient       authenticationClient        = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                                                                      .SetHttpService(CommonTestData.HttpServiceMock.Object)
                                                                      .SetTransactionContext(TransactionContext.PERSONAL).Build <AuthenticationClient>();

            try
            {
                CommonTestData.HttpServiceMock.Setup(x => x.Send <AuthenticationResult>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <AuthenticationResultRequest>(), It.IsAny <string>())).Throws(new FrejaEidException(INVALID_REFERENCE_ERROR_MESSAGE, INVALID_REFERENCE_ERROR_CODE));
                AuthenticationResult response = authenticationClient.GetResult(authenticationResultRequest);
                Assert.Fail("Test should throw exception!");
            }
            catch (FrejaEidException rpEx)
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResult>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_GET_RESULT), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, CommonTestData.RELYING_PARTY_ID));
                Assert.AreEqual(INVALID_REFERENCE_ERROR_CODE, rpEx.ErrorCode);
                Assert.AreEqual(INVALID_REFERENCE_ERROR_MESSAGE, rpEx.Message);
            }
        }
Esempio n. 6
0
        private void PollForResultFinalResponseRejected(AuthenticationResultRequest authenticationResultRequest, TransactionContext transactionContext, string relyingPartyId)
        {
            AuthenticationResult  expectedResponse     = new AuthenticationResult(CommonTestData.DETAILS, TransactionStatus.REJECTED, CommonTestData.DETAILS, null);
            IAuthenticationClient authenticationClient = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                                                         .SetHttpService(CommonTestData.HttpServiceMock.Object)
                                                         .SetTransactionContext(transactionContext).Build <AuthenticationClient>();

            CommonTestData.HttpServiceMock.Setup(x => x.Send <AuthenticationResult>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <AuthenticationResultRequest>(), It.IsAny <string>())).Returns(expectedResponse);
            AuthenticationResult response = authenticationClient.PollForResult(authenticationResultRequest, WAITING_TIME_IN_SEC);

            if (transactionContext.Equals(TransactionContext.PERSONAL))
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResult>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_GET_RESULT), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, relyingPartyId));
            }
            else
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResult>(new Uri(FrejaEnvironment.TEST + MethodUrl.ORGANISATION_AUTHENTICATION_GET_ONE_RESULT), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, relyingPartyId));
            }
            Assert.AreEqual(expectedResponse.Status, response.Status);
        }
Esempio n. 7
0
        public AuthenticationResult PollForResult(AuthenticationResultRequest authenticationResultRequest, int maxWaitingTimeInSec)
        {
            long pollingEndTime = Convert.ToInt64(DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + TimeSpan.FromSeconds(maxWaitingTimeInSec).TotalMilliseconds);

            while (maxWaitingTimeInSec == 0 || ((DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond + pollingTimeoutInMilliseconds) < pollingEndTime))
            {
                AuthenticationResult authenticationResult = GetResult(authenticationResultRequest);
                if (maxWaitingTimeInSec == 0 || IsFinalStatus(authenticationResult.Status))
                {
                    return(authenticationResult);
                }
                try
                {
                    Thread.Sleep(pollingTimeoutInMilliseconds);
                }
                catch (Exception ex)
                {
                    throw new FrejaEidClientInternalException(message: $"An error occured while waiting to make another request with {maxWaitingTimeInSec} polling timeout.", cause: ex);
                }
            }
            throw new FrejaEidClientPollingException(message: $"A timeout of {maxWaitingTimeInSec} was reached while sending request.");
        }
Esempio n. 8
0
        private void GetAuthenticationResult(AuthenticationResultRequest authenticationResultRequest, TransactionContext transactionContext, string relyingPartyId)
        {
            AuthenticationResult  expectedResponse     = new AuthenticationResult(CommonTestData.REFERENCE, TransactionStatus.STARTED, CommonTestData.DETAILS, CommonTestData.REQUESTED_ATTRIBUTES);
            IAuthenticationClient authenticationClient = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                                                         .SetHttpService(CommonTestData.HttpServiceMock.Object)
                                                         .SetTransactionContext(transactionContext).Build <AuthenticationClient>();

            CommonTestData.HttpServiceMock.Setup(x => x.Send <AuthenticationResult>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <AuthenticationResultRequest>(), It.IsAny <string>())).Returns(expectedResponse);
            AuthenticationResult response = authenticationClient.GetResult(authenticationResultRequest);

            if (transactionContext.Equals(TransactionContext.PERSONAL))
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResult>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_GET_RESULT), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, relyingPartyId));
            }
            else
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResult>(new Uri(FrejaEnvironment.TEST + MethodUrl.ORGANISATION_AUTHENTICATION_GET_ONE_RESULT), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, relyingPartyId));
            }
            Assert.AreEqual(CommonTestData.REFERENCE, response.AuthRef);
            Assert.AreEqual(TransactionStatus.STARTED, response.Status);
            Assert.AreEqual(CommonTestData.DETAILS, response.Details);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES, response.RequestedAttributes);
        }
Esempio n. 9
0
        public void GetAuthenticationResultOrganisational_success()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(CommonTestData.REFERENCE, CommonTestData.RELYING_PARTY_ID);

            GetAuthenticationResult(authenticationResultRequest, TransactionContext.ORGANISATIONAL, CommonTestData.RELYING_PARTY_ID);
        }
Esempio n. 10
0
        public void GetAuthenticationResultRelyignPartyIdNull_success()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(CommonTestData.REFERENCE);

            GetAuthenticationResult(authenticationResultRequest, TransactionContext.PERSONAL, null);
        }
Esempio n. 11
0
        public void GetResult_relyingPartyIdEmpty_expectError()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(REFERENCE, "");

            ValidateRequest_expectError("RelyingPartyId cannot be empty.", () => authenticationClient.GetResult(authenticationResultRequest));
        }
Esempio n. 12
0
        public void GetResult_referenceNull_expectError()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(null);

            ValidateRequest_expectError("Reference cannot be null or empty.", () => authenticationClient.GetResult(authenticationResultRequest));
        }
Esempio n. 13
0
 public AuthenticationResult PollForResult(AuthenticationResultRequest authenticationResultRequest, int maxWaitingTimeInSec)
 {
     RequestValidationService.ValidateResultRequest(authenticationResultRequest);
     return(authenticationService.PollForResult(authenticationResultRequest, maxWaitingTimeInSec));
 }
Esempio n. 14
0
 public AuthenticationResult GetResult(AuthenticationResultRequest authenticationResultRequest)
 {
     RequestValidationService.ValidateResultRequest(authenticationResultRequest);
     return(authenticationService.GetResult(authenticationResultRequest));
 }
Esempio n. 15
0
 public static void ValidateResultRequest(AuthenticationResultRequest authenticationResultRequest)
 {
     ValidateRequest(authenticationResultRequest);
     ValidateReference(authenticationResultRequest.AuthRef);
     ValidateRelyingPartyIdIsEmpty(authenticationResultRequest.RelyingPartyId);
 }
Esempio n. 16
0
        public void PollForResultRelyingPartyIdNull_finalResponseRejected_success()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(CommonTestData.REFERENCE);

            PollForResultFinalResponseRejected(authenticationResultRequest, TransactionContext.PERSONAL, null);
        }
Esempio n. 17
0
        public void PollForResultRelyingPartyIdNotNull_finalResponseRejected_success()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create(CommonTestData.REFERENCE, CommonTestData.RELYING_PARTY_ID);

            PollForResultFinalResponseRejected(authenticationResultRequest, TransactionContext.ORGANISATIONAL, CommonTestData.RELYING_PARTY_ID);
        }
Esempio n. 18
0
        public AuthenticationResult GetResult(AuthenticationResultRequest authenticationResultRequest)
        {
            string methodUri = transactionContext == TransactionContext.ORGANISATIONAL ? MethodUrl.ORGANISATION_AUTHENTICATION_GET_ONE_RESULT : MethodUrl.AUTHENTICATION_GET_RESULT;

            return(httpService.Send <AuthenticationResult>(GetUri(serverAddress, methodUri), RequestTemplate.AUTHENTICATION_RESULT_TEMPLATE, authenticationResultRequest, authenticationResultRequest.RelyingPartyId));
        }