Пример #1
0
  private User setupAppUser(UUID appId, String username, String email, boolean activated)
      throws Exception {
    Mailbox.clearAll();

    EntityManager em = setup.getEmf().getEntityManager(appId);

    Map<String, Object> userProps = new LinkedHashMap<String, Object>();
    userProps.put("username", username);
    userProps.put("email", email);
    userProps.put("activated", activated);

    User user = em.create(User.ENTITY_TYPE, User.class, userProps);
    setup.getEntityIndex().refresh(app.getId());

    return user;
  }
Пример #2
0
  /** Tests to make sure a normal user must be activated by the admin after confirmation. */
  @Test
  public void testAppUserConfirmationMail() throws Exception {
    final String orgName = uniqueOrg();
    final String appName = uniqueApp();
    final String userName = uniqueUsername();
    final String email = uniqueEmail();
    final String passwd = "testpassword";

    OrganizationOwnerInfo orgOwner;

    orgOwner = createOwnerAndOrganization(orgName, appName, userName, email, passwd, false, false);
    assertNotNull(orgOwner);

    setup.getEntityIndex().refresh(app.getId());

    ApplicationInfo app =
        setup.getMgmtSvc().createApplication(orgOwner.getOrganization().getUuid(), appName);
    setup.refreshIndex(app.getId());
    assertNotNull(app);
    enableEmailConfirmation(app.getId());
    enableAdminApproval(app.getId());

    setup.getEntityIndex().refresh(app.getId());

    final String appUserEmail = uniqueEmail();
    final String appUserUsername = uniqueUsername();

    User user = setupAppUser(app.getId(), appUserUsername, appUserEmail, true);

    OrganizationConfig orgConfig =
        setup.getMgmtSvc().getOrganizationConfigByUuid(orgOwner.getOrganization().getUuid());

    String subject = "User Account Confirmation: " + appUserEmail;
    String confirmation_url =
        orgConfig.getFullUrl(
            WorkflowUrl.USER_CONFIRMATION_URL, orgName, appName, user.getUuid().toString());

    // request confirmation
    setup.getMgmtSvc().startAppUserActivationFlow(app.getId(), user);

    List<Message> inbox = Mailbox.get(appUserEmail);
    assertFalse(inbox.isEmpty());
    MockImapClient client = new MockImapClient("test.com", appUserUsername, "somepassword");
    client.processMail();

    // subject ok
    Message confirmation = inbox.get(0);
    assertEquals(subject, confirmation.getSubject());

    // confirmation url ok
    String mailContent =
        (String) ((MimeMultipart) confirmation.getContent()).getBodyPart(1).getContent();
    logger.info(mailContent);
    assertTrue(StringUtils.contains(mailContent.toLowerCase(), confirmation_url.toLowerCase()));

    // token ok
    String token = getTokenFromMessage(confirmation);
    logger.info(token);
    ActivationState activeState =
        setup.getMgmtSvc().handleConfirmationTokenForAppUser(app.getId(), user.getUuid(), token);
    assertEquals(ActivationState.CONFIRMED_AWAITING_ACTIVATION, activeState);
  }