-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hamza Mahjoubi <[email protected]>
- Loading branch information
Showing
14 changed files
with
269 additions
and
203 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,25 +3,8 @@ | |
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail; | ||
|
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 |
---|---|---|
|
@@ -3,27 +3,9 @@ | |
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail; | ||
|
||
use JsonSerializable; | ||
|
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 |
---|---|---|
|
@@ -2,25 +2,9 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Service\PhishingDetection; | ||
|
@@ -30,11 +14,7 @@ | |
use OCP\IL10N; | ||
|
||
class ContactCheck { | ||
protected IL10N $l10n; | ||
private ContactsIntegration $contactIntegration; | ||
|
||
|
||
public function __construct(ContactsIntegration $contactIntegration, IL10N $l10n) { | ||
public function __construct(private ContactsIntegration $contactIntegration, private IL10N $l10n) { | ||
$this->l10n = $l10n; | ||
$this->contactIntegration = $contactIntegration; | ||
} | ||
|
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 |
---|---|---|
|
@@ -2,25 +2,9 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Service\PhishingDetection; | ||
|
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 |
---|---|---|
|
@@ -2,25 +2,9 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Service\PhishingDetection; | ||
|
@@ -39,7 +23,7 @@ public function __construct(IL10N $l10n, ITimeFactory $timeFactory) { | |
} | ||
|
||
public function run(string $date): PhishingDetectionResult { | ||
$now = $this->timeFactory->getDateTime(); | ||
$now = $this->timeFactory->getDateTime('now'); | ||
$dt = $this->timeFactory->getDateTime($date); | ||
if ($dt > $now) { | ||
return new PhishingDetectionResult(PhishingDetectionResult::DATE_CHECK, true, $this->l10n->t("Sent date is in the future")); | ||
|
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 |
---|---|---|
|
@@ -2,25 +2,9 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Service\PhishingDetection; | ||
|
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 |
---|---|---|
|
@@ -2,25 +2,9 @@ | |
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Service\PhishingDetection; | ||
|
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 |
---|---|---|
@@ -1,23 +1,7 @@ | ||
<!-- | ||
- @copyright 2024 Hamza Mahjoubi <hamza.mahjoubi221@proton.me> | ||
- | ||
- @author 2024 Hamza Mahjoubi <[email protected]> | ||
- | ||
- @license AGPL-3.0-or-later | ||
- | ||
- This program is free software: you can redistribute it and/or modify | ||
- it under the terms of the GNU Affero General Public License as | ||
- published by the Free Software Foundation, either version 3 of the | ||
- License, or (at your option) any later version. | ||
- | ||
- This program is distributed in the hope that it will be useful, | ||
- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
- GNU Affero General Public License for more details. | ||
- | ||
- You should have received a copy of the GNU Affero General Public License | ||
- along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
<template> | ||
<div class="warning"> | ||
<div class="warning__title"> | ||
|
20 changes: 2 additions & 18 deletions
20
tests/Integration/Service/Phishing/PhishingDetectionServiceIntegrationTest.php
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 |
---|---|---|
@@ -1,23 +1,7 @@ | ||
<?php | ||
/** | ||
* @copyright 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @author 2024 Hamza Mahjoubi <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Tests\Integration\Service\Phishing; | ||
|
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* 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\ContactsIntegration; | ||
use OCA\Mail\Service\PhishingDetection\ContactCheck; | ||
use OCP\IL10N; | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
class ContactCheckTest extends TestCase { | ||
|
||
private IL10N|MockObject $l10n; | ||
private ContactsIntegration|MockObject $contactsIntegration; | ||
private ContactCheck|MockObject $service; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->l10n = $this->createMock(IL10N::class); | ||
$this->contactsIntegration = $this->createMock(ContactsIntegration::class); | ||
$this->service = new ContactCheck($this->contactsIntegration, $this->l10n); | ||
} | ||
|
||
public function testContactInABCorrectEmail(): void { | ||
|
||
$fn = "John Doe"; | ||
$email = "[email protected]" ; | ||
$contacts = [ | ||
[ | ||
"email" => ["[email protected]"] | ||
] | ||
]; | ||
$this->contactsIntegration->method('getContactsWithName')->willReturn($contacts); | ||
$result = $this->service->run($fn, $email); | ||
|
||
|
||
$this->assertFalse($result->isPhishing()); | ||
} | ||
|
||
public function testContactInABWrongEmail(): void { | ||
|
||
$fn = "John Doe"; | ||
$email = "[email protected]" ; | ||
$contacts = [ | ||
[ | ||
"email" => ["[email protected]"] | ||
] | ||
]; | ||
$this->contactsIntegration->method('getContactsWithName')->willReturn($contacts); | ||
$result = $this->service->run($fn, $email); | ||
|
||
|
||
$this->assertTrue($result->isPhishing()); | ||
} | ||
|
||
public function testContactNotInAB(): void { | ||
|
||
$fn = "John Doe"; | ||
$email = "[email protected]" ; | ||
$contacts = []; | ||
$this->contactsIntegration->method('getContactsWithName')->willReturn($contacts); | ||
$result = $this->service->run($fn, $email); | ||
$this->assertFalse($result->isPhishing()); | ||
} | ||
|
||
} |
Oops, something went wrong.