|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace devtoolboxuk\cerberus; |
|
4
|
|
|
|
|
5
|
|
|
use devtoolboxuk\cerberus\Handlers\EmailHandler; |
|
6
|
|
|
use devtoolboxuk\cerberus\Handlers\TextHandler; |
|
7
|
|
|
use devtoolboxuk\cerberus\Handlers\ThrottleHandler; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
class xDetectionTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
|
|
13
|
|
|
private $options = []; |
|
14
|
|
|
|
|
15
|
|
|
function __construct($name = null, array $data = [], $dataName = '') |
|
16
|
|
|
{ |
|
17
|
|
|
parent::__construct($name, $data, $dataName); |
|
18
|
|
|
$this->options = $this->getTestData(); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
private function getTestData() |
|
22
|
|
|
{ |
|
23
|
|
|
/** @noinspection PhpIncludeInspection */ |
|
24
|
|
|
return include __DIR__ . '/options.php'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function testEmailDetection() |
|
28
|
|
|
{ |
|
29
|
|
|
|
|
30
|
|
|
$cerberus = new CerberusService(); |
|
31
|
|
|
$cerberus->setOptions($this->getOptions()); |
|
32
|
|
|
|
|
33
|
|
|
$data = '<span>http://dev-toolbox.co.uk'; |
|
34
|
|
|
$email_data = '[email protected]'; |
|
35
|
|
|
|
|
36
|
|
|
$detection = $cerberus |
|
37
|
|
|
->pushHandler(new EmailHandler($email_data)) |
|
38
|
|
|
->pushHandler(new TextHandler($data)); |
|
39
|
|
|
|
|
40
|
|
|
// print_r($detection->toArray()); |
|
41
|
|
|
print_r($detection->getResult()); |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
echo "\n"; |
|
45
|
|
|
$email_data = '[email protected]'; |
|
46
|
|
|
$detection = $cerberus |
|
47
|
|
|
->resetHandlers() |
|
48
|
|
|
->pushHandler(new EmailHandler($email_data)) |
|
49
|
|
|
->pushHandler(new TextHandler($data)); |
|
50
|
|
|
|
|
51
|
|
|
print_r($detection->toArray()); |
|
52
|
|
|
print_r($detection->getResult()); |
|
53
|
|
|
print_r($detection->isBlocked()); |
|
54
|
|
|
echo "\n\n"; |
|
55
|
|
|
|
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function getOptions() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->options; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
// function testUrlDetection() |
|
65
|
|
|
// { |
|
66
|
|
|
// $cerberus = new cerberusService(); |
|
67
|
|
|
// $cerberus->setOptions($this->getOptions()); |
|
68
|
|
|
// $data = '<span>http://google.com'; |
|
69
|
|
|
// $detection = $cerberus |
|
70
|
|
|
// ->resetHandlers() |
|
71
|
|
|
// ->pushHandler(new TextHandler($data)); |
|
72
|
|
|
// $this->assertEquals(2,$detection->getScore()); |
|
73
|
|
|
// |
|
74
|
|
|
// } |
|
75
|
|
|
// |
|
76
|
|
|
// function getOptions() |
|
77
|
|
|
// { |
|
78
|
|
|
// echo "\n"; |
|
79
|
|
|
// $options = [ |
|
80
|
|
|
// 'config' => [ |
|
81
|
|
|
// 'threshold' => 100, |
|
82
|
|
|
// 'hashing' => [ |
|
83
|
|
|
// 'key' => 'test_key' |
|
84
|
|
|
// ] |
|
85
|
|
|
// ], |
|
86
|
|
|
// 'Detection' => [ |
|
87
|
|
|
// 'Rules' => [ |
|
88
|
|
|
// 'html' => [ |
|
89
|
|
|
// 'active' => 1, |
|
90
|
|
|
// 'score' => '46', |
|
91
|
|
|
// 'params' => '' |
|
92
|
|
|
// ], |
|
93
|
|
|
// 'DisposableEmail' => [ |
|
94
|
|
|
// 'active' => 1, |
|
95
|
|
|
// 'score' => '46', |
|
96
|
|
|
// 'params' => '' |
|
97
|
|
|
// ], |
|
98
|
|
|
// 'bot' => [ |
|
99
|
|
|
// 'active' => 1, |
|
100
|
|
|
// 'params' => 'sensu' |
|
101
|
|
|
// ] |
|
102
|
|
|
// ] |
|
103
|
|
|
// ] |
|
104
|
|
|
// ]; |
|
105
|
|
|
// |
|
106
|
|
|
// return $options; |
|
107
|
|
|
// } |
|
108
|
|
|
// |
|
109
|
|
|
// function testEmailDetection() |
|
110
|
|
|
// { |
|
111
|
|
|
// |
|
112
|
|
|
// $cerberus = new Detect(); |
|
113
|
|
|
// $cerberus->setOptions($this->getOptions()); |
|
114
|
|
|
// |
|
115
|
|
|
// $email_data = '[email protected]'; |
|
116
|
|
|
// |
|
117
|
|
|
// $detection = $cerberus |
|
118
|
|
|
// ->resetHandlers() |
|
119
|
|
|
// ->pushHandler(new EmailHandler($email_data)); |
|
120
|
|
|
// $this->assertEquals(46,$detection->getScore()); |
|
121
|
|
|
// |
|
122
|
|
|
// } |
|
123
|
|
|
} |
|
124
|
|
|
|