From 8aa9aaf76a98335e3b58eb779079eafb7180891a Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Sun, 19 May 2024 01:00:19 +0200 Subject: [PATCH] Add trailing commas --- public/login.php | 2 +- public/proxy.php | 2 +- public/utility/validateTicket.php | 2 +- src/Cas/AttributeExtractor.php | 4 +- src/Cas/Protocol/SamlValidateResponder.php | 2 +- src/Cas/Ticket/SQLTicketStore.php | 4 +- src/Cas/Ticket/TicketFactory.php | 2 +- tests/config/module_casserver.php | 8 +-- tests/public/LoginIntegrationTest.php | 72 +++++++++---------- tests/src/AttributeExtractorTest.php | 34 ++++----- tests/src/Cas/Protocol/Cas20Test.php | 2 +- tests/src/Cas/Protocol/SamlValidateTest.php | 2 +- tests/src/ServiceValidatorTest.php | 38 +++++----- .../src/Ticket/DelegatingTicketStoreTest.php | 17 ++--- tests/src/TicketValidatorTest.php | 4 +- 15 files changed, 98 insertions(+), 97 deletions(-) diff --git a/public/login.php b/public/login.php index dfc3c74..db2416e 100644 --- a/public/login.php +++ b/public/login.php @@ -197,7 +197,7 @@ 'userName' => $mappedAttributes['user'], 'attributes' => $mappedAttributes['attributes'], 'proxies' => [], - 'sessionId' => $sessionTicket['id'] + 'sessionId' => $sessionTicket['id'], ]); $ticketStore->addTicket($serviceTicket); diff --git a/public/proxy.php b/public/proxy.php index f7cc572..0a59594 100644 --- a/public/proxy.php +++ b/public/proxy.php @@ -66,7 +66,7 @@ 'forceAuthn' => $proxyGrantingTicket['forceAuthn'], 'attributes' => $proxyGrantingTicket['attributes'], 'proxies' => $proxyGrantingTicket['proxies'], - 'sessionId' => $proxyGrantingTicket['sessionId'] + 'sessionId' => $proxyGrantingTicket['sessionId'], ] ); diff --git a/public/utility/validateTicket.php b/public/utility/validateTicket.php index f01adfe..92353e0 100644 --- a/public/utility/validateTicket.php +++ b/public/utility/validateTicket.php @@ -101,7 +101,7 @@ 'attributes' => $attributes, 'forceAuthn' => false, 'proxies' => array_merge([$serviceUrl], $serviceTicket['proxies']), - 'sessionId' => $serviceTicket['sessionId'] + 'sessionId' => $serviceTicket['sessionId'], ]); $httpUtils = new Utils\HTTP(); try { diff --git a/src/Cas/AttributeExtractor.php b/src/Cas/AttributeExtractor.php index a5d94e5..17e776f 100644 --- a/src/Cas/AttributeExtractor.php +++ b/src/Cas/AttributeExtractor.php @@ -61,7 +61,7 @@ public function extractUserAndAttributes(array $attributes, Configuration $casco return [ 'user' => $userName, - 'attributes' => $casAttributes + 'attributes' => $casAttributes, ]; } @@ -79,7 +79,7 @@ private function invokeAuthProc(array $attributes, Configuration $casconfig): ar $filters = $casconfig->getOptionalArray('authproc', []); $state = [ - 'Attributes' => $attributes + 'Attributes' => $attributes, ]; foreach ($filters as $config) { $className = Module::resolveClass( diff --git a/src/Cas/Protocol/SamlValidateResponder.php b/src/Cas/Protocol/SamlValidateResponder.php index cad347a..87ce821 100644 --- a/src/Cas/Protocol/SamlValidateResponder.php +++ b/src/Cas/Protocol/SamlValidateResponder.php @@ -29,7 +29,7 @@ public function convertToSaml(array $ticket): Chunk $ar = new AuthnResponse(); $idpMetadata = [ // CAS doesn't seem to care what this is, however SSP code requires it to be set - 'entityid' => 'localhost' + 'entityid' => 'localhost', ]; $spMetadata = [ 'entityid' => $serviceUrl, diff --git a/src/Cas/Ticket/SQLTicketStore.php b/src/Cas/Ticket/SQLTicketStore.php index 97736fa..5ab0d84 100644 --- a/src/Cas/Ticket/SQLTicketStore.php +++ b/src/Cas/Ticket/SQLTicketStore.php @@ -185,8 +185,8 @@ private function setTableVersion(string $name, int $version): void ['_name'], [ '_name' => $name, - '_version' => $version - ] + '_version' => $version, + ], ); $this->tableVersions[$name] = $version; } diff --git a/src/Cas/Ticket/TicketFactory.php b/src/Cas/Ticket/TicketFactory.php index 994663d..4a1f4f2 100644 --- a/src/Cas/Ticket/TicketFactory.php +++ b/src/Cas/Ticket/TicketFactory.php @@ -62,7 +62,7 @@ public function createSessionTicket(string $sessionId, int $expiresAt): array return [ 'id' => $sessionId, 'validBefore' => $expiresAt, - 'renewId' => $randomUtils->generateID() + 'renewId' => $randomUtils->generateID(), ]; } diff --git a/tests/config/module_casserver.php b/tests/config/module_casserver.php index ee48627..faa6199 100644 --- a/tests/config/module_casserver.php +++ b/tests/config/module_casserver.php @@ -15,12 +15,12 @@ 'scopes' => [ 'mobile' => [ 'https://idp1.domain:1234/saml2/idp/metadata.php', - 'https://idp2.domain:5678/saml2/idp/metadata.php' + 'https://idp2.domain:5678/saml2/idp/metadata.php', ], 'desktop' => [ 'https://idp3.domain:1234/saml2/idp/metadata.php', - 'https://idp4.domain:5678/saml2/idp/metadata.php' - ] + 'https://idp4.domain:5678/saml2/idp/metadata.php', + ], ], 'legal_service_urls' => [ @@ -33,7 +33,7 @@ ], 'http://changeTicketParam' => [ 'ticketName' => 'myTicket', - ] + ], ], 'legal_target_service_urls' => [ diff --git a/tests/public/LoginIntegrationTest.php b/tests/public/LoginIntegrationTest.php index fc02253..f9eb41a 100644 --- a/tests/public/LoginIntegrationTest.php +++ b/tests/public/LoginIntegrationTest.php @@ -83,7 +83,7 @@ protected function setup(): void 'module.enable' => [ 'casserver' => true, - ] + ], ]); } @@ -124,8 +124,8 @@ public function testNoQueryParameters(): void [ CURLOPT_COOKIEJAR => $this->cookies_file, CURLOPT_COOKIEFILE => $this->cookies_file, - CURLOPT_FOLLOWLOCATION => true - ] + CURLOPT_FOLLOWLOCATION => true, + ], ); $this->assertEquals(200, $resp['code']); @@ -148,15 +148,15 @@ public function testWrongServiceUrl(): void [ CURLOPT_COOKIEJAR => $this->cookies_file, CURLOPT_COOKIEFILE => $this->cookies_file, - CURLOPT_FOLLOWLOCATION => true - ] + CURLOPT_FOLLOWLOCATION => true, + ], ); $this->assertEquals(500, $resp['code']); $this->assertStringContainsString( 'CAS server is not listed as a legal service', $resp['body'], - 'Illegal cas service urls should be rejected' + 'Illegal cas service urls should be rejected', ); } @@ -178,15 +178,15 @@ public function testValidServiceUrl(string $serviceParam, string $ticketParam): [$serviceParam => $service_url], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $this->assertEquals(303, $resp['code']); $this->assertStringStartsWith( $service_url . '?' . $ticketParam . '=ST-', $resp['headers']['Location'], - 'Ticket should be part of the redirect.' + 'Ticket should be part of the redirect.', ); // Config ticket can be validated @@ -198,11 +198,11 @@ public function testValidServiceUrl(string $serviceParam, string $ticketParam): [ $serviceParam => $service_url, 'ticket' => $ticket, - ], + ], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $expectedResponse = DOMDocumentFactory::fromFile( @@ -217,7 +217,7 @@ public function validServiceUrlProvider(): array { return [ ['service', 'ticket'], - ['TARGET', 'SAMLart'] + ['TARGET', 'SAMLart'], ]; } @@ -235,15 +235,15 @@ public function testValidTicketNameOverride(): void ['TARGET' => $service_url], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $this->assertEquals(303, $resp['code']); $this->assertStringStartsWith( $service_url . '?myTicket=ST-', $resp['headers']['Location'], - 'Ticket should be part of the redirect.' + 'Ticket should be part of the redirect.', ); } @@ -260,15 +260,15 @@ public function testDebugOutput(): void ['service' => $service_url, 'debugMode' => 'true'], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $this->assertEquals(200, $resp['code']); $this->assertStringContainsString( '<cas:eduPersonPrincipalName>testuser@example.com</cas:eduPersonPrincipalName>', $resp['body'], - 'Attributes should have been printed.' + 'Attributes should have been printed.', ); } @@ -285,8 +285,8 @@ public function testDebugOutputSamlValidate(): void ['service' => $service_url, 'debugMode' => 'samlValidate'], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $this->assertEquals(200, $resp['code']); @@ -294,7 +294,7 @@ public function testDebugOutputSamlValidate(): void $this->assertStringContainsString( 'testuser@example.com</NameIdentifier', $resp['body'], - 'Attributes should have been printed.' + 'Attributes should have been printed.', ); } @@ -311,19 +311,19 @@ public function testAlternateServiceConfigUsed(): void ['service' => $service_url, 'debugMode' => 'true'], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $this->assertEquals(200, $resp['code']); $this->assertStringContainsString( '<cas:user>testuser</cas:user>', $resp['body'], - 'cas:user attribute should have been overridden' + 'cas:user attribute should have been overridden', ); $this->assertStringContainsString( '<cas:cn>Test User</cas:cn>', $resp['body'], - 'Attributes should have been printed with alternate attribute release' + 'Attributes should have been printed with alternate attribute release', ); } @@ -344,8 +344,8 @@ public function testValidServiceUrlWithPost(): void ], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); // POST responds with a form that is uses JavaScript to submit @@ -372,12 +372,12 @@ public function testValidServiceUrlWithPost(): void } $this->assertEquals( 'ticket', - $item->getAttribute('name') + $item->getAttribute('name'), ); $this->assertStringStartsWith( 'ST-', $item->getAttribute('value'), - '' + '', ); } @@ -394,15 +394,15 @@ public function testSamlValidate(): void ['service' => $service_url], [ CURLOPT_COOKIEJAR => $this->cookies_file, - CURLOPT_COOKIEFILE => $this->cookies_file - ] + CURLOPT_COOKIEFILE => $this->cookies_file, + ], ); $this->assertEquals(303, $resp['code']); $this->assertStringStartsWith( $service_url . '?ticket=ST-', $resp['headers']['Location'], - 'Ticket should be part of the redirect.' + 'Ticket should be part of the redirect.', ); $location = $resp['headers']['Location']; @@ -425,7 +425,7 @@ public function testSamlValidate(): void $soapRequest, [ 'TARGET' => $service_url, - ] + ], ); $this->assertEquals(200, $resp['code']); @@ -445,8 +445,8 @@ private function authenticate(): void [ CURLOPT_COOKIEJAR => $this->cookies_file, CURLOPT_COOKIEFILE => $this->cookies_file, - CURLOPT_FOLLOWLOCATION => true - ] + CURLOPT_FOLLOWLOCATION => true, + ], ); $this->assertEquals(200, $resp['code'], $resp['body']); } diff --git a/tests/src/AttributeExtractorTest.php b/tests/src/AttributeExtractorTest.php index 2cfef43..0ae8d65 100644 --- a/tests/src/AttributeExtractorTest.php +++ b/tests/src/AttributeExtractorTest.php @@ -21,12 +21,12 @@ public function testNoCasConfig(): void $attributes = [ 'eduPersonPrincipalName' => ['testuser@example.com'], - 'additionalAttribute' => ['Taco Club'] + 'additionalAttribute' => ['Taco Club'], ]; $attributeExtractor = new AttributeExtractor(); $result = $attributeExtractor->extractUserAndAttributes( $attributes, - Configuration::loadFromArray($casConfig) + Configuration::loadFromArray($casConfig), ); $this->assertEquals('testuser@example.com', $result['user']); @@ -40,17 +40,17 @@ public function testNoCasConfig(): void public function testNoAttributeCopying(): void { $casConfig = [ - 'attributes' => false + 'attributes' => false, ]; $attributes = [ 'eduPersonPrincipalName' => ['testuser@example.com'], - 'additionalAttribute' => ['Taco Club'] + 'additionalAttribute' => ['Taco Club'], ]; $attributeExtractor = new AttributeExtractor(); $result = $attributeExtractor->extractUserAndAttributes( $attributes, - Configuration::loadFromArray($casConfig) + Configuration::loadFromArray($casConfig), ); $this->assertEquals('testuser@example.com', $result['user']); @@ -67,18 +67,18 @@ public function testCustomAttributeCopy(): void 'attrname' => 'userNameAttribute', 'attributes_to_transfer' => [ 'exampleAttribute', - 'additionalAttribute' - ] + 'additionalAttribute', + ], ]; $attributes = [ 'userNameAttribute' => ['testuser@example.com'], - 'additionalAttribute' => ['Taco Club'] + 'additionalAttribute' => ['Taco Club'], ]; $attributeExtractor = new AttributeExtractor(); $result = $attributeExtractor->extractUserAndAttributes( $attributes, - Configuration::loadFromArray($casConfig) + Configuration::loadFromArray($casConfig), ); $this->assertEquals('testuser@example.com', $result['user']); @@ -103,7 +103,7 @@ public function testEmptyAuthproc(): void $attributeExtractor = new AttributeExtractor(); $result = $attributeExtractor->extractUserAndAttributes( $attributes, - Configuration::loadFromArray($casConfig) + Configuration::loadFromArray($casConfig), ); $this->assertEquals('testuser@example.com', $result['user']); @@ -124,30 +124,30 @@ public function testAuthprocConfig(): void [ 'class' => 'core:AttributeMap', 'oid2name', - 'urn:example' => 'additionalAttribute' - ] + 'urn:example' => 'additionalAttribute', + ], ], 'attributes_to_transfer' => [ 'not-affected-by-authproc', - 'additionalAttribute' - ] + 'additionalAttribute', + ], ]; $attributes = [ 'urn:oid:1.3.6.1.4.1.5923.1.1.1.6' => ['testuser@example.com'], 'urn:example' => ['Taco Club'], - 'not-affected-by-authproc' => ['Value'] + 'not-affected-by-authproc' => ['Value'], ]; $attributeExtractor = new AttributeExtractor(); // The authproc filters will remap the attributes prior to mapping them to CAS attributes $result = $attributeExtractor->extractUserAndAttributes( $attributes, - Configuration::loadFromArray($casConfig) + Configuration::loadFromArray($casConfig), ); $expectedAttributes = [ 'additionalAttribute' => ['Taco Club'], - 'not-affected-by-authproc' => ['Value'] + 'not-affected-by-authproc' => ['Value'], ]; $this->assertEquals('testuser@example.com', $result['user']); $this->assertEquals($expectedAttributes, $result['attributes']); diff --git a/tests/src/Cas/Protocol/Cas20Test.php b/tests/src/Cas/Protocol/Cas20Test.php index 07135bd..2c12205 100644 --- a/tests/src/Cas/Protocol/Cas20Test.php +++ b/tests/src/Cas/Protocol/Cas20Test.php @@ -45,7 +45,7 @@ public function testAttributeToXmlConversion(): void 'urn:oid:0.9.2342.19200300.100.1.1' => ['someValue'], 'urn:oid:1.3.6.1.4.1.34199.1.7.1.5.2' => [ 'CN=Some-Service,OU=Non-Privileged,OU=Groups,DC=example,DC=com', - 'CN=Other Servics,OU=Non-Privileged,OU=Groups,DC=example,DC=com' + 'CN=Other Servics,OU=Non-Privileged,OU=Groups,DC=example,DC=com', ], ]; diff --git a/tests/src/Cas/Protocol/SamlValidateTest.php b/tests/src/Cas/Protocol/SamlValidateTest.php index d9ce298..5fed386 100644 --- a/tests/src/Cas/Protocol/SamlValidateTest.php +++ b/tests/src/Cas/Protocol/SamlValidateTest.php @@ -20,7 +20,7 @@ public function testSamlValidatXmlGeneration(): void $ticket = [ 'userName' => 'saisusr', 'attributes' => [ - 'UDC_IDENTIFIER' => [$udcValue] + 'UDC_IDENTIFIER' => [$udcValue], ], 'service' => $serviceUrl, ]; diff --git a/tests/src/ServiceValidatorTest.php b/tests/src/ServiceValidatorTest.php index 5e52504..18829b6 100644 --- a/tests/src/ServiceValidatorTest.php +++ b/tests/src/ServiceValidatorTest.php @@ -33,7 +33,7 @@ public function testOverridingServiceConfig(string $service, array $expectedConf [ 'class' => 'core:AttributeMap', 'oid2name', - 'urn:example' => 'example' + 'urn:example' => 'example', ], ], 'legal_service_urls' => [ @@ -49,11 +49,11 @@ public function testOverridingServiceConfig(string $service, array $expectedConf [ 'class' => 'core:AttributeMap', 'oid2custom', - 'urn:example' => 'example' + 'urn:example' => 'example', ], ], ], - ] + ], ]; $serviceValidator = new ServiceValidator(Configuration::loadFromArray($casConfig)); @@ -80,9 +80,9 @@ public function overridingDataProvider(): array [ 'class' => 'core:AttributeMap', 'oid2name', - 'urn:example' => 'example' + 'urn:example' => 'example', ], - ] + ], ]; return [ [ @@ -90,18 +90,18 @@ public function overridingDataProvider(): array [ 'casService' => [ 'matchingUrl' => 'https://myservice.com', - 'serviceUrl' => 'https://myservice.com/abcd' - ] - ] + $defaultConfig + 'serviceUrl' => 'https://myservice.com/abcd', + ], + ] + $defaultConfig, ], [ 'https://default.subdomain.com/abcd', [ 'casService' => [ 'matchingUrl' => '|^https://.*\.subdomain.com/|', - 'serviceUrl' => 'https://default.subdomain.com/abcd' - ] - ] + $defaultConfig + 'serviceUrl' => 'https://default.subdomain.com/abcd', + ], + ] + $defaultConfig, ], [ 'http://override.config.com/xyz', @@ -109,9 +109,9 @@ public function overridingDataProvider(): array 'attrname' => 'alternateAttribute', 'casService' => [ 'matchingUrl' => 'http://override.config.com/', - 'serviceUrl' => 'http://override.config.com/xyz' - ] - ] + $defaultConfig + 'serviceUrl' => 'http://override.config.com/xyz', + ], + ] + $defaultConfig, ], [ 'https://override.more.com/avd/qrx', @@ -121,14 +121,14 @@ public function overridingDataProvider(): array [ 'class' => 'core:AttributeMap', 'oid2custom', - 'urn:example' => 'example' + 'urn:example' => 'example', ], ], 'casService' => [ 'matchingUrl' => '@^https://override.more.com/avd@', - 'serviceUrl' => 'https://override.more.com/avd/qrx' - ] - ] + $defaultConfig + 'serviceUrl' => 'https://override.more.com/avd/qrx', + ], + ] + $defaultConfig, ], ]; } @@ -157,7 +157,7 @@ public function testCheckServiceURL(string $service, bool $allowed): void // Invalid settings don't blow up '|invalid-regex', '', - ] + ], ]; $serviceValidator = new ServiceValidator(Configuration::loadFromArray($casConfig)); $config = $serviceValidator->checkServiceURL(urldecode($service)); diff --git a/tests/src/Ticket/DelegatingTicketStoreTest.php b/tests/src/Ticket/DelegatingTicketStoreTest.php index db6f7b9..5af1748 100644 --- a/tests/src/Ticket/DelegatingTicketStoreTest.php +++ b/tests/src/Ticket/DelegatingTicketStoreTest.php @@ -4,6 +4,7 @@ namespace SimpleSAML\Casserver\Ticket; +use Exception; use PHPUnit\Framework\TestCase; use SimpleSAML\Configuration; use SimpleSAML\Logger; @@ -51,7 +52,7 @@ public function setup(): void 'module.enable' => [ 'casserver' => true, - 'exampleauth' => true + 'exampleauth' => true, ], 'debug' => true, @@ -71,7 +72,7 @@ public function setup(): void 'directory' => dirname(__DIR__, 2) . '/ticketcacheAlt', ], 'error' => [ - 'class' => ErroringTicketStore::class + 'class' => ErroringTicketStore::class, ], 'name2' => [ 'class' => 'casserver:FileSystemTicketStore', @@ -81,7 +82,7 @@ public function setup(): void 'class' => 'casserver:FileSystemTicketStore', 'directory' => 'does-not-exist', ], - ] + ], ]; $this->fileStore1 = new FileSystemTicketStore( @@ -180,22 +181,22 @@ public function testDelegateErrorsIfNoSuccess(): void 'delegateTo' => 'all', 'ticketStores' => [ 'error' => [ - 'class' => ErroringTicketStore::class - ] - ] + 'class' => ErroringTicketStore::class, + ], + ], ]; $ticketStore = new DelegatingTicketStore(Configuration::loadFromArray(['ticketstore' => $config])); try { $ticketStore->getTicket('abc'); $this->fail('Exceptione expected'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertEquals('Sample get error', $e->getMessage()); } try { $ticketStore->addTicket(['a' => 'b']); $this->fail('Exceptione expected'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertEquals('Sample add error', $e->getMessage()); } } diff --git a/tests/src/TicketValidatorTest.php b/tests/src/TicketValidatorTest.php index 05f44b2..320ac36 100644 --- a/tests/src/TicketValidatorTest.php +++ b/tests/src/TicketValidatorTest.php @@ -153,7 +153,7 @@ public function urlSanitizationProvider(): array [ 'https://k.edu/kc/portal.do;jsessionid=99AC064A127?ct=Search&cu=https://k.edu/kc/as.do?ssf=456*&rsol=1', 'https://k.edu/kc/portal.do?ct=Search&cu=https://k.edu/kc/as.do?ssf=456*&rsol=1', - ] + ], ]; } @@ -177,7 +177,7 @@ private function createTicket(string $serviceUrl, int $expiration = 0): array 'userName' => 'bob', 'attributes' => [], 'proxies' => [], - 'sessionId' => 'sesId' + 'sessionId' => 'sesId', ]; $this->ticketStore->addTicket($serviceTicket); return $serviceTicket;