Search in sources :

Example 1 with ListScanConfigsPagedResponse

use of com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse in project java-websecurityscanner by googleapis.

the class VPCServiceControlNegativeTest method testScanConfigList.

@Test
public void testScanConfigList() throws IOException {
    // try to get the list of scan configs - it must fail
    WebSecurityScannerSettings wssSetting = getWssSettingWithCredentials();
    final String formattedParent = ProjectName.format(OUT_VPCSC_PROJECT);
    try (WebSecurityScannerClient wssClient = WebSecurityScannerClient.create(wssSetting)) {
        ListScanConfigsRequest lscRequest = ListScanConfigsRequest.newBuilder().setParent(formattedParent).build();
        ListScanConfigsPagedResponse scanConfigsList = wssClient.listScanConfigs(lscRequest);
        fail("Exception must occur for non-acceessible project scan-configs");
    } catch (PermissionDeniedException expected) {
    }
}
Also used : ListScanConfigsRequest(com.google.cloud.websecurityscanner.v1beta.ListScanConfigsRequest) WebSecurityScannerSettings(com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerSettings) WebSecurityScannerClient(com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient) ListScanConfigsPagedResponse(com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse) PermissionDeniedException(com.google.api.gax.rpc.PermissionDeniedException) Test(org.junit.Test)

Example 2 with ListScanConfigsPagedResponse

use of com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse in project java-websecurityscanner by googleapis.

the class WebSecurityScannerClientTest method listScanConfigsTest.

@Test
public void listScanConfigsTest() throws Exception {
    ScanConfig responsesElement = ScanConfig.newBuilder().build();
    ListScanConfigsResponse expectedResponse = ListScanConfigsResponse.newBuilder().setNextPageToken("").addAllScanConfigs(Arrays.asList(responsesElement)).build();
    mockWebSecurityScanner.addResponse(expectedResponse);
    ProjectName parent = ProjectName.of("[PROJECT]");
    ListScanConfigsPagedResponse pagedListResponse = client.listScanConfigs(parent);
    List<ScanConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getScanConfigsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockWebSecurityScanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListScanConfigsRequest actualRequest = ((ListScanConfigsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListScanConfigsPagedResponse(com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse) Test(org.junit.Test)

Example 3 with ListScanConfigsPagedResponse

use of com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse in project java-websecurityscanner by googleapis.

the class WebSecurityScannerClientTest method listScanConfigsTest2.

@Test
public void listScanConfigsTest2() throws Exception {
    ScanConfig responsesElement = ScanConfig.newBuilder().build();
    ListScanConfigsResponse expectedResponse = ListScanConfigsResponse.newBuilder().setNextPageToken("").addAllScanConfigs(Arrays.asList(responsesElement)).build();
    mockWebSecurityScanner.addResponse(expectedResponse);
    String parent = "parent-995424086";
    ListScanConfigsPagedResponse pagedListResponse = client.listScanConfigs(parent);
    List<ScanConfig> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getScanConfigsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockWebSecurityScanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListScanConfigsRequest actualRequest = ((ListScanConfigsRequest) actualRequests.get(0));
    Assert.assertEquals(parent, actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListScanConfigsPagedResponse(com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse) Test(org.junit.Test)

Aggregations

ListScanConfigsPagedResponse (com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient.ListScanConfigsPagedResponse)3 Test (org.junit.Test)3 AbstractMessage (com.google.protobuf.AbstractMessage)2 PermissionDeniedException (com.google.api.gax.rpc.PermissionDeniedException)1 ListScanConfigsRequest (com.google.cloud.websecurityscanner.v1beta.ListScanConfigsRequest)1 WebSecurityScannerClient (com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerClient)1 WebSecurityScannerSettings (com.google.cloud.websecurityscanner.v1beta.WebSecurityScannerSettings)1