use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class PasswordFlowTest method create_user_then_login.
@Test
public void create_user_then_login() {
User user = UserUtility.createUser();
ResponseEntity<DefaultOAuth2AccessToken> user1 = UserUtility.register(user);
Assert.assertEquals(HttpStatus.OK, user1.getStatusCode());
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = UserUtility.login(user.getEmail(), user.getPassword());
Assert.assertEquals(HttpStatus.OK, tokenResponse.getStatusCode());
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserTest method forget_password.
@Test
public void forget_password() throws JsonProcessingException {
ResponseEntity<DefaultOAuth2AccessToken> registerTokenResponse = OAuth2Utility.getOAuth2ClientCredentialToken(AppConstant.CLIENT_ID_REGISTER_ID, AppConstant.EMPTY_CLIENT_SECRET);
String value = registerTokenResponse.getBody().getValue();
User user = UserUtility.createUser();
UserUtility.register(user);
ForgetPasswordRequest forgetPasswordRequest = new ForgetPasswordRequest();
forgetPasswordRequest.setEmail(user.getEmail());
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(value);
String s1 = mapper.writeValueAsString(forgetPasswordRequest);
HttpEntity<String> request = new HttpEntity<>(s1, headers);
String url = UrlUtility.getAccessUrl("/users" + "/forgetPwd");
ResponseEntity<Object> exchange = TestContext.getRestTemplate().exchange(url, HttpMethod.POST, request, Object.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
forgetPasswordRequest.setToken("123456789");
forgetPasswordRequest.setNewPassword("P1!" + UUID.randomUUID().toString().replaceAll("-", "").substring(0, 10));
String s2 = mapper.writeValueAsString(forgetPasswordRequest);
HttpHeaders header2 = new HttpHeaders();
header2.setContentType(MediaType.APPLICATION_JSON);
header2.setBearerAuth(value);
HttpEntity<String> request2 = new HttpEntity<>(s2, header2);
String url2 = UrlUtility.getAccessUrl("/users" + "/resetPwd");
TestContext.getRestTemplate().exchange(url2, HttpMethod.POST, request2, Object.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
// login
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = UserUtility.login(forgetPasswordRequest.getEmail(), forgetPasswordRequest.getNewPassword());
Assert.assertEquals(HttpStatus.OK, tokenResponse.getStatusCode());
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserTest method should_not_able_to_update_user_authority_to_root_with_user_account.
@Test
public void should_not_able_to_update_user_authority_to_root_with_user_account() throws JsonProcessingException {
User user = UserUtility.createUser();
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = UserUtility.login(AppConstant.ACCOUNT_USERNAME_USER, AppConstant.ACCOUNT_PASSWORD_USER);
String bearer = tokenResponse.getBody().getValue();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(bearer);
user.setGrantedAuthorities(List.of(AccessConstant.ADMIN_USER_ID, AccessConstant.USER_USER_ID));
String s1 = mapper.writeValueAsString(user);
HttpEntity<String> request = new HttpEntity<>(s1, headers);
String url = UrlUtility.getAccessUrl(USER_MNGMT + "/" + root_index);
ResponseEntity<DefaultOAuth2AccessToken> exchange = TestContext.getRestTemplate().exchange(url, HttpMethod.PUT, request, DefaultOAuth2AccessToken.class);
Assert.assertEquals(HttpStatus.FORBIDDEN, exchange.getStatusCode());
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserUtility method userCreateDraft.
public static User userCreateDraft(String username, String password) {
User user = new User();
user.setEmail(username);
user.setPassword("P1!" + password.substring(0, 10));
user.setMobileNumber("1231231234");
user.setCountryCode("1");
return user;
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserApiSecurityTest method should_not_able_to_create_user_w_client_missing_right_role.
@Test
public void should_not_able_to_create_user_w_client_missing_right_role() {
User user = UserUtility.createUser();
ResponseEntity<DefaultOAuth2AccessToken> registerTokenResponse = OAuth2Utility.getOAuth2ClientCredentialToken(CLIENT_ID_RIGHT_ROLE_NOT_SUFFICIENT_RESOURCE_ID, EMPTY_CLIENT_SECRET);
String value = registerTokenResponse.getBody().getValue();
ResponseEntity<Void> pendingUser = UserUtility.createPendingUser(user, value, new PendingResourceOwner());
Assert.assertEquals(HttpStatus.FORBIDDEN, pendingUser.getStatusCode());
}
Aggregations