|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Azine\MailgunWebhooksBundle\Tests\Services\HetrixtoolsService; |
|
4
|
|
|
|
|
5
|
|
|
use Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\AzineMailgunHetrixtoolsService; |
|
6
|
|
|
use Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\HetrixtoolsServiceResponse; |
|
7
|
|
|
use Psr\Log\NullLogger; |
|
8
|
|
|
|
|
9
|
|
|
class AzineMailgunHetrixtoolsServiceTest extends \PHPUnit\Framework\TestCase |
|
10
|
|
|
{ |
|
11
|
|
|
private $responseJson = '{ |
|
12
|
|
|
"status": "SUCCESS", |
|
13
|
|
|
"api_calls_left": 1976, |
|
14
|
|
|
"blacklist_check_credits_left": 81, |
|
15
|
|
|
"blacklisted_count": 3, |
|
16
|
|
|
"blacklisted_on": [ |
|
17
|
|
|
{ |
|
18
|
|
|
"rbl": "example1.com", |
|
19
|
|
|
"delist": "https://1.example.com/ip/198.51.100.42" |
|
20
|
|
|
}, |
|
21
|
|
|
{ |
|
22
|
|
|
"rbl": "example2.org", |
|
23
|
|
|
"delist": "https://2.example.com/query/ip/198.51.100.42" |
|
24
|
|
|
}, |
|
25
|
|
|
{ |
|
26
|
|
|
"rbl": "example3.org", |
|
27
|
|
|
"delist": "https://3.example.com/query/ip/198.51.100.42" |
|
28
|
|
|
} |
|
29
|
|
|
], |
|
30
|
|
|
"links": { |
|
31
|
|
|
"report_link": "https://3.example.com/report/blacklist/token/", |
|
32
|
|
|
"whitelabel_report_link": "", |
|
33
|
|
|
"api_report_link": "https://api.example.com/v1/token/report/198.51.100.42/", |
|
34
|
|
|
"api_blacklist_check_link": "https://api.example.com/v2/token/blacklist-check/ipv4/198.51.100.42/" |
|
35
|
|
|
} |
|
36
|
|
|
}'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @expectedException \InvalidArgumentException |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testIfApiKeyisNotSet() |
|
42
|
|
|
{ |
|
43
|
|
|
$apiKey = ''; |
|
44
|
|
|
$url = 'blacklistIpCheckUr'; |
|
45
|
|
|
|
|
46
|
|
|
$ip = '198.51.100.42'; |
|
47
|
|
|
$service = new AzineMailgunHetrixtoolsService(new NullLogger(), $apiKey, $url); |
|
48
|
|
|
$service->checkIpAddressInBlacklist($ip); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @expectedException \InvalidArgumentException |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testIfEmptyIpIsGiven() |
|
55
|
|
|
{ |
|
56
|
|
|
$apiKey = 'testApiKey'; |
|
57
|
|
|
$url = 'blacklistIpCheckUr'; |
|
58
|
|
|
$ip = ''; |
|
59
|
|
|
|
|
60
|
|
|
$service = new AzineMailgunHetrixtoolsService(new NullLogger(), $apiKey, $url); |
|
61
|
|
|
$service->checkIpAddressInBlacklist($ip); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @expectedException \InvalidArgumentException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testIfInvalidIpIsGiven() |
|
68
|
|
|
{ |
|
69
|
|
|
$apiKey = 'testApiKey'; |
|
70
|
|
|
$url = 'blacklistIpCheckUr'; |
|
71
|
|
|
$ip = 'invalidIpAddress'; |
|
72
|
|
|
|
|
73
|
|
|
$service = new AzineMailgunHetrixtoolsService(new NullLogger(), $apiKey, $url); |
|
74
|
|
|
$service->checkIpAddressInBlacklist($ip); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testSuccessReponse() |
|
78
|
|
|
{ |
|
79
|
|
|
$apiKey = 'test'; |
|
80
|
|
|
$url = 'https://api.example.com/v2/testkey/blacklist-check/ipv4/198.51.100.42/'; |
|
81
|
|
|
|
|
82
|
|
|
$hetrixtoolsService = $this->getMockBuilder("Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\AzineMailgunHetrixtoolsService") |
|
83
|
|
|
->setConstructorArgs(array(new NullLogger(), $apiKey, $url)) |
|
84
|
|
|
->setMethods(array('executeCheck'))->getMock(); |
|
85
|
|
|
$hetrixtoolsService->expects($this->once())->method('executeCheck')->will($this->returnValue($this->responseJson)); |
|
86
|
|
|
|
|
87
|
|
|
/** @var AzineMailgunHetrixtoolsService $hetrixtoolsService */ |
|
88
|
|
|
$response = $hetrixtoolsService->checkIpAddressInBlacklist('198.51.100.42'); |
|
89
|
|
|
|
|
90
|
|
|
$this->assertInstanceOf(HetrixtoolsServiceResponse::class, $response); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|