Failing Integration tests
Issue 1 :
Around 36 integration tests were failing whenever data-partition-id=nonexistenttenant/invalid tenant passed in an HTTP request. expected 401, getting 500. following test cases were failing for all Resgister service API
- should_return401_when_noAccessOnCustomerTenantOps
- should_return401_when_noAccessOnCustomerTenantAdm
- should_return401_when_noAccessOnCustomerTenantEditor
Analysis - TenantInfoFactory class throws AppExcpetion 401 as the tenant does not exist. also, there is one more exception created i.e BeanCreationFactory with a cause - AppException 401. and GlobalExceptionMapper maps this exception to default Exception mapper which hides the original exception i.e AppExeption 401 and generates 500 error.
Issue 2 :
The below 3 test cases were failing from TestRetrieveActionApi expected 401 whenever the nonexistent tenant passed but getting 500 because AppException raised by TenantInfoFactory handled in Action Controller
Class : org.opengroup.osdu.register.action.TestRetrieveActionApi (3 test case) - Test Case 1 - org.opengroup.osdu.register.action.TestRetrieveActionApi
- should_return401_when_noAccessOnCustomerTenantEditor(org.opengroup.osdu.register.action.TestRetrieveActionApi)
- should_return401_when_noAccessOnCustomerTenantAdm(org.opengroup.osdu.register.action.TestRetrieveActionApi)
- should_return401_when_noAccessOnCustomerTenantOps(org.opengroup.osdu.register.action.TestRetrieveActionApi)
Analysis - TenantFactoy from core-common throws AppException when a tenant does not exist then GlobalExceptionMapper generates an error response for it. as per the below code snippet because of the catch block in the ActionAPI Controller class, AppException caught in catch-block and it generates 500 error response.
public ResponseEntity<List<Action>> retrieveAction(@RequestBody JsonNode jsonObject) {
try {
List<Action> query = repo.getAllActions();
List<Action> output = this.retrieveActionService.getActions(query, jsonObject);
return new ResponseEntity<>(output, HttpStatus.OK);
} catch (Exception e) {
this.log.error("retrieve action failed", e);
//throw e;
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
Proposed Changes -
- remove catch block in Action Controller as we have GlobalExceptionMapper class to handle Exception
- change error response code in Assert statement
- rethrow an exception caught in a catch block
Issue 3 :
Currently, there is no data-partition-id/tenant validation in the Core module. Tenant validation logic will not execute unless and until the invocation of the TenantInfo class. Expected 401, getting 200.
Class - org.opengroup.osdu.register.subscriber.TestListTopicsApi
- should_return401_when_noAccessOnCustomerTenantEditor(org.opengroup.osdu.register.subscriber.TestListTopicsApi)
- should_return401_when_noAccessOnCustomerTenantAdm(org.opengroup.osdu.register.subscriber.TestListTopicsApi)
- should_return401_when_noAccessOnCustomerTenantOps(org.opengroup.osdu.register.subscriber.TestListTopicsApi)
Issue 4 :
as of now, a subscriptionID variable is initialized by hardcoded value. it should be initialized by the environment variable like done for LOCAL environment if-block
config.subscriptionId = "cmVjb3Jkcy1jaGFuZ2VkaHR0cHM6Ly9vcy1yZWdpc3Rlci1kb3Qtb3BlbmRlcy5hcHBzcG90LmNvbS9hcGkvcmVnaXN0ZXIvdjEvdGVzdC9jaGFsbGVuZ2UvMQ==";
Proposed Changes -
config.subscriptionId = System.getProperty("TEST_SUBSCRIPTION_ID", System.getenv("TEST_SUBSCRIPTION_ID"));