mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
use shiro-unit for manager permission tests
This commit is contained in:
@@ -34,6 +34,12 @@
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.sdorra</groupId>
|
||||
<artifactId>shiro-unit</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
|
||||
@@ -33,6 +33,13 @@
|
||||
|
||||
package sonia.scm;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -40,10 +47,28 @@ package sonia.scm;
|
||||
* @param <T>
|
||||
* @param <E>
|
||||
*/
|
||||
public abstract class ManagerTestBase<T extends ModelObject,
|
||||
E extends Exception> extends AbstractTestBase
|
||||
public abstract class ManagerTestBase<T extends ModelObject, E extends Exception>
|
||||
{
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
protected SCMContextProvider contextProvider;
|
||||
|
||||
protected Manager<T, E> manager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
contextProvider = MockUtil.getSCMContextProvider(tempFolder.newFolder());
|
||||
manager = createManager();
|
||||
manager.init(contextProvider);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws IOException {
|
||||
manager.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -52,33 +77,4 @@ public abstract class ManagerTestBase<T extends ModelObject,
|
||||
*/
|
||||
protected abstract Manager<T, E> createManager();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void postSetUp() throws Exception
|
||||
{
|
||||
manager = createManager();
|
||||
manager.init(contextProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
protected void preTearDown() throws Exception
|
||||
{
|
||||
manager.close();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected Manager<T, E> manager;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.legman.Subscribe;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
|
||||
import org.apache.shiro.subject.Subject;
|
||||
|
||||
@@ -47,7 +48,6 @@ import sonia.scm.Manager;
|
||||
import sonia.scm.ManagerTestBase;
|
||||
import sonia.scm.event.ScmEventBus;
|
||||
import sonia.scm.repository.api.HookContext;
|
||||
import sonia.scm.util.MockUtil;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -61,8 +61,7 @@ import java.util.Collection;
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class RepositoryManagerTestBase
|
||||
extends ManagerTestBase<Repository, RepositoryException>
|
||||
public abstract class RepositoryManagerTestBase extends ManagerTestBase<Repository, RepositoryException>
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -378,19 +377,6 @@ public abstract class RepositoryManagerTestBase
|
||||
assertEquals(2, hook.eventsReceived);
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setAdminSubject()
|
||||
{
|
||||
Subject admin = MockUtil.createAdminSubject();
|
||||
|
||||
setSubject(admin);
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -243,6 +243,13 @@
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.sdorra</groupId>
|
||||
<artifactId>shiro-unit</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>sonia.scm.plugins</groupId>
|
||||
<artifactId>scm-git-plugin</artifactId>
|
||||
|
||||
@@ -35,6 +35,8 @@ package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -60,14 +62,23 @@ import java.io.IOException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import org.junit.Rule;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@SubjectAware(
|
||||
username = "trillian",
|
||||
password = "secret",
|
||||
configuration = "classpath:sonia/scm/repository/shiro.ini"
|
||||
)
|
||||
public class DefaultRepositoryManagerTest extends RepositoryManagerTestBase
|
||||
{
|
||||
|
||||
@Rule
|
||||
public ShiroRule shiro = new ShiroRule();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -35,6 +35,8 @@ package sonia.scm.user;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.github.sdorra.shiro.ShiroRule;
|
||||
import com.github.sdorra.shiro.SubjectAware;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -51,14 +53,23 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.junit.Rule;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
@SubjectAware(
|
||||
username = "trillian",
|
||||
password = "secret",
|
||||
configuration = "classpath:sonia/scm/repository/shiro.ini"
|
||||
)
|
||||
public class DefaultUserManagerTest extends UserManagerTestBase
|
||||
{
|
||||
|
||||
@Rule
|
||||
public ShiroRule shiro = new ShiroRule();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -107,18 +118,6 @@ public class DefaultUserManagerTest extends UserManagerTestBase
|
||||
verify(userDAO, times(2)).add(any(User.class));
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*/
|
||||
@Before
|
||||
public void setAdminSubject()
|
||||
{
|
||||
setSubject(MockUtil.createAdminSubject());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
[users]
|
||||
trillian = secret, admin
|
||||
|
||||
[roles]
|
||||
admin = *
|
||||
Reference in New Issue
Block a user