use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testCheckPathValiditygetSession.
@Test(description = "Test for path limitation with getSession")
public void testCheckPathValiditygetSession() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/echoName", "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
;
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "wso2");
String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
String sessionId = CookieUtils.getCookie(cookie).value;
cMsg = MessageUtils.generateHTTPMessage("/counter/echo2", "GET");
cMsg.setHeader(COOKIE_HEADER, SESSION_ID + sessionId);
response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertTrue(responseMsgPayload.contains("failed to get session: " + "/counter is not an allowed path"));
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testHttpOnlyFlagInSessionCookie.
@Test(description = "Test for HttpOnly flag in session cookie")
public void testHttpOnlyFlagInSessionCookie() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test1", "GET");
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(responseMsg);
String cookie = responseMsg.getHeader(RESPONSE_COOKIE_HEADER);
Assert.assertNotNull(cookie);
Assert.assertTrue(CookieUtils.getCookie(cookie).httpOnly);
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetAttributeNamesFunction.
@Test(description = "Test for getAttributeNames function")
public void testGetAttributeNamesFunction() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample2/names", "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "arraysize:2");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testGetSessionWithoutSessionIDCheck.
@Test(description = "Test for getting a session without Id at first time")
public void testGetSessionWithoutSessionIDCheck() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/sample/test2", "GET");
HTTPCarbonMessage responseMsg = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(responseMsg);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(responseMsg).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "no session id available");
}
use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.
the class HTTPSessionEssentialMethodsTest method testCheckPathValidity.
@Test(description = "Test for path limitation")
public void testCheckPathValidity() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/counter/echo", "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
;
Assert.assertNotNull(responseMsgPayload);
Assert.assertEquals(responseMsgPayload, "1");
String cookie = response.getHeader(RESPONSE_COOKIE_HEADER);
String sessionId = CookieUtils.getCookie(cookie).value;
cMsg = MessageUtils.generateHTTPMessage("/sample2/echoName", "GET");
cMsg.setHeader(COOKIE_HEADER, SESSION_ID + sessionId);
response = Services.invokeNew(compileResult, TEST_ENDPOINT_NAME, cMsg);
Assert.assertNotNull(response);
responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertNotNull(responseMsgPayload);
Assert.assertTrue(responseMsgPayload.contains("failed to get session: /sample2 is not an allowed path"));
}
Aggregations