Skip to content

Commit

Permalink
Expand SessionCookieConfig tests for new generic attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Dec 3, 2021
1 parent e3715f5 commit 65a3a0e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public void contextInitialized(ServletContextEvent sce) {
Boolean isSecure = true;
Boolean httpOnly = false;
int maxage = 50000;
String attrName = "a1";
String attrValue= "b2";
String name = "TCK_Cookie_Name";

SessionCookieConfig scf = sce.getServletContext().getSessionCookieConfig();
Expand All @@ -44,6 +46,7 @@ public void contextInitialized(ServletContextEvent sce) {
scf.setMaxAge(maxage);
scf.setPath(path);
scf.setSecure(isSecure);
scf.setAttribute(attrName, attrValue);

if (!scf.getPath().equals(path)) {
testData.append("|getPathFAILED-expecting-" + path + "-got-" + scf.getPath());
Expand All @@ -57,14 +60,18 @@ public void contextInitialized(ServletContextEvent sce) {
testData.append("|isHttpOnlyFAILED-expecting-" + httpOnly + "-got-" + scf.isHttpOnly());
}

if (!scf.getDomain().equals(domain.toString())) {
if (!scf.getDomain().equals(domain)) {
testData.append("|getDomainFAILED-expecting-" + domain + "-got-" + scf.getDomain());
}

if (scf.getMaxAge() != maxage) {
testData.append("|getMaxAgeFAILED-expecting-" + maxage + "-got-" + scf.getMaxAge());
}

if (!scf.getAttribute(attrName).equals(attrValue)) {
testData.append("|getAttributeFAILED-expecting-" + attrValue + "-got-" + scf.getAttribute(attrName));
}

if (scf.getName() != null) {
testData.append("|getNameFAILED-expecting-null-got-" + scf.getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
public class TestServlet extends HttpTCKServlet {

public void constructortest1(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpServletResponse response) throws IOException {
request.getSession(true);

String results = (String) getServletContext().getAttribute(TestListener.class.getName());
Expand All @@ -46,9 +46,9 @@ public void constructortest1(HttpServletRequest request,
}

public void setNameTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpServletResponse response) throws IOException {
String name = "WHO_SHOULD_NOT_BE_NAMED_HERE";
Boolean pass = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -66,9 +66,9 @@ public void setNameTest(HttpServletRequest request,
}

public void setCommentTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpServletResponse response) throws IOException {
String comment = "WHO_SHOULD_NOT_BE_NAMED_HERE";
Boolean pass = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -86,9 +86,9 @@ public void setCommentTest(HttpServletRequest request,
}

public void setPathTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpServletResponse response) throws IOException {
String path = "WHO_SHOULD_NOT_BE_NAMED_HERE";
Boolean pass = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -106,9 +106,9 @@ public void setPathTest(HttpServletRequest request,
}

public void setDomainTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpServletResponse response) throws IOException {
String domain = "WHO_SHOULD_NOT_BE_NAMED_HERE";
Boolean pass = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -126,9 +126,9 @@ public void setDomainTest(HttpServletRequest request,
}

public void setMaxAgeTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
HttpServletResponse response) throws IOException {
int maxage = 12345;
Boolean pass = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -146,9 +146,9 @@ public void setMaxAgeTest(HttpServletRequest request,
}

public void setHttpOnlyTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Boolean http = true;
Boolean pass = true;
HttpServletResponse response) throws IOException {
boolean http = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -166,9 +166,9 @@ public void setHttpOnlyTest(HttpServletRequest request,
}

public void setSecureTest(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
Boolean secure = true;
Boolean pass = true;
HttpServletResponse response) throws IOException {
boolean secure = true;
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

Expand All @@ -184,4 +184,24 @@ public void setSecureTest(HttpServletRequest request,
ServletTestUtil.printResult(pw, pass);
}
}

public void setAttributeTest(HttpServletRequest request,
HttpServletResponse response) throws IOException {
String attribute = "WHO_SHOULD_NOT_BE_NAMED_HERE";
boolean pass = true;
PrintWriter pw = response.getWriter();
HttpSession session = request.getSession();

try {
pw.println("calling method setAttribute");
getServletContext().getSessionCookieConfig().setAttribute(attribute, attribute);
pass = false;
pw.println("Expected IllegalStateException not thrown");
} catch (IllegalStateException ex) {
pw.println("Expected IllegalStateException thrown");
} finally {
session.invalidate();
ServletTestUtil.printResult(pw, pass);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,18 @@ public void setSecureTest() throws Fault {
TEST_PROPS.setProperty(APITEST, "setSecureTest");
invoke();
}

/*
* @testName: setAttributeTest
*
* @assertion_ids:
*
* @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn
* HttpSession on; Verify in servlet SessionCookieConfig.setAttribute cannot be
* called once is set.
*/
public void setAttributeTest() throws Fault {
TEST_PROPS.setProperty(APITEST, "setAttributeTest");
invoke();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.PrintWriter;

import com.sun.javatest.Status;
import com.sun.ts.lib.harness.EETest.Fault;
import com.sun.ts.tests.servlet.common.client.AbstractUrlClient;

public class URLClient extends AbstractUrlClient {
Expand Down Expand Up @@ -177,4 +178,18 @@ public void setSecureTest() throws Fault {
TEST_PROPS.setProperty(APITEST, "setSecureTest");
invoke();
}

/*
* @testName: setAttributeTest
*
* @assertion_ids:
*
* @test_Strategy: Create a Servlet TestServlet, In the Servlet, turn
* HttpSession on; Verify in servlet SessionCookieConfig.setAttribute cannot be
* called once is set.
*/
public void setAttributeTest() throws Fault {
TEST_PROPS.setProperty(APITEST, "setAttributeTest");
invoke();
}
}

0 comments on commit 65a3a0e

Please sign in to comment.