use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserUtility method registerNewUserThenLogin.
/**
* register new user then login.
*
* @return login token
*/
public static String registerNewUserThenLogin() {
User randomUser = createUser();
register(randomUser);
ResponseEntity<DefaultOAuth2AccessToken> loginTokenResponse = login(randomUser.getEmail(), randomUser.getPassword());
return Objects.requireNonNull(loginTokenResponse.getBody()).getValue();
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserUtility method randomRegisterAnUser.
public static User randomRegisterAnUser() {
User random = createUser();
register(random);
return random;
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserTest method lock_then_unlock_user.
@Test
public void lock_then_unlock_user() {
User user = UserUtility.createUser();
ResponseEntity<DefaultOAuth2AccessToken> createResp = UserUtility.register(user);
String s = createResp.getHeaders().getLocation().toString();
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = UserUtility.login(AppConstant.ACCOUNT_USERNAME_ADMIN, AppConstant.ACCOUNT_PASSWORD_ADMIN);
String bearer = tokenResponse.getBody().getValue();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(bearer);
user.setGrantedAuthorities(List.of(AccessConstant.USER_USER_ID));
user.setLocked(true);
user.setVersion(0);
HttpEntity<User> request = new HttpEntity<>(user, headers);
String url = UrlUtility.getAccessUrl(USER_MNGMT + "/" + s);
ResponseEntity<DefaultOAuth2AccessToken> exchange = TestContext.getRestTemplate().exchange(url, HttpMethod.PUT, request, DefaultOAuth2AccessToken.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
// login to verify account has been locked
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse1 = UserUtility.login(user.getEmail(), user.getPassword());
Assert.assertEquals(HttpStatus.BAD_REQUEST, tokenResponse1.getStatusCode());
user.setLocked(false);
user.setVersion(1);
HttpEntity<User> request22 = new HttpEntity<>(user, headers);
ResponseEntity<DefaultOAuth2AccessToken> exchange22 = TestContext.getRestTemplate().exchange(url, HttpMethod.PUT, request22, DefaultOAuth2AccessToken.class);
Assert.assertEquals(HttpStatus.OK, exchange22.getStatusCode());
// login to verify account has been unlocked
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse12 = UserUtility.login(user.getEmail(), user.getPassword());
Assert.assertEquals(HttpStatus.OK, tokenResponse12.getStatusCode());
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserTest method should_not_able_to_create_user_with_user_name_not_email.
@Test
public void should_not_able_to_create_user_with_user_name_not_email() {
User user = UserUtility.userCreateDraft(UUID.randomUUID().toString(), UUID.randomUUID().toString());
ResponseEntity<DefaultOAuth2AccessToken> user1 = UserUtility.register(user);
Assert.assertEquals(HttpStatus.BAD_REQUEST, user1.getStatusCode());
}
use of com.hw.helper.User in project mt-auth by publicdevop2019.
the class UserTest method delete_user.
@Test
public void delete_user() {
User user = UserUtility.createUser();
ResponseEntity<DefaultOAuth2AccessToken> user1 = UserUtility.register(user);
String s = user1.getHeaders().getLocation().toString();
String url = UrlUtility.getAccessUrl(USER_MNGMT + "/" + s);
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse12 = UserUtility.login(user.getEmail(), user.getPassword());
Assert.assertEquals(HttpStatus.OK, tokenResponse12.getStatusCode());
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = UserUtility.login(AppConstant.ACCOUNT_USERNAME_ADMIN, AppConstant.ACCOUNT_PASSWORD_ADMIN);
HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(tokenResponse.getBody().getValue());
HttpEntity<Object> request = new HttpEntity<>(null, headers);
ResponseEntity<Object> exchange = TestContext.getRestTemplate().exchange(url, HttpMethod.DELETE, request, Object.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse123 = UserUtility.login(user.getEmail(), user.getPassword());
Assert.assertEquals(HttpStatus.UNAUTHORIZED, tokenResponse123.getStatusCode());
}
Aggregations