Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/Controller/SAMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
Expand All @@ -48,6 +49,8 @@ class SAMLController extends Controller {
private $urlGenerator;
/** @var IUserManager */
private $userManager;
/** @var ILogger */
private $logger;

/**
* @param string $appName
Expand All @@ -59,6 +62,7 @@ class SAMLController extends Controller {
* @param IConfig $config
* @param IURLGenerator $urlGenerator
* @param IUserManager $userManager
* @param ILogger $logger
*/
public function __construct($appName,
IRequest $request,
Expand All @@ -68,7 +72,8 @@ public function __construct($appName,
UserBackend $userBackend,
IConfig $config,
IURLGenerator $urlGenerator,
IUserManager $userManager) {
IUserManager $userManager,
ILogger $logger) {
parent::__construct($appName, $request);
$this->session = $session;
$this->userSession = $userSession;
Expand All @@ -77,6 +82,7 @@ public function __construct($appName,
$this->config = $config;
$this->urlGenerator = $urlGenerator;
$this->userManager = $userManager;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -169,6 +175,8 @@ public function getMetadata() {
* @NoCSRFRequired
* @UseSession
* @OnlyUnauthenticatedUsers
*
* @return Http\RedirectResponse|void
*/
public function assertionConsumerService() {
$AuthNRequestID = $this->session->get('user_saml.AuthNRequestID');
Expand All @@ -181,14 +189,14 @@ public function assertionConsumerService() {

$errors = $auth->getErrors();

// FIXME: Appframworkize
if (!empty($errors)) {
print_r('<p>'.implode(', ', $errors).'</p>');
foreach($errors as $error) {
$this->logger->error($error, ['app' => $this->appName]);
}
}

if (!$auth->isAuthenticated()) {
echo "<p>Not authenticated</p>";
exit();
return new Http\RedirectResponse($this->urlGenerator->linkToRouteAbsolute('user_saml.SAML.notProvisioned'));
}

// Check whether the user actually exists, if not redirect to an error page
Expand All @@ -197,7 +205,6 @@ public function assertionConsumerService() {
$this->autoprovisionIfPossible($auth->getAttributes());
} catch (NoUserFoundException $e) {
return new Http\RedirectResponse($this->urlGenerator->linkToRouteAbsolute('user_saml.SAML.notProvisioned'));

}

$this->session->set('user_saml.samlUserData', $auth->getAttributes());
Expand Down
7 changes: 6 additions & 1 deletion lib/Settings/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ class Section implements IIconSection {
/** @var IURLGenerator */
private $url;

public function __construct(IL10N $l, IURLGenerator $url) {
/**
* @param IL10N $l
* @param IURLGenerator $url
*/
public function __construct(IL10N $l,
IURLGenerator $url) {
$this->l = $l;
$this->url = $url;
}
Expand Down
1 change: 1 addition & 0 deletions lib/samlsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct(IURLGenerator $urlGenerator,
public function getOneLoginSettingsArray() {
$settings = [
'strict' => true,
'debug' => $this->config->getSystemValue('debug', false),
'security' => [
'nameIdEncrypted' => ($this->config->getAppValue('user_saml', 'security-nameIdEncrypted', '0') === '1') ? true : false,
'authnRequestsSigned' => ($this->config->getAppValue('user_saml', 'security-authnRequestsSigned', '0') === '1') ? true : false,
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/Controller/SAMLControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserBackend;
use OCP\IUserManager;
use OCP\IUserSession;
use Test\TestCase;
Expand All @@ -52,6 +52,8 @@ class SAMLControllerTest extends TestCase {
private $urlGenerator;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var SAMLController */
private $samlController;

Expand All @@ -66,6 +68,7 @@ public function setUp() {
$this->config = $this->createMock(IConfig::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->logger = $this->createMock(ILogger::class);

$this->samlController = new SAMLController(
'user_saml',
Expand All @@ -76,7 +79,8 @@ public function setUp() {
$this->userBackend,
$this->config,
$this->urlGenerator,
$this->userManager
$this->userManager,
$this->logger
);
}

Expand Down
20 changes: 18 additions & 2 deletions tests/unit/Settings/SectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@

namespace OCA\User_SAML\Tests\Settings;

use OCP\IL10N;
use OCP\IURLGenerator;

class SectionTest extends \Test\TestCase {
/** @var \OCA\User_SAML\Settings\Section */
private $section;
/** @var \OCP\IL10N */
/** @var IL10N|\PHPUnit_Framework_MockObject_MockObject */
private $l10n;
/** @var IURLGenerator|\PHPUnit_Framework_MockObject_MockObject */
private $urlGenerator;

public function setUp() {
$this->l10n = $this->createMock(\OCP\IL10N::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->section = new \OCA\User_SAML\Settings\Section(
$this->l10n
$this->l10n,
$this->urlGenerator
);

return parent::setUp();
Expand All @@ -53,4 +60,13 @@ public function testGetName() {
public function testGetPriority() {
$this->assertSame(75, $this->section->getPriority());
}

public function testGetIcon() {
$this->urlGenerator
->expects($this->once())
->method('imagePath')
->with('user_saml', 'app-dark.svg')
->willReturn('/apps/user_saml/myicon.svg');
$this->assertSame('/apps/user_saml/myicon.svg', $this->section->getIcon());
}
}