use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ReadSequencingObjectPermissionTest method testRejectPermission.
@Test
public void testRejectPermission() {
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertFalse("permission was granted.", permission.isAllowed(auth, 1L));
verify(sequencingObjectRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(ssoRepository).getSampleForSequencingObject(sf);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ReadSequencingObjectPermissionTest method testGrantPermission.
@Test
public void testGrantPermission() {
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
SingleEndSequenceFile sf = new SingleEndSequenceFile(null);
SampleSequencingObjectJoin join = new SampleSequencingObjectJoin(s, sf);
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sequencingObjectRepository.findOne(1L)).thenReturn(sf);
when(ssoRepository.getSampleForSequencingObject(sf)).thenReturn(join);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(true);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertTrue("permission was not granted.", permission.isAllowed(auth, 1L));
verify(sequencingObjectRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
verify(ssoRepository).getSampleForSequencingObject(sf);
verify(readProjectPermission).isAllowed(any(), eq(p));
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ReadProjectPermissionTest method testRejectPermission.
@Test
public void testRejectPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, new User(), ProjectRole.PROJECT_USER));
when(userRepository.loadUserByUsername(username)).thenReturn(u);
when(projectRepository.findOne(1L)).thenReturn(p);
when(pujRepository.getUsersForProject(p)).thenReturn(projectUsers);
when(ugpjRepository.findGroupsByProject(p)).thenReturn(ImmutableList.of());
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertFalse("permission was granted.", readProjectPermission.isAllowed(auth, 1L));
verify(userRepository).loadUserByUsername(username);
verify(projectRepository).findOne(1L);
verify(pujRepository).getUsersForProject(p);
verifyZeroInteractions(ugRepository);
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class ReadSamplePermissionTest method testRejectPermission.
@Test
public void testRejectPermission() {
String username = "fbristow";
User u = new User();
u.setUsername(username);
Project p = new Project();
Sample s = new Sample();
List<Join<Project, Sample>> projectSampleList = new ArrayList<>();
projectSampleList.add(new ProjectSampleJoin(p, s, true));
List<Join<Project, User>> projectUsers = new ArrayList<>();
projectUsers.add(new ProjectUserJoin(p, new User(), ProjectRole.PROJECT_USER));
when(psjRepository.getProjectForSample(s)).thenReturn(projectSampleList);
when(sampleRepository.findOne(1L)).thenReturn(s);
when(readProjectPermission.isAllowed(any(), eq(p))).thenReturn(false);
Authentication auth = new UsernamePasswordAuthenticationToken("fbristow", "password1");
assertFalse("permission was granted.", readSamplePermission.isAllowed(auth, 1L));
verify(sampleRepository).findOne(1L);
verify(psjRepository).getProjectForSample(s);
}
use of ca.corefacility.bioinformatics.irida.model.joins.Join in project irida by phac-nml.
the class UsersControllerTest method testGetOtherUsersSpecificPage.
@Test
public void testGetOtherUsersSpecificPage() {
Principal principal = () -> USER_NAME;
Long userId = 1L;
String roleString = "User";
ExtendedModelMap model = new ExtendedModelMap();
User puser = new User(userId, USER_NAME, null, null, null, null, null);
puser.setSystemRole(Role.ROLE_USER);
User user = new User(userId, "tom", null, null, null, null, null);
user.setSystemRole(Role.ROLE_USER);
@SuppressWarnings("unchecked") List<Join<Project, User>> joins = Lists.newArrayList(new ProjectUserJoin(new Project("good project"), user, ProjectRole.PROJECT_USER));
when(userService.read(userId)).thenReturn(user);
when(userService.getUserByUsername(USER_NAME)).thenReturn(puser);
when(messageSource.getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class))).thenReturn(roleString);
when(projectService.getProjectsForUser(user)).thenReturn(joins);
String userSpecificPage = controller.getUserSpecificPage(userId, true, model, principal);
assertEquals(USERS_DETAILS_PAGE, userSpecificPage);
assertEquals(false, model.get("canEditUser"));
verify(userService).read(userId);
verify(userService).getUserByUsername(USER_NAME);
verify(messageSource).getMessage(eq("systemrole." + Role.ROLE_USER.getName()), eq(null), any(Locale.class));
verify(projectService).getProjectsForUser(user);
}
Aggregations