コード例 #1
0
        private void SendInitAuthRequestAndAssertResponse(InitiateAuthenticationRequest expectedRequest, InitiateAuthenticationRequest validRequest, String initAuthResponseString)
        {
            StartMockServer(expectedRequest, (int)HttpStatusCode.OK, initAuthResponseString);
            String reference = authenticationClient.Initiate(validRequest);

            StopServer();
            Assert.AreEqual(REFERENCE, reference);
        }
        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);
            }
        }
コード例 #4
0
 public void InitAuth_requestNull()
 {
     ValidateRequest_expectError("Request cannot be null value.", () => authenticationClient.Initiate(null));
 }