From d7c6108adc3498b6c7c6ace7f99188f6866eeec9 Mon Sep 17 00:00:00 2001 From: Hamza Mahjoubi Date: Thu, 27 Jun 2024 03:15:50 +0200 Subject: [PATCH] fixup! Feat: phishing detection Signed-off-by: Hamza Mahjoubi --- lib/PhishingDetectionList.php | 21 +----- lib/PhishingDetectionResult.php | 22 +----- .../PhishingDetection/ContactCheck.php | 28 ++------ .../PhishingDetection/CustomEmailCheck.php | 22 +----- lib/Service/PhishingDetection/DateCheck.php | 24 ++----- .../PhishingDetectionService.php | 22 +----- .../PhishingDetection/ReplyToCheck.php | 22 +----- src/components/PhishingWarning.vue | 22 +----- ...hishingDetectionServiceIntegrationTest.php | 20 +----- .../Service/Phishing/ContactCheckTest.php | 72 +++++++++++++++++++ .../Service/Phishing/CustomEmailCheckTest.php | 49 +++++++++++++ tests/Unit/Service/Phishing/DateCheckTest.php | 68 ++++++++++++++++++ .../PhishingDetectionServiceTest.php | 30 ++------ .../Service/Phishing/ReplyToCheckTest.php | 50 +++++++++++++ 14 files changed, 269 insertions(+), 203 deletions(-) create mode 100644 tests/Unit/Service/Phishing/ContactCheckTest.php create mode 100644 tests/Unit/Service/Phishing/CustomEmailCheckTest.php create mode 100644 tests/Unit/Service/Phishing/DateCheckTest.php rename tests/Unit/Service/{ => Phishing}/PhishingDetectionServiceTest.php (63%) create mode 100644 tests/Unit/Service/Phishing/ReplyToCheckTest.php diff --git a/lib/PhishingDetectionList.php b/lib/PhishingDetectionList.php index 30ebe1f7c3..802ec1b7ed 100644 --- a/lib/PhishingDetectionList.php +++ b/lib/PhishingDetectionList.php @@ -3,25 +3,8 @@ declare(strict_types=1); /** - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . - * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail; diff --git a/lib/PhishingDetectionResult.php b/lib/PhishingDetectionResult.php index ddb9448b43..3cb0bc3842 100644 --- a/lib/PhishingDetectionResult.php +++ b/lib/PhishingDetectionResult.php @@ -3,27 +3,9 @@ declare(strict_types=1); /** - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . - * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Mail; use JsonSerializable; diff --git a/lib/Service/PhishingDetection/ContactCheck.php b/lib/Service/PhishingDetection/ContactCheck.php index 99067331e0..46d219f099 100644 --- a/lib/Service/PhishingDetection/ContactCheck.php +++ b/lib/Service/PhishingDetection/ContactCheck.php @@ -2,25 +2,9 @@ declare(strict_types=1); -/* - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . +/** + * 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; } diff --git a/lib/Service/PhishingDetection/CustomEmailCheck.php b/lib/Service/PhishingDetection/CustomEmailCheck.php index 5f934043ee..82f2375978 100644 --- a/lib/Service/PhishingDetection/CustomEmailCheck.php +++ b/lib/Service/PhishingDetection/CustomEmailCheck.php @@ -2,25 +2,9 @@ declare(strict_types=1); -/* - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Service\PhishingDetection; diff --git a/lib/Service/PhishingDetection/DateCheck.php b/lib/Service/PhishingDetection/DateCheck.php index 846ef496e4..0704d089b8 100644 --- a/lib/Service/PhishingDetection/DateCheck.php +++ b/lib/Service/PhishingDetection/DateCheck.php @@ -2,25 +2,9 @@ declare(strict_types=1); -/* - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . +/** + * 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")); diff --git a/lib/Service/PhishingDetection/PhishingDetectionService.php b/lib/Service/PhishingDetection/PhishingDetectionService.php index 9bc8640375..7c0896daa1 100644 --- a/lib/Service/PhishingDetection/PhishingDetectionService.php +++ b/lib/Service/PhishingDetection/PhishingDetectionService.php @@ -2,25 +2,9 @@ declare(strict_types=1); -/* - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Service\PhishingDetection; diff --git a/lib/Service/PhishingDetection/ReplyToCheck.php b/lib/Service/PhishingDetection/ReplyToCheck.php index 220004bc91..c96ce17791 100644 --- a/lib/Service/PhishingDetection/ReplyToCheck.php +++ b/lib/Service/PhishingDetection/ReplyToCheck.php @@ -2,25 +2,9 @@ declare(strict_types=1); -/* - * @copyright 2024 Hamza Mahjoubi - * - * @author 2024 Hamza Mahjoubi - * - * @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 . +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Service\PhishingDetection; diff --git a/src/components/PhishingWarning.vue b/src/components/PhishingWarning.vue index 11b77869de..e277d3d317 100644 --- a/src/components/PhishingWarning.vue +++ b/src/components/PhishingWarning.vue @@ -1,23 +1,7 @@ + - SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors + - SPDX-License-Identifier: AGPL-3.0-or-later +-->