Skip to content

Commit

Permalink
Review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-krueger committed Mar 25, 2024
1 parent c504dde commit 585b81f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -875,36 +875,29 @@ public void containsHeaderStringTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
assertTrue(context.containsHeaderString("header1", "value"::equalsIgnoreCase));
assertTrue(context.containsHeaderString("header1", "value"::equals));
assertTrue(context.containsHeaderString("HEADER1", ",", "value2"::equals));
//Incorrect separator character
assertFalse(context.containsHeaderString("header1", ";", "value2"::equalsIgnoreCase));
assertFalse(context.containsHeaderString("header1", ";", "value2"::equals));
//Shouldn't find first value when separator character is incorrect
assertFalse(context.containsHeaderString("header1", ";", "value1"::equalsIgnoreCase));
assertFalse(context.containsHeaderString("header1", ";", "Value1"::equalsIgnoreCase));
//Test regular expression
assertTrue(context.containsHeaderString("header1", ";|,", "value2"::equalsIgnoreCase));
assertTrue(context.containsHeaderString("header1", ";|,", "VALUE2"::equalsIgnoreCase));
//White space in value not trimmed
assertFalse(context.containsHeaderString("header1", "whitespace"::equalsIgnoreCase));
assertFalse(context.containsHeaderString("header1", "whitespace"::equals));
//Multiple character separator
assertTrue(context.containsHeaderString("header2", "::", "Value5"::equalsIgnoreCase));
//Test default separator is comma
assertFalse(context.containsHeaderString("header3","value6"::equalsIgnoreCase));
String entity = "Success";
Response r = Response.ok(entity).build();
assertTrue(context.containsHeaderString("header2", ";;", "Value5"::equalsIgnoreCase));
Response r = Response.ok().build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider)
.header("header1", "value")
.header("header1", "value1 , value2")
.header("header1", "Value3,white space ")
.header("header2", "Value4::Value5")
.header("header3", "value6;value7")
.header("header2", "Value4;;Value5")
.buildGet();
Response response = invoke(invocation);

String entity = response.readEntity(String.class);
assertTrue(entity.contains("Success"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,38 +438,30 @@ protected void checkFilterContext(ClientRequestContext requestContext,
*/
@Test
public void containsHeaderStringTest() throws Fault {
final String header1 = "Header1";
final String value1 = "no-store";
final String value2 = "{Max - Age, no-transform}";
final String header2 = "header2";
final String value3 = "{no-store;no-transform}";

ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext,
ClientResponseContext responseContext) throws Fault {
assertTrue(responseContext.containsHeaderString("header1", "value"::equalsIgnoreCase));
assertTrue(responseContext.containsHeaderString("header1", "value"::equals));
assertTrue(responseContext.containsHeaderString("HEADER1", ",", "value2"::equals));
//Incorrect separator character
assertFalse(responseContext.containsHeaderString("header1", ";", "value2"::equalsIgnoreCase));
assertFalse(responseContext.containsHeaderString("header1", ";", "value2"::equals));
//Shouldn't find first value when separator character is incorrect
assertFalse(responseContext.containsHeaderString("header1", ";", "value1"::equalsIgnoreCase));
assertFalse(responseContext.containsHeaderString("header1", ";", "Value1"::equalsIgnoreCase));
//Test regular expression
assertTrue(responseContext.containsHeaderString("header1", ";|,", "value2"::equalsIgnoreCase));
assertTrue(responseContext.containsHeaderString("header1", ";|,", "VALUE2"::equalsIgnoreCase));
//White space in value not trimmed
assertFalse(responseContext.containsHeaderString("header1", "whitespace"::equalsIgnoreCase));
//Multiple character separator
assertTrue(responseContext.containsHeaderString("header2", "::", "Value5"::equalsIgnoreCase));
//Test default separator is comma
assertFalse(responseContext.containsHeaderString("header3","value6"::equalsIgnoreCase));
assertTrue(responseContext.containsHeaderString("header2", ";;", "Value5"::equalsIgnoreCase));
}
};
Response response = Response.ok()
.header("header1", "value")
.header("header1", "value1 , value2")
.header("header1", "Value3,white space ")
.header("header2", "Value4::Value5")
.header("header3", "value6;value7")
.header("header2", "Value4;;Value5")
.build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,32 @@ public String headersGet() {
@Path("/contains-headers")
public String containsHeadersGet() {
sb = new StringBuffer();
List<String> myHeaders = Arrays.asList("Accept", "Content-Type", "Header3");
sb.append("containsHeaderString= ");

try {
assertTrue(hs.containsHeaderString("accept", "text/html"::equalsIgnoreCase));
sb.append("Header: accept contains text/html; ");
if(hs.containsHeaderString("accept", "text/html"::equals)) {
sb.append("Test1: accept contains text/html; ");
}

//Verify Predicate and separator character usage
assertTrue(hs.containsHeaderString("Accept", ",", "Text/html;Level=1"::equalsIgnoreCase));
sb.append("Header: accept contains text/html;level=1; ");
if (hs.containsHeaderString("Accept", ",", "Text/html;Level=1"::equalsIgnoreCase)) {
sb.append("Test2: accept contains text/html;level=1; ");
}

//Verify incorrect separator character fails
assertFalse(hs.containsHeaderString("Accept", ";", "text/html;level=1"::equals));
sb.append("Incorrect separator character fails as expected; ");
if (!(hs.containsHeaderString("Accept", ";", "text/html;level=1"::equals))) {
sb.append("Test3: Incorrect separator character fails as expected; ");
}

//Verify white space in parameter not trimmed
assertFalse(hs.containsHeaderString("header3", "**", "value3"::equalsIgnoreCase));
sb.append("White space not trimmed from parameter as expected; ");
//Verify white space in value not trimmed and double character separator
if (!(hs.containsHeaderString("header3", ";;", "value3"::equals))) {
sb.append("Test4: White space not trimmed from value as expected; ");
}

//Verify white space in front and back of value trimmed
assertTrue(hs.containsHeaderString("HEADER3", "**", "value2"::equalsIgnoreCase));
sb.append("White space trimmed around value as expected; ");
if (hs.containsHeaderString("HEADER3", ";;", "value2"::equalsIgnoreCase)) {
sb.append("Test5: White space trimmed around value as expected; ");
}
} catch (Throwable ex) {
sb.append("Unexpected exception thrown in containsHeadersGet: "
+ ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,13 @@ public void containsHeaderStringTest() throws Fault {
setProperty(Property.REQUEST_HEADERS,
"Content-Type:application/xml;charset=utf8");
setProperty(Property.REQUEST_HEADERS,
"Header3:value1 ** value2 **value 3");
"Header3:value1 ;; Value2 ;;value 3");
setProperty(Property.REQUEST, buildRequest(Request.GET, "contains-headers"));
setProperty(Property.SEARCH_STRING, "Test1");
setProperty(Property.SEARCH_STRING, "Test2");
setProperty(Property.SEARCH_STRING, "Test3");
setProperty(Property.SEARCH_STRING, "Test4");
setProperty(Property.SEARCH_STRING, "Test5");
invoke();
}

Expand Down

0 comments on commit 585b81f

Please sign in to comment.