### Question:
CoreTokenResourceAuthzModule extends AdminOnlyAuthzModule { @Override protected Promise<AuthorizationResult, ResourceException> authorize(Context context) { if (!enabled) { if (debug.messageEnabled()) { debug.message("CoreTokenResourceAuthzModule :: Restricted access to CoreTokenResource"); } return Promises.newResultPromise(AuthorizationResult.accessDenied("CoreTokenResource not enabled.")); } if (debug.messageEnabled()) { debug.message("CoreTokenResourceAuthzModule :: Request forwarded to AdminOnlyAuthzModule."); } return super.authorize(context); } @Inject  CoreTokenResourceAuthzModule(Config<SessionService> sessionService, Debug debug, boolean enabled); @Override String getName(); final static String NAME; }### Answer:
@Test public void shouldBlockAllAccessIfResourceDisabled() throws Exception { CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, false); SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class); Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext); assertFalse(result.get().isAuthorized()); }
@Test public void shouldAuthorizeAccessToSuperUserIfResourceEnabled() throws Exception { CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, true); SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class); SSOToken mockSSOToken = mock(SSOToken.class); given(mockSSOTokenContext.getCallerSSOToken()).willReturn(mockSSOToken); given(mockSSOToken.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("test"); given(mockService.isSuperUser("test")).willReturn(true); Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext); assertTrue(result.get().isAuthorized()); }
@Test public void shouldBlockAllAccessIfResourceEnabledButNonSuperUser() throws Exception { CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, true); SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class); SSOToken mockSSOToken = mock(SSOToken.class); given(mockSSOTokenContext.getCallerSSOToken()).willReturn(mockSSOToken); given(mockSSOToken.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("test"); given(mockService.isSuperUser("test")).willReturn(false); Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext); assertFalse(result.get().isAuthorized()); }