Browse Source

Small improvements and tests for the logout plugin

pull/8296/head
Aleksander Machniak 4 years ago
parent
commit
d4cfb94c3d
  1. 1
      CHANGELOG.md
  2. 23
      plugins/autologout/autologout.php
  3. 25
      plugins/autologout/tests/Autologout.php
  4. 1
      tests/phpunit.xml

1
CHANGELOG.md

@ -17,6 +17,7 @@
- SMTP: If requested use TLS also without authentication (#4590, #8111) - SMTP: If requested use TLS also without authentication (#4590, #8111)
- Display a generic error page on initial DB/configuration errors (#8222) - Display a generic error page on initial DB/configuration errors (#8222)
- Display telephone numbers as tel: links (#8240) - Display telephone numbers as tel: links (#8240)
- Autologout: A new plugin to auto log out users with a POST request (#8270)
- Enigma: Upgrade to OpenPGP.js v5.0 - Enigma: Upgrade to OpenPGP.js v5.0
- Identicon: Make background color of the image to match the current skin colors (#8256) - Identicon: Make background color of the image to match the current skin colors (#8256)
- Password: Remove password_blowfish_cost option, in favor of password_algorithm_options - Password: Remove password_blowfish_cost option, in favor of password_algorithm_options

23
plugins/autologout/autologout.php

@ -28,12 +28,18 @@ class autologout extends rcube_plugin
{ {
public $task = 'logout'; public $task = 'logout';
function init()
/**
* Plugin initialization
*/
public function init()
{ {
$this->add_hook('startup', [$this, 'startup']); $this->add_hook('startup', [$this, 'startup']);
} }
function startup($args)
/**
* Request handler
*/
public function startup($args)
{ {
$rcmail = rcmail::get_instance(); $rcmail = rcmail::get_instance();
@ -46,13 +52,16 @@ class autologout extends rcube_plugin
return $args; return $args;
} }
function known_client()
/**
* Checks if the request came from an allowed client IP
*/
private function known_client()
{ {
/**
* If you want to restrict the use of this plugin to specific
* remote clients, you can verify the remote client's IP like this:
/*
* If you want to restrict the use of this plugin to specific
* remote clients, you can verify the remote client's IP like this:
* *
* return in_array(rcube_utils::remote_addr(), ['123.123.123.123', '124.124.124.124']);
* return in_array(rcube_utils::remote_addr(), ['123.123.123.123', '124.124.124.124']);
*/ */
return true; return true;

25
plugins/autologout/tests/Autologout.php

@ -0,0 +1,25 @@
<?php
class Autologout_Plugin extends PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass(): void
{
include_once __DIR__ . '/../autologout.php';
}
/**
* Plugin object construction test
*/
function test_constructor()
{
$rcube = rcube::get_instance();
$plugin = new autologout($rcube->plugins);
$this->assertInstanceOf('autologout', $plugin);
$this->assertInstanceOf('rcube_plugin', $plugin);
// TODO
$plugin->startup([]);
}
}

1
tests/phpunit.xml

@ -32,6 +32,7 @@
<file>./../plugins/archive/tests/Archive.php</file> <file>./../plugins/archive/tests/Archive.php</file>
<file>./../plugins/attachment_reminder/tests/AttachmentReminder.php</file> <file>./../plugins/attachment_reminder/tests/AttachmentReminder.php</file>
<file>./../plugins/autologon/tests/Autologon.php</file> <file>./../plugins/autologon/tests/Autologon.php</file>
<file>./../plugins/autologout/tests/Autologout.php</file>
<file>./../plugins/database_attachments/tests/DatabaseAttachments.php</file> <file>./../plugins/database_attachments/tests/DatabaseAttachments.php</file>
<file>./../plugins/debug_logger/tests/DebugLogger.php</file> <file>./../plugins/debug_logger/tests/DebugLogger.php</file>
<file>./../plugins/emoticons/tests/Emoticons.php</file> <file>./../plugins/emoticons/tests/Emoticons.php</file>

Loading…
Cancel
Save