### Question:
SessionResourceAuthzModule extends TokenOwnerAuthzModule { @Override public Promise<AuthorizationResult, ResourceException> authorizeAction(Context context, ActionRequest request) { if (actionCanBeInvokedByNonAdmin(request.getAction())) { return Promises.newResultPromise(AuthorizationResult.accessPermitted()); } return super.authorizeAction(context, request); } @Inject  SessionResourceAuthzModule(SSOTokenManager ssoTokenManager); @Override String getName(); @Override Promise<AuthorizationResult, ResourceException> authorizeAction(Context context, ActionRequest request); final static String NAME; }### Answer:
@Test public void shouldAllowLogoutAction() throws ExecutionException, InterruptedException { Context mockContext = mock(Context.class); ActionRequest mockRequest = mock(ActionRequest.class); given(mockRequest.getAction()).willReturn("logout"); Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest); assertTrue(result.get().isAuthorized()); }
@Test public void shouldAllowValidateAction() throws ExecutionException, InterruptedException { Context mockContext = mock(Context.class); ActionRequest mockRequest = mock(ActionRequest.class); given(mockRequest.getAction()).willReturn("validate"); Promise<AuthorizationResult, ResourceException> result = testModule.authorizeAction(mockContext, mockRequest); assertTrue(result.get().isAuthorized()); }
@Test public void shouldDeferAllOthers() { RootContext rootContext = new RootContext(); ActionRequest mockRequest = mock(ActionRequest.class); given(mockRequest.getAction()).willReturn("something else"); Promise<AuthorizationResult, ResourceException> promise = testModule.authorizeAction(rootContext, mockRequest); assertThat(promise).failedWithException().isExactlyInstanceOf(ForbiddenException.class); }