You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by Alex Orlov <oo...@mail.ru> on 2020/12/05 13:11:57 UTC
How to build mock subject for test having certain permissions?
Hello all,
I am trying to build mock subject for my tests. In my system I use the following code to check authorization:
var permission = new ResourcePermission(this.getResourceId(), action);
if (!subject.isPermitted(permission)) {
throw new AuthorizationException();
}
Now, I am trying to build a mock subject for my test:
Subject subjectUnderTest = new Subject
.Builder(securityManager)
.authenticated(true)
.???
.buildSubject();
Could anyone say, how to build a mock subject having certain permissions? Or do I miss something?
--
Best regards, Alex Orlov
Re: How to build mock subject for test having certain permissions?
Posted by Brian Demers <bd...@apache.org>.
Are you using a mock framework like Mockito or EasyMock? Here is an example
that uses EasyMock (and still sets up the thread context):
https://github.com/apache/shiro/blob/master/core/src/test/java/org/apache/shiro/test/ExampleShiroUnitTest.java
On Sat, Dec 5, 2020 at 8:12 AM Alex Orlov <oo...@mail.ru> wrote:
> Hello all,
>
> I am trying to build mock subject for my tests. In my system I use the
> following code to check authorization:
> var permission = new ResourcePermission(this.getResourceId(),
> action);
> if (!subject.isPermitted(permission)) {
> throw new AuthorizationException();
> }
>
> Now, I am trying to build a mock subject for my test:
>
> Subject subjectUnderTest = new Subject
> .Builder(securityManager)
> .authenticated(true)
> .???
> .buildSubject();
>
> Could anyone say, how to build a mock subject having certain permissions?
> Or do I miss something?
>
>
>
>
> --
> Best regards, Alex Orlov
>