コード例 #1
0
        public void AbstractController_ProcessRequest_GivenNotAuthenticated_ExpectUnauthorized1()
        {
            var mockNameValue = new Mock <NameValueCollection>();

            mockNameValue.Setup(o => o.Get(It.IsAny <string>()))
            .Throws(new Exception("false exception for testing catch"));

            var mock = new Mock <IPrincipal>();

            mock.Setup(o => o.Identity.IsAuthenticated)
            .Returns(true);

            var path    = "https://localhost/token/Hello%20World.json?Name=";
            var request = new HttpRequestMessage(HttpMethod.Get, path)
            {
                Headers = { { "Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9hdXRoZW50aWNhdGlvbiI6InsnVXNlckdyb3Vwcyc6IFt7J05hbWUnOiAncHVibGljJyB9XX0iLCJuYmYiOjE1OTExOTcyMDEsImV4cCI6MTU5MTE5ODQwMSwiaWF0IjoxNTkxMTk3MjAxfQ.1zo2d8Z7yxDvGZGVXbCf8zQKh7WZeyGx7BfWu4drt4g" } },
                Content = new StringContent("Some content"),
            };

            var controller = new AbstractControllerForTesting
            {
                User    = mock.Object,
                Request = request
            };
            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(false, mockNameValue.Object);

            var result = response.Content.ReadAsStringAsync().Result;

            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.AreEqual("Internal Server Error", response.ReasonPhrase);
            Assert.AreEqual("{\r\n  \"Error\": {\r\n    \"Status\": 500,\r\n    \"Title\": \"internal_server_error\",\r\n    \"Message\": \"not expected to be executed\"\r\n  }\r\n}", result);
        }
コード例 #2
0
        public void AbstractController_ProcessRequest_GivenNotAuthenticated_ExpectUnauthorized()
        {
            var controller = new AbstractControllerForTesting
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "/token/Hello%20World.json?Name=")
            };
            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(false);

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Unauthorized);
            Assert.AreEqual(response.ReasonPhrase, "Unauthorized");
        }
コード例 #3
0
        public void AbstractController_ProcessRequest_GivenNotAuthenticated_ExpectUnauthorized()
        {
            var controller = new AbstractControllerForTesting
            {
                Request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:3241/token/Hello%20World.json?Name=")
            };
            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(false);

            var result = response.Content.ReadAsStringAsync().Result;

            Assert.AreEqual(response.StatusCode, HttpStatusCode.Unauthorized);
            Assert.AreEqual(response.ReasonPhrase, "Unauthorized");
            Assert.AreEqual("{\r\n  \"Error\": {\r\n    \"Status\": 401,\r\n    \"Title\": \"user_unauthorized\",\r\n    \"Message\": \"Authorization has been denied for this user.\"\r\n  }\r\n}", result);
        }
コード例 #4
0
        public void AbstractController_ProcessRequest_GivenTokenNotAuthenticated_ExpectUnauthorized()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "https://localhost/token/Hello%20World.json?Name=")
            {
                Headers = { { "Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9hdXRoZW50aWNhdGlvbiI6InsnVXNlckdyb3Vwcyc6IFt7J05hbWUnOiAncHVibGljJyB9XX0iLCJuYmYiOjE1OTExOTcyMDEsImV4cCI6MTU5MTE5ODQwMSwiaWF0IjoxNTkxMTk3MjAxfQ.1zo2d8Z7yxDvGZGVXbCf8zQKh7WZeyGx7BfWu4drt4g" } },
                Content = new StringContent("Some content"),
            };
            var controller = new AbstractControllerForTesting
            {
                Request = request
            };
            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(true);

            Assert.AreEqual(Warewolf.Resource.Errors.ErrorResource.TokenNotAuthorizedToExecuteOuterWorkflowException, response.ReasonPhrase);
        }
コード例 #5
0
        public void AbstractController_ProcessRequest_GivenTokenEmptyNotAuthenticated_ExpectUnauthorized()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "https://localhost/token/Hello%20World.json?Name=")
            {
                Headers = { { "Authorization", "bearer " } },
                Content = new StringContent("Some content"),
            };
            var controller = new AbstractControllerForTesting
            {
                Request = request
            };

            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(true);

            Assert.AreEqual(Warewolf.Resource.Errors.ErrorResource.TokenNotAuthorizedToExecuteOuterWorkflowException, response.ReasonPhrase);
        }
コード例 #6
0
        public void AbstractController_ProcessRequest_GivenTokenNotAuthenticated_ExpectUnauthorized()
        {
            var pathhh  = "https://localhost/token/Hello%20World.json?Name=";
            var path    = pathhh.Split(new[] { "/apis.json" }, StringSplitOptions.RemoveEmptyEntries);
            var request = new HttpRequestMessage(HttpMethod.Get, pathhh)
            {
                Headers = { { "Authorization", "bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9hdXRoZW50aWNhdGlvbiI6InsnVXNlckdyb3Vwcyc6IFt7J05hbWUnOiAncHVibGljJyB9XX0iLCJuYmYiOjE1OTExOTcyMDEsImV4cCI6MTU5MTE5ODQwMSwiaWF0IjoxNTkxMTk3MjAxfQ.1zo2d8Z7yxDvGZGVXbCf8zQKh7WZeyGx7BfWu4drt4g" } },
                Content = new StringContent("Some content"),
            };
            var controller = new AbstractControllerForTesting
            {
                Request = request
            };
            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(true);
            var result   = response.Content.ReadAsStringAsync().Result;

            Assert.AreEqual(HttpStatusCode.Unauthorized.ToString(), response.ReasonPhrase);
            Assert.AreEqual("{\r\n  \"Error\": {\r\n    \"Status\": 401,\r\n    \"Title\": \"token_unauthorized\",\r\n    \"Message\": \"Authorization has been denied for this token.\"\r\n  }\r\n}", result);
        }
コード例 #7
0
        public void AbstractController_ProcessRequest_GivenTokenEmptyNotAuthenticated_ExpectUnauthorized()
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "https://localhost/token/Hello%20World.json?Name=")
            {
                Headers = { { "Authorization", "bearer " } },
                Content = new StringContent("Some content"),
            };
            var controller = new AbstractControllerForTesting
            {
                Request = request
            };


            var response = controller.TestProcessRequest <AssertNotExecutedRequestHandlerForTesting>(true);

            var result = response.Content.ReadAsStringAsync().Result;

            Assert.IsFalse(response.IsSuccessStatusCode);
            Assert.AreEqual(HttpStatusCode.Unauthorized.ToString(), response.ReasonPhrase);
            Assert.AreEqual("{\r\n  \"Error\": {\r\n    \"Status\": 401,\r\n    \"Title\": \"token_unauthorized\",\r\n    \"Message\": \"Authorization has been denied for this token.\"\r\n  }\r\n}", result);
        }