-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathLinkCheckTest.php
More file actions
99 lines (65 loc) · 2.82 KB
/
Copy pathLinkCheckTest.php
File metadata and controls
99 lines (65 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Mail\Tests\Unit\Service\PhishingDetection;
use ChristophWurst\Nextcloud\Testing\TestCase;
use OCA\Mail\Service\PhishingDetection\LinkCheck;
use OCP\IL10N;
class LinkCheckTest extends TestCase {
private LinkCheck $check;
private IL10N $l10n;
protected function setUp(): void {
parent::setUp();
$this->l10n = $this->createMock(IL10N::class);
$this->l10n->method('t')->willReturnArgument(0);
$this->check = new LinkCheck($this->l10n);
}
public function testPlainTextWithoutLinksReturnsSafe(): void {
$result = $this->check->run('<p>This is plain text without links</p>');
$this->assertFalse($result->isPhishing());
}
public function testHtmlWithoutLinksReturnsSafe(): void {
$html = '<html><body><p>This is plain text without links</p></body></html>';
$result = $this->check->run($html);
$this->assertFalse($result->isPhishing());
}
public function testLinkWithMatchingDomainReturnsSafe(): void {
$html = '<html><body><a href="https://example.com/login">https://example.com/login</a></body></html>';
$result = $this->check->run($html);
$this->assertFalse($result->isPhishing());
}
public function testLinkWithMismatchedDomainReturnsWarning(): void {
$html = '<html><body><a href="https://malicious.com">https://example.com</a></body></html>';
$result = $this->check->run($html);
$this->assertTrue($result->isPhishing());
}
public function testLinkTextNotLookingLikeUrlReturnsSafe(): void {
$html = '<html><body><a href="https://malicious.com">Click here</a></body></html>';
$result = $this->check->run($html);
$this->assertFalse($result->isPhishing());
}
public function testMultipleLinksOnePhishingReturnsWarning(): void {
$html = '<html><body><a href="https://example.com">https://example.com</a><a href="https://malicious.com">https://example.com</a></body></html>';
$result = $this->check->run($html);
$this->assertTrue($result->isPhishing());
}
public function testLinkWithBracketsReturnsSafe(): void {
$html = '<html><body><a href="https://example.com">(https://example.com)</a></body></html>';
$result = $this->check->run($html);
$this->assertFalse($result->isPhishing());
}
public function testLinkWithQuotesReturnsSafe(): void {
$html = '<html><body><a href="https://example.com">"https://example.com"</a></body></html>';
$result = $this->check->run($html);
$this->assertFalse($result->isPhishing());
}
public function testMalformedUrlReturnsSafe(): void {
// Test that malformed URLs don't cause errors but are silently skipped
$html = '<html><body><a href="ht!tp://exa mple">Click here</a></body></html>';
$result = $this->check->run($html);
$this->assertFalse($result->isPhishing());
}
}