예제 #1
0
 public void TestInitialize()
 {
     jsonService = new JsonService();
     initiateAuthenticationResponse = new InitiateAuthenticationResponse(REFERENCE);
     authenticationResult           = new AuthenticationResult(REFERENCE, TransactionStatus.STARTED, null, null);
     authenticationResultWithRequestedAttributes = new AuthenticationResult(REFERENCE, TransactionStatus.APPROVED, DETAILS, REQUESTED_ATTRIBUTES);
     authenticationResults = new AuthenticationResults(new List <AuthenticationResult> {
         authenticationResult
     });
     authenticationClient = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                            .SetTestModeCustomUrl(CUSTOM_URL).SetTransactionContext(TransactionContext.PERSONAL).Build <AuthenticationClient>();
     StopServer();
 }
예제 #2
0
 public void AuthClientInit_invalidPoolingTime_expectError()
 {
     try
     {
         AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
         .SetPollingTimeout(INVALID_POLLING_TIMEOUT)
         .Build <AuthenticationClient>();
         Assert.Fail("Test should throw exception!");
     }
     catch (FrejaEidClientInternalException ex)
     {
         Assert.AreEqual("Polling timeout must be between 1 and 30 seconds.", ex.Message);
     }
 }
        private void RelyingPartyNull_success(InitiateAuthenticationRequest initiateAuthenticationRequest)
        {
            InitiateAuthenticationResponse expectedResponse = new InitiateAuthenticationResponse(CommonTestData.REFERENCE);

            CommonTestData.HttpServiceMock.Setup(x => x.Send <InitiateAuthenticationResponse>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <InitiateAuthenticationRequest>(), null)).Returns(expectedResponse);

            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>();
            string reference = authenticationClient.Initiate(initiateAuthenticationRequest);

            CommonTestData.HttpServiceMock.Verify(x => x.Send <InitiateAuthenticationResponse>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_INIT), RequestTemplate.INIT_AUTHENTICATION_TEMPLATE, initiateAuthenticationRequest, null));
            Assert.AreEqual(CommonTestData.REFERENCE, reference);
        }
        public void InvalidUserInfo_expectError()
        {
            InitiateAuthenticationRequest initiateAuthenticationRequest = InitiateAuthenticationRequest.CreateCustom().SetPhoneNumber(CommonTestData.EMAIL).SetRelyingPartyId(CommonTestData.RELYING_PARTY_ID).Build();

            try
            {
                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>();

                CommonTestData.HttpServiceMock.Setup(x => x.Send <InitiateAuthenticationResponse>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <InitiateAuthenticationRequest>(), It.IsAny <string>())).Throws(new FrejaEidException(INVALID_USER_INFO_ERROR_MESSAGE, INVALID_USER_INFO_ERROR_CODE));
                authenticationClient.Initiate(initiateAuthenticationRequest);
                Assert.Fail("Test should throw exception!");
            }
            catch (FrejaEidException rpEx)
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <InitiateAuthenticationResponse>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_INIT), RequestTemplate.INIT_AUTHENTICATION_TEMPLATE, initiateAuthenticationRequest, CommonTestData.RELYING_PARTY_ID));
                Assert.AreEqual(1002, rpEx.ErrorCode);
                Assert.AreEqual("Invalid or missing userInfo.", rpEx.Message);
            }
        }
예제 #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);
            }
        }
예제 #6
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);
        }
예제 #7
0
        private void GetAuthenticationResults(AuthenticationResultsRequest getAuthenticationResultsRequest, TransactionContext transactionContext, string relyingPartyId)
        {
            AuthenticationResults expectedResponse     = PrepareAuthenticationResultsResponse();
            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 <AuthenticationResults>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <AuthenticationResultsRequest>(), It.IsAny <string>())).Returns(expectedResponse);
            List <AuthenticationResult> response = authenticationClient.GetResults(getAuthenticationResultsRequest);

            if (transactionContext.Equals(TransactionContext.PERSONAL))
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResults>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_GET_RESULTS), RequestTemplate.AUTHENTICATION_RESULTS_TEMPLATE, getAuthenticationResultsRequest, relyingPartyId));
            }
            else
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <AuthenticationResults>(new Uri(FrejaEnvironment.TEST + MethodUrl.ORGANISATION_AUTHENTICATION_GET_RESULTS), RequestTemplate.AUTHENTICATION_RESULTS_TEMPLATE, getAuthenticationResultsRequest, relyingPartyId));
            }
            AuthenticationResult first = response[0];

            Assert.AreEqual(CommonTestData.REFERENCE, first.AuthRef);
            Assert.AreEqual(TransactionStatus.STARTED, first.Status);
            Assert.AreEqual(CommonTestData.DETAILS, first.Details);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.BasicUserInfo.Name, first.RequestedAttributes.BasicUserInfo.Name);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.BasicUserInfo.Surname, first.RequestedAttributes.BasicUserInfo.Surname);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.DateOfBirth, first.RequestedAttributes.DateOfBirth);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.EmailAddress, first.RequestedAttributes.EmailAddress);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.CustomIdentifier, first.RequestedAttributes.CustomIdentifier);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.Ssn.Country, first.RequestedAttributes.Ssn.Country);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.Ssn.Ssn, first.RequestedAttributes.Ssn.Ssn);
            Assert.AreEqual(CommonTestData.REQUESTED_ATTRIBUTES.OrganisationIdIdentifier, first.RequestedAttributes.OrganisationIdIdentifier);
            AuthenticationResult second = response[1];

            Assert.AreEqual(CommonTestData.REFERENCE, second.AuthRef);
            Assert.AreEqual(TransactionStatus.DELIVERED_TO_MOBILE, second.Status);
            Assert.AreEqual(CommonTestData.DETAILS, second.Details);
            Assert.AreEqual(CommonTestData.CUSTOM_IDENTIFIER, second.RequestedAttributes.CustomIdentifier);
        }
예제 #8
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);
            }
        }
예제 #9
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);
        }
예제 #10
0
        public void InitAuth_organisationalTransaction_success()
        {
            AuthenticationClient authenticationClient = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                                                        .SetTestModeCustomUrl(CUSTOM_URL).SetTransactionContext(TransactionContext.ORGANISATIONAL).Build <AuthenticationClient>();
            InitiateAuthenticationRequest initAuthenticationRequestWithRequestedAttributesUserInfoOrganisationId = InitiateAuthenticationRequest.CreateCustom()
                                                                                                                   .SetOrganisationId(ORGANISATION_ID)
                                                                                                                   .SetAttributesToReturn(AttributeToReturn.BASIC_USER_INFO, AttributeToReturn.EMAIL_ADDRESS, AttributeToReturn.SSN, AttributeToReturn.CUSTOM_IDENTIFIER, AttributeToReturn.INTEGRATOR_SPECIFIC_USER_ID, AttributeToReturn.ORGANISATION_ID_IDENTIFIER)
                                                                                                                   .Build();

            String initAuthResponseString = jsonService.SerializeToJson(initiateAuthenticationResponse);

            StartMockServer(initAuthenticationRequestWithRequestedAttributesUserInfoOrganisationId, (int)HttpStatusCode.OK, initAuthResponseString);
            String reference = authenticationClient.Initiate(initAuthenticationRequestWithRequestedAttributesUserInfoOrganisationId);

            StopServer();
            Assert.AreEqual(REFERENCE, reference);
        }
예제 #11
0
 public void TestInitialize()
 {
     authenticationClient = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                            .SetTestModeCustomUrl(TEST_URL).SetTransactionContext(TransactionContext.PERSONAL).Build <AuthenticationClient>();
 }
예제 #12
0
 public void AuthClientInit_success()
 {
     IAuthenticationClient authenticationClientPKCS12 = AuthenticationClient.Create(SslSettings.Create(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH)), FrejaEnvironment.TEST)
                                                        .SetTransactionContext(TransactionContext.PERSONAL).Build <AuthenticationClient>();
 }
예제 #13
0
 public void AuthClientInit_invalidEmptyParameter_expectInternalError()
 {
     AuthClientInit_assertError(EMPTY_PATH, TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH), "KeyStore Path, keyStore password or server certificate path cannot be null or empty.");
 }
예제 #14
0
 public void AuthClientInit_invalidKeystoreFileAuthentication_expectKeystoreError()
 {
     AuthClientInit_assertError(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.INVALID_KEYSTORE_FILE), TestKeystoreUtil.KEYSTORE_PASSWORD, TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.CERTIFICATE_PATH), "Failed to initialize SSL Context with given client certificate path or password.");
 }
예제 #15
0
 public void AuthClientInit_invalidCertificatePath_expectKeystoreError()
 {
     AuthClientInit_assertError(TestKeystoreUtil.GetKeystorePath(TestKeystoreUtil.KEYSTORE_PATH_PKCS12), TestKeystoreUtil.KEYSTORE_PASSWORD, INVALID_CERTIFICATE_PATH, "Failed to initialize SSL Context with given server certificate path or password.");
 }
예제 #16
0
        private void CancelAuthentication(CancelAuthenticationRequest cancelAuthenticationRequest, TransactionContext transactionContext, string RelyingPartyId)
        {
            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 <EmptyFrejaResponse>(It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <CancelAuthenticationRequest>(), It.IsAny <string>())).Returns(new EmptyFrejaResponse());
            authenticationClient.Cancel(cancelAuthenticationRequest);
            if (transactionContext.Equals(TransactionContext.PERSONAL))
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <EmptyFrejaResponse>(new Uri(FrejaEnvironment.TEST + MethodUrl.AUTHENTICATION_CANCEL), RequestTemplate.CANCEL_AUTHENTICATION_TEMPLATE, cancelAuthenticationRequest, RelyingPartyId));
            }
            else
            {
                CommonTestData.HttpServiceMock.Verify(x => x.Send <EmptyFrejaResponse>(new Uri(FrejaEnvironment.TEST + MethodUrl.ORGANISATION_AUTHENTICATION_CANCEL), RequestTemplate.CANCEL_AUTHENTICATION_TEMPLATE, cancelAuthenticationRequest, RelyingPartyId));
            }
        }