Example #1
0
 public static function createConfig(IOInterface $io = null, $cwd = null)
 {
     $cwd = $cwd ?: getcwd();
     $home = self::getHomeDir();
     $cacheDir = self::getCacheDir($home);
     foreach (array($home, $cacheDir) as $dir) {
         if (!file_exists($dir . '/.htaccess')) {
             if (!is_dir($dir)) {
                 @mkdir($dir, 0777, true);
             }
             @file_put_contents($dir . '/.htaccess', 'Deny from all');
         }
     }
     $config = new Config(true, $cwd);
     $config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir)));
     $file = new JsonFile($config->get('home') . '/config.json');
     if ($file->exists()) {
         if ($io && $io->isDebug()) {
             $io->writeError('Loading config file ' . $file->getPath());
         }
         $config->merge($file->read());
     }
     $config->setConfigSource(new JsonConfigSource($file));
     $file = new JsonFile($config->get('home') . '/auth.json');
     if ($file->exists()) {
         if ($io && $io->isDebug()) {
             $io->writeError('Loading config file ' . $file->getPath());
         }
         $config->merge(array('config' => $file->read()));
     }
     $config->setAuthConfigSource(new JsonConfigSource($file, true));
     return $config;
 }
Example #2
0
 /**
  * @dataProvider getAssetTypes
  */
 public function testRedirectUrlWithNonexistentRepository($type, $filename)
 {
     $this->setExpectedException('RuntimeException');
     $repoUrl = 'http://github.com/composer-test/repo-name';
     $repoApiUrl = 'https://api.github.com/repos/composer-test/repo-name';
     $identifier = 'v0.0.0';
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $io->expects($this->any())->method('isInteractive')->will($this->returnValue(true));
     $remoteFilesystem = $this->getMockBuilder('Composer\\Util\\RemoteFilesystem')->setConstructorArgs(array($io))->getMock();
     $remoteFilesystem->expects($this->at(0))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     $io->expects($this->once())->method('ask')->with($this->equalTo('Username: '******'someuser'));
     $io->expects($this->once())->method('askAndHideAnswer')->with($this->equalTo('Password: '******'somepassword'));
     $io->expects($this->any())->method('setAuthentication')->with($this->equalTo('github.com'), $this->matchesRegularExpression('{someuser|abcdef}'), $this->matchesRegularExpression('{somepassword|x-oauth-basic}'));
     $remoteFilesystem->expects($this->at(1))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo('https://github.com/composer-test/repo-name'), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     $remoteFilesystem->expects($this->at(2))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     $remoteFilesystem->expects($this->at(3))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/authorizations'), $this->equalTo(false))->will($this->returnValue('[]'));
     $remoteFilesystem->expects($this->at(4))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo('https://api.github.com/authorizations'), $this->equalTo(false))->will($this->returnValue('{"token": "abcdef"}'));
     $remoteFilesystem->expects($this->at(5))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     $remoteFilesystem->expects($this->at(6))->method('getContents')->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl . '/contents/' . $filename . '?ref=' . $identifier), $this->equalTo(false))->will($this->throwException(new TransportException('HTTP/1.1 404 Not Found', 404)));
     $configSource = $this->getMock('Composer\\Config\\ConfigSourceInterface');
     $authConfigSource = $this->getMock('Composer\\Config\\ConfigSourceInterface');
     /* @var ConfigSourceInterface $configSource */
     /* @var ConfigSourceInterface $authConfigSource */
     $this->config->setConfigSource($configSource);
     $this->config->setAuthConfigSource($authConfigSource);
     $repoConfig = array('url' => $repoUrl, 'asset-type' => $type, 'filename' => $filename);
     /* @var IOInterface $io */
     /* @var RemoteFilesystem $remoteFilesystem */
     $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, null, $remoteFilesystem);
     $firstNonexistent = false;
     try {
         $gitHubDriver->initialize();
     } catch (TransportException $e) {
         $firstNonexistent = true;
     }
     $this->assertTrue($firstNonexistent);
     $gitHubDriver->getComposerInformation($identifier);
 }
Example #3
0
 /**
  * @return Config
  */
 private function getConfiguration()
 {
     $config = new Config();
     // add dir to the config
     $config->merge(array('config' => array('home' => $this->getComposerHome())));
     // load global auth file
     $file = new JsonFile($config->get('home') . '/auth.json');
     if ($file->exists()) {
         $config->merge(array('config' => $file->read()));
     }
     $config->setAuthConfigSource(new JsonConfigSource($file, true));
     return $config;
 }
Example #4
0
 /**
  * @param  IOInterface|null $io
  * @return Config
  */
 public static function createConfig(IOInterface $io = null, $cwd = null)
 {
     $cwd = $cwd ?: getcwd();
     $config = new Config(true, $cwd);
     // determine and add main dirs to the config
     $home = self::getHomeDir();
     $config->merge(array('config' => array('home' => $home, 'cache-dir' => self::getCacheDir($home), 'data-dir' => self::getDataDir($home))));
     // Protect directory against web access. Since HOME could be
     // the www-data's user home and be web-accessible it is a
     // potential security risk
     $dirs = array($config->get('home'), $config->get('cache-dir'), $config->get('data-dir'));
     foreach ($dirs as $dir) {
         if (!file_exists($dir . '/.htaccess')) {
             if (!is_dir($dir)) {
                 Silencer::call('mkdir', $dir, 0777, true);
             }
             Silencer::call('file_put_contents', $dir . '/.htaccess', 'Deny from all');
         }
     }
     // load global config
     $file = new JsonFile($config->get('home') . '/config.json');
     if ($file->exists()) {
         if ($io && $io->isDebug()) {
             $io->writeError('Loading config file ' . $file->getPath());
         }
         $config->merge($file->read());
     }
     $config->setConfigSource(new JsonConfigSource($file));
     // load global auth file
     $file = new JsonFile($config->get('home') . '/auth.json');
     if ($file->exists()) {
         if ($io && $io->isDebug()) {
             $io->writeError('Loading config file ' . $file->getPath());
         }
         $config->merge(array('config' => $file->read()));
     }
     $config->setAuthConfigSource(new JsonConfigSource($file, true));
     // load COMPOSER_AUTH environment variable if set
     if ($composerAuthEnv = getenv('COMPOSER_AUTH')) {
         $authData = json_decode($composerAuthEnv, true);
         if (is_null($authData)) {
             throw new \UnexpectedValueException('COMPOSER_AUTH environment variable is malformed, should be a valid JSON object');
         }
         if ($io && $io->isDebug()) {
             $io->writeError('Loading auth config from COMPOSER_AUTH');
         }
         $config->merge(array('config' => $authData));
     }
     return $config;
 }
Example #5
0
 /**
  * @param IOInterface|null $io
  * @return Config
  */
 public static function createConfig(IOInterface $io = null, $cwd = null)
 {
     $cwd = $cwd ?: getcwd();
     // determine home and cache dirs
     $home = self::getHomeDir();
     $cacheDir = self::getCacheDir($home);
     $dataDir = self::getDataDir($home);
     // Protect directory against web access. Since HOME could be
     // the www-data's user home and be web-accessible it is a
     // potential security risk
     foreach (array($home, $cacheDir, $dataDir) as $dir) {
         if (!file_exists($dir . '/.htaccess')) {
             if (!is_dir($dir)) {
                 @mkdir($dir, 0777, true);
             }
             @file_put_contents($dir . '/.htaccess', 'Deny from all');
         }
     }
     $config = new Config(true, $cwd);
     // add dirs to the config
     $config->merge(array('config' => array('home' => $home, 'cache-dir' => $cacheDir, 'data-dir' => $dataDir)));
     // load global config
     $file = new JsonFile($config->get('home') . '/config.json');
     if ($file->exists()) {
         if ($io && $io->isDebug()) {
             $io->writeError('Loading config file ' . $file->getPath());
         }
         $config->merge($file->read());
     }
     $config->setConfigSource(new JsonConfigSource($file));
     // load global auth file
     $file = new JsonFile($config->get('home') . '/auth.json');
     if ($file->exists()) {
         if ($io && $io->isDebug()) {
             $io->writeError('Loading config file ' . $file->getPath());
         }
         $config->merge(array('config' => $file->read()));
     }
     $config->setAuthConfigSource(new JsonConfigSource($file, true));
     return $config;
 }