Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENEUROPA-1501: Implement configuration UI for Authentication. #42

Merged
merged 10 commits into from
Jan 11, 2019
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"nikic/php-parser": "~3.0",
"openeuropa/code-review": "~1.0.0-alpha4",
"openeuropa/drupal-core-require-dev": "^8.6",
"openeuropa/task-runner": "~1.0-beta3",
"openeuropa/task-runner": "~1.0-beta4",
"symfony/browser-kit": "~3.0||~4.0",
"phpunit/phpunit": "~6.0"
},
Expand Down
5 changes: 5 additions & 0 deletions oe_authentication.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
oe_authentication.settings:
title: Authentication settings
description: 'Configure Authentication settings.'
route_name: oe_authentication.settings
parent: system.admin_config_system
3 changes: 3 additions & 0 deletions oe_authentication.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
administer authentication configuration:
title: 'Administer Authentication configuration'
restrict access: false
7 changes: 7 additions & 0 deletions oe_authentication.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
oe_authentication.settings:
path: '/admin/config/system/oe_authentication'
defaults:
_form: 'Drupal\oe_authentication\Form\AuthenticationSettingsForm'
_title: 'Authentication settings'
requirements:
_permission: 'administer authentication configuration'
80 changes: 80 additions & 0 deletions src/Form/AuthenticationSettingsForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_authentication\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Settings form for module.
*/
class AuthenticationSettingsForm extends ConfigFormBase {

/**
* Name of the config being edited.
*/
const CONFIGNAME = 'oe_authentication.settings';

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'oe_authentication_settings';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['protocol'] = [
'#type' => 'textfield',
'#title' => $this->t('Application authentication protocol'),
'#default_value' => $this->config(static::CONFIGNAME)->get('protocol'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"#description" could be useful.
This remark is relevant to other fields too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no description provided in the configurations either. I would not add anything based on my own assumption.

];
$form['register_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Application register path'),
'#default_value' => $this->config(static::CONFIGNAME)->get('register_path'),
];
$form['validation_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Application validation path'),
'#default_value' => $this->config(static::CONFIGNAME)->get('validation_path'),
];
$form['assurance_level'] = [
'#type' => 'textfield',
'#title' => $this->t('Application assurance levels'),
'#default_value' => $this->config(static::CONFIGNAME)->get('assurance_level'),
];
$form['ticket_types'] = [
'#type' => 'textfield',
'#title' => $this->t('Application available ticket types'),
'#default_value' => $this->config(static::CONFIGNAME)->get('ticket_types'),
];
return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config(static::CONFIGNAME)
->set('protocol', $form_state->getValues()['protocol'])
upchuk marked this conversation as resolved.
Show resolved Hide resolved
->set('register_path', $form_state->getValues()['register_path'])
->set('validation_path', $form_state->getValues()['validation_path'])
->set('assurance_level', $form_state->getValues()['assurance_level'])
->set('ticket_types', $form_state->getValues()['ticket_types'])
->save();
parent::submitForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['oe_authentication.settings'];
}

}
25 changes: 24 additions & 1 deletion tests/Behat/AuthenticationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ class AuthenticationContext extends ConfigContext {
/**
* Configures the CAS module to use Drupal login.
*
* @Given the site is configured to use Drupal login
* @BeforeScenario @DrupalLogin
*/
public function setConfigDrupalLogin(): void {
$this->setConfig('cas.settings', 'forced_login.enabled', FALSE);
}

/**
* Configures the CAS module to use CAS login.
*
* @AfterScenario @DrupalLogin
*/
public function setConfigCasLogin(): void {
$this->setConfig('cas.settings', 'forced_login.enabled', TRUE);
}

/**
* Configures the CAS module to initialize this client as a proxy.
*
Expand Down Expand Up @@ -60,4 +69,18 @@ public function blockUser(string $username): void {
}
}

/**
* Backup configs that need to be reverted in AfterScenario by ConfigContext.
*
* @BeforeScenario @BackupCasConfigs
*/
public function backupCasConfigs(): void {
$name = 'oe_authentication.settings';

$configs = $this->getDriver()->getCore()->configGet($name);
foreach ($configs as $key => $backup) {
$this->config[$name][$key] = $backup;
}
}

}
30 changes: 30 additions & 0 deletions tests/features/configure_authentication.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@api
Feature: Authentication
As the site manager
I need to be able to configure the settings

Background:
Given I am logged in as a user with the "administer authentication configuration" permission

@DrupalLogin @BackupCasConfigs
nagyad marked this conversation as resolved.
Show resolved Hide resolved
Scenario: Configure Authentication settings
Given I am on "admin/config/system/oe_authentication"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I should see "Authentication settings"
# Check for the default config is there.
And the "Application authentication protocol" field should contain "eulogin"
And the "Application register path" field should contain "eim/external/register.cgi"
And the "Application validation path" field should contain "TicketValidationService"
And the "Application assurance levels" field should contain "TOP"
And the "Application available ticket types" field should contain "SERVICE,PROXY"
# Change the configuration values.
When I fill in "Application authentication protocol" with "something"
And I fill in "Application register path" with "test/something"
And I fill in "Application validation path" with "validation/path"
And I fill in "Application assurance levels" with "assurance"
And I fill in "Application available ticket types" with "ticket.test"
And I press "Save configuration"
And the "Application authentication protocol" field should contain "something"
nagyad marked this conversation as resolved.
Show resolved Hide resolved
And the "Application register path" field should contain "test/something"
And the "Application validation path" field should contain "validation/path"
And the "Application assurance levels" field should contain "assurance"
And the "Application available ticket types" field should contain "ticket.test"
5 changes: 2 additions & 3 deletions tests/features/drupal-login.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ Feature: Login through Drupal
If configured properly
I can access the CMS backend through Drupal

@DrupalLogin
Scenario: If configured properly I can access the CMS backend through Drupal
Given the site is configured to use Drupal login

When I am logged in as a user with the "authenticated" role
Given I am logged in as a user with the "authenticated" role
Then I should see the link "Log out"

When I click "Log out"
Expand Down