Skip to content

Commit

Permalink
Ignore null session IDs passed in a command's JSON body. This adds to…
Browse files Browse the repository at this point in the history
…lerance for

clients that serialize a null session ID as part of a new session command.
  • Loading branch information
jleyba committed Jul 16, 2014
1 parent e532af1 commit d85c6e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ public int compare(CommandSpec a, CommandSpec b) {
String name = nameToSpec.inverse().get(spec);
SessionId sessionId = null;
if (parameters.containsKey(SESSION_ID_PARAM)) {
sessionId = new SessionId((String) parameters.remove(SESSION_ID_PARAM));
String id = (String) parameters.remove(SESSION_ID_PARAM);
if (id != null) {
sessionId = new SessionId(id);
}
}

return new Command(sessionId, name, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,26 @@ public void extractsAllPrameters() throws JSONException, URISyntaxException {
codec.defineCommand("pick", POST, "/fruit/:fruit/size/:size");

Command decoded = codec.decode(request);
assertThat(decoded.getSessionId(), is(new SessionId("sessionX")));
assertThat(decoded.getParameters(), is((Map) ImmutableMap.of(
"fruit", "apple", "size", "large", "color", "red")));
}

@Test
public void ignoresNullSessionIdInSessionBody() throws JSONException, URISyntaxException {
String data = new JSONObject()
.put("sessionId", JSONObject.NULL)
.put("fruit", "apple")
.put("color", "red")
.put("size", "large")
.toString();

HttpRequest request = new HttpRequest(POST, "/fruit/apple/size/large");
request.setContent(data.getBytes(UTF_8));
codec.defineCommand("pick", POST, "/fruit/:fruit/size/:size");

Command decoded = codec.decode(request);
assertThat(decoded.getSessionId(), is(nullValue()));
assertThat(decoded.getParameters(), is((Map) ImmutableMap.of(
"fruit", "apple", "size", "large", "color", "red")));
}
Expand Down

0 comments on commit d85c6e1

Please sign in to comment.