Skip to content

Commit

Permalink
feat: unit tests for link checking
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Sep 2, 2024
1 parent 2490ae8 commit 146b2f5
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/Unit/Service/Phishing/LinkCheckTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Mail\Tests\Unit\Service\Phishing;

use ChristophWurst\Nextcloud\Testing\TestCase;

use OCA\Mail\Service\PhishingDetection\LinkCheck;
use OCP\IL10N;

use PHPUnit\Framework\MockObject\MockObject;

class LinkCheckTest extends TestCase {

private IL10N&MockObject $l10n;
private LinkCheck|MockObject $service;

protected function setUp(): void {
parent::setUp();
$this->l10n = $this->createMock(IL10N::class);
$this->service = new LinkCheck($this->l10n);
}

public function testNakedAddressPass(): void {
$htmlMessage = '<html><body><a href="https://nextcloud.com/">nextcloud.com</a></p></body></html>';

$result = $this->service->run($htmlMessage);

$this->assertFalse($result->isPhishing());
}

public function testCompleteAddressPass(): void {
$htmlMessage = '<html><body><a href="https://nextcloud.com/">https://nextcloud.com/</a></body></html>';

$result = $this->service->run($htmlMessage);

$this->assertFalse($result->isPhishing());
}

public function testCompleteAddressFail(): void {
$htmlMessage = '<html><body><a href="https://nextcloud.com/">https://google.com/</a></p></body></html>';

$result = $this->service->run($htmlMessage);

$this->assertTrue($result->isPhishing());
}

public function testDeepAddressPass(): void {
$htmlMessage = '<html><body><a href="https://nextcloud.com/"><span class="text-big" style="color:hsl(0,75%,60%);font-family: Courier, monospace;"><i><strong>nextcloud.com</strong></i></span></a></body></html>';

$result = $this->service->run($htmlMessage);

$this->assertFalse($result->isPhishing());
}
}

0 comments on commit 146b2f5

Please sign in to comment.