/** * Ask user which resources the public key should have access to * * @param InputInterface $input * @param OutputInterface $output * @return array */ private function askForResources(InputInterface $input, OutputInterface $output) { $question = new ChoiceQuestion('Which resources should the public key have access to? ', [self::RESOURCES_READ_ONLY, self::RESOURCES_READ_WRITE, self::RESOURCES_ALL, self::RESOURCES_SPECIFIC, self::RESOURCES_CUSTOM], self::RESOURCES_SPECIFIC); $type = $this->getHelper('question')->ask($input, $output, $question); switch ($type) { case self::RESOURCES_READ_ONLY: return Resource::getReadOnlyResources(); case self::RESOURCES_READ_WRITE: return Resource::getReadWriteResources(); case self::RESOURCES_ALL: return Resource::getAllResources(); case self::RESOURCES_CUSTOM: return $this->askForCustomResources($input, $output); } return $this->askForSpecificResources($input, $output); }
public function testMethodsReturnsArrays() { $this->assertInternalType('array', Resource::getReadOnlyResources()); $this->assertInternalType('array', Resource::getReadWriteResources()); $this->assertInternalType('array', Resource::getAllResources()); }
<?php /** * This file is part of the Imbo package * * (c) Christer Edvartsen <*****@*****.**> * * For the full copyright and license information, please view the LICENSE file that was * distributed with this source code. */ use Imbo\Auth\AccessControl\Adapter\ArrayAdapter, Imbo\Resource; /** * Use individual read-only/read+write keys */ return ['accessControl' => function () { return new ArrayAdapter([['publicKey' => 'ro-pubkey', 'privateKey' => 'read-only-key', 'acl' => [['resources' => Resource::getReadOnlyResources(), 'users' => ['someuser']]]], ['publicKey' => 'rw-pubkey', 'privateKey' => 'read+write-key', 'acl' => [['resources' => Resource::getReadWriteResources(), 'users' => ['someuser']]]], ['publicKey' => 'foo', 'privateKey' => 'bar', 'acl' => [['resources' => Resource::getReadOnlyResources(), 'users' => ['user']]]]]); }];
/** * @covers ImboCli\Command\AddPublicKey::execute * @covers ImboCli\Command\AddPublicKey::askForAnotherAclRule * @covers ImboCli\Command\AddPublicKey::askForResources * @covers ImboCli\Command\AddPublicKey::askForUsers */ public function testContinuesAskingForAclRulesIfUserSaysThereAreMoreRulesToAdd() { $this->adapter->expects($this->exactly(3))->method('addAccessRule')->withConsecutive([$this->equalTo('foo'), $this->callback(function ($rule) { $diff = array_diff($rule['resources'], Resource::getReadOnlyResources()); return count($rule['users']) === 2 && in_array('espenh', $rule['users']) && in_array('kribrabr', $rule['users']) && empty($diff); })], [$this->equalTo('foo'), $this->callback(function ($rule) { $diff = array_diff($rule['resources'], Resource::getReadWriteResources()); return count($rule['users']) === 2 && in_array('rexxars', $rule['users']) && in_array('kbrabrand', $rule['users']) && empty($diff); })], [$this->equalTo('foo'), $this->callback(function ($rule) { $diff = array_diff($rule['resources'], Resource::getAllResources()); return $rule['users'] === '*' && empty($diff); })]); $helper = $this->command->getHelper('question'); $helper->setInputStream($this->getInputStream(['0', 'espenh,kribrabr', 'y', '1', 'rexxars, kbrabrand', 'y', '2', '*', 'n'])); $commandTester = new CommandTester($this->command); $commandTester->execute(['publicKey' => 'foo', 'privateKey' => 'bar']); $this->assertSame(3, substr_count($commandTester->getDisplay(true), 'Create more ACL-rules for this public key?')); }