Search in sources :

Example 1 with CheckmarxAdapterContext

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;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) CheckmarxAdapterContext(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext) CheckmarxAdapterConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig) RestOperations(org.springframework.web.client.RestOperations)

Example 2 with CheckmarxAdapterContext

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");
}
Also used : CheckmarxAdapterContext(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext) Test(org.junit.Test)

Example 3 with CheckmarxAdapterContext

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;
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) CheckmarxAdapterContext(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext) RestOperations(org.springframework.web.client.RestOperations)

Example 4 with CheckmarxAdapterContext

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());
}
Also used : CheckmarxAdapterContext(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext) Test(org.junit.jupiter.api.Test)

Example 5 with CheckmarxAdapterContext

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;
}
Also used : CheckmarxAdapterContext(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext)

Aggregations

CheckmarxAdapterContext (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterContext)8 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)2 ResponseEntity (org.springframework.http.ResponseEntity)2 RestOperations (org.springframework.web.client.RestOperations)2 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)1