summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorPiotr Janik2011-06-09 05:25:59 (EDT)
committer Szymon Brandys2011-06-09 05:25:59 (EDT)
commit6f263d5c55081747442c2f5fdc3826674165c377 (patch)
treea5b6f255dcf3f12dd5eddd0b2ab4324d3256ed6d
parentad812b5bc72aa5c50947a9ae7b73c984fe67fd8d (diff)
downloadorg.eclipse.orion.server-6f263d5c55081747442c2f5fdc3826674165c377.zip
org.eclipse.orion.server-6f263d5c55081747442c2f5fdc3826674165c377.tar.gz
org.eclipse.orion.server-6f263d5c55081747442c2f5fdc3826674165c377.tar.bz2
bug 348748 - [server][git] GET on git config returns 500 when repository
is in subfolder https://bugs.eclipse.org/bugs/show_bug.cgi?id=348748
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitConfigHandlerV1.java35
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitConfigTest.java254
2 files changed, 152 insertions, 137 deletions
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitConfigHandlerV1.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitConfigHandlerV1.java
index 88d13a7..58fb7a1 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitConfigHandlerV1.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitConfigHandlerV1.java
@@ -67,7 +67,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
Path p = new Path(path);
if (p.segment(0).equals("clone") && p.segment(1).equals("file")) { //$NON-NLS-1$ //$NON-NLS-2$
// expected path /gitapi/config/clone/file/{path}
- File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1).uptoSegment(2));
+ File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
FileBasedConfig config = getLocalConfig(gitDir);
URI baseLocation = getURI(request);
@@ -76,7 +76,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
return true;
} else if (p.segment(1).equals("clone") && p.segment(2).equals("file")) { //$NON-NLS-1$ //$NON-NLS-2$
// expected path /gitapi/config/{key}/clone/file/{path}
- File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2).uptoSegment(2));
+ File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
Repository db = new FileRepository(gitDir);
StoredConfig config = db.getConfig();
URI baseLocation = getURI(request);
@@ -85,10 +85,10 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
String[] keySegments = keyToSegments(key);
if (keySegments == null)
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Config entry key must be provided in the following form: section[.subsection].name", null));
- JSONObject result = configEntryToJSON(config, keySegments, baseLocation);
- if (result == null)
+ if (!variableExist(config, keySegments))
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "There is no config entry with key provided", null));
+ JSONObject result = configEntryToJSON(config, keySegments, baseLocation);
OrionServlet.writeJSONResponse(request, response, result);
return true;
}
@@ -99,7 +99,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
Path p = new Path(path);
if (p.segment(0).equals("clone") && p.segment(1).equals("file")) { //$NON-NLS-1$ //$NON-NLS-2$
// expected path /gitapi/config/clone/file/{path}
- File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1).uptoSegment(2));
+ File gitDir = GitUtils.getGitDir(p.removeFirstSegments(1));
FileBasedConfig config = getLocalConfig(gitDir);
URI baseLocation = getURI(request);
@@ -115,9 +115,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Config entry key must be provided in the following form: section[.subsection].name", null));
// determine if config entry is already present
- boolean present = false;
- if (config.getString(keySegments[0], keySegments[1], keySegments[2]) != null)
- present = true;
+ boolean present = variableExist(config, keySegments);
// set new value
config.setString(keySegments[0], keySegments[1], keySegments[2], value);
@@ -137,7 +135,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
Path p = new Path(path);
if (p.segment(1).equals("clone") && p.segment(2).equals("file")) { //$NON-NLS-1$ //$NON-NLS-2$
// expected path /gitapi/config/{key}/clone/file/{path}
- File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2).uptoSegment(2));
+ File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
FileBasedConfig config = getLocalConfig(gitDir);
URI baseLocation = getURI(request);
@@ -155,7 +153,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Config entry key must be provided in the following form: section[.subsection].name", null));
// PUT allows only to modify existing config entries
- if (config.getString(keySegments[0], keySegments[1], keySegments[2]) == null) {
+ if (!variableExist(config, keySegments)) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return true;
}
@@ -176,7 +174,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
Path p = new Path(path);
if (p.segment(1).equals("clone") && p.segment(2).equals("file")) { //$NON-NLS-1$ //$NON-NLS-2$
// expected path /gitapi/config/{key}/clone/file/{path}
- File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2).uptoSegment(2));
+ File gitDir = GitUtils.getGitDir(p.removeFirstSegments(2));
FileBasedConfig config = getLocalConfig(gitDir);
String key = p.segment(0);
@@ -185,7 +183,7 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Config entry key must be provided in the following form: section[.subsection].name", null));
// determine if config entry exist
- if (config.getString(keySegments[0], keySegments[1], keySegments[2]) != null) {
+ if (variableExist(config, keySegments)) {
// delete
config.unset(keySegments[0], keySegments[1], keySegments[2]);
config.save();
@@ -225,11 +223,10 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
}
// reads configuration entry and converts it to JSON representation
- // returns null if there is no entry with given key
JSONObject configEntryToJSON(Config config, String[] keySegments, URI baseLocation) throws JSONException, URISyntaxException {
String value = config.getString(keySegments[0], keySegments[1], keySegments[2]);
if (value == null)
- return null;
+ value = "";
String key = segmentsToKey(keySegments);
JSONObject result = new JSONObject();
@@ -239,6 +236,16 @@ public class GitConfigHandlerV1 extends ServletResourceHandler<String> {
return result;
}
+ // checks if given variable exist in configuration
+ boolean variableExist(Config config, String[] keySegments) {
+ if (keySegments[1] != null && !config.getNames(keySegments[0], keySegments[1]).contains(keySegments[2]))
+ return false;
+ else if (keySegments[1] == null && !config.getNames(keySegments[0]).contains(keySegments[2]))
+ return false;
+
+ return true;
+ }
+
// converts segments of key to key representation
// returns null if input array is invalid
private String segmentsToKey(String[] segments) {
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitConfigTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitConfigTest.java
index f4e63b9..4332c30 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitConfigTest.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitConfigTest.java
@@ -113,134 +113,142 @@ public class GitConfigTest extends GitTest {
@Test
public void testSetAndUnsetConfigValues() throws Exception {
- // clone a repo
URI workspaceLocation = createWorkspace(getMethodName());
- JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
- IPath clonePath = new Path("file").append(project.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
- String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
-
- // get project metadata
- WebRequest request = getGetFilesRequest(contentLocation);
- WebResponse response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- project = new JSONObject(response.getText());
- JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
- assertNotNull(gitSection);
-
- String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);
- assertNotNull(gitConfigUri);
-
- // get list of config entries
- request = getGetGitConfigRequest(gitConfigUri);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- JSONObject configResponse = new JSONObject(response.getText());
- JSONArray configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
- // initial number of config entries
- int initialConfigEntriesCount = configEntries.length();
-
- // set some dummy value
- final String ENTRY_KEY = "sectionA.subsectionB.nameC";
- final String ENTRY_VALUE = "valueXYZ";
-
- request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
-
- // get list of config entries again
- request = getGetGitConfigRequest(gitConfigUri);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- configResponse = new JSONObject(response.getText());
- configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
- assertEquals(initialConfigEntriesCount + 1, configEntries.length());
-
- String entryLocation = null;
- for (int i = 0; i < configEntries.length(); i++) {
- JSONObject configEntry = configEntries.getJSONObject(i);
- if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
- assertEquals(ENTRY_VALUE, configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_VALUE));
- entryLocation = configEntry.getString(ProtocolConstants.KEY_LOCATION);
+ JSONObject projectTop = createProjectOrLink(workspaceLocation, getMethodName() + "-top", null);
+ IPath clonePathTop = new Path("file").append(projectTop.getString(ProtocolConstants.KEY_ID)).makeAbsolute();
+
+ JSONObject projectFolder = createProjectOrLink(workspaceLocation, getMethodName() + "-folder", null);
+ IPath clonePathFolder = new Path("file").append(projectFolder.getString(ProtocolConstants.KEY_ID)).append("folder").makeAbsolute();
+
+ IPath[] clonePaths = new IPath[] {clonePathTop, clonePathFolder};
+
+ for (IPath clonePath : clonePaths) {
+ // clone a repo
+ String contentLocation = clone(clonePath).getString(ProtocolConstants.KEY_CONTENT_LOCATION);
+
+ // get project metadata
+ WebRequest request = getGetFilesRequest(contentLocation);
+ WebResponse response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject project = new JSONObject(response.getText());
+ JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT);
+ assertNotNull(gitSection);
+
+ String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);
+ assertNotNull(gitConfigUri);
+
+ // get list of config entries
+ request = getGetGitConfigRequest(gitConfigUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ JSONObject configResponse = new JSONObject(response.getText());
+ JSONArray configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ // initial number of config entries
+ int initialConfigEntriesCount = configEntries.length();
+
+ // set some dummy value
+ final String ENTRY_KEY = "sectionA.subsectionB.nameC";
+ final String ENTRY_VALUE = "valueXYZ";
+
+ request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());
+
+ // get list of config entries again
+ request = getGetGitConfigRequest(gitConfigUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ configResponse = new JSONObject(response.getText());
+ configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(initialConfigEntriesCount + 1, configEntries.length());
+
+ String entryLocation = null;
+ for (int i = 0; i < configEntries.length(); i++) {
+ JSONObject configEntry = configEntries.getJSONObject(i);
+ if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
+ assertEquals(ENTRY_VALUE, configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_VALUE));
+ entryLocation = configEntry.getString(ProtocolConstants.KEY_LOCATION);
+ }
}
- }
- assertNotNull(entryLocation);
-
- // update config entry using POST
- final String NEW_ENTRY_VALUE_1 = "valueABC";
-
- request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, NEW_ENTRY_VALUE_1);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
-
- // get list of config entries again
- request = getGetGitConfigRequest(gitConfigUri);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- configResponse = new JSONObject(response.getText());
- configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
- assertEquals(initialConfigEntriesCount + 1, configEntries.length());
-
- entryLocation = null;
- for (int i = 0; i < configEntries.length(); i++) {
- JSONObject configEntry = configEntries.getJSONObject(i);
- if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
- assertEquals(NEW_ENTRY_VALUE_1, configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_VALUE));
- entryLocation = configEntry.getString(ProtocolConstants.KEY_LOCATION);
+ assertNotNull(entryLocation);
+
+ // update config entry using POST
+ final String NEW_ENTRY_VALUE_1 = "valueABC";
+
+ request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, NEW_ENTRY_VALUE_1);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // get list of config entries again
+ request = getGetGitConfigRequest(gitConfigUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ configResponse = new JSONObject(response.getText());
+ configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(initialConfigEntriesCount + 1, configEntries.length());
+
+ entryLocation = null;
+ for (int i = 0; i < configEntries.length(); i++) {
+ JSONObject configEntry = configEntries.getJSONObject(i);
+ if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
+ assertEquals(NEW_ENTRY_VALUE_1, configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_VALUE));
+ entryLocation = configEntry.getString(ProtocolConstants.KEY_LOCATION);
+ }
}
- }
- assertNotNull(entryLocation);
-
- // update config entry using PUT
- final String NEW_ENTRY_VALUE_2 = "valueABCXYZ";
-
- request = getPutGitConfigRequest(entryLocation, NEW_ENTRY_VALUE_2);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
-
- // get list of config entries again
- request = getGetGitConfigRequest(gitConfigUri);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- configResponse = new JSONObject(response.getText());
- configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
- assertEquals(initialConfigEntriesCount + 1, configEntries.length());
-
- entryLocation = null;
- for (int i = 0; i < configEntries.length(); i++) {
- JSONObject configEntry = configEntries.getJSONObject(i);
- if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
- assertEquals(NEW_ENTRY_VALUE_2, configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_VALUE));
- entryLocation = configEntry.getString(ProtocolConstants.KEY_LOCATION);
+ assertNotNull(entryLocation);
+
+ // update config entry using PUT
+ final String NEW_ENTRY_VALUE_2 = "valueABCXYZ";
+
+ request = getPutGitConfigRequest(entryLocation, NEW_ENTRY_VALUE_2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // get list of config entries again
+ request = getGetGitConfigRequest(gitConfigUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ configResponse = new JSONObject(response.getText());
+ configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(initialConfigEntriesCount + 1, configEntries.length());
+
+ entryLocation = null;
+ for (int i = 0; i < configEntries.length(); i++) {
+ JSONObject configEntry = configEntries.getJSONObject(i);
+ if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY))) {
+ assertEquals(NEW_ENTRY_VALUE_2, configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_VALUE));
+ entryLocation = configEntry.getString(ProtocolConstants.KEY_LOCATION);
+ }
}
+ assertNotNull(entryLocation);
+
+ // test PUT with invalid entry
+ String invalidEntryLocation = entryLocation.replace(ENTRY_KEY, "qwerty.asdfg");
+ request = getPutGitConfigRequest(invalidEntryLocation, NEW_ENTRY_VALUE_2);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
+
+ // delete config entry
+ request = getDeleteGitConfigRequest(entryLocation);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+
+ // get list of config entries again
+ request = getGetGitConfigRequest(gitConfigUri);
+ response = webConversation.getResponse(request);
+ assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
+ configResponse = new JSONObject(response.getText());
+ configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
+ assertEquals(initialConfigEntriesCount, configEntries.length());
+
+ boolean found = false;
+ for (int i = 0; i < configEntries.length(); i++) {
+ JSONObject configEntry = configEntries.getJSONObject(i);
+ if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY)))
+ found = true;
+ }
+ assertEquals(false, found);
}
- assertNotNull(entryLocation);
-
- // test PUT with invalid entry
- String invalidEntryLocation = entryLocation.replace(ENTRY_KEY, "qwerty.asdfg");
- request = getPutGitConfigRequest(invalidEntryLocation, NEW_ENTRY_VALUE_2);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
-
- // delete config entry
- request = getDeleteGitConfigRequest(entryLocation);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
-
- // get list of config entries again
- request = getGetGitConfigRequest(gitConfigUri);
- response = webConversation.getResponse(request);
- assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
- configResponse = new JSONObject(response.getText());
- configEntries = configResponse.getJSONArray(ProtocolConstants.KEY_CHILDREN);
- assertEquals(initialConfigEntriesCount, configEntries.length());
-
- boolean found = false;
- for (int i = 0; i < configEntries.length(); i++) {
- JSONObject configEntry = configEntries.getJSONObject(i);
- if (ENTRY_KEY.equals(configEntry.getString(GitConstants.KEY_CONFIG_ENTRY_KEY)))
- found = true;
- }
- assertEquals(false, found);
}
static WebRequest getDeleteGitConfigRequest(String location) {