Skip to content

Commit

Permalink
fixup! Feat: phishing detection
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Jun 27, 2024
1 parent e642d05 commit d7c6108
Show file tree
Hide file tree
Showing 14 changed files with 269 additions and 203 deletions.
21 changes: 2 additions & 19 deletions lib/PhishingDetectionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 2 additions & 20 deletions lib/PhishingDetectionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
28 changes: 4 additions & 24 deletions lib/Service/PhishingDetection/ContactCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
22 changes: 3 additions & 19 deletions lib/Service/PhishingDetection/CustomEmailCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 4 additions & 20 deletions lib/Service/PhishingDetection/DateCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"));
Expand Down
22 changes: 3 additions & 19 deletions lib/Service/PhishingDetection/PhishingDetectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 3 additions & 19 deletions lib/Service/PhishingDetection/ReplyToCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 3 additions & 19 deletions src/components/PhishingWarning.vue
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">
Expand Down
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;
Expand Down
72 changes: 72 additions & 0 deletions tests/Unit/Service/Phishing/ContactCheckTest.php
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());
}

}
Loading

0 comments on commit d7c6108

Please sign in to comment.