MarkAHershberger has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/182643

Change subject: update tests to check patches and signatures
......................................................................

update tests to check patches and signatures

Still need to add some tests for i18n patches

Change-Id: I2cbfbed00e98480126a5dce277abf1ce783f5413
---
M make-release/testReleaseTarball.php
1 file changed, 168 insertions(+), 30 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/tools/release 
refs/changes/43/182643/1

diff --git a/make-release/testReleaseTarball.php 
b/make-release/testReleaseTarball.php
index cf4fc05..394ee39 100644
--- a/make-release/testReleaseTarball.php
+++ b/make-release/testReleaseTarball.php
@@ -22,25 +22,119 @@
        /** Version we will test out */
        protected static $version;
 
+       /** Previous version */
+       protected static $prevVersion;
+
        /** Filename of the tarball for the version */
        protected static $tarball;
 
+       /** Filename of the tarball for the version */
+       protected static $prevTarball;
+
+       /** Filename of the tarball for the version */
+       protected static $prevBaseTarball;
+
+       /** Filename of the tarball for the version */
+       protected static $prevTarballPath;
+
+       /** Filename of the tarball for the version */
+       protected static $prevTarballURL;
+
        /** Path where the tarball got extracted to */
        protected static $basePath;
+
+       /** Path where the tarball got extracted to */
+       protected static $prevBasePath;
+
+       /** Base URL for download */
+       protected static $baseURL;
+
+       /** Base name for download */
+       protected static $baseName;
+
+       /** Base name for download */
+       protected static $prevBaseName;
+
+       /** Base name for download */
+       protected static $baseNamePath;
+
+       /** Base name for download */
+       protected static $prevBaseNamePath;
+
+       /** Base name for download */
+       protected static $tarballPath;
+
+       private static function verifyFile( $sig, $file ) {
+               $cmd = "gpg --verify $sig $file 2> /dev/null";
+               exec( $cmd, $output, $exitCode );
+               if ( $exitCode === 0 ) {
+                       return true;
+               }
+               echo "Failure verifying $file\n";
+               exit;
+       }
+
+       private static function removeDir( $path ) {
+               $cmd = 'rm -rf ' . escapeshellarg( $path );
+               exec( $cmd );
+               self::assertFalse( file_exists( $path ) );
+        }
+
+       private static function getFile( $url, $file ) {
+               $cmd = 'wget -O ' . $file . ' ' . $url;
+               exec( $cmd, $output, $exitCode );
+               if ( file_exists( $file ) && $exitCode === 0 ) {
+                       return true;
+               }
+               echo "Failure fetching $url to $file\n";
+               exit;
+       }
 
        /**
         * Helper to easily set the target version AND the tarball name
         */
        protected static function setTargetVersion( $version ) {
                self::$version = $version;
-               self::$tarball = "build/mediawiki-{$version}.tar.gz";
-               self::$basePath = "mediawiki-{$version}";
+               self::$basePath = __DIR__ . "/build/";
+               self::$baseURL = 'http://releases.wikimedia.org/mediawiki/';
+               self::$baseName = "mediawiki-{$version}";
+               self::$baseNamePath = self::$basePath . self::$baseName;
+               self::$tarball = self::$baseName . ".tar.gz";
+               self::$tarballPath = self::$basePath . self::$tarball;
+
+               $comp = explode( '.', self::$version );
+               if( $comp && $comp[2] > 0 ) {
+                       $comp[2]--;
+                       $prevVersion = implode( '.', $comp );
+                       self::$prevVersion = $prevVersion;
+                       self::$prevBaseName = "mediawiki-{$prevVersion}";
+                       self::$prevBaseNamePath = self::$basePath . 
self::$prevBaseName;
+                       self::$prevTarball = self::$prevBaseName . ".tar.gz";
+                       self::$prevTarballPath = self::$basePath . 
self::$prevTarball;
+                       self::$prevTarballURL = self::$baseURL . $comp[0] . '.' 
.
+                               $comp[1] . '/' . self::$prevTarball;
+
+                       if ( ! file_exists( self::$prevTarballPath ) ) {
+                               self::getFile( self::$prevTarballURL, 
self::$prevTarballPath );
+                       }
+
+                       $sigFile = self::$prevTarballPath . ".sig";
+                       $sigURL  = self::$prevTarballURL . ".sig";
+                       if ( ! file_exists( $sigFile ) ) {
+                               self::getFile( $sigURL, $sigFile );
+                       }
+
+                       self::verifyFile( $sigFile, self::$prevTarballPath );
+               }
        }
 
        public static function setUpBeforeClass() {
                parent::setUpBeforeClass();
                //version tag is the last argument
-               self::setTargetVersion( array_pop( $_SERVER['argv'] ) );
+               $argv = $_SERVER['argv'];
+               if( count( $argv ) >= 2 ) {
+                       self::setTargetVersion( $argv[2] );
+               }
        }
 
        public static function tearDownAfterClass() {
@@ -49,9 +143,8 @@
                        # There seems to be a handle on the language files 
immediately after
                        # install, so lets wait a bit
                        sleep(1);
-
-                       $cmd = 'rm -r ' . escapeshellarg( self::$basePath );
-                       exec( $cmd );
+                       self::removeDir( self::$baseNamePath );
+                       self::removeDir( self::$prevBaseNamePath );
                }
 
                parent::tearDownAfterClass();
@@ -61,6 +154,7 @@
         * Make sure the version passed to us is valid
         */
        public function testTargetVersionIsValid() {
+               $this->assertInternalType('string', self::$version );
                $this->assertRegExp( '/\d\.\d+\.\d+.*/',
                        self::$version,
                        "Must be passed a valid MediaWiki version"
@@ -68,14 +162,28 @@
        }
 
        public function testHaveATarballForTargetVersion() {
-               $this->assertFileExists( self::$tarball,
-                       self::$tarball . " could not be find. Please run: 
make-release.py " . self::$version
-               );
+               $this->assertFileExists( self::$tarballPath,
+                       self::$tarball . " could not be found. Please run: 
make-release.py " .
+                       self::$version );
        }
 
-       public function testExtractTarball() {
-               // extract tarball as described in 
http://www.mediawiki.org/wiki/Manual:Installing_MediaWiki
-               $cmd = 'tar xzf ' . escapeshellarg( self::$tarball );
+       public function testVerifyTarballSignature() {
+               $sigFile = self::$tarballPath . ".sig";
+               $this->assertTrue( self::verifyFile( $sigFile, 
self::$tarballPath ),
+                       "Couldn't verify tarball" );
+       }
+
+       public function testVerifyPatchSignature() {
+               $patchFile = self::$baseNamePath . ".patch.gz";
+               $this->assertTrue( self::verifyFile( "$patchFile.sig", 
$patchFile ),
+                       "Couldn't verify patchfile" );
+       }
+
+       public function extractTarball( $tarballPath, $baseNamePath ) {
+                               // extract tarball as described in
+               // http://www.mediawiki.org/wiki/Manual:Installing_MediaWiki
+               $cmd = 'tar -C ' . self::$basePath . " -xzf " .
+                       escapeshellarg( $tarballPath );
 
                exec( $cmd, $output, $exitCode );
                $this->assertEquals( 0, $exitCode,
@@ -83,18 +191,47 @@
                );
 
                # TODO: this assertion is not enough
-               $this->assertFileExists( self::$basePath,
-                       "Tarball " . self::$tarball . "should have been 
extracted to "
+               $this->assertTrue( is_dir( $baseNamePath ),
+                       "Tarball " . $tarballPath . "should have been extracted 
to "
                        . self::$basePath
                );
 
-               $this->assertFileExists( self::$basePath . 
'/includes/DefaultSettings.php',
+               $this->assertFileExists( $baseNamePath . 
'/includes/DefaultSettings.php',
                        "DefaultSettings.php could not be found."
                );
        }
 
+       public function testExtractTarball() {
+               $this->extractTarball( self::$tarballPath, self::$baseNamePath 
);
+       }
+
+       public function testPreviousVersionCanBePatched() {
+               // Can't patch .0 releases
+               $this->assertRegExp( '/\d\.\d+\.[1-9]*.*/',
+                  self::$version,
+                  "Can't test diffs against this version"
+               );
+       }
+
+       public function testPreviousTarballExists() {
+               $this->assertFileExists( self::$prevTarballPath );
+       }
+
+       public function testExtractPreviousTarball() {
+               $this->extractTarball( self::$prevTarballPath, 
self::$prevBaseNamePath );
+       }
+
+       public function testApplyPatches() {
+               # apply patch
+               $cmd = "cd " . self::$prevBaseNamePath . "; zcat " . 
self::$baseNamePath . ".patch.gz | patch -p1 > /dev/null";
+               exec( $cmd, $output, $exitCode );
+
+               # fail on error
+               $this->assertTrue( $exitCode === 0, "Patch didn't apply", 
"Exited with $exitCode" );
+       }
+
        public function testWgversionMatchTargetedVersion() {
-               $file = file_get_contents( self::$basePath . 
'/includes/DefaultSettings.php' );
+               $file = file_get_contents( self::$baseNamePath . 
'/includes/DefaultSettings.php' );
                preg_match( '/\$wgVersion\s+=\s+\'(.*)\';/',
                        $file, $matches
                );
@@ -105,25 +242,26 @@
        }
 
        public function testCliInstaller() {
-               $cmd = 'php ' . escapeshellarg( self::$basePath ) . 
'/maintenance/install.php'
-                               //SQLite for installation
-                               .' --dbtype=sqlite'
-                               //Put SQLite file in MW install path
-                               .' --dbpath=' . escapeshellarg( self::$basePath 
)
-                               //Put required DB name in
-                               .' --dbname=tmp'
-                               //admin pass
-                               .' --pass=releaseTest'
-                               //name
-                               .' TarballTestInstallation'
-                               //admin
-                               .' WikiSysop';
+               $cmd = 'php ' . escapeshellarg( self::$baseNamePath ) .
+                       '/maintenance/install.php'
+                       //SQLite for installation
+                       .' --dbtype=sqlite'
+                       //Put SQLite file in MW install path
+                       .' --dbpath=' . escapeshellarg( self::$baseNamePath )
+                       //Put required DB name in
+                       .' --dbname=tmp'
+                       //admin pass
+                       .' --pass=releaseTest'
+                       //name
+                       .' TarballTestInstallation'
+                       //admin
+                       .' WikiSysop';
 
                exec( $cmd, $output, $exitCode );
                $this->assertEquals( 0, $exitCode,
                        "Shell command $cmd failed with exit code $exitCode"
                );
-               $this->assertFileExists( self::$basePath . '/LocalSettings.php',
+               $this->assertFileExists( self::$baseNamePath . 
'/LocalSettings.php',
                        "Installation failed: LocalSettings.php could not be 
found."
                );
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/182643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2cbfbed00e98480126a5dce277abf1ce783f5413
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/tools/release
Gerrit-Branch: master
Gerrit-Owner: MarkAHershberger <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to