コード例 #1
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);
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
        public void GetResult_missingReference_expectError()
        {
            AuthenticationResultRequest authenticationResultRequest = AuthenticationResultRequest.Create("");

            ValidateRequest_expectError("Reference cannot be null or empty.", () => authenticationClient.GetResult(authenticationResultRequest));
        }