use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext in project sechub by mercedes-benz.
the class CheckmarxOAuthSupportTest method createContextWithRestSimulation.
private CheckmarxAdapterContext createContextWithRestSimulation(CheckmarxOAuthData alreadyExistingOauthData) {
CheckmarxAdapterContext context = createMockedContext(alreadyExistingOauthData);
when(context.json()).thenReturn(JSONAdapterSupport.FOR_UNKNOWN_ADAPTER);
String url = "https://somerest.api.example.com/auth/identity/connect/token";
when(context.getAPIURL("auth/identity/connect/token")).thenReturn(url);
CheckmarxAdapterConfig config = mock(CheckmarxAdapterConfig.class);
RestOperations restOperations = mock(RestOperations.class);
ResponseEntity<String> repsonseEntity1 = new ResponseEntity<>("{\"access_token\": \"mytoken1\",\"expires_in\": 3600,\"token_type\": \"Bearer\"}", HttpStatus.OK);
ResponseEntity<String> repsonseEntity2 = new ResponseEntity<>("{\"access_token\": \"mytoken2\",\"expires_in\": 3600,\"token_type\": \"Bearer\"}", HttpStatus.OK);
when(restOperations.postForEntity(eq(url), any(), eq(String.class))).thenReturn(repsonseEntity1).thenReturn(repsonseEntity2);
when(context.getConfig()).thenReturn(config);
when(context.getRestOperations()).thenReturn(restOperations);
return context;
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext in project sechub by mercedes-benz.
the class CheckmarxScanReportSupportTest method fetchReportResult__support_does_remove_existing_byte_order_marks.
@Test
public void fetchReportResult__support_does_remove_existing_byte_order_marks() throws Exception {
/* prepare */
CheckmarxAdapterContext context = prepareContent(UTF8_BOM + "<?xml bla");
/* execute */
supportToTest.fetchReportResult(oauthSupport, context);
/* test */
verify(context).setResult("<?xml bla");
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext in project sechub by mercedes-benz.
the class CheckmarxScanReportSupportTest method prepareContent.
private CheckmarxAdapterContext prepareContent(String content) {
ResponseEntity<String> entity = new ResponseEntity<>(content, HttpStatus.OK);
RestOperations restOperations = mock(RestOperations.class);
CheckmarxAdapterContext context = mock(CheckmarxAdapterContext.class);
when(context.getRestOperations()).thenReturn(restOperations);
when(context.getAPIURL(any())).thenReturn("path");
when(restOperations.getForEntity(eq("path"), eq(String.class))).thenReturn(entity);
return context;
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext in project sechub by mercedes-benz.
the class CheckmarxOAuthSupportTest method refreshBearerTokenWhenNecessary_leads_NOT_to_newer_oauth_data_object_when_no_refresh_necessary.
@Test
void refreshBearerTokenWhenNecessary_leads_NOT_to_newer_oauth_data_object_when_no_refresh_necessary() throws Exception {
/* prepare */
CheckmarxOAuthData alreadyExistingOauthData = new CheckmarxOAuthData();
alreadyExistingOauthData.expiresInSeconds = 20;
CheckmarxAdapterContext context = createContextWithRestSimulation(alreadyExistingOauthData);
/* check precondition */
assertFalse(supportToTest.isTokenRefreshNecessary(context));
/* execute */
// this will NOT refresh, because 20 seconds
supportToTest.refreshBearerTokenWhenNecessary(context);
/* test */
// never called
verify(context, times(0)).markAuthenticated(any());
}
use of com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext in project sechub by mercedes-benz.
the class CheckmarxOAuthSupportTest method createMockedContext.
private CheckmarxAdapterContext createMockedContext(CheckmarxOAuthData oauthData) {
CheckmarxAdapterContext context = mock(CheckmarxAdapterContext.class);
when(context.getoAuthData()).thenReturn(oauthData);
return context;
}
Aggregations