use of okhttp3.FormBody.Builder in project keywhiz by square.
the class GroupResourceTest method createSecret.
private Response createSecret(String group, String secret) throws IOException {
SecretResourceTest secretResourceTest = new SecretResourceTest();
secretResourceTest.mutualSslClient = mutualSslClient;
Response response = secretResourceTest.create(CreateSecretRequestV2.builder().name(secret).content("test").groups(group).build());
assertThat(response.code()).isEqualTo(201);
return response;
}
use of okhttp3.FormBody.Builder in project keywhiz by square.
the class GroupResourceTest method createGroup_success.
@Test
public void createGroup_success() throws Exception {
Response httpResponse = create(CreateGroupRequestV2.builder().name("group1").build());
assertThat(httpResponse.code()).isEqualTo(201);
URI location = URI.create(httpResponse.header(LOCATION));
assertThat(location.getPath()).isEqualTo("/automation/v2/groups/group1");
}
use of okhttp3.FormBody.Builder in project keywhiz by square.
the class SecretResourceTest method secretChangeVersion_invalidVersion.
@Test
public void secretChangeVersion_invalidVersion() throws Exception {
int totalVersions = 3;
String name = "secret22";
List<SecretDetailResponseV2> versions;
SecretDetailResponseV2 initialCurrentVersion;
SecretDetailResponseV2 finalCurrentVersion;
assertThat(listing()).doesNotContain(name);
// get current time to calculate timestamps off for expiry
long now = System.currentTimeMillis() / 1000L;
// Create secrets
for (int i = 0; i < totalVersions; i++) {
createOrUpdate(CreateOrUpdateSecretRequestV2.builder().content(encoder.encodeToString(format("supa secret22_v%d", i).getBytes(UTF_8))).description(format("%s, version %d", name, i)).expiry(now + 86400 * 2).metadata(ImmutableMap.of("version", Integer.toString(i))).build(), name);
}
// Get the current version (the last version created)
initialCurrentVersion = lookup(name);
assertThat(initialCurrentVersion.name().equals(name));
assertThat(initialCurrentVersion.description().equals(format("%s, version %d", name, totalVersions)));
// Get an invalid version of this secret
versions = listVersions(name, 0, totalVersions);
Optional<Long> maxValidVersion = versions.stream().map(SecretDetailResponseV2::version).max(Long::compare);
if (maxValidVersion.isPresent()) {
// Reset the current version to this version
Request post = clientRequest(String.format("/automation/v2/secrets/%s/setversion", name)).post(RequestBody.create(JSON, mapper.writeValueAsString(SetSecretVersionRequestV2.builder().name(name).version(maxValidVersion.get() + 1).build()))).build();
Response httpResponse = mutualSslClient.newCall(post).execute();
assertThat(httpResponse.code()).isEqualTo(400);
// Get the current version, which should not have changed
finalCurrentVersion = lookup(name);
assertThat(finalCurrentVersion.equals(initialCurrentVersion));
}
}
use of okhttp3.FormBody.Builder in project keywhiz by square.
the class SecretResourceTest method partialUpdateSecret_notFound.
@Test
public void partialUpdateSecret_notFound() throws Exception {
PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().description("a more detailed description").descriptionPresent(true).expiry(1487268151L).expiryPresent(true).build();
RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(request));
Request post = clientRequest("/automation/v2/secrets/non-existent/partialupdate").post(body).build();
Response httpResponse = mutualSslClient.newCall(post).execute();
assertThat(httpResponse.code()).isEqualTo(404);
}
use of okhttp3.FormBody.Builder in project keywhiz by square.
the class SecretResourceTest method partialUpdateSecret_success.
//---------------------------------------------------------------------------------------
// partialUpdateSecret
//---------------------------------------------------------------------------------------
@Test
public void partialUpdateSecret_success() throws Exception {
// Create a secret to update
CreateOrUpdateSecretRequestV2 createRequest = CreateOrUpdateSecretRequestV2.builder().content(encoder.encodeToString("supa secret".getBytes(UTF_8))).description("desc").metadata(ImmutableMap.of("owner", "root", "mode", "0440")).type("password").build();
Response httpResponse = createOrUpdate(createRequest, "secret3");
assertThat(httpResponse.code()).isEqualTo(201);
URI location = URI.create(httpResponse.header(LOCATION));
assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3");
// Update the secret's description and set its expiry
PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().description("a more detailed description").descriptionPresent(true).expiry(1487268151L).expiryPresent(true).build();
httpResponse = partialUpdate(request, "secret3");
assertThat(httpResponse.code()).isEqualTo(201);
location = URI.create(httpResponse.header(LOCATION));
assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3");
}
Aggregations