Skip to content
Snippets Groups Projects
Commit 16c9f1f9 authored by Tim van Dijen's avatar Tim van Dijen
Browse files

Fix several coding style issues; make phpcs/psalter mandatory to pass

parent 9b299861
No related branches found
No related tags found
No related merge requests found
...@@ -194,7 +194,7 @@ jobs: ...@@ -194,7 +194,7 @@ jobs:
uses: codecov/codecov-action@v1 uses: codecov/codecov-action@v1
- name: PHP Code Sniffer - name: PHP Code Sniffer
continue-on-error: true continue-on-error: false
run: php vendor/bin/phpcs run: php vendor/bin/phpcs
- name: Psalm - name: Psalm
...@@ -202,5 +202,5 @@ jobs: ...@@ -202,5 +202,5 @@ jobs:
run: php vendor/bin/psalm --show-info=true run: php vendor/bin/psalm --show-info=true
- name: Psalter - name: Psalter
continue-on-error: true continue-on-error: false
run: php vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run run: php vendor/bin/psalter --issues=UnnecessaryVarAnnotation --dry-run
...@@ -269,7 +269,7 @@ class Localization ...@@ -269,7 +269,7 @@ class Localization
$this->addDomain($this->localeDir, 'attributes'); $this->addDomain($this->localeDir, 'attributes');
list($theme,) = explode(':', $this->configuration->getString('theme.use', 'default')); list($theme,) = explode(':', $this->configuration->getString('theme.use', 'default'));
if($theme !== 'default') { if ($theme !== 'default') {
$this->addModuleDomain($theme, null, 'attributes'); $this->addModuleDomain($theme, null, 'attributes');
} }
} }
......
...@@ -14,7 +14,12 @@ ...@@ -14,7 +14,12 @@
<file>src</file> <file>src</file>
<file>tests</file> <file>tests</file>
<file>www</file> <file>www</file>
<exclude-pattern>modules/adfs/*</exclude-pattern> <exclude-pattern>modules/adfs/*</exclude-pattern>
<exclude-pattern>www/assets/css/stylesheet.css</exclude-pattern>
<exclude-pattern>www/assets/js/bundle.js</exclude-pattern>
<exclude-pattern>www/assets/js/logout.js</exclude-pattern>
<exclude-pattern>www/assets/js/stylesheet.js</exclude-pattern>
<!-- This is the rule we inherit from. If you want to exlude some specific rules, see the docs on how to do that --> <!-- This is the rule we inherit from. If you want to exlude some specific rules, see the docs on how to do that -->
<rule ref="PSR12"/> <rule ref="PSR12"/>
......
...@@ -13,6 +13,9 @@ use SimpleSAML\XHTML\Template; ...@@ -13,6 +13,9 @@ use SimpleSAML\XHTML\Template;
use Symfony\Bridge\Twig\Extension\TranslationExtension; use Symfony\Bridge\Twig\Extension\TranslationExtension;
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Finder\SplFileInfo;
use Twig\Environment;
use Twig\Extra\Intl\IntlExtension;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter; use Twig\TwigFilter;
use Twig\TwigFunction; use Twig\TwigFunction;
...@@ -21,7 +24,8 @@ use Twig\TwigFunction; ...@@ -21,7 +24,8 @@ use Twig\TwigFunction;
*/ */
class TemplateTranslationTest extends TestCase class TemplateTranslationTest extends TestCase
{ {
public function testCoreCardinalityErrorTemplate(): void { public function testCoreCardinalityErrorTemplate(): void
{
$c = Configuration::loadFromArray([], '', 'simplesaml'); $c = Configuration::loadFromArray([], '', 'simplesaml');
$t = new Template($c, 'core:cardinality_error.twig'); $t = new Template($c, 'core:cardinality_error.twig');
...@@ -30,18 +34,18 @@ class TemplateTranslationTest extends TestCase ...@@ -30,18 +34,18 @@ class TemplateTranslationTest extends TestCase
'test 2' => [1, 2], 'test 2' => [1, 2],
]; ];
$getContent = function() { $getContent = function () {
/** @var Template $this */ /** @var \SimpleSAML\XHTML\Template $this */
return $this->getContents(); return $this->getContents();
}; };
$html = $getContent->call($t); $html = $getContent->call($t);
$this->assertStringContainsString('got 0 values, want 1', $html); $this->assertStringContainsString('got 0 values, want 1', $html);
$this->assertStringContainsString('got 1 values, want 2', $html); $this->assertStringContainsString('got 1 values, want 2', $html);
} }
public function testCoreLoginUserPassTemplate(): void { public function testCoreLoginUserPassTemplate(): void
{
$c = Configuration::loadFromArray([], '', 'simplesaml'); $c = Configuration::loadFromArray([], '', 'simplesaml');
$t = new Template($c, 'core:loginuserpass.twig'); $t = new Template($c, 'core:loginuserpass.twig');
...@@ -53,8 +57,8 @@ class TemplateTranslationTest extends TestCase ...@@ -53,8 +57,8 @@ class TemplateTranslationTest extends TestCase
$t->data['rememberMeEnabled'] = false; $t->data['rememberMeEnabled'] = false;
$t->data['stateparams'] = []; $t->data['stateparams'] = [];
$getContent = function() { $getContent = function () {
/** @var Template $this */ /** @var \SimpleSAML\XHTML\Template $this */
return $this->getContents(); return $this->getContents();
}; };
$html = $getContent->call($t); $html = $getContent->call($t);
...@@ -62,7 +66,8 @@ class TemplateTranslationTest extends TestCase ...@@ -62,7 +66,8 @@ class TemplateTranslationTest extends TestCase
$this->assertStringContainsString('value="h.c oersted"', $html); $this->assertStringContainsString('value="h.c oersted"', $html);
} }
public function testCoreLogoutIframeTemplate(): void { public function testCoreLogoutIframeTemplate(): void
{
$c = Configuration::loadFromArray([], '', 'simplesaml'); $c = Configuration::loadFromArray([], '', 'simplesaml');
$t = new Template($c, 'core:logout-iframe.twig'); $t = new Template($c, 'core:logout-iframe.twig');
...@@ -86,8 +91,8 @@ class TemplateTranslationTest extends TestCase ...@@ -86,8 +91,8 @@ class TemplateTranslationTest extends TestCase
], ],
]; ];
$getContent = function() { $getContent = function () {
/** @var Template $this */ /** @var \SimpleSAML\XHTML\Template $this */
return $this->getContents(); return $this->getContents();
}; };
$html = $getContent->call($t); $html = $getContent->call($t);
...@@ -96,7 +101,8 @@ class TemplateTranslationTest extends TestCase ...@@ -96,7 +101,8 @@ class TemplateTranslationTest extends TestCase
$this->assertStringContainsString('ze missing service', $html); $this->assertStringContainsString('ze missing service', $html);
} }
public function testAuthStatusTemplate(): void { public function testAuthStatusTemplate(): void
{
$c = Configuration::loadFromArray([], '', 'simplesaml'); $c = Configuration::loadFromArray([], '', 'simplesaml');
$t = new Template($c, 'auth_status.twig'); $t = new Template($c, 'auth_status.twig');
...@@ -106,44 +112,78 @@ class TemplateTranslationTest extends TestCase ...@@ -106,44 +112,78 @@ class TemplateTranslationTest extends TestCase
$t->data['trackid'] = ''; $t->data['trackid'] = '';
$t->data['authData'] = false; $t->data['authData'] = false;
$getContent = function() { $getContent = function () {
/** @var Template $this */ /** @var \SimpleSAML\XHTML\Template $this */
return $this->getContents(); return $this->getContents();
}; };
$html = $getContent->call($t); $html = $getContent->call($t);
$this->assertStringContainsString('Your session is valid for ' . $t->data['remaining'] . ' seconds from now.', $html); $this->assertStringContainsString(
'Your session is valid for ' . $t->data['remaining'] . ' seconds from now.',
$html
);
} }
public function testValidateTwigFiles() public function testValidateTwigFiles(): void
{ {
$root = dirname(dirname((dirname(dirname(__DIR__))))); $root = dirname(dirname((dirname(dirname(__DIR__)))));
// Setup basic twig environment // Setup basic twig environment
$loader = new \Twig\Loader\FilesystemLoader(['templates', 'modules'], $root); $loader = new FilesystemLoader(['templates', 'modules'], $root);
$twig = new \Twig\Environment($loader, ['cache' => false]); $twig = new Environment($loader, ['cache' => false]);
$twigTranslator = new TwigTranslator([Translate::class, 'translateSingularGettext']); $twigTranslator = new TwigTranslator([Translate::class, 'translateSingularGettext']);
$twig->addExtension(new TranslationExtension($twigTranslator)); $twig->addExtension(new TranslationExtension($twigTranslator));
$twig->addExtension(new \Twig\Extra\Intl\IntlExtension()); $twig->addExtension(new IntlExtension());
// Fake functions // Fake functions
$twig->addFunction(new TwigFunction('asset', function() { return ''; })); $twig->addFunction(
$twig->addFunction(new TwigFunction('moduleURL', function() { return ''; })); new TwigFunction(
'asset',
function () {
return '';
}
)
);
$twig->addFunction(
new TwigFunction(
'moduleURL',
function () {
return '';
}
)
);
// Fake filters // Fake filters
$twig->addFilter(new TwigFilter('translateFromArray', function() { return ''; }, ['needs_context' => true])); $twig->addFilter(
$twig->addFilter(new TwigFilter('entityDisplayName', function() { return ''; })); new TwigFilter(
'translateFromArray',
function () {
return '';
},
['needs_context' => true]
)
);
$twig->addFilter(
new TwigFilter(
'entityDisplayName',
function () {
return '';
}
)
);
$files = Finder::create() $files = Finder::create()
->name('*.twig') ->name('*.twig')
->in([ ->in(
$root . '/templates', [
$root . '/modules' $root . '/templates',
]); $root . '/modules'
]
);
foreach ($files as $file) { foreach ($files as $file) {
/** @var SplFileInfo $file */ /** @var \Symfony\Component\Finder\SplFileInfo $file */
$twig->load($file->getRelativePathname()); $twig->load($file->getRelativePathname());
} }
......
...@@ -5,6 +5,7 @@ declare(strict_types=1); ...@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace SimpleSAML\Test\Module\saml\IdP; namespace SimpleSAML\Test\Module\saml\IdP;
use InvalidArgumentException; use InvalidArgumentException;
use SAML2\XML\Chunk;
use SimpleSAML\Configuration; use SimpleSAML\Configuration;
use SimpleSAML\Error\Exception; use SimpleSAML\Error\Exception;
use SimpleSAML\IdP; use SimpleSAML\IdP;
...@@ -288,8 +289,13 @@ EOT; ...@@ -288,8 +289,13 @@ EOT;
$this->assertArrayHasKey('SingleLogoutService', $hostedMd); $this->assertArrayHasKey('SingleLogoutService', $hostedMd);
$this->assertIsArray($hostedMd['SingleLogoutService']); $this->assertIsArray($hostedMd['SingleLogoutService']);
$this->assertCount(1, $hostedMd['SingleLogoutService']); $this->assertCount(1, $hostedMd['SingleLogoutService']);
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', $this->assertEquals(
'Location' => 'http://localhost/simplesaml/saml2/idp/SingleLogoutService.php'], $hostedMd['SingleLogoutService'][0]); [
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
'Location' => 'http://localhost/simplesaml/saml2/idp/SingleLogoutService.php'
],
$hostedMd['SingleLogoutService'][0]
);
$this->assertArrayHasKey('keys', $hostedMd); $this->assertArrayHasKey('keys', $hostedMd);
$this->assertIsArray($hostedMd['keys']); $this->assertIsArray($hostedMd['keys']);
...@@ -349,8 +355,14 @@ EOT; ...@@ -349,8 +355,14 @@ EOT;
$this->assertArrayHasKey('ArtifactResolutionService', $hostedMd); $this->assertArrayHasKey('ArtifactResolutionService', $hostedMd);
$this->assertIsArray($hostedMd['ArtifactResolutionService']); $this->assertIsArray($hostedMd['ArtifactResolutionService']);
$this->assertCount(1, $hostedMd['ArtifactResolutionService']); $this->assertCount(1, $hostedMd['ArtifactResolutionService']);
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP', 'index' => 0, $this->assertEquals(
'Location' => 'http://localhost/simplesaml/saml2/idp/ArtifactResolutionService.php'], $hostedMd['ArtifactResolutionService'][0]); [
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
'index' => 0,
'Location' => 'http://localhost/simplesaml/saml2/idp/ArtifactResolutionService.php'
],
$hostedMd['ArtifactResolutionService'][0]
);
} }
public function testIdPGetHostedMetadataHolderOfKey(): void public function testIdPGetHostedMetadataHolderOfKey(): void
...@@ -361,9 +373,14 @@ EOT; ...@@ -361,9 +373,14 @@ EOT;
$this->assertArrayHasKey('SingleSignOnService', $hostedMd); $this->assertArrayHasKey('SingleSignOnService', $hostedMd);
$this->assertIsArray($hostedMd['SingleSignOnService']); $this->assertIsArray($hostedMd['SingleSignOnService']);
$this->assertCount(2, $hostedMd['SingleSignOnService']); $this->assertCount(2, $hostedMd['SingleSignOnService']);
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser', $this->assertEquals(
'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php', [
'hoksso:ProtocolBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'], $hostedMd['SingleSignOnService'][0]); 'Binding' => 'urn:oasis:names:tc:SAML:2.0:profiles:holder-of-key:SSO:browser',
'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php',
'hoksso:ProtocolBinding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
],
$hostedMd['SingleSignOnService'][0]
);
$this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect', $this->assertEquals(['Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php'], $hostedMd['SingleSignOnService'][1]); 'Location' => 'http://localhost/simplesaml/saml2/idp/SSOService.php'], $hostedMd['SingleSignOnService'][1]);
} }
...@@ -527,19 +544,26 @@ EOT; ...@@ -527,19 +544,26 @@ EOT;
{ {
$dom = \SAML2\DOMDocumentFactory::create(); $dom = \SAML2\DOMDocumentFactory::create();
$republishRequest = $dom->createElementNS('http://eduid.cz/schema/metadata/1.0', 'eduidmd:RepublishRequest'); $republishRequest = $dom->createElementNS('http://eduid.cz/schema/metadata/1.0', 'eduidmd:RepublishRequest');
$republishTarget = $dom->createElementNS('http://eduid.cz/schema/metadata/1.0', 'eduidmd:RepublishTarget', 'http://edugain.org/'); $republishTarget = $dom->createElementNS(
'http://eduid.cz/schema/metadata/1.0',
'eduidmd:RepublishTarget',
'http://edugain.org/'
);
$republishRequest->appendChild($republishTarget); $republishRequest->appendChild($republishTarget);
$ext = [new \SAML2\XML\Chunk($republishRequest)]; $ext = [new Chunk($republishRequest)];
$config = [ $config = [
'saml:Extensions' => $ext, 'saml:Extensions' => $ext,
]; ];
$md = $this->idpMetadataHandlerHelper($config); $md = $this->idpMetadataHandlerHelper($config);
$this->assertArrayHasKey('saml:Extensions', $md); $this->assertArrayHasKey('saml:Extensions', $md);
$this->assertCount(1, $md['saml:Extensions']); $this->assertCount(1, $md['saml:Extensions']);
$this->assertInstanceOf(\SAML2\XML\Chunk::class, $md['saml:Extensions'][0]); $this->assertInstanceOf(Chunk::class, $md['saml:Extensions'][0]);
$this->assertEquals('http://edugain.org/', $md['saml:Extensions'][0]->getXML()->firstChild->firstChild->textContent); $this->assertEquals(
'http://edugain.org/',
$md['saml:Extensions'][0]->getXML()->firstChild->firstChild->textContent
);
} }
/** /**
...@@ -723,15 +747,17 @@ EOT; ...@@ -723,15 +747,17 @@ EOT;
$globalConfig = [ $globalConfig = [
'technicalcontact_email' => 'na@example.org', 'technicalcontact_email' => 'na@example.org',
'technicalcontact_name' => 'Someone von Somewhere', 'technicalcontact_name' => 'Someone von Somewhere',
]; ];
$config = ['contacts' => [ $config = [
[ 'contacts' => [
'contactType' => 'technical', [
'emailAddress' => 'j.doe@example.edu', 'contactType' => 'technical',
'surName' => 'Doe', 'emailAddress' => 'j.doe@example.edu',
], 'surName' => 'Doe',
]]; ],
]
];
$md = $this->idpMetadataHandlerHelper($config, $globalConfig); $md = $this->idpMetadataHandlerHelper($config, $globalConfig);
$this->assertCount(1, $md['contacts']); $this->assertCount(1, $md['contacts']);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment