/** * Test that adding arguments works. * * @return void */ public function testAddCommandLineArgument() { $config = new TensideJsonConfig(new JsonArray()); $this->assertEquals(null, $config->getPhpCliArguments()); $this->assertSame($config, $config->addCommandLineArgument('test1')); $this->assertEquals(['test1'], $config->getPhpCliArguments()); $this->assertSame($config, $config->addCommandLineArgument('test2')); $this->assertEquals(['test1', 'test2'], $config->getPhpCliArguments()); }
/** * Test that the spawner spawns the process in background. * * @return void */ public function testRunBackground() { $config = new TensideJsonConfig(new JsonArray()); $config->setForceToBackground(true); $process = PhpProcessSpawner::create($config, $this->getTempDir())->spawn(['--version']); $cli = $process->getCommandLine(); if ('\\' === DIRECTORY_SEPARATOR) { $this->assertEquals('start /B ' . escapeshellarg('php') . ' ' . escapeshellarg('--version'), $cli); } else { $this->assertEquals(escapeshellarg('php') . ' ' . escapeshellarg('--version') . ' &', $cli); } }
/** * Test that the spawner really spawns the process correctly. * * @return void */ public function testRun() { $config = new TensideJsonConfig(new JsonArray()); $config->setPhpCliArguments(['-dmemory_limit=1G']); $config->setPhpCliEnvironment(['TESTVAR=TESTVALUE']); $process = PhpProcessSpawner::create($config, $this->getTempDir())->spawn(['-r', 'echo getenv(\'TESTVAR\') . ini_get(\'memory_limit\');']); $process->run(); $cli = $process->getCommandLine(); $this->assertEquals('php \'-dmemory_limit=1G\' ' . '\'-r\' \'echo getenv(\'\\\'\'TESTVAR\'\\\'\') . ini_get(\'\\\'\'memory_limit\'\\\'\');\'', $cli); $this->assertEquals(0, $process->getExitCode()); $this->assertEquals('TESTVALUE1G', $process->getOutput()); $this->assertEquals('', $process->getErrorOutput()); }
/** * Build the internal process builder. * * @param array $arguments The arguments. * * @return ProcessBuilder */ private function buildInternal(array $arguments) { $builder = ProcessBuilder::create($this->config->getPhpCliBinary()); if (null !== ($cliArguments = $this->config->getPhpCliArguments())) { $builder->addArguments($cliArguments); } $builder->addArguments($arguments); if (null !== ($environment = $this->config->getPhpCliEnvironment())) { foreach ($environment as $name => $value) { $builder->setEnv($name, $value); } } // MUST be kept last. $builder->setEnv('COMPOSER', $this->homePath . DIRECTORY_SEPARATOR . 'composer.json'); return $builder; }
/** * Calculate the hash. * * @param string $uri The uri to calculate the hash for. * * @return string */ private function computeHash($uri) { if (!isset($this->secret)) { $this->secret = $this->tensideConfig->getSecret(); } return urlencode(base64_encode(hash_hmac('sha256', $uri, $this->secret, true))); }
/** * Retrieve the command line environment variables to use. * * @return array */ private function getEnvironment() { $variables = $this->getDefinedEnvironmentVariables(); if (null === ($environment = $this->config->getPhpCliEnvironment())) { return $variables; } $variables = array_merge($variables, $environment); return $variables; }
/** * Create a new instance. * * @param TensideJsonConfig $config The configuration. * * @throws \LogicException When no secret has been defined. */ public function __construct(TensideJsonConfig $config) { $this->secret = $config->getSecret(); $this->localId = $config->getLocalDomain(); }
/** * Test that authenticating a token with valid credentials for which no user can be loaded fails. * * @return void * * @expectedException \Symfony\Component\Security\Core\Exception\AuthenticationException * * @expectedExceptionMessage Invalid token - could not derive user from credentials. */ public function testAuthenticateTokenFailsWhenUserCanNotBeLoaded() { $config = new TensideJsonConfig(new JsonFile($this->getTempDir() . DIRECTORY_SEPARATOR . 'tenside.json')); $config->set('secret', 'very-secret-secret'); $auth = new JWTAuthenticator($config); $token = $this->getMockBuilder(TokenInterface::class)->setMethods(['getCredentials'])->getMockForAbstractClass(); $token->method('getCredentials')->willReturn((object) ['username' => 'user']); $userProvider = $this->getMockForAbstractClass(UserProviderInterface::class); $auth->authenticateToken($token, $userProvider, 'provider-key'); }