Search in sources :

Example 6 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationControllerTest method regEmailValidateUnclaimedAccountButEnableAutoDeprecateDisableOnClientTest.

@Test
public void regEmailValidateUnclaimedAccountButEnableAutoDeprecateDisableOnClientTest() {
    String email = "email1@test.orcid.org";
    String orcid = "0000-0000-0000-0000";
    when(emailManager.emailExists(email)).thenReturn(true);
    when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(profileEntityManager.isProfileClaimedByEmail(email)).thenReturn(false);
    when(profileEntityManager.isDeactivated(orcid)).thenReturn(false);
    //Set enable auto deprecate off
    when(emailManager.isAutoDeprecateEnableForEmail(email)).thenReturn(false);
    when(servletRequest.getScheme()).thenReturn("http");
    Registration reg = new Registration();
    reg.setEmail(Text.valueOf("email1@test.orcid.org"));
    reg.setEmailConfirm(Text.valueOf("email1@test.orcid.org"));
    reg = registrationController.regEmailValidate(servletRequest, reg, false, true);
    assertNotNull(reg);
    assertNotNull(reg.getEmail());
    assertNotNull(reg.getEmail().getErrors());
    assertEquals(1, reg.getEmail().getErrors().size());
    assertEquals("email1@test.orcid.org already exists in our system as an unclaimed record. Would you like to <a href=\"http://testserver.orcid.org/resend-claim?email=email1%40test.orcid.org\">resend the claim email</a>?", reg.getEmail().getErrors().get(0));
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 7 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationControllerTest method regEmailValidateUnclaimedAccountTest.

@Test
public void regEmailValidateUnclaimedAccountTest() {
    String email = "email1@test.orcid.org";
    String orcid = "0000-0000-0000-0000";
    when(emailManager.emailExists(email)).thenReturn(true);
    when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(profileEntityManager.isProfileClaimedByEmail(email)).thenReturn(false);
    when(profileEntityManager.isDeactivated(orcid)).thenReturn(false);
    when(emailManager.isAutoDeprecateEnableForEmail(email)).thenReturn(true);
    Registration reg = new Registration();
    reg.setEmail(Text.valueOf("email1@test.orcid.org"));
    reg.setEmailConfirm(Text.valueOf("email1@test.orcid.org"));
    reg = registrationController.regEmailValidate(servletRequest, reg, false, true);
    assertNotNull(reg);
    assertNotNull(reg.getEmail());
    assertNotNull(reg.getEmail().getErrors());
    //No errors, since the account can be auto deprecated
    assertTrue(reg.getEmail().getErrors().isEmpty());
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 8 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationControllerTest method regEmailValidateDeactivatedAccountTest.

@Test
public void regEmailValidateDeactivatedAccountTest() {
    String email = "email1@test.orcid.org";
    String orcid = "0000-0000-0000-0000";
    when(emailManager.emailExists(email)).thenReturn(true);
    when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(profileEntityManager.isProfileClaimedByEmail(email)).thenReturn(false);
    //Set it as deactivated
    when(profileEntityManager.isDeactivated(orcid)).thenReturn(true);
    Registration reg = new Registration();
    reg.setEmail(Text.valueOf("email1@test.orcid.org"));
    reg.setEmailConfirm(Text.valueOf("email1@test.orcid.org"));
    reg = registrationController.regEmailValidate(servletRequest, reg, false, true);
    assertNotNull(reg);
    assertNotNull(reg.getEmail());
    assertNotNull(reg.getEmail().getErrors());
    assertEquals(1, reg.getEmail().getErrors().size());
    assertTrue(reg.getEmail().getErrors().get(0).startsWith("orcid.frontend.verify.deactivated_email"));
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 9 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class OauthRegistrationControllerTest method testStripHtmlFromNames.

@SuppressWarnings("unchecked")
@Test
public void testStripHtmlFromNames() throws UnsupportedEncodingException {
    HttpSession session = mock(HttpSession.class);
    RequestInfoForm rf = new RequestInfoForm();
    RedirectView mv = new RedirectView();
    when(servletRequest.getSession()).thenReturn(session);
    when(servletRequest.getSession().getAttribute("requestInfoForm")).thenReturn(rf);
    when(authorizationEndpoint.approveOrDeny(Matchers.anyMap(), Matchers.anyMap(), Matchers.any(SessionStatus.class), Matchers.any(Principal.class))).thenReturn(mv);
    when(authenticationManager.authenticate(Matchers.any(Authentication.class))).thenAnswer(new Answer<Authentication>() {

        @Override
        public Authentication answer(InvocationOnMock invocation) throws Throwable {
            OrcidOAuth2Authentication mockedAuthentication = mock(OrcidOAuth2Authentication.class);
            return mockedAuthentication;
        }
    });
    Text email = Text.valueOf(System.currentTimeMillis() + "@test.orcid.org");
    OauthRegistrationForm reg = new OauthRegistrationForm();
    org.orcid.pojo.ajaxForm.Visibility fv = new org.orcid.pojo.ajaxForm.Visibility();
    fv.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
    reg.setActivitiesVisibilityDefault(fv);
    reg.setEmail(email);
    reg.setEmailConfirm(email);
    reg.setFamilyNames(Text.valueOf("<button onclick=\"alert('hello')\">Family Name</button>"));
    reg.setGivenNames(Text.valueOf("<button onclick=\"alert('hello')\">Given Names</button>"));
    reg.setPassword(Text.valueOf("1234abcd"));
    reg.setPasswordConfirm(Text.valueOf("1234abcd"));
    reg.setValNumClient(2L);
    reg.setValNumServer(4L);
    reg.setApproved(true);
    Checkbox c = new Checkbox();
    c.setValue(true);
    reg.setTermsOfUse(c);
    reg.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
    reg.setPersistentTokenEnabled(true);
    oauthRegistrationController.registerAndAuthorize(servletRequest, servletResponse, reg);
    ArgumentCaptor<HttpServletRequest> argument1 = ArgumentCaptor.forClass(HttpServletRequest.class);
    ArgumentCaptor<Registration> argument2 = ArgumentCaptor.forClass(Registration.class);
    ArgumentCaptor<Boolean> argument3 = ArgumentCaptor.forClass(Boolean.class);
    ArgumentCaptor<Locale> argument4 = ArgumentCaptor.forClass(Locale.class);
    ArgumentCaptor<String> argument5 = ArgumentCaptor.forClass(String.class);
    verify(registrationController).createMinimalRegistration(argument1.capture(), argument2.capture(), argument3.capture(), argument4.capture(), argument5.capture());
    assertNotNull(argument2.getValue());
    Registration registration = argument2.getValue();
    assertEquals(email.getValue(), registration.getEmail().getValue());
    assertEquals("Given Names", registration.getGivenNames().getValue());
    assertEquals("Family Name", registration.getFamilyNames().getValue());
}
Also used : Locale(java.util.Locale) HttpServletRequest(javax.servlet.http.HttpServletRequest) OauthRegistrationForm(org.orcid.pojo.ajaxForm.OauthRegistrationForm) Checkbox(org.orcid.pojo.ajaxForm.Checkbox) Registration(org.orcid.pojo.ajaxForm.Registration) SessionStatus(org.springframework.web.bind.support.SessionStatus) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) HttpSession(javax.servlet.http.HttpSession) Text(org.orcid.pojo.ajaxForm.Text) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) OrcidOAuth2Authentication(org.orcid.core.oauth.OrcidOAuth2Authentication) Authentication(org.springframework.security.core.Authentication) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RedirectView(org.springframework.web.servlet.view.RedirectView) Principal(java.security.Principal) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 10 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method testCreateMinimalRegistrationWithExistingEmailThatCanBeAutoDeprecated.

@Test
public void testCreateMinimalRegistrationWithExistingEmailThatCanBeAutoDeprecated() {
    //Create the user, but set it as unclaimed
    String email = "new_user_" + System.currentTimeMillis() + "@test.orcid.org";
    //Create a record by a member
    OrcidProfile orcidProfile = createBasicProfile(email, false, CLIENT_ID_AUTODEPRECATE_ENABLED);
    orcidProfile = orcidProfileManager.createOrcidProfile(orcidProfile, true, true);
    assertNotNull(orcidProfile);
    assertNotNull(orcidProfile.getOrcidIdentifier());
    assertNotNull(orcidProfile.getOrcidIdentifier().getPath());
    String orcidBefore = orcidProfile.getOrcidIdentifier().getPath();
    Map<String, String> map1 = emailManager.findOricdIdsByCommaSeparatedEmails(email);
    assertNotNull(map1);
    assertEquals(orcidBefore, map1.get(email));
    //Then try to create it again, this time claimed and without source
    Registration form = createRegistrationForm(email, true);
    String orcidAfter = registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
    assertTrue(OrcidStringUtils.isValidOrcid(orcidAfter));
    assertThat(orcidAfter, is(not(equalTo(orcidBefore))));
    Map<String, String> map2 = emailManager.findOricdIdsByCommaSeparatedEmails(email);
    assertNotNull(map2);
    assertEquals(orcidAfter, map2.get(email));
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Registration (org.orcid.pojo.ajaxForm.Registration)13 Test (org.junit.Test)11 DBUnitTest (org.orcid.test.DBUnitTest)11 Locale (java.util.Locale)2 HttpSession (javax.servlet.http.HttpSession)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 Checkbox (org.orcid.pojo.ajaxForm.Checkbox)2 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)2 Text (org.orcid.pojo.ajaxForm.Text)2 InvalidRequestException (org.springframework.security.oauth2.common.exceptions.InvalidRequestException)2 Principal (java.security.Principal)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)1 Visibility (org.orcid.jaxb.model.common_v2.Visibility)1 OauthRegistrationForm (org.orcid.pojo.ajaxForm.OauthRegistrationForm)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 SessionStatus (org.springframework.web.bind.support.SessionStatus)1