OpenFlyers SSO WordPress plugin 1.2.0
Read the member name and email from a custom report (profile_report_id).
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
<?php
|
||||
|
||||
// Command-line only: this script rewrites settings and accounts, it must never run from a web request.
|
||||
if (PHP_SAPI !== 'cli') {
|
||||
exit;
|
||||
}
|
||||
/**
|
||||
* Functional test of the plugin inside a real WordPress installation.
|
||||
*
|
||||
@@ -99,7 +94,7 @@ require_once ABSPATH . 'wp-admin/includes/template.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/screen.php';
|
||||
|
||||
// Remove anything left by a previous run so the script is repeatable.
|
||||
foreach (array('pilote.test', 'of-7777', 'of-8888') as $login) {
|
||||
foreach (array('pilote.test', 'of-7777', 'of-8888', 'of-9191', 'of-9292', 'of-9393') as $login) {
|
||||
$stale = get_user_by('login', $login);
|
||||
if ($stale) {
|
||||
wp_delete_user($stale->ID);
|
||||
@@ -336,6 +331,68 @@ check('the profile filter fills the e-mail', $created->user_email === 'nouveau@e
|
||||
check('the profile filter fills the display name', $created->display_name === 'Nouveau Membre', $created->display_name);
|
||||
remove_all_filters('of_sso_user_profile');
|
||||
|
||||
// --- member report (name and e-mail) ------------------------------------------
|
||||
/**
|
||||
* Client whose report call is answered locally, the way the OpenFlyers resource server answers: the
|
||||
* row is the one of the token's user ($connectedPersonId), here carried by the test token.
|
||||
*/
|
||||
class OF_SSO_Report_Test_Client extends OF_SSO_Client
|
||||
{
|
||||
public $answers = array();
|
||||
public $replacementLists = array();
|
||||
|
||||
public function getReport(array $token, $reportId, $resourceType = 'report', array $replacementList = array())
|
||||
{
|
||||
$this->replacementLists[] = $replacementList;
|
||||
$memberId = isset($token['test_user_id']) ? $token['test_user_id'] : 0;
|
||||
return isset($this->answers[$memberId]) ? $this->answers[$memberId] : false;
|
||||
}
|
||||
}
|
||||
|
||||
$settings['profile_report_id'] = '12';
|
||||
update_option('of_sso_settings', OF_SSO_Admin::sanitize($settings));
|
||||
check('the report number is stored as an integer', of_sso_get_settings()['profile_report_id'] === 12);
|
||||
|
||||
$redirects = array();
|
||||
$_GET = array('of_sso' => 'login');
|
||||
capture(array('OF_SSO_Auth', 'route'));
|
||||
parse_str((string) parse_url((string) end($redirects), PHP_URL_QUERY), $query);
|
||||
check('the custom reports scope is requested once a report is set', $query['scope'] === 'default.login reports.readonly', $query['scope']);
|
||||
$_GET = array();
|
||||
|
||||
$reportClient = new OF_SSO_Report_Test_Client(array());
|
||||
$reportClient->answers = array(
|
||||
9191 => "first_name;last_name;email\nÉlodie;D'Artagnan;elodie@example.test\n",
|
||||
4242 => "first_name;last_name;email\nPaul;PILOTE;paul.pilote@example.test\n",
|
||||
9292 => "first_name;last_name;email\nJean;MARTIN;paul.pilote@example.test\n",
|
||||
);
|
||||
|
||||
$result = $resolve->invoke(null, 9191, array('test_user_id' => 9191), $reportClient);
|
||||
$created = get_user_by('id', $result->ID);
|
||||
check('a new member gets the name from the report', $created->first_name === 'Élodie' && $created->last_name === "D'Artagnan");
|
||||
check('a new member is displayed under that name', $created->display_name === "Élodie D'Artagnan", $created->display_name);
|
||||
check('a new member gets the e-mail from the report', $created->user_email === 'elodie@example.test', $created->user_email);
|
||||
check('the login name stays technical', $created->user_login === 'of-9191');
|
||||
|
||||
$result = $resolve->invoke(null, 4242, array('test_user_id' => 4242), $reportClient);
|
||||
$updated = get_user_by('id', $linkedId);
|
||||
check('a linked member is updated at the next login', $updated->display_name === 'Paul PILOTE' && $updated->user_email === 'paul.pilote@example.test', $updated->display_name . ' ' . $updated->user_email);
|
||||
|
||||
$result = $resolve->invoke(null, 9292, array('test_user_id' => 9292), $reportClient);
|
||||
check('an e-mail used by another account does not block the login', $result instanceof WP_User, is_wp_error($result) ? $result->get_error_message() : '');
|
||||
$created = get_user_by('id', $result->ID);
|
||||
check('that e-mail is not copied to the new account', $created->user_email === '', $created->user_email);
|
||||
check('the name is still filled', $created->display_name === 'Jean MARTIN', $created->display_name);
|
||||
|
||||
$result = $resolve->invoke(null, 9393, array('test_user_id' => 9393), $reportClient);
|
||||
check('an unreadable report does not block the login', $result instanceof WP_User, is_wp_error($result) ? $result->get_error_message() : '');
|
||||
check('the member then keeps the technical name', get_user_by('id', $result->ID)->display_name === 'of-9393');
|
||||
check('no member identifier is ever sent to the report', $reportClient->replacementLists === array(array(), array(), array(), array()), wp_json_encode($reportClient->replacementLists));
|
||||
|
||||
$settings['profile_report_id'] = '';
|
||||
update_option('of_sso_settings', OF_SSO_Admin::sanitize($settings));
|
||||
check('an empty report number disables the report', of_sso_get_settings()['profile_report_id'] === 0);
|
||||
|
||||
// --- shortcodes -------------------------------------------------------------
|
||||
check('the login shortcode is registered', shortcode_exists('openflyers_login'));
|
||||
check('the member shortcode is registered', shortcode_exists('openflyers_membre'));
|
||||
@@ -366,6 +423,7 @@ check('the settings page renders', strlen($page) > 1000, strlen($page) . ' bytes
|
||||
check('it shows the callback URL to declare', strpos($page, esc_html(of_sso_get_redirect_uri())) !== false);
|
||||
check('it exposes every certificate field', substr_count($page, 'of_sso_settings[') >= 15);
|
||||
check('it offers the certificate folder field', strpos($page, 'name="of_sso_settings[cert_dir]"') !== false);
|
||||
check('it offers the member report field', strpos($page, 'name="of_sso_settings[profile_report_id]"') !== false);
|
||||
check('it offers the connection test button', strpos($page, 'name="of_sso_test_connection"') !== false);
|
||||
check('the stored secret is never printed back', strpos($page, 'value="secret"') === false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user