-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enforce configuration of Safe Browsing API key
The built-in fallback API key must not be used anymore. Enforce configuration of a custom API key and deactivate the feature, if none is provided.
- Loading branch information
Showing
5 changed files
with
86 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,13 +63,16 @@ public function test(): void { | |
'{"error":{"message":"Invalid API key"}}' | ||
); | ||
|
||
// Specify API key. | ||
$this->update_options( array( 'safe_browsing_key' => 'custom-api-key' ) ); | ||
|
||
AntiVirus_SafeBrowsing::check_safe_browsing(); | ||
|
||
// Validate the request. | ||
self::assertEquals( | ||
'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=AIzaSyCGHXUd7vQAySRLNiC5y1M_wzR2W0kCVKI', | ||
'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=custom-api-key', | ||
$request_url, | ||
'expected call to Safe Browsing API with default key' | ||
'expected call to Safe Browsing API with custom key' | ||
); | ||
self::assertIsArray( $request_data, 'unexpected request' ); | ||
$request_body = json_decode( $request_data['body'] ); | ||
|
@@ -107,12 +110,7 @@ public function test(): void { | |
/* | ||
* Case 3: With custom API key and notification address. | ||
*/ | ||
$this->update_options( | ||
array( | ||
'notify_email' => '[email protected]', | ||
'safe_browsing_key' => 'custom-api-key', | ||
) | ||
); | ||
$this->update_options( array( 'notify_email' => '[email protected]' ) ); | ||
|
||
AntiVirus_SafeBrowsing::check_safe_browsing(); | ||
|
||
|
@@ -149,5 +147,18 @@ public function test(): void { | |
'expected different subject for Safe Browsing check failing with 400' | ||
); | ||
self::assertStringContainsString( "\r\n Invalid API key\r\n", $mail_body, 'Message from response not transported to mail' ); | ||
|
||
/* | ||
* Case 6: Without API key. | ||
*/ | ||
$this->update_options( array( 'safe_browsing_key' => '' ) ); | ||
$request_url = null; | ||
|
||
AntiVirus_SafeBrowsing::check_safe_browsing(); | ||
|
||
self::assertNull( | ||
$request_url, | ||
'API should not be called without an API key' | ||
); | ||
} | ||
} |