|
18 | 18 |
|
19 | 19 | import io.netty.util.AsciiString; |
20 | 20 | import org.cloudfoundry.AbstractIntegrationTest; |
| 21 | +import org.cloudfoundry.uaa.clients.BatchCreateClientsRequest; |
| 22 | +import org.cloudfoundry.uaa.clients.BatchCreateClientsResponse; |
| 23 | +import org.cloudfoundry.uaa.clients.BatchDeleteClientsRequest; |
21 | 24 | import org.cloudfoundry.uaa.clients.Client; |
| 25 | +import org.cloudfoundry.uaa.clients.CreateClient; |
22 | 26 | import org.cloudfoundry.uaa.clients.CreateClientRequest; |
23 | 27 | import org.cloudfoundry.uaa.clients.CreateClientResponse; |
24 | 28 | import org.cloudfoundry.uaa.clients.DeleteClientRequest; |
@@ -64,16 +68,60 @@ public void batchChangeSecret() { |
64 | 68 | // |
65 | 69 | } |
66 | 70 |
|
67 | | - @Ignore("TODO: Await https://www.pivotaltracker.com/story/show/125554031") |
68 | 71 | @Test |
69 | 72 | public void batchCreate() { |
70 | | - // |
| 73 | + String clientId1 = this.nameFactory.getClientId(); |
| 74 | + String clientId2 = this.nameFactory.getClientId(); |
| 75 | + String clientSecret = this.nameFactory.getClientSecret(); |
| 76 | + |
| 77 | + this.uaaClient.clients() |
| 78 | + .batchCreate(BatchCreateClientsRequest.builder() |
| 79 | + .client(CreateClient.builder() |
| 80 | + .approvalsDeleted(true) |
| 81 | + .authorizedGrantType(PASSWORD) |
| 82 | + .clientId(clientId1) |
| 83 | + .clientSecret(clientSecret) |
| 84 | + .scope("client.read", "client.write") |
| 85 | + .tokenSalt("test-token-salt") |
| 86 | + .build()) |
| 87 | + .client(CreateClient.builder() |
| 88 | + .approvalsDeleted(true) |
| 89 | + .authorizedGrantType(PASSWORD, REFRESH_TOKEN) |
| 90 | + .clientId(clientId2) |
| 91 | + .clientSecret(clientSecret) |
| 92 | + .scope("client.write") |
| 93 | + .tokenSalt("filtered-test-token-salt") |
| 94 | + .build()) |
| 95 | + .build()) |
| 96 | + .flatMapIterable(BatchCreateClientsResponse::getClients) |
| 97 | + .filter(client -> clientId1.equals(client.getClientId())) |
| 98 | + .subscribe(this.<Client>testSubscriber() |
| 99 | + .expectThat(response -> { |
| 100 | + assertEquals(Arrays.asList(PASSWORD, REFRESH_TOKEN), response.getAuthorizedGrantTypes()); |
| 101 | + assertEquals(clientId1, response.getClientId()); |
| 102 | + assertEquals(Arrays.asList("client.read", "client.write"), response.getScopes()); |
| 103 | + assertEquals("test-token-salt", response.getTokenSalt()); |
| 104 | + })); |
71 | 105 | } |
72 | 106 |
|
73 | | - @Ignore("TODO: Await https://www.pivotaltracker.com/story/show/125575011") |
74 | 107 | @Test |
75 | 108 | public void batchDelete() { |
76 | | - // |
| 109 | + String clientId1 = this.nameFactory.getClientId(); |
| 110 | + String clientId2 = this.nameFactory.getClientId(); |
| 111 | + String clientSecret = this.nameFactory.getClientSecret(); |
| 112 | + |
| 113 | + batchCreateClients(this.uaaClient, clientId1, clientId2, clientSecret) |
| 114 | + .flatMapIterable(BatchCreateClientsResponse::getClients) |
| 115 | + .map(Client::getClientId) |
| 116 | + .collectList() |
| 117 | + .then(clientIds -> this.uaaClient.clients() |
| 118 | + .batchDelete(BatchDeleteClientsRequest.builder() |
| 119 | + .clientIds(clientIds) |
| 120 | + .build())) |
| 121 | + .flatMap(ignore -> requestListClients(this.uaaClient)) |
| 122 | + .filter(client -> clientId1.equals(client.getClientId()) || clientId2.equals(client.getClientId())) |
| 123 | + .subscribe(this.testSubscriber() |
| 124 | + .expectCount(0)); |
77 | 125 | } |
78 | 126 |
|
79 | 127 | @Ignore("TODO: Await https://www.pivotaltracker.com/story/show/125572281") |
@@ -240,6 +288,28 @@ public void updateMetadata() { |
240 | 288 | })); |
241 | 289 | } |
242 | 290 |
|
| 291 | + private static Mono<BatchCreateClientsResponse> batchCreateClients(UaaClient uaaClient, String clientId1, String clientId2, String clientSecret) { |
| 292 | + return uaaClient.clients() |
| 293 | + .batchCreate(BatchCreateClientsRequest.builder() |
| 294 | + .client(CreateClient.builder() |
| 295 | + .approvalsDeleted(true) |
| 296 | + .authorizedGrantType(PASSWORD) |
| 297 | + .clientId(clientId1) |
| 298 | + .clientSecret(clientSecret) |
| 299 | + .scope("client.read", "client.write") |
| 300 | + .tokenSalt("test-token-salt") |
| 301 | + .build()) |
| 302 | + .client(CreateClient.builder() |
| 303 | + .approvalsDeleted(true) |
| 304 | + .authorizedGrantType(PASSWORD, REFRESH_TOKEN) |
| 305 | + .clientId(clientId2) |
| 306 | + .clientSecret(clientSecret) |
| 307 | + .scope("client.write") |
| 308 | + .tokenSalt("alternate-test-token-salt") |
| 309 | + .build()) |
| 310 | + .build()); |
| 311 | + } |
| 312 | + |
243 | 313 | private static Mono<CreateClientResponse> requestCreateClient(UaaClient uaaClient, String clientId, String clientSecret) { |
244 | 314 | return uaaClient.clients() |
245 | 315 | .create(CreateClientRequest.builder() |
|
0 commit comments