Package com.porterhead.rest.user.domain

Examples of com.porterhead.rest.user.domain.User


    }

    @Test
    public void sendRegistrationEmail() throws Exception {
        AuthenticatedUserToken userToken = createUserWithRandomUserName(Role.authenticated);
        User user = userRepository.findByUuid(userToken.getUserId());
        VerificationToken token = new VerificationToken(user,
                VerificationToken.VerificationTokenType.emailRegistration, 120);
        mailService.sendRegistrationEmail(new EmailServiceTokenModel(user, token, config.getHostNameUrl()));
        assertOnMailResult(user, token);
    }
View Full Code Here


    }

    @Test
    public void sendLostPasswordEmail() throws Exception {
        AuthenticatedUserToken userToken = createUserWithRandomUserName(Role.authenticated);
        User user = userRepository.findByUuid(userToken.getUserId());
        VerificationToken token = new VerificationToken(user,
                VerificationToken.VerificationTokenType.lostPassword, 120);
        mailService.sendLostPasswordEmail(new EmailServiceTokenModel(user, token, config.getHostNameUrl()));
        assertOnMailResult(user, token);
    }
View Full Code Here

        verify(verificationTokenService, times(0)).sendEmailVerificationToken(any(String.class));
    }

    @Test
    public void userTriesToModifyAnotherUserProfile() {
        User user = new User();
        ClientResponse response = super.resource().path("user/" + user.getUuid().toString()).entity(createUpdateUserRequest("foobar@example.com"),
                APPLICATION_JSON).accept(APPLICATION_JSON).put(ClientResponse.class);
        assertThat(response.getStatus(), is(403));
    }
View Full Code Here

        assertThat(context.isUserInRole(Role.authenticated.name().toUpperCase()), is(true));
    }

    @Test(expected = InvalidAuthorizationHeaderException.class)
    public void authenticationFailure() {
        User user = new User();
        user.setRole(Role.authenticated);
        ExternalUser externalUser = null;
        SecurityContext context = new SecurityContextImpl(externalUser);
        context.isUserInRole(Role.authenticated.name());
    }
View Full Code Here

        context.isUserInRole(Role.authenticated.name());
    }


    private SecurityContext createSecurityContext(Role role) {
        User user = new User();
        user.setRole(role);
        ExternalUser externalUser = new ExternalUser(user);
        SecurityContext context = new SecurityContextImpl(externalUser);
        return context;
    }
View Full Code Here

    }


    @Test
    public void sendLostPasswordToken() {
        User user = generateTestUser();
        when(userRepository.findByEmailAddress(user.getEmailAddress())).thenReturn(user);
        VerificationToken token = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        assertThat(user.getVerificationTokens().size(), is(1));
        assertThat(user.getActiveLostPasswordToken(), is(token));
        assertThat(token, is(not(Matchers.<Object>nullValue())));
        assertThat(tokens.size(), is(1));
        String sentToken = tokens.get(0);
        assertThat(sentToken, is(not(nullValue())));
        assertThat(sentToken, is(token.getToken()));
View Full Code Here

    }

    @Test
    public void sendLostPasswordTokenAgain() {
        User user = generateTestUser();
        when(userRepository.findByEmailAddress(user.getEmailAddress())).thenReturn(user);
        VerificationToken token1 = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        VerificationToken token2 = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        assertThat(token1, is(token2));
        assertThat(user.getVerificationTokens().size(), is(1));
        assertThat(tokens.size(), is(2))//gateway called twice

    }
View Full Code Here

    }

    @Test
    public void resetPassword() throws Exception {
        User user = generateTestUser();
        when(userRepository.save(user)).thenReturn(user);
        when(userRepository.findByEmailAddress(user.getEmailAddress())).thenReturn(user);
        VerificationToken token = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        when(tokenRepository.findByToken(token.getToken())).thenReturn(token);
        String encodedToken = new String(Base64.encodeBase64(token.getToken().getBytes()));
        VerificationToken verifiedToken = verificationTokenService.resetPassword(encodedToken, new PasswordRequest("newpassword"));
        assertThat(verifiedToken.isVerified(), is(true));
        assertThat(user.getHashedPassword(), is(user.hashPassword("newpassword")));
        assertThat(user.getVerificationTokens().get(0).isVerified(), is(true));
        //user should also be verified
        assertThat(user.isVerified(), is(true));
    }
View Full Code Here

        assertThat(user.isVerified(), is(true));
    }

    @Test
    public void resetPasswordGetNewToken() {
        User user = generateTestUser();
        when(userRepository.save(user)).thenReturn(user);
        when(userRepository.findByEmailAddress(user.getEmailAddress())).thenReturn(user);
        VerificationToken token = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        when(tokenRepository.findByToken(token.getToken())).thenReturn(token);
        String encodedToken = new String(Base64.encodeBase64(token.getToken().getBytes()));
        VerificationToken verifiedToken = verificationTokenService.resetPassword(encodedToken, new PasswordRequest("newpassword"));
        VerificationToken token2 = verificationTokenService.sendLostPasswordToken(new LostPasswordRequest(user.getEmailAddress()));
        assertThat(token2.getToken(), is(not(token.getToken())));
    }
View Full Code Here

        assertThat(token2.getToken(), is(not(token.getToken())));
    }

    @Test
    public void sendEmailToken() {
        User user = generateTestUser();
        when(userRepository.findByUuid(user.getUuid().toString())).thenReturn(user);
        VerificationToken token = verificationTokenService.sendEmailVerificationToken(user.getUuid().toString());
        assertThat(user.getVerificationTokens().size(), is(1));
        assertThat(token, is(not(Matchers.<Object>nullValue())));
        assertThat(tokens.size(), is(1));
        String sentToken = tokens.get(0);
        assertThat(sentToken, is(not(nullValue())));
        assertThat(sentToken, is(token.getToken()));
View Full Code Here

TOP

Related Classes of com.porterhead.rest.user.domain.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.