Commit 1ba0abcb authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

WebProtect: Check the initial response for synchronous results

For scans that return synchronously, the verdicts will be present in
the initial upload response. This CL checks that response for verdicts
and adds a test for this behavior.

Bug: 980784
Change-Id: I3f7c17f293d66f6aa410819f453b4a24f337e3c0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1764408
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Auto-Submit: Daniel Rubery <drubery@chromium.org>
Reviewed-by: default avatarRoger Tawa <rogerta@chromium.org>
Cr-Commit-Position: refs/heads/master@{#689676}
parent 29d85c44
...@@ -167,6 +167,10 @@ void BinaryUploadService::OnUploadComplete(Request* request, ...@@ -167,6 +167,10 @@ void BinaryUploadService::OnUploadComplete(Request* request,
base::BindRepeating(&BinaryUploadService::OnGetResponse, base::BindRepeating(&BinaryUploadService::OnGetResponse,
weakptr_factory_.GetWeakPtr(), request)); weakptr_factory_.GetWeakPtr(), request));
active_uploads_.erase(request); active_uploads_.erase(request);
// Synchronous scans can return results in the initial response proto, so
// check for those.
OnGetResponse(request, response);
} }
void BinaryUploadService::OnGetResponse(Request* request, void BinaryUploadService::OnGetResponse(Request* request,
......
...@@ -241,6 +241,8 @@ TEST_F(BinaryUploadServiceTest, TimesOut) { ...@@ -241,6 +241,8 @@ TEST_F(BinaryUploadServiceTest, TimesOut) {
DeepScanningClientResponse scanning_response; DeepScanningClientResponse scanning_response;
std::unique_ptr<MockRequest> request = std::unique_ptr<MockRequest> request =
MakeRequest(&scanning_result, &scanning_response); MakeRequest(&scanning_result, &scanning_response);
request->set_request_dlp_scan(DlpDeepScanningClientRequest());
request->set_request_malware_scan(MalwareDeepScanningClientRequest());
ExpectInstanceID("valid id"); ExpectInstanceID("valid id");
ExpectNetworkResponse(true, DeepScanningClientResponse()); ExpectNetworkResponse(true, DeepScanningClientResponse());
...@@ -257,6 +259,8 @@ TEST_F(BinaryUploadServiceTest, OnInstanceIDAfterTimeout) { ...@@ -257,6 +259,8 @@ TEST_F(BinaryUploadServiceTest, OnInstanceIDAfterTimeout) {
DeepScanningClientResponse scanning_response; DeepScanningClientResponse scanning_response;
std::unique_ptr<MockRequest> request = std::unique_ptr<MockRequest> request =
MakeRequest(&scanning_result, &scanning_response); MakeRequest(&scanning_result, &scanning_response);
request->set_request_dlp_scan(DlpDeepScanningClientRequest());
request->set_request_malware_scan(MalwareDeepScanningClientRequest());
BinaryFCMService::GetInstanceIDCallback instance_id_callback; BinaryFCMService::GetInstanceIDCallback instance_id_callback;
ON_CALL(*fcm_service_, GetInstanceID(_)) ON_CALL(*fcm_service_, GetInstanceID(_))
...@@ -284,6 +288,8 @@ TEST_F(BinaryUploadServiceTest, OnUploadCompleteAfterTimeout) { ...@@ -284,6 +288,8 @@ TEST_F(BinaryUploadServiceTest, OnUploadCompleteAfterTimeout) {
DeepScanningClientResponse scanning_response; DeepScanningClientResponse scanning_response;
std::unique_ptr<MockRequest> request = std::unique_ptr<MockRequest> request =
MakeRequest(&scanning_result, &scanning_response); MakeRequest(&scanning_result, &scanning_response);
request->set_request_dlp_scan(DlpDeepScanningClientRequest());
request->set_request_malware_scan(MalwareDeepScanningClientRequest());
ExpectInstanceID("valid id"); ExpectInstanceID("valid id");
ExpectNetworkResponse(true, DeepScanningClientResponse()); ExpectNetworkResponse(true, DeepScanningClientResponse());
...@@ -305,6 +311,8 @@ TEST_F(BinaryUploadServiceTest, OnGetResponseAfterTimeout) { ...@@ -305,6 +311,8 @@ TEST_F(BinaryUploadServiceTest, OnGetResponseAfterTimeout) {
DeepScanningClientResponse scanning_response; DeepScanningClientResponse scanning_response;
std::unique_ptr<MockRequest> request = std::unique_ptr<MockRequest> request =
MakeRequest(&scanning_result, &scanning_response); MakeRequest(&scanning_result, &scanning_response);
request->set_request_dlp_scan(DlpDeepScanningClientRequest());
request->set_request_malware_scan(MalwareDeepScanningClientRequest());
ExpectInstanceID("valid id"); ExpectInstanceID("valid id");
ExpectNetworkResponse(true, DeepScanningClientResponse()); ExpectNetworkResponse(true, DeepScanningClientResponse());
...@@ -320,4 +328,26 @@ TEST_F(BinaryUploadServiceTest, OnGetResponseAfterTimeout) { ...@@ -320,4 +328,26 @@ TEST_F(BinaryUploadServiceTest, OnGetResponseAfterTimeout) {
EXPECT_EQ(scanning_result, BinaryUploadService::Result::TIMEOUT); EXPECT_EQ(scanning_result, BinaryUploadService::Result::TIMEOUT);
} }
TEST_F(BinaryUploadServiceTest, OnGetSynchronousResponse) {
BinaryUploadService::Result scanning_result =
BinaryUploadService::Result::UNKNOWN;
DeepScanningClientResponse scanning_response;
std::unique_ptr<MockRequest> request =
MakeRequest(&scanning_result, &scanning_response);
request->set_request_dlp_scan(DlpDeepScanningClientRequest());
request->set_request_malware_scan(MalwareDeepScanningClientRequest());
ExpectInstanceID("valid id");
DeepScanningClientResponse simulated_response;
simulated_response.mutable_dlp_scan_verdict();
simulated_response.mutable_malware_scan_verdict();
ExpectNetworkResponse(true, simulated_response);
service_->UploadForDeepScanning(std::move(request));
content::RunAllTasksUntilIdle();
EXPECT_EQ(scanning_result, BinaryUploadService::Result::SUCCESS);
}
} // namespace safe_browsing } // namespace safe_browsing
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment