use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testDeleteUserSettingsByName.
@Test
public void testDeleteUserSettingsByName() throws Exception {
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
PentahoSystem.registerObject(policy);
final RepositoryFile repositoryFile = mock(RepositoryFile.class);
when(repositoryFile.getId()).thenReturn(USER_FOLDER_ID);
when(repository.getFile(anyString())).thenReturn(repositoryFile);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
final Map<String, Serializable> settings = (Map<String, Serializable>) invocation.getArguments()[1];
assertNotNull(settings);
assertEquals(2, settings.size());
final Iterator<String> iterator = settings.keySet().iterator();
assertFalse(iterator.next().startsWith(UserSettingService.SETTING_PREFIX));
assertFalse(iterator.next().startsWith(UserSettingService.SETTING_PREFIX));
return null;
}
}).when(repository).setFileMetadata(eq(USER_FOLDER_ID), anyMap());
userSettingService.deleteUserSettings("test");
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class UserSettingServiceTest method testGetUserSettingByName.
@Test
public void testGetUserSettingByName() throws Exception {
final String settingName = USER_SETTING_NAME_3;
final String defaultValue = "defaultValue";
IAuthorizationPolicy policy = mock(IAuthorizationPolicy.class);
when(policy.isAllowed(anyString())).thenReturn(true);
PentahoSystem.registerObject(policy);
// try to get existing setting
final IUserSetting userSetting = userSettingService.getUserSetting("test", settingName, defaultValue);
assertEquals(settingName, userSetting.getSettingName());
assertEquals(USER_SETTING_VALUE_3, userSetting.getSettingValue());
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class FileServiceTest method testDoCanAdministerException.
@Test
public void testDoCanAdministerException() throws Exception {
IAuthorizationPolicy authorizationPolicy = mock(IAuthorizationPolicy.class);
doReturn(authorizationPolicy).when(fileService).getPolicy();
doThrow(new InternalError()).when(authorizationPolicy).isAllowed(RepositoryReadAction.NAME);
doReturn(true).when(authorizationPolicy).isAllowed(RepositoryCreateAction.NAME);
doReturn(false).when(authorizationPolicy).isAllowed(AdministerSecurityAction.NAME);
try {
assertFalse(fileService.doCanAdminister());
fail();
} catch (InternalError e) {
}
doReturn(false).when(authorizationPolicy).isAllowed(RepositoryReadAction.NAME);
doThrow(new InternalError()).when(authorizationPolicy).isAllowed(RepositoryCreateAction.NAME);
doReturn(true).when(authorizationPolicy).isAllowed(AdministerSecurityAction.NAME);
try {
assertFalse(fileService.doCanAdminister());
} catch (InternalError e) {
// the first comparison fail and the result should be false and no exception returned
fail();
}
doReturn(true).when(authorizationPolicy).isAllowed(RepositoryReadAction.NAME);
doReturn(false).when(authorizationPolicy).isAllowed(RepositoryCreateAction.NAME);
doThrow(new InternalError()).when(authorizationPolicy).isAllowed(AdministerSecurityAction.NAME);
try {
assertFalse(fileService.doCanAdminister());
} catch (InternalError e) {
// the second comparison fail and the result should be false and no exception returned
fail();
}
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class PasswordResourceTest method testEncodePassword.
@Test
public void testEncodePassword() throws Exception {
final IAuthorizationPolicy policy = Mockito.mock(IAuthorizationPolicy.class);
PasswordResource resource = getPasswordResource(policy);
Mockito.when(policy.isAllowed(AdministerSecurityAction.NAME)).thenReturn(true);
Response response = resource.encryptPassword("password");
Assert.assertTrue(response.getEntity().toString().contains("ENC:Encrypted 2be98afc86aa7f2e4bb18bd63c99dbdde"));
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(200, resource.encryptionForm().getStatus());
}
use of org.pentaho.platform.api.engine.IAuthorizationPolicy in project pentaho-platform by pentaho.
the class ActionRunnerTest method testCallWithStreamProvider.
@Test
public void testCallWithStreamProvider() throws Exception {
Map<String, Serializable> paramsMap = createMapWithUserLocale();
IAction actionBeanSpy = Mockito.spy(new TestAction());
IBackgroundExecutionStreamProvider mockStreamProvider = Mockito.mock(IBackgroundExecutionStreamProvider.class);
InputStream mockInputStream = Mockito.mock(InputStream.class);
OutputStream mockOutputStream = Mockito.mock(OutputStream.class);
when(mockStreamProvider.getInputStream()).thenReturn(mockInputStream);
String mockOutputPath = "/someUser/someOutput";
when(mockStreamProvider.getOutputPath()).thenReturn(mockOutputPath);
when(mockStreamProvider.getOutputStream()).thenReturn(mockOutputStream);
ISecurityHelper mockSecurityHelper = Mockito.mock(ISecurityHelper.class);
SecurityHelper.setMockInstance(mockSecurityHelper);
when(mockSecurityHelper.runAsUser(Mockito.anyString(), Mockito.any())).thenReturn(mockOutputPath);
PowerMockito.mockStatic(PentahoSystem.class);
IUnifiedRepository mockRepository = Mockito.mock(IUnifiedRepository.class);
when(PentahoSystem.get(isA(IUnifiedRepository.class.getClass()), Mockito.any())).thenReturn(mockRepository);
IAuthorizationPolicy mockAuthorizationPolicy = Mockito.mock(IAuthorizationPolicy.class);
when(PentahoSystem.get(isA(IAuthorizationPolicy.class.getClass()), Mockito.any())).thenReturn(mockAuthorizationPolicy);
when(mockAuthorizationPolicy.isAllowed(SchedulerOutputPathResolver.SCHEDULER_ACTION_NAME)).thenReturn(true);
String repoId = "SOME_REPO_ID";
Map<String, Serializable> dummyMetaData = new HashMap<>();
dummyMetaData.put(RepositoryFile.SCHEDULABLE_KEY, true);
when(mockRepository.getFileMetadata(repoId)).thenReturn(dummyMetaData);
RepositoryFile mockRepoFile = Mockito.mock(RepositoryFile.class);
when(mockRepoFile.isFolder()).thenReturn(true);
when(mockRepoFile.getId()).thenReturn(repoId);
ActionRunner actionRunner = new ActionRunner(actionBeanSpy, "actionUser", paramsMap, mockStreamProvider);
actionRunner.call();
Mockito.verify(actionBeanSpy).execute();
}
Aggregations