diff options
author | Harald Musum <musum@oath.com> | 2017-12-11 08:19:26 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2017-12-11 08:19:26 +0100 |
commit | da89e2c96641045428f36b0df5da3e10656ce7f0 (patch) | |
tree | 5c3ea6fcc09e9b7f294c099bada3b92656c44008 /node-repository | |
parent | 8ab402d1a54c8db21d9a78d1c335792801663469 (diff) |
Fix off-by-one error when getting hostname from request
The / would be included in hostname, which just happened to work because
code further down handled getting //hostname in requests
Diffstat (limited to 'node-repository')
2 files changed, 6 insertions, 2 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java index 797453b12c9..b47b3544d17 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/v2/NodesApiHandler.java @@ -184,8 +184,7 @@ public class NodesApiHandler extends LoggingRequestHandler { } private Node nodeFromRequest(HttpRequest request) { - String path = request.getUri().getPath(); - String hostname = path.substring(path.lastIndexOf("/")); + String hostname = lastElement(request.getUri().getPath()); return nodeRepository.getNode(hostname).orElseThrow(() -> new NotFoundException("No node found with hostname " + hostname)); diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java index 2739b4d1cf8..c23a7f9990a 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/v2/RestApiTest.java @@ -455,6 +455,11 @@ public class RestApiTest { Request.Method.PATCH), "{\"message\":\"Updated host4.yahoo.com\"}"); + assertResponse(new Request("http://localhost:8080/nodes/v2/node/doesnotexist.yahoo.com", + Utf8.toBytes("{\"currentRestartGeneration\": 1}"), + Request.Method.PATCH), + 404, "{\"error-code\":\"NOT_FOUND\",\"message\":\"No node found with hostname doesnotexist.yahoo.com\"}"); + assertResponse(new Request("http://localhost:8080/nodes/v2/node/host5.yahoo.com", Utf8.toBytes("{\"currentRestartGeneration\": 1}"), Request.Method.PATCH), |