Search in sources :

Example 21 with LongParam

use of io.dropwizard.jersey.params.LongParam in project keywhiz by square.

the class SecretsResourceTest method canDelete.

@Test
public void canDelete() {
    when(secretController.getSecretById(0xdeadbeef)).thenReturn(Optional.of(secret));
    HashSet<Group> groups = new HashSet<>();
    groups.add(new Group(0, "group1", "", NOW, null, NOW, null, null));
    groups.add(new Group(0, "group2", "", NOW, null, NOW, null, null));
    when(aclDAO.getGroupsFor(secret)).thenReturn(groups);
    Response response = resource.deleteSecret(user, new LongParam(Long.toString(0xdeadbeef)));
    verify(secretDAO).deleteSecretsByName("name");
    assertThat(response.getStatus()).isEqualTo(204);
}
Also used : Response(javax.ws.rs.core.Response) SecretDetailResponse(keywhiz.api.SecretDetailResponse) Group(keywhiz.api.model.Group) LongParam(io.dropwizard.jersey.params.LongParam) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 22 with LongParam

use of io.dropwizard.jersey.params.LongParam in project keywhiz by square.

the class GroupsResourceTest method getSpecificIncludesAllTheThings.

@Test
public void getSpecificIncludesAllTheThings() {
    when(groupDAO.getGroupById(4444)).thenReturn(Optional.of(group));
    SanitizedSecret secret = SanitizedSecret.of(1, "name", "checksum", null, now, "creator", now, "creator", null, null, null, 1136214245, 125L);
    when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of(secret));
    Client client = new Client(1, "client", "desc", now, "creator", now, "creator", null, true, false);
    when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of(client));
    GroupDetailResponse response = resource.getGroup(user, new LongParam("4444"));
    assertThat(response.getId()).isEqualTo(group.getId());
    assertThat(response.getName()).isEqualTo(group.getName());
    assertThat(response.getDescription()).isEqualTo(group.getDescription());
    assertThat(response.getCreationDate()).isEqualTo(group.getCreatedAt());
    assertThat(response.getCreatedBy()).isEqualTo(group.getCreatedBy());
    assertThat(response.getUpdateDate()).isEqualTo(group.getUpdatedAt());
    assertThat(response.getUpdatedBy()).isEqualTo(group.getUpdatedBy());
    assertThat(response.getSecrets()).containsExactly(secret);
    assertThat(response.getClients()).containsExactly(client);
}
Also used : SanitizedSecret(keywhiz.api.model.SanitizedSecret) GroupDetailResponse(keywhiz.api.GroupDetailResponse) LongParam(io.dropwizard.jersey.params.LongParam) Client(keywhiz.api.model.Client) Test(org.junit.Test)

Example 23 with LongParam

use of io.dropwizard.jersey.params.LongParam in project keywhiz by square.

the class MembershipResourceTest method missingSecretAllow.

@Test(expected = NotFoundException.class)
public void missingSecretAllow() {
    doThrow(IllegalStateException.class).when(aclDAO).findAndAllowAccess(3, group.getId(), auditLog, "user", new HashMap<>());
    resource.allowAccess(user, new LongParam("3"), new LongParam(Long.toString(group.getId())));
}
Also used : LongParam(io.dropwizard.jersey.params.LongParam) Test(org.junit.Test)

Example 24 with LongParam

use of io.dropwizard.jersey.params.LongParam in project keywhiz by square.

the class MembershipResourceTest method canEvict.

@Test
public void canEvict() {
    resource.evictClient(user, new LongParam(Long.toString(client.getId())), new LongParam(Long.toString(group.getId())));
    verify(aclDAO).findAndEvictClient(client.getId(), group.getId(), auditLog, "user", new HashMap<>());
}
Also used : LongParam(io.dropwizard.jersey.params.LongParam) Test(org.junit.Test)

Example 25 with LongParam

use of io.dropwizard.jersey.params.LongParam in project keywhiz by square.

the class MembershipResourceTest method canAllowAccess.

@Test
public void canAllowAccess() {
    Response response = resource.allowAccess(user, new LongParam("66"), new LongParam("55"));
    assertThat(response.getStatus()).isEqualTo(200);
    verify(aclDAO).findAndAllowAccess(66, 55, auditLog, "user", new HashMap<>());
}
Also used : Response(javax.ws.rs.core.Response) LongParam(io.dropwizard.jersey.params.LongParam) Test(org.junit.Test)

Aggregations

LongParam (io.dropwizard.jersey.params.LongParam)30 Test (org.junit.Test)30 Response (javax.ws.rs.core.Response)6 SecretDetailResponse (keywhiz.api.SecretDetailResponse)5 ClientDetailResponse (keywhiz.api.ClientDetailResponse)4 Group (keywhiz.api.model.Group)4 GroupDetailResponse (keywhiz.api.GroupDetailResponse)3 SanitizedSecret (keywhiz.api.model.SanitizedSecret)3 Client (keywhiz.api.model.Client)2 Secret (keywhiz.api.model.Secret)2 HashSet (java.util.HashSet)1 NotFoundException (javax.ws.rs.NotFoundException)1 KeywhizClient (keywhiz.client.KeywhizClient)1