Skip to content

Commit 5394adb

Browse files
committed
updates adding tests
1 parent 78a50a4 commit 5394adb

10 files changed

Lines changed: 996 additions & 20 deletions

File tree

.github/workflows/tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master, main ]
6+
pull_request:
7+
branches: [ master, main ]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php-version: ['8.0', '8.1', '8.2', '8.3']
15+
16+
name: PHP ${{ matrix.php-version }}
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php-version }}
26+
extensions: imap, mbstring, soap
27+
coverage: xdebug
28+
29+
- name: Install dependencies
30+
run: composer install --prefer-dist --no-progress
31+
32+
- name: Run tests
33+
run: vendor/bin/phpunit --colors=always
34+
35+
- name: Run tests with coverage
36+
if: matrix.php-version == '8.2'
37+
run: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.xml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.phpunit.result.cache
12
composer.lock
23
vendor/
34
.bettercodehub.yml

README.md

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,79 @@
1-
# Abuse handling plugin for MyAdmin
1+
# MyAdmin Abuse Plugin
22

3-
Abuse handling plugin for MyAdmin
3+
[![Tests](https://github.com/detain/myadmin-abuse-plugin/actions/workflows/tests.yml/badge.svg)](https://github.com/detain/myadmin-abuse-plugin/actions/workflows/tests.yml)
4+
[![Latest Stable Version](https://poser.pugx.org/detain/myadmin-abuse-plugin/version)](https://packagist.org/packages/detain/myadmin-abuse-plugin)
5+
[![Total Downloads](https://poser.pugx.org/detain/myadmin-abuse-plugin/downloads)](https://packagist.org/packages/detain/myadmin-abuse-plugin)
6+
[![License](https://poser.pugx.org/detain/myadmin-abuse-plugin/license)](https://packagist.org/packages/detain/myadmin-abuse-plugin)
47

5-
## Build Status and Code Analysis
8+
Abuse handling plugin for the [MyAdmin](https://github.com/detain/myadmin) control panel. This plugin monitors IMAP mailboxes for incoming abuse complaints (spam reports, blacklist notifications, phishing alerts), matches the offending IP addresses to customer services, and automatically notifies the responsible account holders.
69

7-
Site | Status
8-
--------------|---------------------------
9-
![Travis-CI](http://i.is.cc/storage/GYd75qN.png "Travis-CI") | [![Build Status](https://travis-ci.org/detain/myadmin-abuse-plugin.svg?branch=master)](https://travis-ci.org/detain/myadmin-abuse-plugin)
10-
![CodeClimate](http://i.is.cc/storage/GYlageh.png "CodeClimate") | [![Code Climate](https://codeclimate.com/github/detain/myadmin-abuse-plugin/badges/gpa.svg)](https://codeclimate.com/github/detain/myadmin-abuse-plugin) [![Test Coverage](https://codeclimate.com/github/detain/myadmin-abuse-plugin/badges/coverage.svg)](https://codeclimate.com/github/detain/myadmin-abuse-plugin/coverage) [![Issue Count](https://codeclimate.com/github/detain/myadmin-abuse-plugin/badges/issue_count.svg)](https://codeclimate.com/github/detain/myadmin-abuse-plugin)
11-
![Scrutinizer](http://i.is.cc/storage/GYeUnux.png "Scrutinizer") | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/myadmin-plugins/abuse-plugin/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/myadmin-plugins/abuse-plugin/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/myadmin-plugins/abuse-plugin/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/myadmin-plugins/abuse-plugin/?branch=master) [![Build Status](https://scrutinizer-ci.com/g/myadmin-plugins/abuse-plugin/badges/build.png?b=master)](https://scrutinizer-ci.com/g/myadmin-plugins/abuse-plugin/build-status/master)
12-
![Codacy](http://i.is.cc/storage/GYi66Cx.png "Codacy") | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/226251fc068f4fd5b4b4ef9a40011d06)](https://www.codacy.com/app/detain/myadmin-abuse-plugin) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/25fa74eb74c947bf969602fcfe87e349)](https://www.codacy.com/app/detain/myadmin-abuse-plugin?utm_source=github.com&utm_medium=referral&utm_content=detain/myadmin-abuse-plugin&utm_campaign=Badge_Coverage)
13-
![Coveralls](http://i.is.cc/storage/GYjNSim.png "Coveralls") | [![Coverage Status](https://coveralls.io/repos/github/detain/db_abstraction/badge.svg?branch=master)](https://coveralls.io/github/detain/myadmin-abuse-plugin?branch=master)
14-
![Packagist](http://i.is.cc/storage/GYacBEX.png "Packagist") | [![Latest Stable Version](https://poser.pugx.org/detain/myadmin-abuse-plugin/version)](https://packagist.org/packages/detain/myadmin-abuse-plugin) [![Total Downloads](https://poser.pugx.org/detain/myadmin-abuse-plugin/downloads)](https://packagist.org/packages/detain/myadmin-abuse-plugin) [![Latest Unstable Version](https://poser.pugx.org/detain/myadmin-abuse-plugin/v/unstable)](//packagist.org/packages/detain/myadmin-abuse-plugin) [![Monthly Downloads](https://poser.pugx.org/detain/myadmin-abuse-plugin/d/monthly)](https://packagist.org/packages/detain/myadmin-abuse-plugin) [![Daily Downloads](https://poser.pugx.org/detain/myadmin-abuse-plugin/d/daily)](https://packagist.org/packages/detain/myadmin-abuse-plugin) [![License](https://poser.pugx.org/detain/myadmin-abuse-plugin/license)](https://packagist.org/packages/detain/myadmin-abuse-plugin)
10+
## Features
1511

12+
- **IMAP Abuse Monitoring** -- Connects to configurable IMAP mailboxes and parses abuse complaint emails using regex pattern matching to extract offending IP addresses.
13+
- **IP-to-Customer Resolution** -- Looks up IP addresses against the server inventory and client IP pools to identify the responsible customer.
14+
- **MailBaby Integration** -- Detects outbound mail abuse through ZoneMTA / MailBaby user matching and message ID correlation.
15+
- **Admin Dashboard** -- Provides an admin interface for manually reporting abuse, importing UCEProtect CSV data, and importing Trend Micro blocklist entries.
16+
- **Client Self-Service** -- Allows customers to view and respond to abuse complaints via authenticated or token-based URLs.
17+
- **Automated Notifications** -- Sends templated email notifications to affected customers with complaint details and response links.
1618

1719
## Installation
1820

19-
Install with composer like
21+
Install with Composer:
2022

2123
```sh
2224
composer require detain/myadmin-abuse-plugin
2325
```
2426

25-
## License
27+
The plugin registers itself with the MyAdmin event dispatcher and adds:
28+
29+
- `system.settings` -- IMAP credential configuration fields
30+
- `ui.menu` -- Admin menu entry for the abuse dashboard
31+
- `function.requirements` -- Page and class autoload registrations
32+
33+
## Usage
34+
35+
### Plugin Registration
36+
37+
The plugin hooks are registered automatically when loaded by the MyAdmin plugin system:
38+
39+
```php
40+
$hooks = \Detain\MyAdminAbuse\Plugin::getHooks();
41+
// Returns: ['system.settings' => ..., 'ui.menu' => ..., 'function.requirements' => ...]
42+
```
43+
44+
### IMAP Abuse Checker
45+
46+
The `ImapAbuseCheck` class processes abuse mailboxes from cron:
47+
48+
```php
49+
$abuse = new ImapAbuseCheck($imapServer, $username, $password, $db);
50+
$abuse->register_preg_match('/pattern with %IP%/', 'headers', 'ip');
51+
$abuse->process('spam', 100);
52+
```
53+
54+
### Admin Interface
2655

27-
The Abuse handling plugin for MyAdmin class is licensed under the LGPL-v2.1 license.
56+
Navigate to the abuse admin page in MyAdmin to:
57+
58+
- View abuse statistics (24-hour, 3-day, 7-day breakdowns)
59+
- Submit individual abuse reports by IP
60+
- Bulk-report multiple IPs
61+
- Import UCEProtect CSV files
62+
- Import Trend Micro blocklist data
63+
64+
## Running Tests
65+
66+
```sh
67+
composer install
68+
vendor/bin/phpunit
69+
```
70+
71+
To generate a coverage report:
72+
73+
```sh
74+
vendor/bin/phpunit --coverage-text
75+
```
76+
77+
## License
2878

79+
This package is licensed under the [LGPL-2.1](https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html) license.

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
"detain/myadmin-plugin-installer": "dev-master"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "*",
29-
"phpunit/phpunit-mock-objects": "*",
30-
"vlucas/phpdotenv": "*",
31-
"codeclimate/php-test-reporter": "dev-master",
32-
"satooshi/php-coveralls": "*",
33-
"codacy/coverage": "dev-master"
28+
"phpunit/phpunit": "^9.6"
3429
},
3530
"autoload": {
3631
"psr-4": {
3732
"Detain\\MyAdminAbuse\\": "src/"
3833
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Detain\\MyAdminAbuse\\Tests\\": "tests/"
38+
}
3939
}
4040
}

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="tests/bootstrap.php"
5+
colors="true"
6+
verbose="true"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
beStrictAboutTestsThatDoNotTestAnything="true">
10+
<testsuites>
11+
<testsuite name="Unit">
12+
<directory>tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<coverage processUncoveredFiles="true">
16+
<include>
17+
<directory suffix=".php">src</directory>
18+
</include>
19+
</coverage>
20+
</phpunit>

tests/FileExistenceTest.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/**
3+
* Tests that all expected source and configuration files exist in the package.
4+
*
5+
* This is a structural test that validates the package layout has not been
6+
* accidentally broken by a refactor or incomplete commit.
7+
*/
8+
9+
namespace Detain\MyAdminAbuse\Tests;
10+
11+
use PHPUnit\Framework\TestCase;
12+
13+
class FileExistenceTest extends TestCase
14+
{
15+
/** @var string Absolute path to the package root */
16+
private $root;
17+
18+
protected function setUp(): void
19+
{
20+
$this->root = dirname(__DIR__);
21+
}
22+
23+
/**
24+
* Tests that the main src/ PHP files exist.
25+
* These are the core source files loaded by the plugin system.
26+
*/
27+
public function testSrcFilesExist(): void
28+
{
29+
$files = [
30+
'src/Plugin.php',
31+
'src/ImapAbuseCheck.php',
32+
'src/abuse.php',
33+
'src/abuse_admin.php',
34+
];
35+
foreach ($files as $file) {
36+
$this->assertFileExists(
37+
$this->root . '/' . $file,
38+
"Source file {$file} should exist"
39+
);
40+
}
41+
}
42+
43+
/**
44+
* Tests that the bin/ script files exist.
45+
* These are cron/CLI scripts used operationally.
46+
*/
47+
public function testBinFilesExist(): void
48+
{
49+
$files = [
50+
'bin/abuse_imap_downloader.php',
51+
'bin/clean_up_abuse_headers.php',
52+
'bin/match_abuse.php',
53+
];
54+
foreach ($files as $file) {
55+
$this->assertFileExists(
56+
$this->root . '/' . $file,
57+
"Bin file {$file} should exist"
58+
);
59+
}
60+
}
61+
62+
/**
63+
* Tests that composer.json exists at the package root.
64+
*/
65+
public function testComposerJsonExists(): void
66+
{
67+
$this->assertFileExists($this->root . '/composer.json');
68+
}
69+
70+
/**
71+
* Tests that README.md exists at the package root.
72+
*/
73+
public function testReadmeExists(): void
74+
{
75+
$this->assertFileExists($this->root . '/README.md');
76+
}
77+
}

0 commit comments

Comments
 (0)