Skip to content

Commit

Permalink
getRequests: handle empty input
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyZ1435 committed Oct 28, 2022
1 parent dcdf8e8 commit b77a477
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions src/main/java/ca/utoronto/utm/mcs/ReqHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public void addActor(HttpExchange r) throws IOException, JSONException {
if (deserialized.has("name") && deserialized.has("actorId")) {
name = deserialized.getString("name");
actorId = deserialized.getString("actorId");
if(name.isEmpty() || actorId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down Expand Up @@ -130,6 +134,10 @@ public void addMovie(HttpExchange r) throws IOException, JSONException {
if (deserialized.has("name") && deserialized.has("movieId")) {
name = deserialized.getString("name");
movieId = deserialized.getString("movieId");
if(name.isEmpty() || movieId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down Expand Up @@ -159,6 +167,10 @@ public void addRelationship(HttpExchange r) throws IOException, JSONException {
if (deserialized.has("actorId") && deserialized.has("movieId")) {
actorId = deserialized.getString("actorId");
movieId = deserialized.getString("movieId");
if(movieId.isEmpty() || actorId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down Expand Up @@ -187,6 +199,10 @@ public void getActor(HttpExchange r) throws IOException {

if (deserialized.has("actorId")) {
actorId = deserialized.getString("actorId");
if(actorId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down Expand Up @@ -220,6 +236,10 @@ public void getMovie(HttpExchange r) throws IOException {

if (deserialized.has("movieId")) {
movieId = deserialized.getString("movieId");
if(movieId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down Expand Up @@ -253,6 +273,10 @@ public void hasRelationship(HttpExchange r) throws IOException {
if (deserialized.has("actorId") && deserialized.has("movieId")) {
movieId = deserialized.getString("movieId");
actorId = deserialized.getString("actorId");
if(movieId.isEmpty() || actorId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down Expand Up @@ -286,6 +310,10 @@ public void computeBaconNumber(HttpExchange r) throws IOException, JSONException

if (deserialized.has("actorId")) {
actorId = deserialized.getString("actorId");
if(actorId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {

r.sendResponseHeaders(400, -1);
Expand Down Expand Up @@ -320,6 +348,10 @@ public void computeBaconPath(HttpExchange r) throws IOException, JSONException{

if (deserialized.has("actorId")) {
actorId = deserialized.getString("actorId");
if(actorId.isEmpty()){
r.sendResponseHeaders(400, -1);
return;
}
} else {
r.sendResponseHeaders(400, -1);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/ca/utoronto/utm/mcs/AppTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void exampleTest() {
public void addActorPass() throws JSONException, IOException, InterruptedException {
JSONObject confirmReq = new JSONObject()
.put("name", "TestActor")
.put("actorId", "12345678901");
.put("actorId", "");
HttpResponse<String> confirmRes = sendRequest("/api/v1/addActor", "PUT", confirmReq.toString());
sendRequest("/api/v1/deleteActor", "DELETE", confirmReq.toString());
assertEquals(HttpURLConnection.HTTP_OK, confirmRes.statusCode());
Expand Down

0 comments on commit b77a477

Please sign in to comment.