mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ZD-611794 Add missing API access key in request for single issue in Redmine
This commit is contained in:
@@ -125,10 +125,7 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
|
||||
// /users/current.json. Unfortunately this endpoint may be unavailable on some old servers (see IDEA-122845)
|
||||
// and in this case we have to come back to requesting issues in this case to test anything at all.
|
||||
|
||||
URIBuilder uriBuilder = new URIBuilder(getRestApiUrl("users", "current.json"));
|
||||
if (isUseApiKeyAuthentication()) {
|
||||
uriBuilder.addParameter("key", getAPIKey());
|
||||
}
|
||||
URIBuilder uriBuilder = createUriBuilderWithApiKey("users", "current.json");
|
||||
myCurrentRequest.setURI(uriBuilder.build());
|
||||
HttpClient client = getHttpClient();
|
||||
|
||||
@@ -182,7 +179,7 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
|
||||
}
|
||||
|
||||
private URI getIssuesUrl(int offset, int limit, boolean withClosed) throws URISyntaxException {
|
||||
URIBuilder builder = new URIBuilder(getRestApiUrl("issues.json"))
|
||||
URIBuilder builder = createUriBuilderWithApiKey("issues.json")
|
||||
.addParameter("offset", String.valueOf(offset))
|
||||
.addParameter("limit", String.valueOf(limit))
|
||||
.addParameter("sort", "updated_on:desc")
|
||||
@@ -194,9 +191,6 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
|
||||
if (myCurrentProject != null && myCurrentProject != UNSPECIFIED_PROJECT) {
|
||||
builder.addParameter("project_id", String.valueOf(myCurrentProject.getId()));
|
||||
}
|
||||
if (isUseApiKeyAuthentication()) {
|
||||
builder.addParameter("key", myAPIKey);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -221,12 +215,9 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
|
||||
|
||||
@NotNull
|
||||
private URI getProjectsUrl(int offset, int limit) throws URISyntaxException {
|
||||
URIBuilder builder = new URIBuilder(getRestApiUrl("projects.json"));
|
||||
URIBuilder builder = createUriBuilderWithApiKey("projects.json");
|
||||
builder.addParameter("offset", String.valueOf(offset));
|
||||
builder.addParameter("limit", String.valueOf(limit));
|
||||
if (isUseApiKeyAuthentication()) {
|
||||
builder.addParameter("key", myAPIKey);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@@ -234,7 +225,7 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
|
||||
@Override
|
||||
public Task findTask(@NotNull String id) throws Exception {
|
||||
ensureProjectsDiscovered();
|
||||
HttpGet method = new HttpGet(getRestApiUrl("issues", id + ".json"));
|
||||
HttpGet method = new HttpGet(createUriBuilderWithApiKey("issues", id + ".json").build());
|
||||
IssueWrapper wrapper = getHttpClient().execute(method, new GsonSingleObjectDeserializer<IssueWrapper>(GSON, IssueWrapper.class, true));
|
||||
if (wrapper == null) {
|
||||
return null;
|
||||
@@ -262,6 +253,15 @@ public class RedmineRepository extends NewBaseRepositoryImpl {
|
||||
return !isUseHttpAuthentication() && StringUtil.isNotEmpty(myAPIKey);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private URIBuilder createUriBuilderWithApiKey(@NotNull Object... pathParts) throws URISyntaxException {
|
||||
final URIBuilder builder = new URIBuilder(getRestApiUrl(pathParts));
|
||||
if (isUseApiKeyAuthentication()) {
|
||||
builder.addParameter("key", myAPIKey);
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableName() {
|
||||
String name = super.getPresentableName();
|
||||
|
||||
+14
@@ -18,6 +18,7 @@ import java.util.List;
|
||||
*/
|
||||
public class RedmineIntegrationTest extends TaskManagerTestCase {
|
||||
private static final String REDMINE_2_0_TEST_SERVER_URL = "http://trackers-tests.labs.intellij.net:8072";
|
||||
private static final String API_ACCESS_KEY = "b60d03b2449869ee1a4ba331011a32e50475f820";
|
||||
|
||||
private RedmineRepository myRepository;
|
||||
|
||||
@@ -125,6 +126,19 @@ public class RedmineIntegrationTest extends TaskManagerTestCase {
|
||||
assertEquals(issues[0].getSummary(), "This issue was created for project filtering tests. Do not change it.");
|
||||
}
|
||||
|
||||
// ZD-611794
|
||||
public void testSingleIssueRequestedWithApiKey() throws Exception {
|
||||
myRepository.setUseHttpAuthentication(false);
|
||||
myRepository.setAPIKey(API_ACCESS_KEY);
|
||||
try {
|
||||
assertNotNull(myRepository.findTask("1"));
|
||||
}
|
||||
finally {
|
||||
myRepository.setAPIKey("");
|
||||
myRepository.setUseHttpAuthentication(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
Reference in New Issue
Block a user