mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
added some permission tests to RepositoryExtendedITCase
This commit is contained in:
@@ -35,7 +35,8 @@ package sonia.scm.it;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
@@ -43,10 +44,11 @@ import org.junit.runners.Parameterized;
|
|||||||
import sonia.scm.repository.Repository;
|
import sonia.scm.repository.Repository;
|
||||||
import sonia.scm.repository.client.RepositoryClient;
|
import sonia.scm.repository.client.RepositoryClient;
|
||||||
import sonia.scm.repository.client.RepositoryClientException;
|
import sonia.scm.repository.client.RepositoryClientException;
|
||||||
import sonia.scm.repository.client.RepositoryClientFactory;
|
|
||||||
import sonia.scm.user.User;
|
import sonia.scm.user.User;
|
||||||
import sonia.scm.util.IOUtil;
|
import sonia.scm.util.IOUtil;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import static sonia.scm.it.IntegrationTestUtil.*;
|
import static sonia.scm.it.IntegrationTestUtil.*;
|
||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
@@ -70,16 +72,68 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
|||||||
* @param owner
|
* @param owner
|
||||||
* @param write
|
* @param write
|
||||||
* @param read
|
* @param read
|
||||||
|
* @param noperm
|
||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
public RepositoryExtendedITCase(Repository repository, User owner,
|
public RepositoryExtendedITCase(Repository repository, User owner,
|
||||||
User write, User read, String password)
|
User write, User read, User noperm,
|
||||||
|
String password)
|
||||||
{
|
{
|
||||||
super(repository, owner, write, read, password);
|
super(repository, owner, write, read, noperm, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@After
|
||||||
|
public void cleanupTest() throws IOException
|
||||||
|
{
|
||||||
|
IOUtil.delete(directory);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws RepositoryClientException
|
||||||
|
*/
|
||||||
|
@Test(expected = RepositoryClientException.class)
|
||||||
|
public void readFailed() throws RepositoryClientException
|
||||||
|
{
|
||||||
|
RepositoryClient rc = createRepositoryClient(nopermUser, directory);
|
||||||
|
|
||||||
|
rc.checkout();
|
||||||
|
|
||||||
|
// ugly workaround
|
||||||
|
if (repository.getType().equals("git"))
|
||||||
|
{
|
||||||
|
for (File f : directory.listFiles())
|
||||||
|
{
|
||||||
|
if (!".git".equals(f.getName()))
|
||||||
|
{
|
||||||
|
fail("checkout works");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RepositoryClientException("checkout failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setupTest()
|
||||||
|
{
|
||||||
|
directory = createTempDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
@@ -90,21 +144,10 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
|||||||
@Test
|
@Test
|
||||||
public void simpleRead() throws RepositoryClientException, IOException
|
public void simpleRead() throws RepositoryClientException, IOException
|
||||||
{
|
{
|
||||||
File directory = createTempDirectory();
|
RepositoryClient rc = createRepositoryClient(readUser, directory);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RepositoryClient rc =
|
|
||||||
RepositoryClientFactory.createClient(repository.getType(), directory,
|
|
||||||
repository.getUrl(), readUser.getName(), password);
|
|
||||||
|
|
||||||
rc.checkout();
|
rc.checkout();
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
IOUtil.delete(directory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
@@ -117,20 +160,31 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
|||||||
@Test
|
@Test
|
||||||
public void simpleWrite() throws RepositoryClientException, IOException
|
public void simpleWrite() throws RepositoryClientException, IOException
|
||||||
{
|
{
|
||||||
File directory = createTempDirectory();
|
RepositoryClient rc = createRepositoryClient(writeUser, directory);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
RepositoryClient rc =
|
|
||||||
RepositoryClientFactory.createClient(repository.getType(), directory,
|
|
||||||
repository.getUrl(), writeUser.getName(), password);
|
|
||||||
|
|
||||||
rc.checkout();
|
rc.checkout();
|
||||||
addTestFiles(rc);
|
addTestFiles(rc);
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
* @throws RepositoryClientException
|
||||||
|
*/
|
||||||
|
@Test(expected = RepositoryClientException.class)
|
||||||
|
public void writeFailed() throws RepositoryClientException, IOException
|
||||||
{
|
{
|
||||||
IOUtil.delete(directory);
|
RepositoryClient rc = createRepositoryClient(readUser, directory);
|
||||||
}
|
|
||||||
|
rc.checkout();
|
||||||
|
addTestFiles(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private File directory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,15 +83,17 @@ public class RepositoryITCaseBase
|
|||||||
* @param owner
|
* @param owner
|
||||||
* @param write
|
* @param write
|
||||||
* @param read
|
* @param read
|
||||||
|
* @param noperm
|
||||||
* @param password
|
* @param password
|
||||||
*/
|
*/
|
||||||
public RepositoryITCaseBase(Repository repository, User owner, User write,
|
public RepositoryITCaseBase(Repository repository, User owner, User write,
|
||||||
User read, String password)
|
User read, User noperm, String password)
|
||||||
{
|
{
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
this.ownerUser = owner;
|
this.ownerUser = owner;
|
||||||
this.writeUser = write;
|
this.writeUser = write;
|
||||||
this.readUser = read;
|
this.readUser = read;
|
||||||
|
this.nopermUser = noperm;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,8 +137,6 @@ public class RepositoryITCaseBase
|
|||||||
{
|
{
|
||||||
File directory = createTempDirectory();
|
File directory = createTempDirectory();
|
||||||
|
|
||||||
System.out.println( repository.getUrl() );
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RepositoryClient rc =
|
RepositoryClient rc =
|
||||||
@@ -164,6 +164,7 @@ public class RepositoryITCaseBase
|
|||||||
deleteUser(client, UserTestData.createTrillian());
|
deleteUser(client, UserTestData.createTrillian());
|
||||||
deleteUser(client, UserTestData.createZaphod());
|
deleteUser(client, UserTestData.createZaphod());
|
||||||
deleteUser(client, UserTestData.createMarvin());
|
deleteUser(client, UserTestData.createMarvin());
|
||||||
|
deleteUser(client, UserTestData.createPerfect());
|
||||||
|
|
||||||
Collection<Repository> repositories =
|
Collection<Repository> repositories =
|
||||||
createResource(client, "repositories").get(
|
createResource(client, "repositories").get(
|
||||||
@@ -213,6 +214,10 @@ public class RepositoryITCaseBase
|
|||||||
|
|
||||||
createUser(read);
|
createUser(read);
|
||||||
|
|
||||||
|
User noperm = UserTestData.createPerfect();
|
||||||
|
|
||||||
|
createUser(noperm);
|
||||||
|
|
||||||
for (Type t : state.getRepositoryTypes())
|
for (Type t : state.getRepositoryTypes())
|
||||||
{
|
{
|
||||||
if (t.getName().equals("git"))
|
if (t.getName().equals("git"))
|
||||||
@@ -220,23 +225,30 @@ public class RepositoryITCaseBase
|
|||||||
Repository gitRepository = createTestRepository("git", owner, write,
|
Repository gitRepository = createTestRepository("git", owner, write,
|
||||||
read);
|
read);
|
||||||
|
|
||||||
params.add(new Object[] { gitRepository, owner, write, read,
|
params.add(new Object[]
|
||||||
"secret" });
|
{
|
||||||
|
gitRepository, owner, write, read, noperm, "secret"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (t.getName().equals("svn"))
|
else if (t.getName().equals("svn"))
|
||||||
{
|
{
|
||||||
Repository svnRepository = createTestRepository("svn", owner, write,
|
Repository svnRepository = createTestRepository("svn", owner, write,
|
||||||
read);
|
read);
|
||||||
|
|
||||||
params.add(new Object[] { svnRepository, owner, write, read,
|
params.add(new Object[]
|
||||||
"secret" });
|
{
|
||||||
|
svnRepository, owner, write, read, noperm, "secret"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (t.getName().equals("hg"))
|
else if (t.getName().equals("hg"))
|
||||||
{
|
{
|
||||||
Repository hgRepository = createTestRepository("hg", owner, write,
|
Repository hgRepository = createTestRepository("hg", owner, write,
|
||||||
read);
|
read);
|
||||||
|
|
||||||
params.add(new Object[] { hgRepository, owner, write, read, "secret" });
|
params.add(new Object[]
|
||||||
|
{
|
||||||
|
hgRepository, owner, write, read, noperm, "secret"
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,8 +317,29 @@ public class RepositoryITCaseBase
|
|||||||
createResource(client, "users/".concat(user.getName())).delete();
|
createResource(client, "users/".concat(user.getName())).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param user
|
||||||
|
* @param directory
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*
|
||||||
|
* @throws RepositoryClientException
|
||||||
|
*/
|
||||||
|
protected RepositoryClient createRepositoryClient(User user, File directory)
|
||||||
|
throws RepositoryClientException
|
||||||
|
{
|
||||||
|
return RepositoryClientFactory.createClient(repository.getType(),
|
||||||
|
directory, repository.getUrl(), user.getName(), password);
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
protected User nopermUser;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected User ownerUser;
|
protected User ownerUser;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user