Search in sources :

Example 16 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientTest method should_not_able_to_create_client_which_is_resource_itself_with_wrong_not_existing_resource_ids.

@Test
public void should_not_able_to_create_client_which_is_resource_itself_with_wrong_not_existing_resource_ids() {
    Client client = ClientUtility.getClientAsNonResource(UUID.randomUUID().toString());
    ResponseEntity<String> exchange = ClientUtility.createClient(client);
    Assert.assertEquals(HttpStatus.BAD_REQUEST, exchange.getStatusCode());
}
Also used : Client(com.hw.helper.Client) Test(org.junit.Test)

Example 17 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientUtility method getInvalidClientAsResource.

public static Client getInvalidClientAsResource(String... resourceIds) {
    Client client = getClientRaw(resourceIds);
    Set<ClientType> strings = new HashSet<>();
    strings.add(ClientType.FRONTEND_APP);
    strings.add(ClientType.FIRST_PARTY);
    client.setTypes(strings);
    client.setResourceIndicator(true);
    return client;
}
Also used : ClientType(com.hw.helper.ClientType) Client(com.hw.helper.Client) HashSet(java.util.HashSet)

Example 18 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientUtility method getClientRaw.

/**
 * create password grant client with given resource ids.
 *
 * @param resourceIds resource client ids
 * @return client
 */
public static Client getClientRaw(String... resourceIds) {
    Client client = new Client();
    client.setName(UUID.randomUUID().toString().replace("-", ""));
    client.setClientSecret(UUID.randomUUID().toString().replace("-", ""));
    client.setGrantTypeEnums(new HashSet<>(Collections.singletonList(GrantTypeEnum.PASSWORD)));
    client.setAccessTokenValiditySeconds(1800);
    client.setRefreshTokenValiditySeconds(null);
    client.setHasSecret(true);
    client.setResourceIds(new HashSet<>(Arrays.asList(resourceIds)));
    return client;
}
Also used : Client(com.hw.helper.Client)

Example 19 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientIdempotentTest method create_client_w_same_changeId_two_times.

@Test
public void create_client_w_same_changeId_two_times() {
    Client oldClient = ClientUtility.getClientAsResource(AppConstant.CLIENT_ID_RESOURCE_ID);
    String s = UUID.randomUUID().toString();
    ResponseEntity<String> client1 = ClientUtility.createClient(oldClient, s);
    Assert.assertEquals(HttpStatus.OK, client1.getStatusCode());
    ResponseEntity<String> client2 = ClientUtility.createClient(oldClient, s);
    Assert.assertEquals(HttpStatus.OK, client2.getStatusCode());
}
Also used : Client(com.hw.helper.Client) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with Client

use of com.hw.helper.Client in project mt-auth by publicdevop2019.

the class ClientIdempotentTest method create_client_w_same_changeId_two_times_concurrent.

@Test
public void create_client_w_same_changeId_two_times_concurrent() {
    Client oldClient = ClientUtility.getClientAsResource(AppConstant.CLIENT_ID_RESOURCE_ID);
    String s = UUID.randomUUID().toString();
    AtomicReference<Integer> success = new AtomicReference<>(0);
    AtomicReference<Integer> failed = new AtomicReference<>(0);
    Runnable runnable2 = () -> {
        TestContext.init();
        ResponseEntity<String> client1 = ClientUtility.createClient(oldClient, s);
        if (client1.getStatusCode().is2xxSuccessful()) {
            success.set(success.get() + 1);
        }
        if (client1.getStatusCode().is4xxClientError()) {
            failed.set(failed.get() + 1);
        }
    };
    ArrayList<Runnable> runnables = new ArrayList<>();
    runnables.add(runnable2);
    runnables.add(runnable2);
    try {
        assertConcurrent("", runnables, 30000);
        Assert.assertEquals(1, (int) success.get());
        Assert.assertEquals(1, (int) failed.get());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) Client(com.hw.helper.Client) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Client (com.hw.helper.Client)36 Test (org.junit.Test)30 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)23 HttpEntity (org.springframework.http.HttpEntity)18 HttpHeaders (org.springframework.http.HttpHeaders)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 HashSet (java.util.HashSet)7 ArrayList (java.util.ArrayList)6 GrantTypeEnum (com.hw.helper.GrantTypeEnum)4 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)4 MultiValueMap (org.springframework.util.MultiValueMap)4 ClientType (com.hw.helper.ClientType)3 SumTotal (com.hw.helper.SumTotal)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ResponseEntity (org.springframework.http.ResponseEntity)3 IOException (java.io.IOException)1 Base64 (java.util.Base64)1 Map (java.util.Map)1 Ignore (org.junit.Ignore)1 OAuth2RefreshToken (org.springframework.security.oauth2.common.OAuth2RefreshToken)1