Merge pull request #678 from Argelbargel/fix-655
Fixes NPE if GitLab connection fails
This commit is contained in:
commit
8ccafe71ee
|
@ -138,7 +138,7 @@ public class GitLabConnectionConfig extends GlobalConfiguration {
|
|||
@QueryParameter int connectionTimeout,
|
||||
@QueryParameter int readTimeout) {
|
||||
try {
|
||||
new GitLabConnection("", url, apiTokenId, clientBuilderId, ignoreCertificateErrors, connectionTimeout, readTimeout).getClient().headCurrentUser();
|
||||
new GitLabConnection("", url, apiTokenId, clientBuilderId, ignoreCertificateErrors, connectionTimeout, readTimeout).getClient().getCurrentUser();
|
||||
return FormValidation.ok(Messages.connection_success());
|
||||
} catch (WebApplicationException e) {
|
||||
return FormValidation.error(Messages.connection_error(e.getMessage()));
|
||||
|
|
|
@ -36,8 +36,6 @@ public interface GitLabClient {
|
|||
|
||||
Branch getBranch(String projectId, String branch);
|
||||
|
||||
void headCurrentUser();
|
||||
|
||||
User getCurrentUser();
|
||||
|
||||
User addUser(String email, String username, String name, String password);
|
||||
|
|
|
@ -198,18 +198,6 @@ final class AutodetectingGitLabClient implements GitLabClient {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
execute(
|
||||
new GitLabOperation<Void>() {
|
||||
@Override
|
||||
Void execute(GitLabClient client) {
|
||||
client.headCurrentUser();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return execute(
|
||||
|
@ -287,7 +275,7 @@ final class AutodetectingGitLabClient implements GitLabClient {
|
|||
for (GitLabClientBuilder candidate : builders) {
|
||||
GitLabClient client = candidate.buildClient(url, token, ignoreCertificateErrors, connectionTimeout, readTimeout);
|
||||
try {
|
||||
client.headCurrentUser();
|
||||
client.getCurrentUser();
|
||||
return client;
|
||||
} catch (NotFoundException ignored) {
|
||||
// api-endpoint not found (== api-level not supported by this client)
|
||||
|
|
|
@ -95,11 +95,6 @@ final class ResteasyGitLabClient implements GitLabClient {
|
|||
return api.getBranch(projectId, branch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
api.headCurrentUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return api.getCurrentUser();
|
||||
|
|
|
@ -46,7 +46,7 @@ public class AutodetectingGitLabClientTest {
|
|||
@Test
|
||||
public void buildClient_success_v3() throws Exception {
|
||||
mockServerClient.when(v3Request).respond(responseOk());
|
||||
api.headCurrentUser();
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V3GitLabApiProxy.class);
|
||||
mockServerClient.verify(v3Request, v3Request);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class AutodetectingGitLabClientTest {
|
|||
public void buildClient_success_v4() throws Exception {
|
||||
mockServerClient.when(v3Request).respond(responseNotFound());
|
||||
mockServerClient.when(v4Request).respond(responseOk());
|
||||
api.headCurrentUser();
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V4GitLabApiProxy.class);
|
||||
mockServerClient.verify(v3Request, v4Request, v4Request);
|
||||
}
|
||||
|
@ -64,12 +64,12 @@ public class AutodetectingGitLabClientTest {
|
|||
public void buildClient_success_switching_apis() throws Exception {
|
||||
mockServerClient.when(v3Request, once()).respond(responseNotFound());
|
||||
mockServerClient.when(v4Request, exactly(2)).respond(responseOk());
|
||||
api.headCurrentUser();
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V4GitLabApiProxy.class);
|
||||
|
||||
mockServerClient.when(v4Request, once()).respond(responseNotFound());
|
||||
mockServerClient.when(v3Request, exactly(2)).respond(responseOk());
|
||||
api.headCurrentUser();
|
||||
api.getCurrentUser();
|
||||
assertApiImpl(api, V3GitLabApiProxy.class);
|
||||
|
||||
mockServerClient.verify(v3Request, v4Request, v4Request, v3Request, v3Request);
|
||||
|
@ -80,7 +80,7 @@ public class AutodetectingGitLabClientTest {
|
|||
mockServerClient.when(v3Request).respond(responseNotFound());
|
||||
mockServerClient.when(v4Request).respond(responseNotFound());
|
||||
try {
|
||||
api.headCurrentUser();
|
||||
api.getCurrentUser();
|
||||
fail("endpoint should throw exception when no matching delegate is found");
|
||||
} catch (NoSuchElementException e) {
|
||||
mockServerClient.verify(v3Request, v4Request);
|
||||
|
|
|
@ -19,7 +19,7 @@ import java.io.IOException;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.ws.rs.HttpMethod.HEAD;
|
||||
import static javax.ws.rs.HttpMethod.GET;
|
||||
import static javax.ws.rs.core.Response.Status.NOT_FOUND;
|
||||
import static javax.ws.rs.core.Response.Status.OK;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
@ -46,7 +46,7 @@ class TestUtility {
|
|||
}
|
||||
|
||||
static HttpRequest versionRequest(String id) {
|
||||
return request().withMethod(HEAD).withPath("/gitlab/api/" + id + "/.*").withHeader("PRIVATE-TOKEN", API_TOKEN);
|
||||
return request().withMethod(GET).withPath("/gitlab/api/" + id + "/.*").withHeader("PRIVATE-TOKEN", API_TOKEN);
|
||||
}
|
||||
|
||||
static HttpResponse responseOk() {
|
||||
|
|
|
@ -139,11 +139,6 @@ class GitLabClientStub implements GitLabClient {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return null;
|
||||
|
|
|
@ -88,11 +88,6 @@ class GitLabClientStub implements GitLabClient {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headCurrentUser() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCurrentUser() {
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue