Skip to content

Commit

Permalink
inserted tests for missing aspects of CORS endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
angelo.andreussi authored and Coduz committed Jul 3, 2023
1 parent a923963 commit a188979
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,69 @@ Scenario: Init Security Context for all scenarios
And I delete endpoint with schema "Schema2", domain "abc.com" and port 2222
And I logout

Scenario: Submission of the same CORS filter in two distinct accounts should not fail
Given I login as user with name "kapua-sys" and password "kapua-password"
Then I create a generic account with name "Account-1" in current scopeId
When I create the following CORS filters
| http | localhost | 8080 |
Then I have 1 CORS filter
Then I select account "kapua-sys"
Then I create a generic account with name "Account-2" in current scopeId
When I create the following CORS filters
| http | localhost | 8080 |
Then I have 1 CORS filter
And I delete all CORS filters
Then I select account "Account-1"
And I delete all CORS filters
Then I logout


Scenario: Submission of one CORS filter should not be blocked just because the same filter is defined in an "ancestor" account different from the father
Given I login as user with name "kapua-sys" and password "kapua-password"
When I create the following CORS filters
| http | localhost | 8080 |
Then I have 1 CORS filter
Then I create a generic account with name "Account-1" in current scopeId
And I configure account service
| type | name | value |
| boolean | infiniteChildEntities | true |
| integer | maxNumberChildEntities | 5 |
When I create the following CORS filters
| http | localhost | 8081 |
Then I have 1 CORS filter
Then I create a generic account with name "Account-2" in current scopeId
When I create the following CORS filters
| http | localhost | 8080 |
Then I have 1 CORS filter
And I delete all CORS filters
Then I select account "Account-1"
And I delete all CORS filters
Then I select account "kapua-sys"
And I delete all CORS filters
Then I logout

Scenario: The search of a CORS filter which is masked by CORS endpoints defined by the father (or other "nearest" ancestors) should result in no findings
Given I login as user with name "kapua-sys" and password "kapua-password"
When I create the following CORS filters
| http | localhost | 8080 |
Then I have 1 CORS filter
Then I create a generic account with name "Account-1" in current scopeId
And I configure account service
| type | name | value |
| boolean | infiniteChildEntities | true |
| integer | maxNumberChildEntities | 5 |
When I create the following CORS filters
| http | localhost | 8081 |
Then I have 1 CORS filter
Then I create a generic account with name "Account-2" in current scopeId
Given I expect the exception "NullPointerException" with the text "*"
When I try to find endpoint with schema "http", domain "localhost" and port 8080 and section "cors"
Then An exception was thrown
Then I select account "Account-1"
And I delete all CORS filters
Then I select account "kapua-sys"
And I delete all CORS filters

Scenario: List CORS filters from kapua-sys account
Login as kapua-sys, create a CORS filter, then get all CORS filter.
There should be 1 CORS filter and no exceptions throw.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.kapua.commons.security.KapuaSession;
import org.eclipse.kapua.commons.util.xml.XmlUtil;
import org.eclipse.kapua.locator.KapuaLocator;
import org.eclipse.kapua.model.query.predicate.AndPredicate;
import org.eclipse.kapua.model.query.predicate.AttributePredicate;
import org.eclipse.kapua.qa.common.DBHelper;
import org.eclipse.kapua.qa.common.StepData;
Expand Down Expand Up @@ -233,30 +234,53 @@ public void iDeleteEndpointWithSchema(String schema, String domain, int port) th

@And("^I try to find endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$")
public void foundEndpointBySchemaDomainPort(String schema, String domain, int port) throws Exception {
primeException();
try {
EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
assertEquals(schema, endpointInfo.getSchema());
assertEquals(domain, endpointInfo.getDns());
assertEquals(port, endpointInfo.getPort());

stepData.put(ENDPOINT_INFO, endpointInfo);
stepData.put("EndpointInfoId", endpointInfo.getId());
} catch (Exception ex) {
verifyException(ex);
}
foundEndpointBySchemaDomainPortSection(schema, domain, port, EndpointInfo.ENDPOINT_TYPE_RESOURCE);
}

@And("^I try to find endpoint with schema \"([^\"]*)\"$")
public void foundEndpointBySchema(String schema) throws Exception {
foundEndpointBySchemaDomainPortSection(schema, null, -1, EndpointInfo.ENDPOINT_TYPE_RESOURCE);
}

@And("^I try to find endpoint with schema \"([^\"]*)\", domain \"([^\"]*)\" and port (\\d+)$ and section \"([^\"]*)\"$")
public void foundEndpointBySchemaDomainPortSection(String schema, String domain, int port, String section) throws Exception {
primeException();
try {
EndpointInfoQuery endpointInfoQuery = endpointInfoFactory.newQuery(getCurrentScopeId());
endpointInfoQuery.setPredicate(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
AndPredicate andPredicate = endpointInfoQuery.andPredicate();

if (section.equals("cors")) {
section = EndpointInfo.ENDPOINT_TYPE_CORS;
} //to simplify argument passing

if (schema != null) {
andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.SCHEMA, schema, AttributePredicate.Operator.EQUAL));
}
if (section != null) {
andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.ENDPOINT_TYPE, section));
}
if (domain != null) {
andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.DNS, domain, AttributePredicate.Operator.EQUAL));
}
if (port != -1) {
andPredicate.and(endpointInfoQuery.attributePredicate(EndpointInfoAttributes.PORT, port, AttributePredicate.Operator.EQUAL));
}

endpointInfoQuery.setPredicate(andPredicate);
EndpointInfo endpointInfo = endpointInfoService.query(endpointInfoQuery).getFirstItem();
assertEquals(schema, endpointInfo.getSchema());

if (schema != null) {
assertEquals(schema, endpointInfo.getSchema());
}
if (section != null) {
assertEquals(section, endpointInfo.getEndpointType());
}
if (domain != null) {
assertEquals(domain, endpointInfo.getDns());
}
if (port != -1) {
assertEquals(port, endpointInfo.getPort());
}

stepData.put(ENDPOINT_INFO, endpointInfo);
stepData.put("EndpointInfoId", endpointInfo.getId());
Expand Down

0 comments on commit a188979

Please sign in to comment.