Commit 6f08588c authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fix on few missing API calls that didn't process auth cookie

parent ab1ae16f
......@@ -545,9 +545,7 @@ ServerConnector.getConfiguration = function(params) {
}
var self = this;
if (this._configuration === undefined) {
return self.getToken(params.token).then(function(token) {
return self.readFile(self.getConfigurationUrl());
}).then(function(content) {
return self.readFile(self.getConfigurationUrl()).then(function(content) {
self._configuration = new Configuration(JSON.parse(content));
return Promise.resolve(self._configuration);
});
......@@ -933,9 +931,6 @@ ServerConnector.getOverlaySourceDownloadUrl = function(params) {
var filterParams = {};
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.getOverlaySourceUrl(queryParams, filterParams);
});
};
......@@ -957,9 +952,6 @@ ServerConnector.getImageDownloadUrl = function(params) {
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.getImageUrl(queryParams, filterParams);
});
};
......@@ -980,9 +972,6 @@ ServerConnector.getModelDownloadUrl = function(params) {
};
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.getModelPartUrl(queryParams, filterParams);
});
};
......@@ -1009,9 +998,6 @@ ServerConnector.getProjectSourceDownloadUrl = function(params) {
var self = this;
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.getProjectSourceUrl(queryParams, filterParams);
});
};
......@@ -1095,9 +1081,6 @@ ServerConnector.addComment = function(params) {
delete filterParams.modelId;
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.sendPostRequest(self.addCommentUrl(queryParams), filterParams);
}).then(function(content) {
var response = JSON.parse(content);
......@@ -1110,9 +1093,6 @@ ServerConnector.addOverlay = function(params) {
var queryParams = {};
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
params.token = token;
return self.sendPostRequest(self.addOverlayUrl(queryParams), params);
}).then(function(content) {
var response = JSON.parse(content);
......@@ -1140,9 +1120,6 @@ ServerConnector.updateOverlay = function(params) {
}
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.sendPatchRequest(self.updateOverlayUrl(queryParams), filterParams);
});
};
......@@ -1155,9 +1132,6 @@ ServerConnector.removeOverlay = function(params) {
var filterParams = {};
return self.getProjectId(params.projectId).then(function(result) {
queryParams.projectId = result;
return self.getToken();
}).then(function(token) {
filterParams.token = token;
return self.sendDeleteRequest(self.deleteOverlayUrl(queryParams), filterParams);
});
};
......
......@@ -30,7 +30,7 @@ function urlToFileName(url) {
var result = url;
var token = OriginalServerConnector.getSessionData().getToken();
if (token!==undefined && url.startsWith("./testFiles/apiCalls")) {
if (!result.endsWith("&")) {
if (!result.endsWith("&") &&!result.endsWith("_") ) {
result +="/";
}
result+="token=" +token+"&";
......@@ -92,7 +92,7 @@ ServerConnectorMock.sendPostRequest = function(url, params) {
}
});
} else {
var mockUrl = replaceAsterisk(url + "/POST_" + self.createGetParams(encodeParams(params)));
var mockUrl = urlToFileName(url + "/POST_" + self.createGetParams(encodeParams(params)));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
......@@ -122,7 +122,7 @@ ServerConnectorMock.sendPutRequest = function(url, params) {
}
});
} else {
var mockUrl = url + "/PUT_" + self.createGetParams(encodeParams(params));
var mockUrl = urlToFileName(url + "/PUT_" + self.createGetParams(encodeParams(params)));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
......@@ -152,7 +152,7 @@ ServerConnectorMock.sendDeleteRequest = function(url, params) {
}
});
} else {
var mockUrl = url + "/DELETE_" + self.createGetParams(encodeParams(params));
var mockUrl = urlToFileName(url + "/DELETE_" + self.createGetParams(encodeParams(params)));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
......@@ -182,7 +182,7 @@ ServerConnectorMock.sendPatchRequest = function(url, params) {
}
});
} else {
var mockUrl = url + "/PATCH_" + self.createGetParams(params);
var mockUrl = urlToFileName(url + "/PATCH_" + self.createGetParams(params));
fs.readFile(mockUrl, 'utf8', function(err, content) {
if (err) {
reject(err);
......
......@@ -83,15 +83,50 @@ describe('ServerConnector', function() {
});
it('getOverlaySourceDownloadUrl', function() {
var id = 123;
var id = 17296;
return ServerConnector.getOverlaySourceDownloadUrl({
overlayId : id
}).then(function(url) {
assert.ok(url);
assert.ok(url.indexOf(id) >= 0);
return ServerConnector.readFile(url);
});
});
it('getImageDownloadUrl', function() {
var modelId = 15781;
return ServerConnector.getImageDownloadUrl({
modelId : modelId,
handlerClass : "lcsb.mapviewer.converter.graphics.PngImageGenerator",
}).then(function(url) {
assert.ok(url);
assert.ok(url.indexOf(modelId) >= 0);
return ServerConnector.readFile(url);
});
});
it('getModelDownloadUrl', function() {
var modelId = 15781;
return ServerConnector.getModelDownloadUrl({
modelId : modelId,
handlerClass : "lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser",
}).then(function(url) {
assert.ok(url);
assert.ok(url.indexOf(modelId) >= 0);
return ServerConnector.readFile(url);
});
});
it('getProjectSourceDownloadUrl', function() {
return ServerConnector.getProjectSourceDownloadUrl().then(function(url) {
assert.ok(url);
return ServerConnector.readFile(url);
});
});
it('addOverlay', function() {
return ServerConnector.addOverlay({
name : "test nam",
......@@ -130,13 +165,12 @@ describe('ServerConnector', function() {
assert.ok(url);
});
});
it('getOverlayById', function() {
return ServerConnector.getOverlayById(18083, "complex_model_with_submaps").then(function(overlay) {
assert.ok(overlay);
});
});
it('getConfiguration', function() {
return ServerConnector.getConfiguration().then(function(configuration) {
......@@ -144,5 +178,4 @@ describe('ServerConnector', function() {
});
});
});
......@@ -11,6 +11,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -67,7 +68,7 @@ public class UserController extends BaseController {
@RequestMapping(value = "/users/{login}", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, Object> getUser(//
@RequestParam(value = "token", required = false) String token, //
@CookieValue(value = Configuration.AUTH_TOKEN) String token, //
@PathVariable(value = "login") String login, //
@RequestParam(value = "columns", defaultValue = "") String columns//
) throws SecurityException, ObjectNotFoundException {
......@@ -75,7 +76,7 @@ public class UserController extends BaseController {
}
@RequestMapping(value = "/doLogout", method = { RequestMethod.GET, RequestMethod.POST }, produces = { MediaType.APPLICATION_JSON_VALUE })
public Map<String, String> logout(@RequestParam(value = "token", required = false) String token) throws SecurityException {
public Map<String, String> logout(@CookieValue(value = Configuration.AUTH_TOKEN) String token) throws SecurityException {
userService.logout(token);
Map<String, String> response = new HashMap<>();
response.put("status", "OK");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment