use of com.formkiq.stacks.client.FormKiqClientConnection in project formkiq-core by formkiq.
the class WebsocketTest method beforeClass.
/**
* beforeclass.
*
* @throws IOException IOException
* @throws URISyntaxException URISyntaxException
*/
@BeforeClass
public static void beforeClass() throws IOException, URISyntaxException {
Region awsregion = Region.of(System.getProperty("testregion"));
String awsprofile = System.getProperty("testprofile");
String app = System.getProperty("testappenvironment");
SqsConnectionBuilder sqsConnection = new SqsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
sqsService = new SqsService(sqsConnection);
SsmConnectionBuilder ssmBuilder = new SsmConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
SsmService ssmService = new SsmServiceImpl(ssmBuilder);
websocketSqsUrl = ssmService.getParameterValue("/formkiq/" + app + "/sqs/WebsocketUrl");
websocketUrl = ssmService.getParameterValue("/formkiq/" + app + "/api/WebsocketUrl");
String cognitoUserPoolId = ssmService.getParameterValue("/formkiq/" + app + "/cognito/UserPoolId");
String cognitoClientId = ssmService.getParameterValue("/formkiq/" + app + "/cognito/UserPoolClientId");
String cognitoIdentitypool = ssmService.getParameterValue("/formkiq/" + app + "/cognito/IdentityPoolId");
CognitoConnectionBuilder adminBuilder = new CognitoConnectionBuilder(cognitoClientId, cognitoUserPoolId, cognitoIdentitypool).setCredentials(awsprofile).setRegion(awsregion);
adminCognitoService = new CognitoService(adminBuilder);
addAndLoginCognito(USER_EMAIL, GROUP);
token = adminCognitoService.login(USER_EMAIL, USER_PASSWORD);
String rootHttpUrl = ssmService.getParameterValue("/formkiq/" + app + "/api/DocumentsHttpUrl");
FormKiqClientConnection connection = new FormKiqClientConnection(rootHttpUrl).cognitoIdToken(token.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
httpClient = new FormKiqClientV1(connection);
webconnectionsTable = ssmService.getParameterValue("/formkiq/" + app + "/dynamodb/WebConnectionsTableName");
dbConnection = new DynamoDbConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
}
use of com.formkiq.stacks.client.FormKiqClientConnection in project formkiq-core by formkiq.
the class DocumentsRequestTest method testGet02.
/**
* Get Not existing file. Test user with no roles with/out siteid
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testGet02() throws Exception {
// given
final String siteId = "finance";
AuthenticationResultType token = login(READONLY_EMAIL, USER_PASSWORD);
FormKiqClientConnection connection = new FormKiqClientConnection(getRootHttpUrl()).cognitoIdToken(token.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
FormKiqClientV1 client = new FormKiqClientV1(connection);
GetDocumentsRequest request = new GetDocumentsRequest().date(new Date());
// when
final HttpResponse<String> responseNoSiteId = client.getDocumentsAsHttpResponse(request);
final HttpResponse<String> responseSiteId = client.getDocumentsAsHttpResponse(request.siteId(siteId));
// then
assertEquals(STATUS_OK, responseNoSiteId.statusCode());
assertRequestCorsHeaders(responseNoSiteId.headers());
assertTrue(responseNoSiteId.body().contains("\"documents\":["));
assertEquals(STATUS_FORBIDDEN, responseSiteId.statusCode());
assertRequestCorsHeaders(responseSiteId.headers());
assertEquals("{\"message\":\"Access Denied\"}", responseSiteId.body());
}
use of com.formkiq.stacks.client.FormKiqClientConnection in project formkiq-core by formkiq.
the class DocumentsRequestTest method testGet03.
/**
* Get Not existing file. Test user with 'USERS' roles with/out siteid
*
* @throws Exception Exception
*/
@Test(timeout = TEST_TIMEOUT)
public void testGet03() throws Exception {
// given
final String siteId = "finance";
AuthenticationResultType token = login(USER_EMAIL, USER_PASSWORD);
FormKiqClientConnection connection = new FormKiqClientConnection(getRootHttpUrl()).cognitoIdToken(token.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
FormKiqClientV1 client = new FormKiqClientV1(connection);
GetDocumentsRequest request = new GetDocumentsRequest().date(new Date());
// when
final HttpResponse<String> responseNoSiteId = client.getDocumentsAsHttpResponse(request);
final HttpResponse<String> responseSiteId = client.getDocumentsAsHttpResponse(request.siteId(siteId));
// then
assertEquals(STATUS_OK, responseNoSiteId.statusCode());
assertRequestCorsHeaders(responseNoSiteId.headers());
assertTrue(responseNoSiteId.body().contains("\"documents\":["));
assertEquals(STATUS_FORBIDDEN, responseSiteId.statusCode());
assertRequestCorsHeaders(responseSiteId.headers());
assertEquals("{\"message\":\"Access Denied\"}", responseSiteId.body());
}
use of com.formkiq.stacks.client.FormKiqClientConnection in project formkiq-core by formkiq.
the class AbstractApiTest method setupCognito.
/**
* Setup Cognito.
*/
private static void setupCognito() {
if (!adminCognitoService.isUserExists(ADMIN_EMAIL)) {
adminCognitoService.addUser(ADMIN_EMAIL, USER_TEMP_PASSWORD);
adminCognitoService.addUserToGroup(ADMIN_EMAIL, "Admins");
adminCognitoService.loginWithNewPassword(ADMIN_EMAIL, USER_TEMP_PASSWORD, USER_PASSWORD);
} else {
adminCognitoService.updateUserAttributes(ADMIN_EMAIL, Arrays.asList(AttributeType.builder().name("email_verified").value("true").build()));
adminCognitoService.setUserPassword(ADMIN_EMAIL, USER_TEMP_PASSWORD, false);
adminCognitoService.loginWithNewPassword(ADMIN_EMAIL, USER_TEMP_PASSWORD, USER_PASSWORD);
}
addAndLoginCognito(USER_EMAIL, DEFAULT_SITE_ID);
addAndLoginCognito(FINANCE_EMAIL, "finance");
addAndLoginCognito(READONLY_EMAIL, "default_read");
adminToken = login(ADMIN_EMAIL, USER_PASSWORD);
FormKiqClientConnection connection = new FormKiqClientConnection(rootHttpUrl).cognitoIdToken(adminToken.idToken()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
httpClient = new FormKiqClientV1(connection);
}
use of com.formkiq.stacks.client.FormKiqClientConnection in project formkiq-core by formkiq.
the class AbstractApiTest method beforeClass.
/**
* Before Class.
*
* @throws IOException IOException
*/
@BeforeClass
public static void beforeClass() throws IOException {
awsregion = Region.of(System.getProperty("testregion"));
String awsprofile = System.getProperty("testprofile");
appenvironment = System.getProperty("testappenvironment");
loadSsmParameterVariables(awsprofile);
try (ProfileCredentialsProvider credentials = ProfileCredentialsProvider.builder().profileName(awsprofile).build()) {
FormKiqClientConnection connection = new FormKiqClientConnection(rootRestUrl).region(awsregion).credentials(credentials.resolveCredentials()).header("Origin", Arrays.asList("http://localhost")).header("Access-Control-Request-Method", Arrays.asList("GET"));
restClient = new FormKiqClientV1(connection);
}
CognitoConnectionBuilder adminBuilder = new CognitoConnectionBuilder(cognitoClientId, cognitoUserPoolId, cognitoIdentitypool).setCredentials(awsprofile).setRegion(awsregion);
adminCognitoService = new CognitoService(adminBuilder);
stsBuilder = new StsConnectionBuilder().setCredentials(awsprofile).setRegion(awsregion);
stsService = new StsService(stsBuilder);
try (StsClient stsClient = stsBuilder.build()) {
GetCallerIdentityResponse identity = stsClient.getCallerIdentity();
String user = identity.arn().substring(identity.arn().lastIndexOf("/") + 1);
IamConnectionBuilder iamBuilder = new IamConnectionBuilder().setCredentials(awsprofile);
IamService iam = new IamService(iamBuilder);
try (IamClient iamClient = iamBuilder.build()) {
iam.addUserToGroup(iamClient, user, apiGatewayInvokeGroup);
}
executeApiSigner = new Aws4SignerParamsBuilder().setRegion(awsregion).setSigningName("execute-api").setCredentials(awsprofile).build();
}
setupCognito();
setupConfigService(awsprofile);
}
Aggregations