mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-22 06:26:56 +01:00
Move scm-webapp integration tests to scm-it
This commit is contained in:
committed by
René Pfeuffer
parent
3e9160a600
commit
6b30da247a
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class AbstractAdminITCaseBase
|
||||
{
|
||||
public AbstractAdminITCaseBase() {
|
||||
client = createAdminClient();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected final ScmClient client;
|
||||
}
|
||||
@@ -1,285 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createResource;
|
||||
import static sonia.scm.it.IntegrationTestUtil.post;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class AbstractPermissionITCaseBase<T>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param credentials
|
||||
*/
|
||||
public AbstractPermissionITCaseBase(Credentials credentials)
|
||||
{
|
||||
this.credentials = credentials;
|
||||
this.client = credentials.isAnonymous()? ScmClient.anonymous(): new ScmClient(credentials.getUsername(), credentials.getPassword());
|
||||
}
|
||||
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Parameters(name = "{1}")
|
||||
public static Collection<Object[]> createParameters()
|
||||
{
|
||||
return asList(
|
||||
new Object[] {new Credentials(), "anonymous"},
|
||||
new Object[] {new Credentials("trillian", "a.trillian124"), "trillian" }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void createTestUser()
|
||||
{
|
||||
User trillian = UserTestData.createTrillian();
|
||||
|
||||
trillian.setPassword("a.trillian124");
|
||||
|
||||
ScmClient client = createAdminClient();
|
||||
|
||||
ClientResponse response = UserITUtil.postUser(client, trillian);
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(201, response.getStatus());
|
||||
response.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@AfterClass
|
||||
public static void removeTestUser()
|
||||
{
|
||||
ScmClient client = createAdminClient();
|
||||
createResource(client, "users/trillian").delete();
|
||||
}
|
||||
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getBasePath();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract T getCreateItem();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getDeletePath();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getGetPath();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract T getModifyItem();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getModifyPath();
|
||||
|
||||
protected abstract String getMediaType();
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void create()
|
||||
{
|
||||
checkResponse(post(client, getBasePath(), getMediaType(), getCreateItem()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void delete()
|
||||
{
|
||||
WebResource.Builder wr = createResource(client, getDeletePath());
|
||||
|
||||
checkResponse(wr.delete(ClientResponse.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void modify()
|
||||
{
|
||||
WebResource.Builder wr = createResource(client, getModifyPath());
|
||||
|
||||
checkResponse(wr.type(getMediaType()).put(ClientResponse.class, getModifyItem()));
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void get()
|
||||
{
|
||||
WebResource.Builder wr = createResource(client, getGetPath());
|
||||
|
||||
checkGetResponse(wr.get(ClientResponse.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void getAll()
|
||||
{
|
||||
WebResource.Builder wr = createResource(client, getBasePath());
|
||||
|
||||
checkGetAllResponse(wr.get(ClientResponse.class));
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
protected void checkGetAllResponse(ClientResponse response)
|
||||
{
|
||||
checkResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
protected void checkGetResponse(ClientResponse response)
|
||||
{
|
||||
checkResponse(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
private void checkResponse(ClientResponse response)
|
||||
{
|
||||
assertNotNull(response);
|
||||
|
||||
if (credentials.isAnonymous())
|
||||
{
|
||||
assertEquals(401, response.getStatus());
|
||||
}
|
||||
else
|
||||
{
|
||||
assertEquals(403, response.getStatus());
|
||||
}
|
||||
|
||||
response.close();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
protected ScmClient client;
|
||||
|
||||
protected Credentials credentials;
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class Credentials
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public Credentials() {}
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param username
|
||||
* @param password
|
||||
*/
|
||||
public Credentials(String username, String password)
|
||||
{
|
||||
this.password = password;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isAnonymous()
|
||||
{
|
||||
return Util.isEmpty(username) && Util.isEmpty(password);
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private String password;
|
||||
|
||||
/** Field description */
|
||||
private String username;
|
||||
}
|
||||
@@ -1,347 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.type.TypeFactory;
|
||||
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.UniformInterfaceException;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.api.rest.ObjectMapperProvider;
|
||||
import sonia.scm.api.v2.resources.RepositoryDto;
|
||||
import sonia.scm.api.v2.resources.UserDto;
|
||||
import sonia.scm.api.v2.resources.UserToUserDtoMapperImpl;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static sonia.scm.it.IntegrationTestUtil.BASE_URL;
|
||||
import static sonia.scm.it.IntegrationTestUtil.REST_BASE_URL;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createResource;
|
||||
import static sonia.scm.it.IntegrationTestUtil.readJson;
|
||||
import static sonia.scm.it.RepositoryITUtil.createRepository;
|
||||
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
|
||||
|
||||
/**
|
||||
* Integration tests for git lfs.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class GitLfsITCase {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private ScmClient adminClient;
|
||||
|
||||
private RepositoryDto repository;
|
||||
|
||||
public GitLfsITCase() {
|
||||
mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(TypeFactory.defaultInstance()));
|
||||
}
|
||||
|
||||
// lifecycle methods
|
||||
|
||||
@Before
|
||||
public void setUpTestDependencies() {
|
||||
adminClient = createAdminClient();
|
||||
repository = createRepository(adminClient, readJson("repository-git.json"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownTestDependencies() {
|
||||
deleteRepository(adminClient, repository);
|
||||
}
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public void testLfsAPIWithAdminPermissions() throws IOException {
|
||||
uploadAndDownload(adminClient);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLfsAPIWithOwnerPermissions() throws IOException {
|
||||
User trillian = UserTestData.createTrillian();
|
||||
trillian.setPassword("secret123");
|
||||
createUser(trillian);
|
||||
|
||||
try {
|
||||
String permissionsUrl = repository.getLinks().getLinkBy("permissions").get().getHref();
|
||||
IntegrationTestUtil.createResource(adminClient, URI.create(permissionsUrl))
|
||||
.accept("*/*")
|
||||
.type(VndMediaType.REPOSITORY_PERMISSION)
|
||||
.post(ClientResponse.class, "{\"name\": \""+ trillian.getId() +"\", \"verbs\":[\"*\"]}");
|
||||
|
||||
ScmClient client = new ScmClient(trillian.getId(), "secret123");
|
||||
|
||||
uploadAndDownload(client);
|
||||
} finally {
|
||||
removeUser(trillian);
|
||||
}
|
||||
}
|
||||
|
||||
private void createUser(User user) {
|
||||
UserDto dto = new UserDto();
|
||||
dto.setName(user.getName());
|
||||
dto.setMail(user.getMail());
|
||||
dto.setDisplayName(user.getDisplayName());
|
||||
dto.setType(user.getType());
|
||||
dto.setActive(user.isActive());
|
||||
dto.setPassword(user.getPassword());
|
||||
createResource(adminClient, "users")
|
||||
.accept("*/*")
|
||||
.type(VndMediaType.USER)
|
||||
.post(ClientResponse.class, dto);
|
||||
}
|
||||
|
||||
private void removeUser(User user) {
|
||||
adminClient.resource(REST_BASE_URL + "users/" + user.getId()).delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLfsAPIWithoutWritePermissions() throws IOException {
|
||||
User trillian = UserTestData.createTrillian();
|
||||
trillian.setPassword("secret123");
|
||||
createUser(trillian);
|
||||
|
||||
expectedException.expect(UniformInterfaceException.class);
|
||||
expectedException.expectMessage(Matchers.containsString("403"));
|
||||
|
||||
|
||||
try {
|
||||
String permissionsUrl = repository.getLinks().getLinkBy("permissions").get().getHref();
|
||||
IntegrationTestUtil.createResource(adminClient, URI.create(permissionsUrl))
|
||||
.accept("*/*")
|
||||
.type(VndMediaType.REPOSITORY_PERMISSION)
|
||||
.post(ClientResponse.class, "{\"name\": \""+ trillian.getId() +"\", \"verbs\":[\"read\"]}");
|
||||
|
||||
ScmClient client = new ScmClient(trillian.getId(), "secret123");
|
||||
uploadAndDownload(client);
|
||||
} finally {
|
||||
removeUser(trillian);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLfsDownloadWithReadPermissions() throws IOException {
|
||||
User trillian = UserTestData.createTrillian();
|
||||
trillian.setPassword("secret123");
|
||||
createUser(trillian);
|
||||
|
||||
|
||||
try {
|
||||
String permissionsUrl = repository.getLinks().getLinkBy("permissions").get().getHref();
|
||||
IntegrationTestUtil.createResource(adminClient, URI.create(permissionsUrl))
|
||||
.accept("*/*")
|
||||
.type(VndMediaType.REPOSITORY_PERMISSION)
|
||||
.post(ClientResponse.class, "{\"name\": \""+ trillian.getId() +"\", \"verbs\":[\"read\",\"pull\"]}");
|
||||
|
||||
// upload data as admin
|
||||
String data = UUID.randomUUID().toString();
|
||||
byte[] dataAsBytes = data.getBytes(Charsets.UTF_8);
|
||||
LfsObject lfsObject = upload(adminClient, dataAsBytes);
|
||||
|
||||
ScmClient client = new ScmClient(trillian.getId(), "secret123");
|
||||
|
||||
// download as user
|
||||
byte[] downloadedData = download(client, lfsObject);
|
||||
|
||||
// assert both are equal
|
||||
assertArrayEquals(dataAsBytes, downloadedData);
|
||||
} finally {
|
||||
removeUser(trillian);
|
||||
}
|
||||
}
|
||||
|
||||
// lfs api
|
||||
|
||||
private void uploadAndDownload(ScmClient client) throws IOException {
|
||||
String data = UUID.randomUUID().toString();
|
||||
byte[] dataAsBytes = data.getBytes(Charsets.UTF_8);
|
||||
LfsObject lfsObject = upload(client, dataAsBytes);
|
||||
byte[] downloadedData = download(client, lfsObject);
|
||||
assertArrayEquals(dataAsBytes, downloadedData);
|
||||
}
|
||||
|
||||
private LfsObject upload(ScmClient client, byte[] data) throws IOException {
|
||||
LfsObject lfsObject = createLfsObject(data);
|
||||
LfsRequestBody request = LfsRequestBody.createUploadRequest(lfsObject);
|
||||
LfsResponseBody response = request(client, request);
|
||||
|
||||
String uploadURL = response.objects[0].actions.upload.href;
|
||||
client.resource(uploadURL).header(HttpUtil.HEADER_USERAGENT, "git-lfs/z").put(data);
|
||||
|
||||
return lfsObject;
|
||||
}
|
||||
|
||||
private LfsResponseBody request(ScmClient client, LfsRequestBody request) throws IOException {
|
||||
String batchUrl = createBatchUrl();
|
||||
String requestAsString = mapper.writeValueAsString(request);
|
||||
|
||||
String json = client
|
||||
.resource(batchUrl)
|
||||
.accept("application/vnd.git-lfs+json")
|
||||
.header(HttpUtil.HEADER_USERAGENT, "git-lfs/z")
|
||||
.header("Content-Type", "application/vnd.git-lfs+json")
|
||||
.post(String.class, requestAsString);
|
||||
return new ObjectMapperProvider().get().readValue(json, LfsResponseBody.class);
|
||||
}
|
||||
|
||||
private String createBatchUrl() {
|
||||
return String.format("%srepo/%s/%s/info/lfs/objects/batch", BASE_URL, repository.getNamespace(), repository.getName());
|
||||
}
|
||||
|
||||
private byte[] download(ScmClient client, LfsObject lfsObject) throws IOException {
|
||||
LfsRequestBody request = LfsRequestBody.createDownloadRequest(lfsObject);
|
||||
LfsResponseBody response = request(client, request);
|
||||
|
||||
String downloadUrl = response.objects[0].actions.download.href;
|
||||
return client.resource(downloadUrl).header(HttpUtil.HEADER_USERAGENT, "git-lfs/z").get(byte[].class);
|
||||
}
|
||||
|
||||
private LfsObject createLfsObject(byte[] data) {
|
||||
Sha256Hash hash = new Sha256Hash(data);
|
||||
String oid = hash.toHex();
|
||||
return new LfsObject(oid, data.length);
|
||||
}
|
||||
|
||||
// LFS DTO objects
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class LfsRequestBody {
|
||||
|
||||
private String operation;
|
||||
private String[] transfers = new String[]{ "basic" };
|
||||
private LfsObject[] objects;
|
||||
|
||||
public LfsRequestBody() {
|
||||
}
|
||||
|
||||
private LfsRequestBody(String operation, LfsObject[] objects) {
|
||||
this.operation = operation;
|
||||
this.objects = objects;
|
||||
}
|
||||
|
||||
public static LfsRequestBody createUploadRequest(LfsObject object) {
|
||||
return new LfsRequestBody("upload", new LfsObject[]{object});
|
||||
}
|
||||
|
||||
public static LfsRequestBody createDownloadRequest(LfsObject object) {
|
||||
return new LfsRequestBody("download", new LfsObject[]{object});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class LfsResponseBody {
|
||||
|
||||
private LfsObject[] objects;
|
||||
|
||||
public LfsResponseBody() {
|
||||
}
|
||||
|
||||
public LfsResponseBody(LfsObject[] objects) {
|
||||
this.objects = objects;
|
||||
}
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class LfsObject {
|
||||
|
||||
private String oid;
|
||||
private long size;
|
||||
private LfsActions actions;
|
||||
|
||||
public LfsObject() {
|
||||
}
|
||||
|
||||
public LfsObject(String oid, long size) {
|
||||
this.oid = oid;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public LfsObject(String oid, long size, LfsActions actions) {
|
||||
this.oid = oid;
|
||||
this.size = size;
|
||||
this.actions = actions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class LfsActions {
|
||||
|
||||
private LfsAction upload;
|
||||
private LfsAction download;
|
||||
|
||||
public LfsActions() {
|
||||
}
|
||||
}
|
||||
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
private static class LfsAction {
|
||||
|
||||
private String href;
|
||||
|
||||
public LfsAction() {
|
||||
}
|
||||
|
||||
public LfsAction(String href) {
|
||||
this.href = href;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,142 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.api.v2.resources.RepositoryDto;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.client.api.ClientCommand;
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static sonia.scm.it.IntegrationTestUtil.ADMIN_PASSWORD;
|
||||
import static sonia.scm.it.IntegrationTestUtil.ADMIN_USERNAME;
|
||||
import static sonia.scm.it.IntegrationTestUtil.BASE_URL;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
|
||||
import static sonia.scm.it.IntegrationTestUtil.readJson;
|
||||
import static sonia.scm.it.RepositoryITUtil.createRepository;
|
||||
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
|
||||
|
||||
/**
|
||||
* Integration test for RepositoryPathMatching with ".git" and without ".git".
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
* @since 1.54
|
||||
*/
|
||||
public class GitRepositoryPathMatcherITCase {
|
||||
|
||||
private static final RepositoryClientFactory REPOSITORY_CLIENT_FACTORY = new RepositoryClientFactory();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
private ScmClient apiClient;
|
||||
private RepositoryDto repository;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
apiClient = createAdminClient();
|
||||
this.repository = createRepository(apiClient, readJson("repository-git.json"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
deleteRepository(apiClient, repository);
|
||||
}
|
||||
|
||||
// tests begin
|
||||
|
||||
@Test
|
||||
public void testWithoutDotGit() throws IOException {
|
||||
String urlWithoutDotGit = createUrl();
|
||||
cloneAndPush(urlWithoutDotGit);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithDotGit() throws IOException {
|
||||
String urlWithDotGit = createUrl() + ".git";
|
||||
cloneAndPush(urlWithDotGit);
|
||||
}
|
||||
|
||||
// tests end
|
||||
|
||||
private String createUrl() {
|
||||
return BASE_URL + "repo/" + repository.getNamespace() + "/" + repository.getName();
|
||||
}
|
||||
|
||||
private void cloneAndPush( String url ) throws IOException {
|
||||
cloneRepositoryAndPushFiles(url);
|
||||
cloneRepositoryAndCheckFiles(url);
|
||||
}
|
||||
|
||||
private void cloneRepositoryAndPushFiles(String url) throws IOException {
|
||||
RepositoryClient repositoryClient = createRepositoryClient(url);
|
||||
|
||||
Files.write("a", new File(repositoryClient.getWorkingCopy(), "a.txt"), Charsets.UTF_8);
|
||||
repositoryClient.getAddCommand().add("a.txt");
|
||||
commit(repositoryClient, "added a");
|
||||
|
||||
Files.write("b", new File(repositoryClient.getWorkingCopy(), "b.txt"), Charsets.UTF_8);
|
||||
repositoryClient.getAddCommand().add("b.txt");
|
||||
commit(repositoryClient, "added b");
|
||||
}
|
||||
|
||||
private void cloneRepositoryAndCheckFiles(String url) throws IOException {
|
||||
RepositoryClient repositoryClient = createRepositoryClient(url);
|
||||
File workingCopy = repositoryClient.getWorkingCopy();
|
||||
|
||||
File a = new File(workingCopy, "a.txt");
|
||||
assertTrue(a.exists());
|
||||
assertEquals("a", Files.toString(a, Charsets.UTF_8));
|
||||
|
||||
File b = new File(workingCopy, "b.txt");
|
||||
assertTrue(b.exists());
|
||||
assertEquals("b", Files.toString(b, Charsets.UTF_8));
|
||||
}
|
||||
|
||||
private void commit(RepositoryClient repositoryClient, String message) throws IOException {
|
||||
repositoryClient.getCommitCommand().commit(
|
||||
new Person("scmadmin", "scmadmin@scm-manager.org"), message
|
||||
);
|
||||
if ( repositoryClient.isCommandSupported(ClientCommand.PUSH) ) {
|
||||
repositoryClient.getPushCommand().push();
|
||||
}
|
||||
}
|
||||
|
||||
private RepositoryClient createRepositoryClient(String url) throws IOException {
|
||||
return REPOSITORY_CLIENT_FACTORY.create("git", url, ADMIN_USERNAME, ADMIN_PASSWORD, tempFolder.newFolder());
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.io.Resources;
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import com.sun.jersey.client.apache.ApacheHttpClient;
|
||||
import com.sun.jersey.client.apache.config.ApacheHttpClientConfig;
|
||||
import com.sun.jersey.client.apache.config.DefaultApacheHttpClientConfig;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import sonia.scm.api.rest.JSONContextResolver;
|
||||
import sonia.scm.api.rest.ObjectMapperProvider;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public final class IntegrationTestUtil
|
||||
{
|
||||
|
||||
public static final Person AUTHOR = new Person("SCM Administrator", "scmadmin@scm-manager.org");
|
||||
|
||||
/** Field description */
|
||||
public static final String ADMIN_PASSWORD = "scmadmin";
|
||||
|
||||
/** Field description */
|
||||
public static final String ADMIN_USERNAME = "scmadmin";
|
||||
|
||||
/** scm-manager base url */
|
||||
public static final String BASE_URL = "http://localhost:8081/scm/";
|
||||
|
||||
/** scm-manager base url for the rest api */
|
||||
public static final String REST_BASE_URL = BASE_URL.concat("api/v2/");
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
private IntegrationTestUtil() {}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
|
||||
public static ScmClient createAdminClient()
|
||||
{
|
||||
return new ScmClient("scmadmin", "scmadmin");
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static Client createClient()
|
||||
{
|
||||
DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig();
|
||||
config.getSingletons().add(new JSONContextResolver(new ObjectMapperProvider().get()));
|
||||
config.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES, true);
|
||||
|
||||
return ApacheHttpClient.create(config);
|
||||
}
|
||||
|
||||
public static String serialize(Object o) {
|
||||
ObjectMapper mapper = new ObjectMapperProvider().get();
|
||||
try {
|
||||
return mapper.writeValueAsString(o);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection<String[]> createRepositoryTypeParameters() {
|
||||
Collection<String[]> params = new ArrayList<>();
|
||||
|
||||
params.add(new String[]{"git"});
|
||||
params.add(new String[]{"svn"});
|
||||
|
||||
if (IOUtil.search("hg") != null)
|
||||
{
|
||||
params.add(new String[]{"hg"});
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
public static URI getLink(HalRepresentation object, String linkName) {
|
||||
return URI.create(object.getLinks().getLinkBy("delete").get().getHref());
|
||||
}
|
||||
|
||||
public static WebResource.Builder createResource(ScmClient client, String url) {
|
||||
return createResource(client, createResourceUrl(url));
|
||||
}
|
||||
public static WebResource.Builder createResource(ScmClient client, URI url) {
|
||||
return client.resource(url.toString());
|
||||
}
|
||||
|
||||
public static ClientResponse post(ScmClient client, String path, String mediaType, Object o) {
|
||||
return createResource(client, path)
|
||||
.type(mediaType)
|
||||
.post(ClientResponse.class, serialize(o));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static URI createResourceUrl(String url)
|
||||
{
|
||||
return URI.create(REST_BASE_URL).resolve(url);
|
||||
}
|
||||
|
||||
public static String readJson(String jsonFileName) {
|
||||
URL url = Resources.getResource(jsonFileName);
|
||||
try {
|
||||
return Resources.toString(url, Charset.forName("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("could not read json file " + jsonFileName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.io.Files;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import org.junit.After;
|
||||
import org.junit.Assume;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import sonia.scm.api.v2.resources.RepositoryDto;
|
||||
import sonia.scm.debug.DebugHookData;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.Person;
|
||||
import sonia.scm.repository.client.api.ClientCommand;
|
||||
import sonia.scm.repository.client.api.RepositoryClient;
|
||||
import sonia.scm.repository.client.api.RepositoryClientFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.core.AllOf.allOf;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createResource;
|
||||
import static sonia.scm.it.IntegrationTestUtil.readJson;
|
||||
import static sonia.scm.it.RepositoryITUtil.createRepository;
|
||||
import static sonia.scm.it.RepositoryITUtil.deleteRepository;
|
||||
|
||||
/**
|
||||
* Integration tests for repository hooks.
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class RepositoryHookITCase extends AbstractAdminITCaseBase
|
||||
{
|
||||
|
||||
private static final long WAIT_TIME = 125;
|
||||
|
||||
private static final RepositoryClientFactory REPOSITORY_CLIENT_FACTORY = new RepositoryClientFactory();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
private final String repositoryType;
|
||||
private RepositoryDto repository;
|
||||
private File workingCopy;
|
||||
private RepositoryClient repositoryClient;
|
||||
|
||||
/**
|
||||
* Constructs a new instance with a repository type.
|
||||
*
|
||||
* @param repositoryType repository type
|
||||
*/
|
||||
public RepositoryHookITCase(String repositoryType)
|
||||
{
|
||||
this.repositoryType = repositoryType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test repository.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
@Before
|
||||
public void setUpTestRepository() throws IOException
|
||||
{
|
||||
repository = createRepository(client, readJson("repository-" + repositoryType + ".json"));
|
||||
workingCopy = tempFolder.newFolder();
|
||||
repositoryClient = createRepositoryClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the tests repository.
|
||||
*/
|
||||
@After
|
||||
public void removeTestRepository()
|
||||
{
|
||||
if (repository != null) {
|
||||
deleteRepository(client, repository);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the debug service has received the commit.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testSimpleHook() throws IOException, InterruptedException
|
||||
{
|
||||
// commit and push commit
|
||||
Files.write("a", new File(workingCopy, "a.txt"), Charsets.UTF_8);
|
||||
repositoryClient.getAddCommand().add("a.txt");
|
||||
Changeset changeset = commit("added a");
|
||||
|
||||
// wait some time, because the debug hook is asnychron
|
||||
Thread.sleep(WAIT_TIME);
|
||||
|
||||
// check debug servlet for pushed commit
|
||||
WebResource.Builder wr = createResource(client, "../debug/" + repository.getNamespace() + "/" + repository.getName() + "/post-receive/last");
|
||||
DebugHookData data = wr.get(DebugHookData.class);
|
||||
assertNotNull(data);
|
||||
assertThat(data.getChangesets(), contains(changeset.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the debug service receives only new commits.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testOnlyNewCommit() throws IOException, InterruptedException
|
||||
{
|
||||
// skip test if branches are not supported by repository type
|
||||
Assume.assumeTrue(repositoryClient.isCommandSupported(ClientCommand.BRANCH));
|
||||
|
||||
// push commit
|
||||
Files.write("a", new File(workingCopy, "a.txt"), Charsets.UTF_8);
|
||||
repositoryClient.getAddCommand().add("a.txt");
|
||||
Changeset a = commit("added a");
|
||||
|
||||
// create branch
|
||||
repositoryClient.getBranchCommand().branch("feature/added-b");
|
||||
|
||||
// commit and push again
|
||||
Files.write("b", new File(workingCopy, "b.txt"), Charsets.UTF_8);
|
||||
repositoryClient.getAddCommand().add("a.txt");
|
||||
Changeset b = commit("added b");
|
||||
|
||||
// wait some time, because the debug hook is asnychron
|
||||
Thread.sleep(WAIT_TIME);
|
||||
|
||||
// check debug servlet that only one commit is present
|
||||
WebResource.Builder wr = createResource(client, String.format("../debug/%s/%s/post-receive/last", repository.getNamespace(), repository.getName()));
|
||||
DebugHookData data = wr.get(DebugHookData.class);
|
||||
assertNotNull(data);
|
||||
assertThat(data.getChangesets(), allOf(
|
||||
contains(b.getId()),
|
||||
not(
|
||||
contains(a.getId())
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
private Changeset commit(String message) throws IOException {
|
||||
Changeset a = repositoryClient.getCommitCommand().commit(
|
||||
new Person("scmadmin", "scmadmin@scm-manager.org"), message
|
||||
);
|
||||
if ( repositoryClient.isCommandSupported(ClientCommand.PUSH) ) {
|
||||
repositoryClient.getPushCommand().push();
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private RepositoryClient createRepositoryClient() throws IOException
|
||||
{
|
||||
return REPOSITORY_CLIENT_FACTORY.create(repositoryType,
|
||||
String.format("%srepo/%s/%s", IntegrationTestUtil.BASE_URL, repository.getNamespace(), repository.getName()),
|
||||
IntegrationTestUtil.ADMIN_USERNAME, IntegrationTestUtil.ADMIN_PASSWORD, workingCopy
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns repository types a test parameter.
|
||||
*
|
||||
* @return repository types test parameter
|
||||
*/
|
||||
@Parameters(name = "{0}")
|
||||
public static Collection<String[]> createParameters()
|
||||
{
|
||||
return IntegrationTestUtil.createRepositoryTypeParameters();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import sonia.scm.api.rest.ObjectMapperProvider;
|
||||
import sonia.scm.api.v2.resources.RepositoryDto;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static sonia.scm.it.IntegrationTestUtil.BASE_URL;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createResource;
|
||||
import static sonia.scm.it.IntegrationTestUtil.getLink;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
public final class RepositoryITUtil
|
||||
{
|
||||
|
||||
private RepositoryITUtil() {}
|
||||
|
||||
public static RepositoryDto createRepository(ScmClient client, String repositoryJson) {
|
||||
ClientResponse response =
|
||||
createResource(client, "repositories")
|
||||
.accept("*/*")
|
||||
.type(VndMediaType.REPOSITORY)
|
||||
.post(ClientResponse.class, repositoryJson);
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(201, response.getStatus());
|
||||
|
||||
URI url = URI.create(response.getHeaders().get("Location").get(0));
|
||||
|
||||
response.close();
|
||||
|
||||
RepositoryDto other = getRepository(client, url);
|
||||
|
||||
assertNotNull(other);
|
||||
assertNotNull(other.getType());
|
||||
assertNotNull(other.getNamespace());
|
||||
assertNotNull(other.getCreationDate());
|
||||
|
||||
return other;
|
||||
}
|
||||
|
||||
public static void deleteRepository(ScmClient client, RepositoryDto repository)
|
||||
{
|
||||
URI deleteUrl = getLink(repository, "delete");
|
||||
ClientResponse response = createResource(client, deleteUrl).delete(ClientResponse.class);
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(204, response.getStatus());
|
||||
response.close();
|
||||
|
||||
URI selfUrl = getLink(repository, "self");
|
||||
response = createResource(client, selfUrl).get(ClientResponse.class);
|
||||
assertNotNull(response);
|
||||
assertEquals(404, response.getStatus());
|
||||
response.close();
|
||||
}
|
||||
|
||||
public static RepositoryDto getRepository(ScmClient client, URI url)
|
||||
{
|
||||
WebResource.Builder wr = createResource(client, url);
|
||||
ClientResponse response = wr.get(ClientResponse.class);
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
String json = response.getEntity(String.class);
|
||||
RepositoryDto repository = null;
|
||||
try {
|
||||
repository = new ObjectMapperProvider().get().readerFor(RepositoryDto.class).readValue(json);
|
||||
} catch (IOException e) {
|
||||
fail("could not read json:\n" + json);
|
||||
}
|
||||
|
||||
response.close();
|
||||
assertNotNull(repository);
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
public static String createUrl(RepositoryDto repository) {
|
||||
return BASE_URL + repository.getType() + "/" + repository.getNamespace() + "/" + repository.getName();
|
||||
}
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import sonia.scm.api.rest.ObjectMapperProvider;
|
||||
import sonia.scm.api.v2.resources.RepositoryDto;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createAdminClient;
|
||||
import static sonia.scm.it.IntegrationTestUtil.createResource;
|
||||
import static sonia.scm.it.IntegrationTestUtil.serialize;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class RepositorySimplePermissionITCase
|
||||
extends AbstractPermissionITCaseBase<RepositoryDto>
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
private static String REPOSITORY_PATH;
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param credentials
|
||||
*/
|
||||
public RepositorySimplePermissionITCase(Credentials credentials, String ignore_testCaseName)
|
||||
{
|
||||
super(credentials);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void createTestRepository() throws IOException {
|
||||
RepositoryDto repository = new RepositoryDto();
|
||||
|
||||
repository.setName("test-repo");
|
||||
repository.setType("git");
|
||||
|
||||
ScmClient client = createAdminClient();
|
||||
|
||||
WebResource.Builder wr = createResource(client, "repositories");
|
||||
ClientResponse response = wr.type(VndMediaType.REPOSITORY).post(ClientResponse.class, serialize(repository));
|
||||
|
||||
assertNotNull(response);
|
||||
assertEquals(201, response.getStatus());
|
||||
|
||||
String repositoryUrl = response.getHeaders().getFirst("Location");
|
||||
|
||||
assertNotNull(repositoryUrl);
|
||||
response.close();
|
||||
response = client.resource(repositoryUrl).get(ClientResponse.class);
|
||||
assertNotNull(response);
|
||||
assertEquals(200, response.getStatus());
|
||||
repository = new ObjectMapperProvider().get().readValue(response.getEntity(String.class), RepositoryDto.class);
|
||||
REPOSITORY_PATH = repository.getNamespace() + "/" + repository.getName();
|
||||
assertNotNull(REPOSITORY_PATH);
|
||||
response.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@AfterClass
|
||||
public static void removeTestRepository()
|
||||
{
|
||||
createResource(createAdminClient(), "repositories/" + REPOSITORY_PATH).delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@Override
|
||||
protected void checkGetAllResponse(ClientResponse response)
|
||||
{
|
||||
if (!credentials.isAnonymous())
|
||||
{
|
||||
assertNotNull(response);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
HalRepresentation repositories =
|
||||
null;
|
||||
try {
|
||||
repositories = new ObjectMapperProvider().get().readValue(response.getEntity(String.class), HalRepresentation.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
assertNotNull(repositories);
|
||||
assertTrue(repositories.getEmbedded().getItemsBy("repositories").isEmpty());
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param response
|
||||
*/
|
||||
@Override
|
||||
protected void checkGetResponse(ClientResponse response)
|
||||
{
|
||||
if (!credentials.isAnonymous())
|
||||
{
|
||||
assertNotNull(response);
|
||||
assertEquals(403, response.getStatus());
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getBasePath()
|
||||
{
|
||||
return "repositories";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryDto getCreateItem()
|
||||
{
|
||||
RepositoryDto repository = new RepositoryDto();
|
||||
|
||||
repository.setName("create-test-repo");
|
||||
repository.setType("svn");
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getDeletePath()
|
||||
{
|
||||
return "repositories/".concat(REPOSITORY_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getGetPath()
|
||||
{
|
||||
return "repositories/".concat(REPOSITORY_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected RepositoryDto getModifyItem()
|
||||
{
|
||||
RepositoryDto repository = new RepositoryDto();
|
||||
|
||||
repository.setName("test-repo");
|
||||
repository.setNamespace("scmadmin");
|
||||
repository.setType("git");
|
||||
repository.setDescription("Test Repository");
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getModifyPath()
|
||||
{
|
||||
return "repositories/".concat(REPOSITORY_PATH);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMediaType() {
|
||||
return VndMediaType.REPOSITORY;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
import com.sun.jersey.api.client.Client;
|
||||
import com.sun.jersey.api.client.WebResource;
|
||||
|
||||
import java.util.Base64;
|
||||
|
||||
import static sonia.scm.it.IntegrationTestUtil.createClient;
|
||||
|
||||
public class ScmClient {
|
||||
private final String user;
|
||||
private final String password;
|
||||
|
||||
private final Client client;
|
||||
|
||||
public static ScmClient anonymous() {
|
||||
return new ScmClient(null, null);
|
||||
}
|
||||
|
||||
public ScmClient(String user, String password) {
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.client = createClient();
|
||||
}
|
||||
|
||||
public WebResource.Builder resource(String url) {
|
||||
if (user == null) {
|
||||
return client.resource(url).getRequestBuilder();
|
||||
} else {
|
||||
return client.resource(url).header("Authorization", createAuthHeaderValue());
|
||||
}
|
||||
}
|
||||
|
||||
public String createAuthHeaderValue() {
|
||||
return "Basic " + Base64.getEncoder().encodeToString((user +":"+ password).getBytes());
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import static sonia.scm.it.IntegrationTestUtil.post;
|
||||
|
||||
public class UserITUtil {
|
||||
public static ClientResponse postUser(ScmClient client, User user) {
|
||||
return post(client, "users", VndMediaType.USER, user);
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/*
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package sonia.scm.it;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.sun.jersey.api.client.ClientResponse;
|
||||
import de.otto.edison.hal.HalRepresentation;
|
||||
import org.junit.Assume;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import sonia.scm.api.rest.ObjectMapperProvider;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.user.UserTestData;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class UserPermissionITCase extends AbstractPermissionITCaseBase<User>
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*
|
||||
* @param credentials
|
||||
*/
|
||||
public UserPermissionITCase(Credentials credentials, String ignore_testCaseName)
|
||||
{
|
||||
super(credentials);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getBasePath()
|
||||
{
|
||||
return "users";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected User getCreateItem()
|
||||
{
|
||||
return UserTestData.createZaphod();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getDeletePath()
|
||||
{
|
||||
return "users/scmadmin";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getGetPath()
|
||||
{
|
||||
return "users/scmadmin";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected User getModifyItem()
|
||||
{
|
||||
User user = new User("scmadmin", "SCM Administrator",
|
||||
"scm-admin@scm-manager.org");
|
||||
|
||||
user.setPassword("hallo123");
|
||||
user.setType("xml");
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getModifyPath()
|
||||
{
|
||||
return "users/scmadmin";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMediaType() {
|
||||
return VndMediaType.USER;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkGetAllResponse(ClientResponse response)
|
||||
{
|
||||
Assume.assumeTrue(credentials.getUsername() == null);
|
||||
if (!credentials.isAnonymous())
|
||||
{
|
||||
assertNotNull(response);
|
||||
assertEquals(200, response.getStatus());
|
||||
|
||||
HalRepresentation repositories =
|
||||
null;
|
||||
try {
|
||||
repositories = new ObjectMapperProvider().get().readValue(response.getEntity(String.class), HalRepresentation.class);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
assertNotNull(repositories);
|
||||
assertTrue(repositories.getEmbedded().getItemsBy("users").isEmpty());
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user