コード例 #1
0
  @Before
  public void before() throws Exception {
    smtpPort = (new Random().nextInt(9999 - 1000) + 1000);
    //        smtpPort = 25;

    // create new user so conflicts don't occur with other tests
    User user = new User("token-test");
    user.setPassword("foobar");
    user.setFirstName("Token");
    user.setLastName("Test");
    user.setEmail("*****@*****.**");
    userManager.saveUser(user);
  }
コード例 #2
0
  @Test
  public void testConsumeRecoveryToken() throws Exception {
    final User user = userManager.getUserByUsername("token-test");
    final Integer version = user.getVersion();

    final String token = passwordTokenManager.generateRecoveryToken(user);
    assertNotNull(token);
    assertTrue(passwordTokenManager.isRecoveryTokenValid(user, token));

    // start SMTP Server
    Wiser wiser = startWiser(smtpPort);

    User updated = userManager.updatePassword(user.getUsername(), null, token, "user", "");

    wiser.stop();
    assertTrue(wiser.getMessages().size() == 1);

    assertTrue(updated.getVersion() > version);
    assertFalse(passwordTokenManager.isRecoveryTokenValid(updated, token));
  }