Skip to content

Commit

Permalink
Hotfix for local MD5 hashing, fixes TechnicPack#498
Browse files Browse the repository at this point in the history
  • Loading branch information
GenPage committed Dec 7, 2015
1 parent 1d3bc34 commit b324203
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 46 deletions.
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ branches:
- /^legacy\/.*$/
- heroku
language: php
cache:
directories:
- $HOME/.composer/cache
php:
- 5.5
- 5.6
Expand All @@ -12,17 +15,21 @@ env:
global:
- APP_ENV='testing'
matrix:
- "DB=pgsql"
- "DB=mysql"
- DB="pgsql" REPO="$TRAVIS_BUILD_DIR/public/resources/default/" REPO_TYPE="local"
- DB="mysql" REPO="$TRAVIS_BUILD_DIR/public/resources/default/" REPO_TYPE="local"
- DB="pgsql" REPO="http://technic.pagefortress.com/" REPO_TYPE="remote"
- DB="mysql" REPO="http://technic.pagefortress.com/" REPO_TYPE="remote"
matrix:
fast_finish: true
exclude:
- php: hhvm
env: DB=pgsql # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency
allow_failures:
- php: 7.0
env: DB="pgsql" REPO="$TRAVIS_BUILD_DIR/public/resources/default/" REPO_TYPE="local" # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency
- php: hhvm
env: DB="pgsql" REPO="http://technic.pagefortress.com/" REPO_TYPE="remote" # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency
sudo: false
before_install:
- hostname
- echo $REPO
- rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
- composer self-update
install: travis_retry composer install --prefer-source --no-interaction
before_script:
Expand Down
2 changes: 1 addition & 1 deletion app/config-sample/testing/solder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* This can be a URL or an absolute file location.
*
**/
'repo_location' => 'http://mirror.technicpack.net/Technic/',
'repo_location' => getenv('REPO'),

/**
* Mirror Location
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public function __construct()
define('SOLDER_STREAM', 'DEV');
}
if(!defined('SOLDER_VERSION')) {
define('SOLDER_VERSION', 'v0.7.3.0');
define('SOLDER_VERSION', 'v0.7.3.1');
}

UpdateUtils::init();
Expand Down
26 changes: 12 additions & 14 deletions app/controllers/ModController.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,19 @@ private function mod_md5($mod, $version)
$location = Config::get('solder.repo_location');
$URI = $location.'mods/'.$mod->name.'/'.$mod->name.'-'.$version.'.zip';

if(filter_var($URI, FILTER_VALIDATE_URL)) {
if (file_exists($URI)) {
Log::info('Found \'' . $URI . '\'');
try {
$filesize = filesize($URI);
$md5 = md5_file($URI);
return array('success' => true, 'md5' => $md5, 'filesize' => $filesize);
} catch (Exception $e) {
Log::error("Error attempting to md5 the file: " . $URI);
return array('success' => false, 'message' => $e->getMessage());
}
} else {
Log::warning('File \'' . $URI . '\' was not found.');
return $this->remote_mod_md5($mod, $version, $location);
if (file_exists($URI)) {
Log::info('Found \'' . $URI . '\'');
try {
$filesize = filesize($URI);
$md5 = md5_file($URI);
return array('success' => true, 'md5' => $md5, 'filesize' => $filesize);
} catch (Exception $e) {
Log::error("Error attempting to md5 the file: " . $URI);
return array('success' => false, 'message' => $e->getMessage());
}
} else if(filter_var($URI, FILTER_VALIDATE_URL)) {
Log::warning('File \'' . $URI . '\' was not found.');
return $this->remote_mod_md5($mod, $version, $location);
} else {
$error = $URI . ' is not a valid URI';
Log::error($error);
Expand Down
6 changes: 3 additions & 3 deletions app/database/seeds/ModTableTestSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public function run()
DB::table('modversions')->delete();

$testmodversion = Modversion::create(array('mod_id' => $testmod->id,
'version' => '0.1',
'md5' => 'fb6582e4d9c9bc208181907ecc108eb1',
'filesize' => '1131456'
'version' => '1.0',
'md5' => 'bdbc6c6cc48c7b037e4aef64b58258a3',
'filesize' => '295'
));

}
Expand Down
46 changes: 25 additions & 21 deletions app/tests/ModTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function testModVersionAddPostInvalidModID()
public function testModVersionAddPost()
{
//Fake an AJAX call.
$response = $this->call('POST', '/mod/add-version/', array("add-version"=>"v1.5.2.v01","add-md5"=>"9ece64de3e11a0f15f55ef34f2194760","mod-id"=>"2"),
$response = $this->call('POST', '/mod/add-version/', array("add-version"=>"1.7.10-4.0.0","add-md5"=>"0925fb5cca71b6e8dd81fac9b257c6d4","mod-id"=>"2"),
array(), array("HTTP_X_REQUESTED_WITH"=>"XMLHttpRequest"));

$this->assertResponseOk();
Expand All @@ -153,15 +153,15 @@ public function testModVersionAddPost()
$this->assertTrue(array_key_exists('filesize', $json));
$this->assertTrue(array_key_exists('md5', $json));
$this->assertEquals('success', $json['status']);
$this->assertEquals('v1.5.2.v01', $json['version']);
$this->assertEquals('9ece64de3e11a0f15f55ef34f2194760', $json['md5']);
$this->assertEquals('0.02 MB', $json['filesize']);
$this->assertEquals('1.7.10-4.0.0', $json['version']);
$this->assertEquals('0925fb5cca71b6e8dd81fac9b257c6d4', $json['md5']);
$this->assertEquals('0.01 MB', $json['filesize']);
}

public function testModVersionAddPostManualMD5()
{
//Fake an AJAX call.
$response = $this->call('POST', '/mod/add-version/', array("add-version"=>"v2.0.1","add-md5"=>"butts","mod-id"=>"2"),
$response = $this->call('POST', '/mod/add-version/', array("add-version"=>"1.7.10-4.0.0","add-md5"=>"butts","mod-id"=>"2"),
array(), array("HTTP_X_REQUESTED_WITH"=>"XMLHttpRequest"));

$this->assertResponseOk();
Expand All @@ -174,10 +174,10 @@ public function testModVersionAddPostManualMD5()
$this->assertTrue(array_key_exists('md5', $json));
$this->assertTrue(array_key_exists('reason', $json));
$this->assertEquals('warning', $json['status']);
$this->assertEquals('v2.0.1', $json['version']);
$this->assertEquals('1.7.10-4.0.0', $json['version']);
$this->assertEquals('butts', $json['md5']);
$this->assertEquals('0.01 MB', $json['filesize']);
$this->assertEquals('MD5 provided does not match file MD5: de40f0fbd51ac178c6dd96e45a14a1f7', $json['reason']);
$this->assertEquals('MD5 provided does not match file MD5: 0925fb5cca71b6e8dd81fac9b257c6d4', $json['reason']);
}

public function testModVersionAddPostMD5Fail()
Expand All @@ -193,7 +193,11 @@ public function testModVersionAddPostMD5Fail()
$this->assertTrue(array_key_exists('status', $json));
$this->assertTrue(array_key_exists('reason', $json));
$this->assertEquals('error', $json['status']);
$this->assertEquals('Remote MD5 failed. URL returned status code - 404', $json['reason']);
if(getenv('REPO_TYPE') == 'remote') {
$this->assertEquals('Remote MD5 failed. URL returned status code - 404', $json['reason']);
} else {
$this->assertEquals('Remote MD5 failed. ' . getenv('REPO') . 'mods/backtools/backtools-v1.5.2.1.zip is not a valid URI', $json['reason']);
}
}

public function testModVersionRehashPostNonAjax()
Expand Down Expand Up @@ -237,7 +241,7 @@ public function testModVersionRehashPostInvalidID()
public function testModVersionRehashPost()
{
//Fake an AJAX call.
$response = $this->call('POST', '/mod/rehash/', array("version-id"=>"3","md5"=>"de40f0fbd51ac178c6dd96e45a14a1f7"),
$response = $this->call('POST', '/mod/rehash/', array("version-id"=>"1","md5"=>"bdbc6c6cc48c7b037e4aef64b58258a3"),
array(), array("HTTP_X_REQUESTED_WITH"=>"XMLHttpRequest"));

$this->assertResponseOk();
Expand All @@ -249,15 +253,15 @@ public function testModVersionRehashPost()
$this->assertTrue(array_key_exists('filesize', $json));
$this->assertTrue(array_key_exists('md5', $json));
$this->assertEquals('success', $json['status']);
$this->assertEquals('3', $json['version_id']);
$this->assertEquals('de40f0fbd51ac178c6dd96e45a14a1f7', $json['md5']);
$this->assertEquals('0.01 MB', $json['filesize']);
$this->assertEquals('1', $json['version_id']);
$this->assertEquals('bdbc6c6cc48c7b037e4aef64b58258a3', $json['md5']);
$this->assertEquals('0.00 MB', $json['filesize']);
}

public function testModVersionRehashPostMD5Manual()
{
//Fake an AJAX call.
$response = $this->call('POST', '/mod/rehash/', array("version-id"=>"3","md5"=>"butts"),
$response = $this->call('POST', '/mod/rehash/', array("version-id"=>"1","md5"=>"butts"),
array(), array("HTTP_X_REQUESTED_WITH"=>"XMLHttpRequest"));

$this->assertResponseOk();
Expand All @@ -270,16 +274,16 @@ public function testModVersionRehashPostMD5Manual()
$this->assertTrue(array_key_exists('md5', $json));
$this->assertTrue(array_key_exists('reason', $json));
$this->assertEquals('warning', $json['status']);
$this->assertEquals('3', $json['version_id']);
$this->assertEquals('1', $json['version_id']);
$this->assertEquals('butts', $json['md5']);
$this->assertEquals('0.01 MB', $json['filesize']);
$this->assertEquals('MD5 provided does not match file MD5: de40f0fbd51ac178c6dd96e45a14a1f7', $json['reason']);
$this->assertEquals('0.00 MB', $json['filesize']);
$this->assertEquals('MD5 provided does not match file MD5: bdbc6c6cc48c7b037e4aef64b58258a3', $json['reason']);
}

public function testModVersionRehashPostMD5Empty()
{
//Fake an AJAX call.
$response = $this->call('POST', '/mod/rehash/', array("version-id"=>"3","md5"=>""),
$response = $this->call('POST', '/mod/rehash/', array("version-id"=>"1","md5"=>""),
array(), array("HTTP_X_REQUESTED_WITH"=>"XMLHttpRequest"));

$this->assertResponseOk();
Expand All @@ -291,9 +295,9 @@ public function testModVersionRehashPostMD5Empty()
$this->assertTrue(array_key_exists('filesize', $json));
$this->assertTrue(array_key_exists('md5', $json));
$this->assertEquals('success', $json['status']);
$this->assertEquals('3', $json['version_id']);
$this->assertEquals('de40f0fbd51ac178c6dd96e45a14a1f7', $json['md5']);
$this->assertEquals('0.01 MB', $json['filesize']);
$this->assertEquals('1', $json['version_id']);
$this->assertEquals('bdbc6c6cc48c7b037e4aef64b58258a3', $json['md5']);
$this->assertEquals('0.00 MB', $json['filesize']);
}

public function testModVersionDeleteNonAjax()
Expand Down Expand Up @@ -349,7 +353,7 @@ public function testModVersionDelete()
$this->assertTrue(array_key_exists('version', $json));
$this->assertEquals('success', $json['status']);
$this->assertEquals('3', $json['version_id']);
$this->assertEquals('v2.0.1', $json['version']);
$this->assertEquals('1.7.10-4.0.0', $json['version']);
}

public function testModDeleteGet()
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit b324203

Please sign in to comment.