Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jun 18, 2024
1 parent 9b550e3 commit a41c4bb
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ public void publishDocument(final String siteId, final String documentId, final

AttributeRecord a = new AttributeRecord().documentId(AttributeKeyReserved.PUBLICATION.getKey())
.key(AttributeKeyReserved.PUBLICATION.getKey()).type(AttributeType.STANDARD)
.dataType(AttributeDataType.PUBLICATIONS);
.dataType(AttributeDataType.PUBLICATION);
if (!this.dbService.exists(a.fromS(a.pk(siteId)), a.fromS(a.sk()))) {
this.dbService.putItem(a.getAttributes(siteId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ public enum AttributeDataType {
/** {@link String}. */
STRING,
/** Publication. */
PUBLICATIONS;
PUBLICATION
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
*/
package com.formkiq.stacks.api.awstest;

import static com.formkiq.aws.services.lambda.ApiResponseStatus.SC_FORBIDDEN;
import static com.formkiq.aws.dynamodb.objects.Objects.notNull;
import static com.formkiq.aws.services.lambda.ApiResponseStatus.SC_UNAUTHORIZED;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import com.formkiq.client.api.DocumentsApi;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class CognitoRequestTest extends AbstractAwsIntegrationTest {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testGetGroups01() throws Exception {

// given
Expand All @@ -76,10 +77,11 @@ public void testGetGroups01() throws Exception {
GetGroupsResponse response = userApi.getGroups(null, null);

// then
assertFalse(response.getGroups().isEmpty());
List<Group> groups = notNull(response.getGroups());
assertFalse(groups.isEmpty());

Optional<Group> o = response.getGroups().stream()
.filter(g -> g.getName().equalsIgnoreCase("admins")).findFirst();
Optional<Group> o =
groups.stream().filter(g -> "admins".equalsIgnoreCase(g.getName())).findFirst();
assertFalse(o.isEmpty());

assertNotNull(o.get().getDescription());
Expand All @@ -94,7 +96,7 @@ public void testGetGroups01() throws Exception {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testGetGroupUsers01() throws Exception {

// given
Expand All @@ -109,9 +111,10 @@ public void testGetGroupUsers01() throws Exception {
GetUsersInGroupResponse response = userApi.getUsersInGroup(groupName, null, null);

// then
assertFalse(response.getUsers().isEmpty());
List<User> users = notNull(response.getUsers());
assertFalse(users.isEmpty());

User user = response.getUsers().get(0);
User user = users.get(0);

assertNotNull(user.getUsername());
assertNotNull(user.getUserStatus());
Expand All @@ -122,14 +125,13 @@ public void testGetGroupUsers01() throws Exception {

/**
* Test 'authentication_only' cognito group.
*
* @throws ApiException ApiException
*
*/
@Test
public void testAuthenticationOnly() throws ApiException {
public void testAuthenticationOnly() {
// given
String username = "noaccess1@formkiq.com";
addAndLoginCognito(username, Arrays.asList("authentication_only"));
addAndLoginCognito(username, List.of("authentication_only"));

ApiClient jwtClient = getApiClientForUser(username, USER_PASSWORD);

Expand All @@ -141,7 +143,7 @@ public void testAuthenticationOnly() throws ApiException {
fail();
} catch (ApiException e) {
// then
assertEquals(SC_FORBIDDEN.getStatusCode(), e.getCode());
assertEquals(SC_UNAUTHORIZED.getStatusCode(), e.getCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
*/
package com.formkiq.stacks.api.awstest;

import static com.formkiq.aws.dynamodb.objects.Objects.notNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void beforeEach() {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testApiKey01() throws Exception {
// given
String name = "My API";
Expand All @@ -113,7 +114,7 @@ public void testApiKey01() throws Exception {

// then
GetApiKeysResponse apiKeys = api.getApiKeys(siteId);
assertFalse(apiKeys.getApiKeys().isEmpty());
assertFalse(notNull(apiKeys.getApiKeys()).isEmpty());
}
}

Expand All @@ -134,14 +135,13 @@ public void testApiKey01() throws Exception {

/**
* Test GET /configuration/apiKeys as readuser user.
*
* @throws Exception Exception
*
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
public void testApiKey02() throws Exception {
@Timeout(value = TEST_TIMEOUT)
public void testApiKey02() {
// given
addAndLoginCognito(FINANCE_EMAIL, Arrays.asList("finance"));
addAndLoginCognito(FINANCE_EMAIL, List.of("finance"));

AuthenticationResultType token = getCognito().login(FINANCE_EMAIL, USER_PASSWORD);

Expand All @@ -156,7 +156,7 @@ public void testApiKey02() throws Exception {
fail();
} catch (ApiException e) {
assertEquals(ApiResponseStatus.SC_UNAUTHORIZED.getStatusCode(), e.getCode());
assertEquals("{\"message\":\"user is unauthorized\"}", e.getResponseBody());
assertEquals("{\"message\":\"fkq access denied to siteId (default)\"}", e.getResponseBody());
}
}

Expand All @@ -166,7 +166,7 @@ public void testApiKey02() throws Exception {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testApiKey03() throws Exception {
// given
String name = "My Read API";
Expand All @@ -176,7 +176,7 @@ public void testApiKey03() throws Exception {
com.formkiq.client.model.AddApiKeyRequest req = new com.formkiq.client.model.AddApiKeyRequest()
.name(name).addPermissionsItem(PermissionsEnum.READ);

for (String siteId : Arrays.asList("default")) {
for (String siteId : List.of("default")) {

// when
this.jwtApiClient.addDefaultHeader("Authorization", token.accessToken());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import static org.junit.jupiter.api.Assertions.fail;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import com.formkiq.aws.dynamodb.SiteIdKeyGenerator;
Expand Down Expand Up @@ -62,7 +62,7 @@ public class ConfigurationRequestTest extends AbstractAwsIntegrationTest {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testGetConfiguration01() throws Exception {
// given
String siteId = SiteIdKeyGenerator.DEFAULT_SITE_ID;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testGetConfiguration02() throws Exception {
// given
String siteId = SiteIdKeyGenerator.DEFAULT_SITE_ID;
String chatGptApiKey = "1239123123";
addAndLoginCognito(FINANCE_EMAIL, Arrays.asList("default_read"));
addAndLoginCognito(FINANCE_EMAIL, List.of("default_read"));

List<ApiClient> apiClients = getApiClients(siteId);
SystemManagementApi api = new SystemManagementApi(apiClients.get(0));
Expand All @@ -126,7 +126,7 @@ public void testGetConfiguration02() throws Exception {
api.updateConfiguration(siteId, req);
fail();
} catch (ApiException e) {
assertEquals(ApiResponseStatus.SC_FORBIDDEN.getStatusCode(), e.getCode());
assertEquals(ApiResponseStatus.SC_UNAUTHORIZED.getStatusCode(), e.getCode());
}

}
Expand All @@ -137,7 +137,7 @@ public void testGetConfiguration02() throws Exception {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testPatchConfiguration02() throws Exception {
// given
final int expected = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class DocumentsFulltextRequestTest extends AbstractAwsIntegrationTest {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testAddFulltextPdf01a() throws Exception {
// given
for (String siteId : Arrays.asList(null, UUID.randomUUID().toString())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static com.formkiq.aws.dynamodb.SiteIdKeyGenerator.DEFAULT_SITE_ID;
import static com.formkiq.aws.dynamodb.objects.Objects.notNull;
import static com.formkiq.aws.services.lambda.ApiResponseStatus.SC_UNAUTHORIZED;
import static com.formkiq.stacks.dynamodb.ConfigService.MAX_DOCUMENTS;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForActionsComplete;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForDocumentContent;
Expand Down Expand Up @@ -120,8 +121,6 @@ public class DocumentsRequestTest extends AbstractAwsIntegrationTest {
private static final int STATUS_BAD_REQUEST = 400;
/** 201 Created. */
private static final int STATUS_CREATED = 201;
/** 403 Forbidden. */
private static final int STATUS_FORBIDDEN = 403;
/** 404 Not Found. */
private static final int STATUS_NOT_FOUND = 404;
/** 200 OK. */
Expand Down Expand Up @@ -268,7 +267,7 @@ public void testGet02() throws Exception {
fail();
} catch (ApiException e) {
// then
assertEquals(STATUS_FORBIDDEN, e.getCode());
assertEquals(SC_UNAUTHORIZED.getStatusCode(), e.getCode());
assertEquals("{\"message\":\"fkq access denied to siteId (finance)\"}", e.getResponseBody());
}
}
Expand Down Expand Up @@ -300,7 +299,7 @@ public void testGet03() throws Exception {
try {
api.getDocuments(siteId, null, null, date, null, null, null, null);
} catch (ApiException e) {
assertEquals(STATUS_FORBIDDEN, e.getCode());
assertEquals(SC_UNAUTHORIZED.getStatusCode(), e.getCode());
assertEquals("{\"message\":\"fkq access denied to siteId (finance)\"}", e.getResponseBody());
}
}
Expand Down Expand Up @@ -569,7 +568,7 @@ public void testPost03() throws Exception {
api.addDocument(req, siteId, null);
} catch (ApiException e) {
// then
assertEquals(STATUS_FORBIDDEN, e.getCode());
assertEquals(SC_UNAUTHORIZED.getStatusCode(), e.getCode());
assertEquals("{\"message\":\"fkq access denied to siteId (finance)\"}", e.getResponseBody());
}
}
Expand Down

0 comments on commit a41c4bb

Please sign in to comment.