use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.
the class RegistrationControllerTest method verifyEmail_InvalidEmailTest.
@Test
public void verifyEmail_InvalidEmailTest() throws UnsupportedEncodingException {
String orcid = "0000-0000-0000-0000";
String email = "user_1@test.orcid.org";
SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenReturn(email);
// Email doesn't exists
when(emailManagerReadOnlyMock.emailExists(email)).thenReturn(false);
when(emailManagerReadOnlyMock.findOrcidIdByEmail(email)).thenReturn(orcid);
when(emailManager.verifyEmail(email, orcid)).thenReturn(true);
when(emailManagerReadOnlyMock.isPrimaryEmail(orcid, email)).thenReturn(true);
when(emailManagerReadOnlyMock.isPrimaryEmailVerified(orcid)).thenReturn(true);
RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
assertNotNull(mav);
assertEquals("redirect:/my-orcid", mav.getViewName());
assertFalse(ra.getFlashAttributes().containsKey("emailVerified"));
assertFalse(ra.getFlashAttributes().containsKey("primaryEmailUnverified"));
verify(emailManager, times(0)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.
the class SamplesControllerTest method testRemoveFileFromSample.
@Test
public void testRemoveFileFromSample() {
Long sampleId = 1L;
Long fileId = 2L;
Sample sample = new Sample();
SequencingObject file = new SingleEndSequenceFile(new SequenceFile(Paths.get("/tmp")));
when(sampleService.read(sampleId)).thenReturn(sample);
when(sequencingObjectService.readSequencingObjectForSample(sample, fileId)).thenReturn(file);
RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
HttpServletRequest request = new MockHttpServletRequest();
controller.removeSequencingObjectFromSample(attributes, sampleId, fileId, request, Locale.US);
verify(sampleService).removeSequencingObjectFromSample(sample, file);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project irida by phac-nml.
the class SamplesControllerTest method testRemoveGenomeAssemblyFromSample.
@Test
public void testRemoveGenomeAssemblyFromSample() {
Long sampleId = 1L;
Long assemblyId = 2L;
GenomeAssembly genomeAssembly = TestDataFactory.constructGenomeAssembly();
Sample sample = new Sample();
when(sampleService.read(sampleId)).thenReturn(sample);
when(sampleService.getGenomeAssemblyForSample(sample, assemblyId)).thenReturn(genomeAssembly);
when(updateSamplePermission.isAllowed(any(Authentication.class), eq(sample))).thenReturn(true);
RedirectAttributesModelMap attributes = new RedirectAttributesModelMap();
HttpServletRequest request = new MockHttpServletRequest();
controller.removeGenomeAssemblyFromSample(attributes, sampleId, assemblyId, request, Locale.US);
verify(sampleService).removeGenomeAssemblyFromSample(sample, assemblyId);
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.
the class RegistrationControllerTest method verifyEmail_NotVerifiedTest.
@Test
public void verifyEmail_NotVerifiedTest() throws UnsupportedEncodingException {
String orcid = "0000-0000-0000-0000";
String email = "user_1@test.orcid.org";
SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenReturn(email);
when(emailManagerReadOnlyMock.emailExists(email)).thenReturn(true);
when(emailManagerReadOnlyMock.findOrcidIdByEmail(email)).thenReturn(orcid);
// For some reason the email wasn't verified
when(emailManager.verifyEmail(email, orcid)).thenReturn(false);
when(emailManagerReadOnlyMock.isPrimaryEmail(orcid, email)).thenReturn(true);
when(emailManagerReadOnlyMock.isPrimaryEmailVerified(orcid)).thenReturn(true);
RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
assertNotNull(mav);
assertEquals("redirect:/my-orcid", mav.getViewName());
assertTrue(ra.getFlashAttributes().containsKey("emailVerified"));
assertFalse((Boolean) ra.getFlashAttributes().get("emailVerified"));
assertFalse(ra.getFlashAttributes().containsKey("primaryEmailUnverified"));
verify(emailManager, times(1)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
use of org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap in project ORCID-Source by ORCID.
the class RegistrationControllerTest method verifyEmail_UnableToDecryptEmailTest.
@Test
public void verifyEmail_UnableToDecryptEmailTest() throws UnsupportedEncodingException {
String orcid = "0000-0000-0000-0000";
String email = "user_1@test.orcid.org";
SecurityContextTestUtils.setupSecurityContextForWebUser(orcid, email);
String encodedEmail = new String(Base64.encodeBase64(email.getBytes()));
when(encryptionManagerMock.decryptForExternalUse(Mockito.anyString())).thenThrow(new EncryptionOperationNotPossibleException());
RedirectAttributesModelMap ra = new RedirectAttributesModelMap();
ModelAndView mav = registrationController.verifyEmail(servletRequest, encodedEmail, ra);
assertNotNull(mav);
assertEquals("redirect:/my-orcid", mav.getViewName());
assertTrue(ra.getFlashAttributes().containsKey("invalidVerifyUrl"));
assertTrue((Boolean) ra.getFlashAttributes().get("invalidVerifyUrl"));
verify(emailManager, times(0)).verifyEmail(Mockito.anyString(), Mockito.anyString());
}
Aggregations