mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15: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 --------------------------------------------------------
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
@@ -43,10 +44,11 @@ import org.junit.runners.Parameterized;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.client.RepositoryClient;
|
||||
import sonia.scm.repository.client.RepositoryClientException;
|
||||
import sonia.scm.repository.client.RepositoryClientFactory;
|
||||
import sonia.scm.user.User;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static sonia.scm.it.IntegrationTestUtil.*;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -70,16 +72,68 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
||||
* @param owner
|
||||
* @param write
|
||||
* @param read
|
||||
* @param noperm
|
||||
* @param password
|
||||
*/
|
||||
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 --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -90,21 +144,10 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
||||
@Test
|
||||
public void simpleRead() throws RepositoryClientException, IOException
|
||||
{
|
||||
File directory = createTempDirectory();
|
||||
|
||||
try
|
||||
{
|
||||
RepositoryClient rc =
|
||||
RepositoryClientFactory.createClient(repository.getType(), directory,
|
||||
repository.getUrl(), readUser.getName(), password);
|
||||
RepositoryClient rc = createRepositoryClient(readUser, directory);
|
||||
|
||||
rc.checkout();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.delete(directory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
@@ -117,20 +160,31 @@ public class RepositoryExtendedITCase extends RepositoryITCaseBase
|
||||
@Test
|
||||
public void simpleWrite() throws RepositoryClientException, IOException
|
||||
{
|
||||
File directory = createTempDirectory();
|
||||
|
||||
try
|
||||
{
|
||||
RepositoryClient rc =
|
||||
RepositoryClientFactory.createClient(repository.getType(), directory,
|
||||
repository.getUrl(), writeUser.getName(), password);
|
||||
RepositoryClient rc = createRepositoryClient(writeUser, directory);
|
||||
|
||||
rc.checkout();
|
||||
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 write
|
||||
* @param read
|
||||
* @param noperm
|
||||
* @param password
|
||||
*/
|
||||
public RepositoryITCaseBase(Repository repository, User owner, User write,
|
||||
User read, String password)
|
||||
User read, User noperm, String password)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.ownerUser = owner;
|
||||
this.writeUser = write;
|
||||
this.readUser = read;
|
||||
this.nopermUser = noperm;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@@ -135,8 +137,6 @@ public class RepositoryITCaseBase
|
||||
{
|
||||
File directory = createTempDirectory();
|
||||
|
||||
System.out.println( repository.getUrl() );
|
||||
|
||||
try
|
||||
{
|
||||
RepositoryClient rc =
|
||||
@@ -164,6 +164,7 @@ public class RepositoryITCaseBase
|
||||
deleteUser(client, UserTestData.createTrillian());
|
||||
deleteUser(client, UserTestData.createZaphod());
|
||||
deleteUser(client, UserTestData.createMarvin());
|
||||
deleteUser(client, UserTestData.createPerfect());
|
||||
|
||||
Collection<Repository> repositories =
|
||||
createResource(client, "repositories").get(
|
||||
@@ -213,6 +214,10 @@ public class RepositoryITCaseBase
|
||||
|
||||
createUser(read);
|
||||
|
||||
User noperm = UserTestData.createPerfect();
|
||||
|
||||
createUser(noperm);
|
||||
|
||||
for (Type t : state.getRepositoryTypes())
|
||||
{
|
||||
if (t.getName().equals("git"))
|
||||
@@ -220,23 +225,30 @@ public class RepositoryITCaseBase
|
||||
Repository gitRepository = createTestRepository("git", owner, write,
|
||||
read);
|
||||
|
||||
params.add(new Object[] { gitRepository, owner, write, read,
|
||||
"secret" });
|
||||
params.add(new Object[]
|
||||
{
|
||||
gitRepository, owner, write, read, noperm, "secret"
|
||||
});
|
||||
}
|
||||
else if (t.getName().equals("svn"))
|
||||
{
|
||||
Repository svnRepository = createTestRepository("svn", owner, write,
|
||||
read);
|
||||
|
||||
params.add(new Object[] { svnRepository, owner, write, read,
|
||||
"secret" });
|
||||
params.add(new Object[]
|
||||
{
|
||||
svnRepository, owner, write, read, noperm, "secret"
|
||||
});
|
||||
}
|
||||
else if (t.getName().equals("hg"))
|
||||
{
|
||||
Repository hgRepository = createTestRepository("hg", owner, write,
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected User nopermUser;
|
||||
|
||||
/** Field description */
|
||||
protected User ownerUser;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user