mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Fixes NPE in HgConfigPackageResource for non-existing packages.
This commit is contained in:
@@ -80,13 +80,16 @@ public class HgConfigPackageResource {
|
|||||||
|
|
||||||
HgPackage pkg = pkgReader.getPackage(pkgId);
|
HgPackage pkg = pkgReader.getPackage(pkgId);
|
||||||
|
|
||||||
// First path param cannot be null (leaving it results in 405)
|
if (pkg != null) {
|
||||||
if (HgInstallerFactory.createInstaller()
|
if (HgInstallerFactory.createInstaller()
|
||||||
.installPackage(client, handler, SCMContext.getContext().getBaseDirectory(), pkg)) {
|
.installPackage(client, handler, SCMContext.getContext().getBaseDirectory(), pkg)) {
|
||||||
response = Response.noContent().build();
|
response = Response.noContent().build();
|
||||||
} else {
|
} else {
|
||||||
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
response = Response.status(Response.Status.NOT_FOUND).build();
|
||||||
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,10 +152,11 @@ public class HgConfigPackageResourceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SubjectAware(username = "writeOnly")
|
@SubjectAware(username = "writeOnly")
|
||||||
public void shouldHandleMissingPackageId() throws Exception {
|
public void shouldHandlePackagesThatAreNotFound() throws Exception {
|
||||||
|
String packageId = "this-package-does-not-ex";
|
||||||
MockHttpResponse response = put(null);
|
when(hgPackageReader.getPackage(packageId)).thenReturn(null);
|
||||||
assertEquals(HttpServletResponse.SC_METHOD_NOT_ALLOWED, response.getStatus());
|
MockHttpResponse response = put(packageId);
|
||||||
|
assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user