diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 00000000..4ad008a5 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,6 @@ +imports: + - php + +tools: + external_code_coverage: + runs: 5 # No Code Coverage on PHP 5.2 and HHVM diff --git a/.travis.yml b/.travis.yml index c6f56a9b..9872b17c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: php +# When adding environments here, the number of runs specified in .scrutinizer.yml +# may have to be adjusted. php: - 5.2 - 5.3.3 @@ -25,4 +27,5 @@ script: - travis/run-phpunit.sh after_success: - - sh -c "if $TRAVIS_SECURE_ENV_VARS; then travis/upload-code-coverage.sh; fi" + - sh -c "if $TRAVIS_SECURE_ENV_VARS; then travis/upload-code-coverage-html.sh; fi" + - sh -c "if [ '$TRAVIS_PHP_VERSION' != '5.2' -a '$TRAVIS_PHP_VERSION' != 'hhvm' ]; then travis/upload-code-coverage-scrutinizer.sh; fi" diff --git a/phpseclib/Crypt/AES.php b/phpseclib/Crypt/AES.php index 9cf78f10..26b1ae8f 100644 --- a/phpseclib/Crypt/AES.php +++ b/phpseclib/Crypt/AES.php @@ -19,7 +19,7 @@ * Here's a short example of how to use this library: * * * * * * * * createKey()); @@ -26,7 +26,7 @@ * Here's an example of how to create signatures and verify signatures with this library: * * createKey()); @@ -1482,6 +1482,19 @@ class Crypt_RSA $this->publicExponent = false; } + switch ($type) { + case CRYPT_RSA_PUBLIC_FORMAT_OPENSSH: + case CRYPT_RSA_PUBLIC_FORMAT_RAW: + $this->setPublicKey(); + break; + case CRYPT_RSA_PRIVATE_FORMAT_PKCS1: + switch (true) { + case strpos($key, '-BEGIN PUBLIC KEY-') !== false: + case strpos($key, '-BEGIN RSA PUBLIC KEY-') !== false: + $this->setPublicKey(); + } + } + return true; } @@ -1508,7 +1521,9 @@ class Crypt_RSA * used in certain contexts. For example, in SSH-2, RSA authentication works by sending the public key along with a * message signed by the private key to the server. The SSH-2 server looks the public key up in an index of public keys * and if it's present then proceeds to verify the signature. Problem is, if your private key doesn't include the public - * exponent this won't work unless you manually add the public exponent. + * exponent this won't work unless you manually add the public exponent. phpseclib tries to guess if the key being used + * is the public key but in the event that it guesses incorrectly you might still want to explicitly set the key as being + * public. * * Do note that when a new key is loaded the index will be cleared. * @@ -1564,6 +1579,40 @@ class Crypt_RSA return true; } + /** + * Defines the private key + * + * If phpseclib guessed a private key was a public key and loaded it as such it might be desirable to force + * phpseclib to treat the key as a private key. This function will do that. + * + * Do note that when a new key is loaded the index will be cleared. + * + * Returns true on success, false on failure + * + * @see getPublicKey() + * @access public + * @param String $key optional + * @param Integer $type optional + * @return Boolean + */ + function setPrivateKey($key = false, $type = false) + { + if ($key === false && !empty($this->publicExponent)) { + unset($this->publicExponent); + return true; + } + + $rsa = new Crypt_RSA(); + if (!$rsa->loadKey($key, $type)) { + return false; + } + unset($rsa->publicExponent); + + // don't overwrite the old key if the new key is invalid + $this->loadKey($rsa); + return true; + } + /** * Returns the public key * diff --git a/phpseclib/Crypt/Random.php b/phpseclib/Crypt/Random.php index ec69f2a8..02773931 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -8,7 +8,7 @@ * Here's a short example of how to use this library: * * diff --git a/phpseclib/Crypt/Rijndael.php b/phpseclib/Crypt/Rijndael.php index 8bf4581c..821547df 100644 --- a/phpseclib/Crypt/Rijndael.php +++ b/phpseclib/Crypt/Rijndael.php @@ -28,7 +28,7 @@ * Here's a short example of how to use this library: * * * * * * * * * * * * * * * * * * * login('username', 'password')) { diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 4dd38805..002c8e6d 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -14,7 +14,7 @@ * Here's a short example of how to use this library: * * login('username', 'password')) { diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index 649668d7..15e659a9 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -8,7 +8,7 @@ * Here's a short example of how to use this library: * * login('username', 'password')) { @@ -22,7 +22,7 @@ * Here's another short example: * * login('username', 'password')) { @@ -704,7 +704,7 @@ class Net_SSH1 break; //case NET_SSH1_CIPHER_RC4: // if (!class_exists('Crypt_RC4')) { - // include_once('Crypt/RC4.php'); + // include_once 'Crypt/RC4.php'; // } // $this->crypto = new Crypt_RC4(); // $this->crypto->enableContinuousBuffer(); diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index efc4656b..6dd29ed1 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -8,7 +8,7 @@ * Here are some examples of how to use this library: * * login('username', 'password')) { @@ -22,8 +22,8 @@ * * * setPassword('whatever'); diff --git a/phpseclib/System/SSH/Agent.php b/phpseclib/System/SSH/Agent.php index 6d1882f0..ead905fa 100644 --- a/phpseclib/System/SSH/Agent.php +++ b/phpseclib/System/SSH/Agent.php @@ -7,8 +7,8 @@ * Here are some examples of how to use this library: * * - - ./tests/ + + ./tests/Unit/ + + + ./tests/Functional/ diff --git a/tests/Net/SFTPFunctionalTest.php b/tests/Functional/Net/SFTPUserStoryTest.php similarity index 99% rename from tests/Net/SFTPFunctionalTest.php rename to tests/Functional/Net/SFTPUserStoryTest.php index 9c43b55b..05c316ba 100644 --- a/tests/Net/SFTPFunctionalTest.php +++ b/tests/Functional/Net/SFTPUserStoryTest.php @@ -6,7 +6,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Net_SFTPFunctionalTest extends PhpseclibFunctionalTestCase +class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase { static protected $scratchDir; static protected $exampleData; diff --git a/tests/Net/SSH2FunctionalTest.php b/tests/Functional/Net/SSH2Test.php similarity index 95% rename from tests/Net/SSH2FunctionalTest.php rename to tests/Functional/Net/SSH2Test.php index 1fd7e271..0f92ca20 100644 --- a/tests/Net/SSH2FunctionalTest.php +++ b/tests/Functional/Net/SSH2Test.php @@ -6,7 +6,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Net_SSH2FunctionalTest extends PhpseclibFunctionalTestCase +class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase { public function setUp() { diff --git a/tests/Crypt/AES/ContinuousBufferTest.php b/tests/Unit/Crypt/AES/ContinuousBufferTest.php similarity index 95% rename from tests/Crypt/AES/ContinuousBufferTest.php rename to tests/Unit/Crypt/AES/ContinuousBufferTest.php index 1d712597..e032dab6 100644 --- a/tests/Crypt/AES/ContinuousBufferTest.php +++ b/tests/Unit/Crypt/AES/ContinuousBufferTest.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Crypt_AES_ContinuousBufferTest extends Crypt_AES_TestCase +class Unit_Crypt_AES_ContinuousBufferTest extends Unit_Crypt_AES_TestCase { // String intented protected $modes = array( diff --git a/tests/Crypt/AES/TestCase.php b/tests/Unit/Crypt/AES/TestCase.php similarity index 91% rename from tests/Crypt/AES/TestCase.php rename to tests/Unit/Crypt/AES/TestCase.php index 317f1e52..c4bf57e6 100644 --- a/tests/Crypt/AES/TestCase.php +++ b/tests/Unit/Crypt/AES/TestCase.php @@ -7,7 +7,7 @@ require_once 'Crypt/AES.php'; -abstract class Crypt_AES_TestCase extends PhpseclibTestCase +abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase { static public function setUpBeforeClass() { diff --git a/tests/Crypt/Hash/MD5Test.php b/tests/Unit/Crypt/Hash/MD5Test.php similarity index 95% rename from tests/Crypt/Hash/MD5Test.php rename to tests/Unit/Crypt/Hash/MD5Test.php index 4b0635de..3651147e 100644 --- a/tests/Crypt/Hash/MD5Test.php +++ b/tests/Unit/Crypt/Hash/MD5Test.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Crypt_Hash_MD5Test extends Crypt_Hash_TestCase +class Unit_Crypt_Hash_MD5Test extends Unit_Crypt_Hash_TestCase { public function getInstance() { diff --git a/tests/Crypt/Hash/TestCase.php b/tests/Unit/Crypt/Hash/TestCase.php similarity index 95% rename from tests/Crypt/Hash/TestCase.php rename to tests/Unit/Crypt/Hash/TestCase.php index 5f469751..040bce2c 100644 --- a/tests/Crypt/Hash/TestCase.php +++ b/tests/Unit/Crypt/Hash/TestCase.php @@ -7,7 +7,7 @@ require_once 'Crypt/Hash.php'; -abstract class Crypt_Hash_TestCase extends PhpseclibTestCase +abstract class Unit_Crypt_Hash_TestCase extends PhpseclibTestCase { static public function setUpBeforeClass() { diff --git a/tests/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php similarity index 65% rename from tests/Crypt/RSA/LoadKeyTest.php rename to tests/Unit/Crypt/RSA/LoadKeyTest.php index 95239d84..cf80d82e 100644 --- a/tests/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -7,7 +7,7 @@ require_once 'Crypt/RSA.php' ; -class Crypt_RSA_LoadKeyTest extends PhpseclibTestCase +class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase { public function testBadKey() { @@ -37,6 +37,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ -----END RSA PRIVATE KEY-----'; $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPrivateKey()); } public function testPKCS1SpacesKey() @@ -59,6 +60,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ $key = str_replace(array("\r", "\n", "\r\n"), ' ', $key); $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPrivateKey()); } public function testPKCS1NoHeaderKey() @@ -78,6 +80,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ 37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0='; $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPrivateKey()); } public function testPKCS1NoWhitespaceNoHeaderKey() @@ -95,7 +98,9 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ 'X6zk7S0ljKtt2jny2+00VsBerQJBAJGC1Mg5Oydo5NwD6BiROrPxGo2bpTbu/fhrT8ebHkTz2epl' . 'U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ' . '37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ4p0='; + $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPrivateKey()); } public function testRawPKCS1Key() @@ -116,5 +121,76 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ $key = base64_decode($key); $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPrivateKey()); + } + + public function testPubKey1() + { + $rsa = new Crypt_RSA(); + + $key = '-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa +D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw +luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB +o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV +gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH +Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB +-----END RSA PUBLIC KEY-----'; + + $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPublicKey()); + $this->assertFalse($rsa->getPrivateKey()); + } + + public function testPubKey2() + { + $rsa = new Crypt_RSA(); + + $key = '-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA61BjmfXGEvWmegnBGSuS ++rU9soUg2FnODva32D1AqhwdziwHINFaD1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBS +EVCgJjtHAGZIm5GL/KA86KDp/CwDFMSwluowcXwDwoyinmeOY9eKyh6aY72xJh7n +oLBBq1N0bWi1e2i+83txOCg4yV2oVXhBo8pYEJ8LT3el6Smxol3C1oFMVdwPgc0v +Tl25XucMcG/ALE/KNY6pqC2AQ6R2ERlVgPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeu +lmCpGSynXNcpZ/06+vofGi/2MlpQZNhHAo8eayMp6FcvNucIpUndo1X8dKMv3Y26 +ZQIDAQAB +-----END PUBLIC KEY-----'; + + $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPublicKey()); + $this->assertFalse($rsa->getPrivateKey()); + } + + public function testSSHPubKey() + { + $rsa = new Crypt_RSA(); + + $key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4e' . + 'CZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMS' . + 'GkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZw== ' . + 'phpseclib-generated-key'; + + $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPublicKey()); + $this->assertFalse($rsa->getPrivateKey()); + } + + public function testSetPrivate() + { + $rsa = new Crypt_RSA(); + + $key = '-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa +D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw +luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB +o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV +gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH +Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB +-----END RSA PUBLIC KEY-----'; + + $this->assertTrue($rsa->loadKey($key)); + $this->assertTrue($rsa->setPrivateKey()); + $this->assertGreaterThanOrEqual(1, strlen("$rsa")); + $this->assertFalse($rsa->getPublicKey()); } } diff --git a/tests/File/ASN1/DevTest.php b/tests/Unit/File/ASN1/DevTest.php similarity index 99% rename from tests/File/ASN1/DevTest.php rename to tests/Unit/File/ASN1/DevTest.php index 6b9d9d99..d0d51042 100644 --- a/tests/File/ASN1/DevTest.php +++ b/tests/Unit/File/ASN1/DevTest.php @@ -7,7 +7,7 @@ require_once 'File/ASN1.php'; -class File_ASN1_DevTest extends PhpseclibTestCase +class Unit_File_ASN1_DevTest extends PhpseclibTestCase { /** * on older versions of File_ASN1 this would yield a PHP Warning diff --git a/tests/Math/BigInteger/BCMathTest.php b/tests/Unit/Math/BigInteger/BCMathTest.php similarity index 86% rename from tests/Math/BigInteger/BCMathTest.php rename to tests/Unit/Math/BigInteger/BCMathTest.php index 72c574d1..d856c1a8 100644 --- a/tests/Math/BigInteger/BCMathTest.php +++ b/tests/Unit/Math/BigInteger/BCMathTest.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Math_BigInteger_BCMathTest extends Math_BigInteger_TestCase +class Unit_Math_BigInteger_BCMathTest extends Unit_Math_BigInteger_TestCase { static public function setUpBeforeClass() { diff --git a/tests/Math/BigInteger/GMPTest.php b/tests/Unit/Math/BigInteger/GMPTest.php similarity index 87% rename from tests/Math/BigInteger/GMPTest.php rename to tests/Unit/Math/BigInteger/GMPTest.php index 27c7a6a4..02a1cae8 100644 --- a/tests/Math/BigInteger/GMPTest.php +++ b/tests/Unit/Math/BigInteger/GMPTest.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Math_BigInteger_GMPTest extends Math_BigInteger_TestCase +class Unit_Math_BigInteger_GMPTest extends Unit_Math_BigInteger_TestCase { static public function setUpBeforeClass() { diff --git a/tests/Math/BigInteger/InternalOpenSSLTest.php b/tests/Unit/Math/BigInteger/InternalOpenSSLTest.php similarity index 85% rename from tests/Math/BigInteger/InternalOpenSSLTest.php rename to tests/Unit/Math/BigInteger/InternalOpenSSLTest.php index 378caacc..06d57a6f 100644 --- a/tests/Math/BigInteger/InternalOpenSSLTest.php +++ b/tests/Unit/Math/BigInteger/InternalOpenSSLTest.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Math_BigInteger_InternalOpenSSLTest extends Math_BigInteger_TestCase +class Unit_Math_BigInteger_InternalOpenSSLTest extends Unit_Math_BigInteger_TestCase { static public function setUpBeforeClass() { diff --git a/tests/Math/BigInteger/InternalTest.php b/tests/Unit/Math/BigInteger/InternalTest.php similarity index 89% rename from tests/Math/BigInteger/InternalTest.php rename to tests/Unit/Math/BigInteger/InternalTest.php index 744b2df1..faa9bb79 100644 --- a/tests/Math/BigInteger/InternalTest.php +++ b/tests/Unit/Math/BigInteger/InternalTest.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Math_BigInteger_InternalTest extends Math_BigInteger_TestCase +class Math_BigInteger_InternalTest extends Unit_Math_BigInteger_TestCase { static public function setUpBeforeClass() { diff --git a/tests/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php similarity index 99% rename from tests/Math/BigInteger/TestCase.php rename to tests/Unit/Math/BigInteger/TestCase.php index d62dcec5..d233dfb4 100644 --- a/tests/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -7,7 +7,7 @@ require_once 'Math/BigInteger.php'; -abstract class Math_BigInteger_TestCase extends PhpseclibTestCase +abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase { static public function setUpBeforeClass() { diff --git a/tests/Net/SSH1Test.php b/tests/Unit/Net/SSH1Test.php similarity index 96% rename from tests/Net/SSH1Test.php rename to tests/Unit/Net/SSH1Test.php index 7c58ceb3..5f4778f3 100644 --- a/tests/Net/SSH1Test.php +++ b/tests/Unit/Net/SSH1Test.php @@ -5,7 +5,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Net_SSH1Test extends PhpseclibTestCase +class Unit_Net_SSH1Test extends PhpseclibTestCase { public function formatLogDataProvider() { diff --git a/tests/Net/SSH2Test.php b/tests/Unit/Net/SSH2Test.php similarity index 65% rename from tests/Net/SSH2Test.php rename to tests/Unit/Net/SSH2Test.php index 26d6e872..ce8f17be 100644 --- a/tests/Net/SSH2Test.php +++ b/tests/Unit/Net/SSH2Test.php @@ -6,7 +6,7 @@ * @license http://www.opensource.org/licenses/mit-license.html MIT License */ -class Net_SSH2Test extends PhpseclibTestCase +class Unit_Net_SSH2Test extends PhpseclibTestCase { public function formatLogDataProvider() { @@ -36,38 +36,27 @@ class Net_SSH2Test extends PhpseclibTestCase $this->assertEquals($expected, $result); } - public function generateIdentifierProvider() + public function testGenerateIdentifier() { - return array( - array('SSH-2.0-phpseclib_0.3', array()), - array('SSH-2.0-phpseclib_0.3 (gmp)', array('gmp')), - array('SSH-2.0-phpseclib_0.3 (bcmath)', array('bcmath')), - array('SSH-2.0-phpseclib_0.3 (mcrypt)', array('mcrypt')), - array('SSH-2.0-phpseclib_0.3 (mcrypt, gmp)', array('mcrypt', 'gmp')), - array('SSH-2.0-phpseclib_0.3 (mcrypt, bcmath)', array('mcrypt', 'bcmath')), - ); - } + $identifier = $this->createSSHMock()->_generate_identifier(); + $this->assertStringStartsWith('SSH-2.0-phpseclib_0.3', $identifier); - /** - * @dataProvider generateIdentifierProvider - */ - public function testGenerateIdentifier($expected, array $requiredExtensions) - { - $notAllowed = array('gmp', 'bcmath', 'mcrypt', 'gmp'); - foreach ($notAllowed as $notAllowedExtension) { - if (in_array($notAllowedExtension, $requiredExtensions)) { - continue; - } - - if (extension_loaded($notAllowedExtension)) { - $this->markTestSkipped('Extension ' . $notAllowedExtension . ' is not allowed for this data-set'); - } + if (extension_loaded('mcrypt')) { + $this->assertContains('mcrypt', $identifier); + } else { + $this->assertNotContains('mcrypt', $identifier); } - $ssh = $this->createSSHMock(); - $identifier = $ssh->_generate_identifier(); - - $this->assertEquals($expected, $identifier); + if (extension_loaded('gmp')) { + $this->assertContains('gmp', $identifier); + $this->assertNotContains('bcmath', $identifier); + } else if (extension_loaded('bcmath')) { + $this->assertNotContains('gmp', $identifier); + $this->assertContains('bcmath', $identifier); + } else { + $this->assertNotContains('gmp', $identifier); + $this->assertNotContains('bcmath', $identifier); + } } public function testGetExitStatusIfNotConnected() diff --git a/travis/run-phpunit.sh b/travis/run-phpunit.sh index 013cf3ae..713e98da 100755 --- a/travis/run-phpunit.sh +++ b/travis/run-phpunit.sh @@ -24,4 +24,5 @@ fi $PHPUNIT_EXTRA_ARGS \ --verbose \ --coverage-text \ + --coverage-clover code_coverage/clover.xml \ --coverage-html code_coverage/ diff --git a/travis/upload-code-coverage.sh b/travis/upload-code-coverage-html.sh similarity index 100% rename from travis/upload-code-coverage.sh rename to travis/upload-code-coverage-html.sh diff --git a/travis/upload-code-coverage-scrutinizer.sh b/travis/upload-code-coverage-scrutinizer.sh new file mode 100755 index 00000000..efcff08c --- /dev/null +++ b/travis/upload-code-coverage-scrutinizer.sh @@ -0,0 +1,13 @@ +#!/bin/sh +# +# This file is part of the phpseclib project. +# +# (c) Andreas Fischer +# +# For the full copyright and license information, please view the LICENSE +# file that was distributed with this source code. +# +set -e + +wget https://scrutinizer-ci.com/ocular.phar +php ocular.phar code-coverage:upload --format=php-clover code_coverage/clover.xml