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