diff --git a/appinfo/routes.php b/appinfo/routes.php index 3cb584c..ae6a88a 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -80,6 +80,9 @@ return [ 'verb' => 'GET', 'defaults' => [ 'providerId' => 1 + ], + 'requirements' => [ + 'providerId' => '\d+' ] ], [ @@ -88,6 +91,9 @@ return [ 'verb' => 'POST', 'defaults' => [ 'providerId' => 1 + ], + 'requirements' => [ + 'providerId' => '\d+' ] ], [ @@ -100,7 +106,10 @@ return [ 'url' => '/settings/providerSettings/{providerId}', 'verb' => 'DELETE', 'defaults' => [ - 'providerId' => '1' + 'providerId' => 1 + ], + 'requirements' => [ + 'providerId' => '\d+' ] ], [ diff --git a/lib/Command/ConfigSet.php b/lib/Command/ConfigSet.php index 8bc4af8..8f55f8b 100644 --- a/lib/Command/ConfigSet.php +++ b/lib/Command/ConfigSet.php @@ -68,7 +68,7 @@ class ConfigSet extends Base { $settings = $this->samlSettings->get($pId); foreach ($input->getOptions() as $key => $value) { - if(!in_array($key, SAMLSettings::IDP_CONFIG_KEYS) || $value === null) { + if (!in_array($key, SAMLSettings::IDP_CONFIG_KEYS) || $value === null) { continue; } if ($value === '') { diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 20e71b3..c35fb35 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -96,7 +96,7 @@ class SettingsController extends Controller { $key = $category . '-' . $setting; } - if (isset ($details['global']) && $details['global']) { + if (isset($details['global']) && $details['global']) { $settings[$category][$setting] = $this->config->getAppValue('user_saml', $key, ''); } else { $settings[$category][$setting] = $storedSettings[$key] ?? ''; diff --git a/lib/Db/ConfigurationsMapper.php b/lib/Db/ConfigurationsMapper.php index c1a6bee..709e736 100644 --- a/lib/Db/ConfigurationsMapper.php +++ b/lib/Db/ConfigurationsMapper.php @@ -45,7 +45,8 @@ class ConfigurationsMapper extends QBMapper { public function deleteById(int $id): void { $entity = new ConfigurationsEntity(); - $entity->setId($id);; + $entity->setId($id); + ; $this->delete($entity); } @@ -98,5 +99,4 @@ class ConfigurationsMapper extends QBMapper { $newEntity->importConfiguration([]); return $this->insert($newEntity)->getId(); } - } diff --git a/lib/Migration/Version5000Date20211025124248.php b/lib/Migration/Version5000Date20211025124248.php index 887e965..336c92b 100644 --- a/lib/Migration/Version5000Date20211025124248.php +++ b/lib/Migration/Version5000Date20211025124248.php @@ -16,7 +16,6 @@ use OCP\Migration\SimpleMigrationStep; * Auto-generated migration step: Please modify to your needs! */ class Version5000Date20211025124248 extends SimpleMigrationStep { - private const IDP_CONFIG_KEYS = [ 'general-idp0_display_name', 'general-uid_mapping', @@ -187,7 +186,7 @@ class Version5000Date20211025124248 extends SimpleMigrationStep { $isPrefixed = \preg_match('/^[0-9]*-/', $prefixedKey, $matches); if ($isPrefixed === 0) { return $prefixedKey; - } else if ($isPrefixed === 1) { + } elseif ($isPrefixed === 1) { return \substr($prefixedKey, strlen($matches[0])); } throw new \RuntimeException('Invalid regex pattern'); diff --git a/lib/SAMLSettings.php b/lib/SAMLSettings.php index 4c27c90..7a63586 100644 --- a/lib/SAMLSettings.php +++ b/lib/SAMLSettings.php @@ -241,7 +241,7 @@ class SAMLSettings { return; } - if ($idp !== -1) { + if ($idp !== -1) { $this->configurations[$idp] = $this->mapper->get($idp); } else { $configs = $this->mapper->getAll(); diff --git a/lib/UserBackend.php b/lib/UserBackend.php index 2461a70..5b0c6f8 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -107,8 +107,8 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @param string $uid * @param array $attributes */ - public function createUserIfNotExists($uid, array $attributes = array()) { - if(!$this->userExistsInDatabase($uid)) { + public function createUserIfNotExists($uid, array $attributes = []) { + if (!$this->userExistsInDatabase($uid)) { $values = [ 'uid' => $uid, ]; @@ -123,12 +123,12 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { if ($home !== '') { //if attribute's value is an absolute path take this, otherwise append it to data dir //check for / at the beginning or pattern c:\ resp. c:/ - if( '/' !== $home[0] + if ('/' !== $home[0] && !(3 < strlen($home) && ctype_alpha($home[0]) && $home[1] === ':' && ('\\' === $home[2] || '/' === $home[2])) ) { $home = $this->config->getSystemValue('datadirectory', - \OC::$SERVERROOT.'/data' ) . '/' . $home; + \OC::$SERVERROOT.'/data') . '/' . $home; } $values['home'] = $home; @@ -137,13 +137,12 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->insert('user_saml_users'); - foreach($values as $column => $value) { + foreach ($values as $column => $value) { $qb->setValue($column, $qb->createNamedParameter($value)); } $qb->execute(); $this->initializeHomeDir($uid); - } } @@ -203,8 +202,8 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { $data = $result->fetchAll(); $result->closeCursor(); - foreach($data as $passwords) { - if(password_verify($password, $passwords['token'])) { + foreach ($data as $passwords) { + if (password_verify($password, $passwords['token'])) { return $uid; } } @@ -219,7 +218,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function deleteUser($uid) { - if($this->userExistsInDatabase($uid)) { + if ($this->userExistsInDatabase($uid)) { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->delete('user_saml_users') @@ -237,7 +236,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @return string */ public function getHome($uid) { - if($this->userExistsInDatabase($uid)) { + if ($this->userExistsInDatabase($uid)) { $qb = $this->db->getQueryBuilder(); $qb->select('home') ->from('user_saml_users') @@ -277,7 +276,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function userExists($uid) { - if($backend = $this->getActualUserBackend($uid)) { + if ($backend = $this->getActualUserBackend($uid)) { return $backend->userExists($uid); } else { return $this->userExistsInDatabase($uid); @@ -285,7 +284,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { } public function setDisplayName($uid, $displayName) { - if($backend = $this->getActualUserBackend($uid)) { + if ($backend = $this->getActualUserBackend($uid)) { return $backend->setDisplayName($uid, $displayName); } @@ -309,10 +308,10 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function getDisplayName($uid) { - if($backend = $this->getActualUserBackend($uid)) { + if ($backend = $this->getActualUserBackend($uid)) { return $backend->getDisplayName($uid); } else { - if($this->userExistsInDatabase($uid)) { + if ($this->userExistsInDatabase($uid)) { $qb = $this->db->getQueryBuilder(); $qb->select('displayname') ->from('user_saml_users') @@ -374,7 +373,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @since 4.5.0 */ public function hasUserListings() { - if($this->autoprovisionAllowed()) { + if ($this->autoprovisionAllowed()) { return true; } @@ -487,14 +486,14 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { public function getCurrentUserId() { $user = \OC::$server->getUserSession()->getUser(); - if($user instanceof IUser && $this->session->get('user_saml.samlUserData')) { + if ($user instanceof IUser && $this->session->get('user_saml.samlUserData')) { $uid = $user->getUID(); } else { $this->userData->setAttributes($this->session->get('user_saml.samlUserData') ?? []); $uid = $this->userData->getEffectiveUid(); } - if($uid !== '' && $this->userExists($uid)) { + if ($uid !== '' && $this->userExists($uid)) { $this->session->set('last-password-confirm', strtotime('+4 year', time())); return $uid; } @@ -527,8 +526,8 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { * @return null|UserInterface */ public function getActualUserBackend($uid) { - foreach(self::$backends as $backend) { - if($backend->userExists($uid)) { + foreach (self::$backends as $backend) { + if ($backend->userExists($uid)) { return $backend; } } @@ -549,8 +548,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { /** * @throws \OCP\DB\Exception */ - private function getAttributeKeys($name) - { + private function getAttributeKeys($name) { $settings = $this->settings->get($this->settings->getProviderId()); $keys = explode(' ', $settings[$name] ?? $this->config->getAppValue('user_saml', $name, '')); @@ -564,17 +562,17 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { $keys = $this->getAttributeKeys($name); $value = ''; - foreach($keys as $key) { + foreach ($keys as $key) { if (isset($attributes[$key])) { if (is_array($attributes[$key])) { foreach ($attributes[$key] as $attribute_part_value) { - if($value !== '') { + if ($value !== '') { $value .= ' '; } $value .= $attribute_part_value; } } else { - if($value !== '') { + if ($value !== '') { $value .= ' '; } $value .= $attributes[$key]; @@ -588,8 +586,8 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { private function getAttributeArrayValue($name, array $attributes) { $keys = $this->getAttributeKeys($name); - $value = array(); - foreach($keys as $key) { + $value = []; + foreach ($keys as $key) { if (isset($attributes[$key])) { if (is_array($attributes[$key])) { $value = array_merge($value, array_values($attributes[$key])); diff --git a/lib/UserData.php b/lib/UserData.php index e0e0607..b4a360c 100644 --- a/lib/UserData.php +++ b/lib/UserData.php @@ -1,4 +1,5 @@ @@ -66,7 +67,7 @@ class UserData { } public function getEffectiveUid(): string { - if($this->uid !== null) { + if ($this->uid !== null) { return $this->uid; } $this->assertIsInitialized(); @@ -83,7 +84,7 @@ class UserData { protected function extractSamlUserId(): string { $uidMapping = $this->getUidMappingAttribute(); - if($uidMapping !== null && isset($this->attributes[$uidMapping])) { + if ($uidMapping !== null && isset($this->attributes[$uidMapping])) { if (is_array($this->attributes[$uidMapping])) { return trim($this->attributes[$uidMapping][0]); } else { @@ -105,13 +106,13 @@ class UserData { } $candidate = base64_decode($uid, true); - if($candidate === false) { + if ($candidate === false) { return $uid; } $candidate = $this->convertObjectGUID2Str($candidate); // the regex only matches the structure of the UUID, not its semantic // (i.e. version or variant) simply to be future compatible - if(preg_match('/^[a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8}$/i', $candidate) === 1) { + if (preg_match('/^[a-f0-9]{8}(-[a-f0-9]{4}){4}[a-f0-9]{8}$/i', $candidate) === 1) { $uid = $candidate; } return $uid; @@ -123,15 +124,15 @@ class UserData { protected function convertObjectGUID2Str($oguid): string { $hex_guid = bin2hex($oguid); $hex_guid_to_guid_str = ''; - for($k = 1; $k <= 4; ++$k) { + for ($k = 1; $k <= 4; ++$k) { $hex_guid_to_guid_str .= substr($hex_guid, 8 - 2 * $k, 2); } $hex_guid_to_guid_str .= '-'; - for($k = 1; $k <= 2; ++$k) { + for ($k = 1; $k <= 2; ++$k) { $hex_guid_to_guid_str .= substr($hex_guid, 12 - 2 * $k, 2); } $hex_guid_to_guid_str .= '-'; - for($k = 1; $k <= 2; ++$k) { + for ($k = 1; $k <= 2; ++$k) { $hex_guid_to_guid_str .= substr($hex_guid, 16 - 2 * $k, 2); } $hex_guid_to_guid_str .= '-' . substr($hex_guid, 16, 4); @@ -141,7 +142,7 @@ class UserData { } protected function assertIsInitialized() { - if($this->attributes === null) { + if ($this->attributes === null) { throw new \LogicException('UserData have to be initialized with setAttributes first'); } } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 1d3ebf5..ec82d0c 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -94,7 +94,6 @@ class FeatureContext implements Context { */ public function theSettingIsSetTo($settingName, $value) { - if (in_array($settingName, [ 'type', 'general-require_provisioned_account', diff --git a/tests/unit/Command/GetMetadataTest.php b/tests/unit/Command/GetMetadataTest.php index bb0e9f5..3e76a0d 100644 --- a/tests/unit/Command/GetMetadataTest.php +++ b/tests/unit/Command/GetMetadataTest.php @@ -29,18 +29,18 @@ use Symfony\Component\Console\Output\OutputInterface; class GetMetadataTest extends \Test\TestCase { - /** @var GetMetadata|MockObject*/ - protected $GetMetadata; - /** @var SAMLSettings|MockObject*/ - private $samlSettings; + /** @var GetMetadata|MockObject*/ + protected $GetMetadata; + /** @var SAMLSettings|MockObject*/ + private $samlSettings; - protected function setUp(): void { - $this->samlSettings = $this->createMock(SAMLSettings::class); - $this->GetMetadata = new GetMetadata($this->samlSettings); + protected function setUp(): void { + $this->samlSettings = $this->createMock(SAMLSettings::class); + $this->GetMetadata = new GetMetadata($this->samlSettings); - parent::setUp(); - } - public function testGetMetadata(){ + parent::setUp(); + } + public function testGetMetadata() { $inputInterface = $this->createMock(InputInterface::class); $outputInterface = $this->createMock(OutputInterface::class); @@ -66,5 +66,4 @@ class GetMetadataTest extends \Test\TestCase { $this->invokePrivate($this->GetMetadata, 'execute', [$inputInterface, $outputInterface]); } - } diff --git a/tests/unit/Settings/AdminTest.php b/tests/unit/Settings/AdminTest.php index 6162455..c36cb6b 100644 --- a/tests/unit/Settings/AdminTest.php +++ b/tests/unit/Settings/AdminTest.php @@ -30,7 +30,7 @@ use OCP\IL10N; use OneLogin\Saml2\Constants; use PHPUnit\Framework\MockObject\MockObject; -class AdminTest extends \Test\TestCase { +class AdminTest extends \Test\TestCase { /** @var SAMLSettings|MockObject */ private $settings; /** @var Admin */ @@ -62,7 +62,7 @@ class AdminTest extends \Test\TestCase { $this->l10n ->expects($this->any()) ->method('t') - ->will($this->returnCallback(function($text, $parameters = array()) { + ->will($this->returnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); }));