use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class BizClientIdempotentTest method create_client_then_update_w_same_changeId_two_times.
@Test
public void create_client_then_update_w_same_changeId_two_times() {
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = action.getJwtPassword(ACCOUNT_USERNAME_ROOT, ACCOUNT_PASSWORD_ROOT);
String bearer = tokenResponse.getBody().getValue();
String s = UUID.randomUUID().toString();
Client oldClient = action.getClientAsResource(CLIENT_ID_RESOURCE_ID);
ResponseEntity<String> client1 = action.createClient(oldClient, s);
Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
oldClient.setAccessTokenValiditySeconds(120);
String url = UserAction.proxyUrl + UserAction.SVC_NAME_AUTH + CLIENTS + "/" + client1.getHeaders().getLocation().toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(bearer);
String s2 = UUID.randomUUID().toString();
headers.set("changeId", s2);
headers.set("X-XSRF-TOKEN", "123");
headers.add(HttpHeaders.COOKIE, "XSRF-TOKEN=123");
oldClient.setVersion(0);
HttpEntity<Client> request = new HttpEntity<>(oldClient, headers);
ResponseEntity<String> exchange = action.restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
oldClient.setVersion(1);
ResponseEntity<String> exchange2 = action.restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
Assert.assertEquals(HttpStatus.OK, exchange2.getStatusCode());
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class BizClientIdempotentTest method create_client_then_delete_w_same_changeId_two_times.
@Test
public void create_client_then_delete_w_same_changeId_two_times() {
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = action.getJwtPassword(ACCOUNT_USERNAME_ROOT, ACCOUNT_PASSWORD_ROOT);
String bearer = tokenResponse.getBody().getValue();
String s = UUID.randomUUID().toString();
Client oldClient = action.getClientAsResource(CLIENT_ID_RESOURCE_ID);
ResponseEntity<String> client1 = action.createClient(oldClient, s);
Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
oldClient.setAccessTokenValiditySeconds(120);
String url = UserAction.proxyUrl + UserAction.SVC_NAME_AUTH + CLIENTS + "/" + client1.getHeaders().getLocation().toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(bearer);
String s2 = UUID.randomUUID().toString();
headers.set("changeId", s2);
headers.set("X-XSRF-TOKEN", "123");
headers.add(HttpHeaders.COOKIE, "XSRF-TOKEN=123");
HttpEntity<Client> request = new HttpEntity<>(oldClient, headers);
ResponseEntity<String> exchange = action.restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
ResponseEntity<String> exchange2 = action.restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
Assert.assertEquals(HttpStatus.OK, exchange2.getStatusCode());
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class BizClientIdempotentTest method create_client_then_update_w_same_changeId_two_times_concurrent.
@Test
public void create_client_then_update_w_same_changeId_two_times_concurrent() {
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = action.getJwtPassword(ACCOUNT_USERNAME_ROOT, ACCOUNT_PASSWORD_ROOT);
String bearer = tokenResponse.getBody().getValue();
String s = UUID.randomUUID().toString();
Client oldClient = action.getClientAsResource(CLIENT_ID_RESOURCE_ID);
ResponseEntity<String> client1 = action.createClient(oldClient, s);
Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
oldClient.setAccessTokenValiditySeconds(120);
String url = UserAction.proxyUrl + UserAction.SVC_NAME_AUTH + CLIENTS + "/" + client1.getHeaders().getLocation().toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(bearer);
String s2 = UUID.randomUUID().toString();
headers.set("changeId", s2);
headers.set("X-XSRF-TOKEN", "123");
headers.add(HttpHeaders.COOKIE, "XSRF-TOKEN=123");
oldClient.setVersion(0);
HttpEntity<Client> request = new HttpEntity<>(oldClient, headers);
Runnable runnable2 = () -> {
ResponseEntity<String> exchange = action.restTemplate.exchange(url, HttpMethod.PUT, request, String.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
};
ArrayList<Runnable> runnables = new ArrayList<>();
runnables.add(runnable2);
runnables.add(runnable2);
try {
assertConcurrent("", runnables, 30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class BizClientIdempotentTest method create_client_then_delete_w_same_changeId_two_times_concurrent.
@Test
public void create_client_then_delete_w_same_changeId_two_times_concurrent() {
ResponseEntity<DefaultOAuth2AccessToken> tokenResponse = action.getJwtPassword(ACCOUNT_USERNAME_ROOT, ACCOUNT_PASSWORD_ROOT);
String bearer = tokenResponse.getBody().getValue();
String s = UUID.randomUUID().toString();
Client oldClient = action.getClientAsResource(CLIENT_ID_RESOURCE_ID);
ResponseEntity<String> client1 = action.createClient(oldClient, s);
Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
oldClient.setAccessTokenValiditySeconds(120);
String url = UserAction.proxyUrl + UserAction.SVC_NAME_AUTH + CLIENTS + "/" + client1.getHeaders().getLocation().toString();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setBearerAuth(bearer);
String s2 = UUID.randomUUID().toString();
headers.set("changeId", s2);
headers.set("X-XSRF-TOKEN", "123");
headers.add(HttpHeaders.COOKIE, "XSRF-TOKEN=123");
HttpEntity<Client> request = new HttpEntity<>(oldClient, headers);
Runnable runnable2 = () -> {
ResponseEntity<String> exchange = action.restTemplate.exchange(url, HttpMethod.DELETE, request, String.class);
Assert.assertEquals(HttpStatus.OK, exchange.getStatusCode());
};
ArrayList<Runnable> runnables = new ArrayList<>();
runnables.add(runnable2);
runnables.add(runnable2);
try {
assertConcurrent("", runnables, 30000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.hw.helper.Client in project mt-auth by publicdevop2019.
the class RefreshTokenTest method refresh_token_should_have_exp.
@Test
public void refresh_token_should_have_exp() {
// create client supports refresh token
Client clientRaw = ClientUtility.getClientRaw();
String clientSecret = clientRaw.getClientSecret();
HashSet<GrantTypeEnum> enums = new HashSet<>();
enums.add(GrantTypeEnum.PASSWORD);
enums.add(GrantTypeEnum.REFRESH_TOKEN);
clientRaw.setResourceIds(Collections.singleton(AppConstant.CLIENT_ID_OAUTH2_ID));
clientRaw.setGrantTypeEnums(enums);
clientRaw.setTypes(new HashSet<>(List.of(ClientType.FIRST_PARTY)));
clientRaw.setAccessTokenValiditySeconds(60);
clientRaw.setRefreshTokenValiditySeconds(1000);
ResponseEntity<String> client = ClientUtility.createClient(clientRaw);
String clientId = client.getHeaders().getLocation().toString();
Assert.assertEquals(HttpStatus.OK, client.getStatusCode());
// get jwt
ResponseEntity<DefaultOAuth2AccessToken> jwtPasswordWithClient = OAuth2Utility.getOAuth2PasswordToken(clientId, clientSecret, AppConstant.ACCOUNT_USERNAME_ADMIN, AppConstant.ACCOUNT_PASSWORD_ADMIN);
Assert.assertEquals(HttpStatus.OK, jwtPasswordWithClient.getStatusCode());
OAuth2RefreshToken refreshToken = jwtPasswordWithClient.getBody().getRefreshToken();
String jwt = refreshToken.getValue();
String jwtBody;
try {
jwtBody = jwt.split("\\.")[1];
} catch (ArrayIndexOutOfBoundsException ex) {
throw new IllegalArgumentException("malformed jwt token");
}
Base64.Decoder decoder = Base64.getDecoder();
byte[] decode = decoder.decode(jwtBody);
String s = new String(decode);
Integer exp;
try {
Map<String, Object> var0 = TestContext.mapper.readValue(s, new TypeReference<Map<String, Object>>() {
});
exp = (Integer) var0.get("exp");
} catch (IOException e) {
throw new IllegalArgumentException("unable to find authorities in authorization header");
}
Assert.assertNotNull(exp);
}
Aggregations