@Test public void testResend() throws IOException, ServletException { EnhancedSecurityContext.logout(); Configuration configuration = makeConfiguration(false); DefaultUser user = makeUser("*****@*****.**"); user.setVerified(false); user.setGuid("test-verify-email-resend"); persistenceService.persist(user); WebappTestRunner runner = new WebappTestRunner(); runner .test("/verify-email") .withMock(Configuration.class, configuration) .withMock(EmailTransportService.class, EmailTestHelper.getService()) .withParameter("email", "*****@*****.**") .post(); assertEquals("verification-email-sent", runner.response.getRedirect()); persistenceService.reload(user); assertFalse(user.isVerified()); assertFalse(user.getGuid().equals("test-verify-email-resend")); assertEquals(1, EmailTestHelper.getEmailResults().size()); }
@Test public void testRegisterVerify() throws Exception { TestUser user = new TestUser(); user.setUsername("*****@*****.**"); assertEquals( RegisterResult.PENDING, userService.register(user, "password", "http://www.example.com/verify-email")); assertFalse(user.isPartial()); assertEquals(1, user.getRoles().size()); assertNotNull(user.getRoles().iterator().next()); Email email = EmailTestHelper.getEmailResults().poll(); assertTrue( email.getHtml().contains("http://www.example.com/verify-email?guid=" + user.getGuid())); }
protected void setupConfigurationAndUserHandlerAndEmail() { final Configuration config = createNiceMock(Configuration.class); expect(config.getString("jcatapult.user.default-role", "user")).andReturn("user"); expect(config.getBoolean("jcatapult.user.verify-emails", false)).andReturn(false); replay(config); addModules( new AbstractModule() { public void configure() { bind(UserHandler.class).to(TestUserHandler.class); bind(Configuration.class).toInstance(config); } }); EmailTestHelper.setup(this); }
@Test public void testVerifyBadGUID() throws IOException, ServletException { EnhancedSecurityContext.logout(); Configuration configuration = makeConfiguration(false); DefaultUser user = makeUser("*****@*****.**"); user.setVerified(false); persistenceService.persist(user); WebappTestRunner runner = new WebappTestRunner(); runner .test("/verify-email") .withMock(Configuration.class, configuration) .withMock(EmailTransportService.class, EmailTestHelper.getService()) .withParameter("guid", "bad-guid") .get(); assertEquals(1, runner.messageStore.getActionMessages(MessageType.ERROR).size()); assertNull(runner.response.getRedirect()); assertTrue(runner.response.getStream().toString().contains("<form")); persistenceService.reload(user); assertFalse(user.isVerified()); }