Esempio n. 1
0
 protected function setUp()
 {
     $this->v1 = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Version::create('1.2.3'));
     $this->v1p = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Version::create('2.0.0-alpha.2'));
     $this->v2 = new Update('test.phar', '0123456789012345678901234567890123456789', 'http://example.com/test.phar', Version::create('4.5.6'));
     $this->manifest = new Manifest(array($this->v1, $this->v1p, $this->v2));
 }
Esempio n. 2
0
 public function testCreate()
 {
     $this->assertInstanceOf('KevinGH\\Version\\Version', $version = Version::create('1.0.0'));
     $this->assertEquals(1, $version->getMajor());
     $this->assertEquals(0, $version->getMinor());
     $this->assertEquals(0, $version->getPatch());
     $this->assertNull($version->getPreRelease());
     $this->assertNull($version->getBuild());
 }
Esempio n. 3
0
 /**
  * Updates the running Phar if any is available.
  *
  * @param string|Version $version  The current version.
  * @param boolean        $major    Lock to current major version?
  * @param boolean        $pre      Allow pre-releases?
  *
  * @return boolean TRUE if an update was performed, FALSE if none available.
  */
 public function update($version, $major = false, $pre = false)
 {
     if (false === $version instanceof Version) {
         $version = Version::create($version);
     }
     if (null !== ($update = $this->manifest->findRecent($version, $major, $pre))) {
         $update->getFile();
         $update->copyTo($this->getRunningFile());
         return true;
     }
     return false;
 }
 /**
  * Updates the running Phar if any is available and checks
  * the fingerprint of the public key.
  *
  * @param string|Version $version The current version.
  * @param bool           $major   Lock to current major version?
  * @param bool           $pre     Allow pre-releases?
  *
  * @return bool TRUE if an update was performed, FALSE if none available.
  */
 public function update($version, $major = false, $pre = false)
 {
     if (false === $version instanceof Version) {
         $version = Version::create($version);
     }
     if (null !== ($update = $this->getManifest()->findRecent($version, $major, $pre))) {
         $tmpfile = $update->getFile();
         if (null !== $this->getPublicKeyHash()) {
             if (false === is_file($tmpfile . '.pubkey')) {
                 echo "ALERT: Update not signed with public key!\n";
                 $update->deleteFile();
                 return false;
             }
             if (hash_file('sha256', $tmpfile . '.pubkey') !== $this->getPublicKeyHash()) {
                 echo "ALERT: Public key fingerprint mismatch!!!\n";
                 $update->deleteFile();
                 return false;
             }
         }
         $update->copyTo($this->getRunningFile());
         return true;
     }
     return false;
 }
Esempio n. 5
0
 public function testUpdateNone()
 {
     $manager = new Manager(new Manifest(array(new Update('new.phar', 'test', 'test', Version::create('2.0.1')))));
     $manager->setRunningFile($this->createFile());
     $this->assertFalse($manager->update('1.0.0', true));
 }
Esempio n. 6
0
 protected function setUp()
 {
     $this->update = new Update('test.phar', '1234567890123456789012345678901234567890', 'http://example.com/test.phar', $this->version = Version::create('1.2.3'), 'http://example.com/test-1.2.3.phar.pubkey');
 }
Esempio n. 7
0
 /**
  * Validates the data, processes it, and returns a new instance of Manifest.
  *
  * @param array $decoded The decoded JSON data.
  * @param Json  $json    The Json instance used to decode the data.
  *
  * @return Manifest The new instance.
  */
 private static function create($decoded, Json $json)
 {
     $json->validate($json->decodeFile(PHAR_UPDATE_MANIFEST_SCHEMA), $decoded);
     $updates = array();
     foreach ($decoded as $update) {
         $updates[] = new Update($update->name, $update->sha1, $update->url, Version::create($update->version), isset($update->publicKey) ? $update->publicKey : null);
     }
     usort($updates, function (Update $a, Update $b) {
         return $a->getVersion()->compareTo($b->getVersion());
     });
     return new static($updates);
 }