From 71e647782764184e3aab4faffe6d99176758979f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 22 Mar 2018 16:48:55 +0200 Subject: [ci skip] 3.1.8 release --- tests/codeigniter/core/compat/hash_test.php | 77 ----- tests/codeigniter/core/compat/mbstring_test.php | 54 ---- tests/codeigniter/core/compat/password_test.php | 159 ---------- tests/codeigniter/core/compat/standard_test.php | 378 ------------------------ 4 files changed, 668 deletions(-) delete mode 100644 tests/codeigniter/core/compat/hash_test.php delete mode 100644 tests/codeigniter/core/compat/mbstring_test.php delete mode 100644 tests/codeigniter/core/compat/password_test.php delete mode 100644 tests/codeigniter/core/compat/standard_test.php (limited to 'tests/codeigniter/core/compat') diff --git a/tests/codeigniter/core/compat/hash_test.php b/tests/codeigniter/core/compat/hash_test.php deleted file mode 100644 index d8cd0bb16..000000000 --- a/tests/codeigniter/core/compat/hash_test.php +++ /dev/null @@ -1,77 +0,0 @@ -markTestSkipped('ext/hash is available on PHP 5.6'); - } - - $this->assertTrue(function_exists('hash_equals')); - is_php('5.5') OR $this->assertTrue(function_exists('hash_pbkdf2')); - } - - // ------------------------------------------------------------------------ - - /** - * hash_equals() test - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_hash_equals() - { - $this->assertTrue(hash_equals('same', 'same')); - $this->assertFalse(hash_equals('not1same', 'not2same')); - $this->assertFalse(hash_equals('short', 'longer')); - $this->assertFalse(hash_equals('longer', 'short')); - $this->assertFalse(hash_equals('', 'notempty')); - $this->assertFalse(hash_equals('notempty', '')); - $this->assertTrue(hash_equals('', '')); - } - - // ------------------------------------------------------------------------ - - /** - * hash_pbkdf2() test - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_hash_pbkdf2() - { - if (is_php('5.5')) - { - return $this->markTestSkipped('hash_pbkdf2() is available on PHP 5.5'); - } - - $this->assertEquals('0c60c80f961f0e71f3a9', hash_pbkdf2('sha1', 'password', 'salt', 1, 20)); - $this->assertEquals( - "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf\x60\x12\x06\x2f\xe0\x37\xa6", - hash_pbkdf2('sha1', 'password', 'salt', 1, 20, TRUE) - ); - $this->assertEquals('3d2eec4fe41c849b80c8d8366', hash_pbkdf2('sha1', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 25)); - $this->assertEquals( - "\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38", - hash_pbkdf2('sha1', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 25, TRUE) - ); - $this->assertEquals('120fb6cffcf8b32c43e7', hash_pbkdf2('sha256', 'password', 'salt', 1, 20)); - $this->assertEquals( - "\x12\x0f\xb6\xcf\xfc\xf8\xb3\x2c\x43\xe7\x22\x52\x56\xc4\xf8\x37\xa8\x65\x48\xc9", - hash_pbkdf2('sha256', 'password', 'salt', 1, 20, TRUE) - ); - $this->assertEquals( - '348c89dbcbd32b2f32d814b8116e84cf2b17347e', - hash_pbkdf2('sha256', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 40) - ); - $this->assertEquals( - "\x34\x8c\x89\xdb\xcb\xd3\x2b\x2f\x32\xd8\x14\xb8\x11\x6e\x84\xcf\x2b\x17\x34\x7e\xbc\x18\x00\x18\x1c\x4e\x2a\x1f\xb8\xdd\x53\xe1\xc6\x35\x51\x8c\x7d\xac\x47\xe9", - hash_pbkdf2('sha256', 'passwordPASSWORDpassword', 'saltSALTsaltSALTsaltSALTsaltSALTsalt', 4096, 40, TRUE) - ); - } - -} \ No newline at end of file diff --git a/tests/codeigniter/core/compat/mbstring_test.php b/tests/codeigniter/core/compat/mbstring_test.php deleted file mode 100644 index 415222446..000000000 --- a/tests/codeigniter/core/compat/mbstring_test.php +++ /dev/null @@ -1,54 +0,0 @@ -markTestSkipped('ext/mbstring is loaded'); - } - - $this->assertTrue(function_exists('mb_strlen')); - $this->assertTrue(function_exists('mb_substr')); - } - - // ------------------------------------------------------------------------ - - /** - * @depends test_bootstrap - */ - public function test_mb_strlen() - { - $this->assertEquals(ICONV_ENABLED ? 4 : 8, mb_strlen('тест')); - $this->assertEquals(ICONV_ENABLED ? 4 : 8, mb_strlen('тест', 'UTF-8')); - } - - // ------------------------------------------------------------------------ - - /** - * @depends test_boostrap - */ - public function test_mb_strpos() - { - $this->assertEquals(ICONV_ENABLED ? 3 : 6, mb_strpos('тест', 'с')); - $this->assertFalse(mb_strpos('тест', 'с', 3)); - $this->assertEquals(ICONV_ENABLED ? 3 : 6, mb_strpos('тест', 'с', 1, 'UTF-8')); - } - - // ------------------------------------------------------------------------ - - /** - * @depends test_boostrap - */ - public function test_mb_substr() - { - $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2)); - $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2)); - $this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2)); - $this->assertEquals(ICONV_ENABLED ? 'стинг' : 'естинг', mb_substr('тестинг', 2, 'UTF-8')); - $this->assertEquals(ICONV_ENABLED ? 'нг' : 'г', mb_substr('тестинг', -2, 'UTF-8')); - $this->assertEquals(ICONV_ENABLED ? 'ст' : 'е', mb_substr('тестинг', 2, 2, 'UTF-8')); - } - -} \ No newline at end of file diff --git a/tests/codeigniter/core/compat/password_test.php b/tests/codeigniter/core/compat/password_test.php deleted file mode 100644 index b6dbcfab1..000000000 --- a/tests/codeigniter/core/compat/password_test.php +++ /dev/null @@ -1,159 +0,0 @@ -markTestSkipped('ext/standard/password is available on PHP 5.5'); - } - // defined as of HHVM 2.3.0, which is also when they introduce password_*() as well - // Note: Do NOT move this after the CRYPT_BLOWFISH check - elseif (defined('HHVM_VERSION')) - { - $this->markTestSkipped('HHVM 2.3.0+ already has it'); - } - elseif ( ! defined('CRYPT_BLOWFISH') OR CRYPT_BLOWFISH !== 1) - { - $this->assertFalse(defined('PASSWORD_BCRYPT')); - return $this->markTestSkipped('CRYPT_BLOWFISH is not available'); - } - - $this->assertTrue(defined('PASSWORD_BCRYPT')); - $this->assertTrue(defined('PASSWORD_DEFAULT')); - $this->assertEquals(1, PASSWORD_BCRYPT); - $this->assertEquals(PASSWORD_BCRYPT, PASSWORD_DEFAULT); - $this->assertTrue(function_exists('password_get_info')); - $this->assertTrue(function_exists('password_hash')); - $this->assertTrue(function_exists('password_needs_rehash')); - $this->assertTrue(function_exists('password_verify')); - } - - // ------------------------------------------------------------------------ - - /** - * password_get_info() test - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_password_get_info() - { - $expected = array( - 'algo' => 1, - 'algoName' => 'bcrypt', - 'options' => array('cost' => 10) - ); - - // default - $this->assertEquals($expected, password_get_info('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y')); - - $expected['options']['cost'] = 11; - - // cost - $this->assertEquals($expected, password_get_info('$2y$11$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y')); - - $expected = array( - 'algo' => 0, - 'algoName' => 'unknown', - 'options' => array() - ); - - // invalid length - $this->assertEquals($expected, password_get_info('$2y$11$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100')); - - // non-bcrypt - $this->assertEquals($expected, password_get_info('$1$rasmusle$rISCgZzpwk3UhDidwXvin0')); - } - - // ------------------------------------------------------------------------ - - /** - * password_hash() test - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_password_hash() - { - // FALSE is returned if no CSPRNG source is available - if ( ! defined('MCRYPT_DEV_URANDOM') && ! function_exists('openssl_random_pseudo_bytes') - && (DIRECTORY_SEPARATOR !== '/' OR ! is_readable('/dev/arandom') OR ! is_readable('/dev/urandom')) - ) - { - $this->assertFalse(password_hash('foo', PASSWORD_BCRYPT)); - } - else - { - $this->assertEquals(60, strlen(password_hash('foo', PASSWORD_BCRYPT))); - $this->assertTrue(($hash = password_hash('foo', PASSWORD_BCRYPT)) === crypt('foo', $hash)); - } - - $this->assertEquals( - '$2y$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi', - password_hash('rasmuslerdorf', PASSWORD_BCRYPT, array('cost' => 7, 'salt' => 'usesomesillystringforsalt')) - ); - - $this->assertEquals( - '$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', - password_hash('test', PASSWORD_BCRYPT, array('salt' => '123456789012345678901'.chr(0))) - ); - } - - // ------------------------------------------------------------------------ - - /** - * password_needs_rehash() test - * - * Borrowed from PHP's own tests - * - * @depends test_password_get_info - */ - public function test_password_needs_rehash() - { - // invalid hash: always rehash - $this->assertTrue(password_needs_rehash('', PASSWORD_BCRYPT)); - - // valid, because it's an unknown algorithm - $this->assertFalse(password_needs_rehash('', 0)); - - // valid with same cost - $this->assertFalse(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10))); - - // valid with same cost and additional parameters - $this->assertFalse(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 10, 'foo' => 3))); - - // invalid: different (lower) cost - $this->assertTrue(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 9))); - - // invalid: different (higher) cost - $this->assertTrue(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 11))); - - // valid with default cost - $this->assertFalse(password_needs_rehash('$2y$'.str_pad(10, 2, '0', STR_PAD_LEFT).'$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT)); - - // invalid: 'foo' is cast to 0 - $this->assertTrue(password_needs_rehash('$2y$10$MTIzNDU2Nzg5MDEyMzQ1Nej0NmcAWSLR.oP7XOR9HD/vjUuOj100y', PASSWORD_BCRYPT, array('cost' => 'foo'))); - } - - // ------------------------------------------------------------------------ - - /** - * password_verify() test - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_password_verify() - { - $this->assertFalse(password_verify(123, 123)); - $this->assertFalse(password_verify('foo', '$2a$07$usesomesillystringforsalt$')); - $this->assertFalse(password_verify('rasmusler', '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi')); - $this->assertTrue(password_verify('rasmuslerdorf', '$2a$07$usesomesillystringfore2uDLvp1Ii2e./U9C8sBjqp8I90dH6hi')); - } - -} diff --git a/tests/codeigniter/core/compat/standard_test.php b/tests/codeigniter/core/compat/standard_test.php deleted file mode 100644 index a98460129..000000000 --- a/tests/codeigniter/core/compat/standard_test.php +++ /dev/null @@ -1,378 +0,0 @@ -markTestSkipped('All array functions are already available on PHP 5.5'); - } - - $this->assertTrue(function_exists('array_column')); - - if ( ! is_php('5.4')) - { - $this->assertTrue(function_exists('hex2bin')); - } - } - - // ------------------------------------------------------------------------ - - /** - * array_column() test - * - * Borrowed from PHP's own tests - * - * @depends test_bootstrap - */ - public function test_array_column() - { - // Basic tests - - $input = array( - array( - 'id' => 1, - 'first_name' => 'John', - 'last_name' => 'Doe' - ), - array( - 'id' => 2, - 'first_name' => 'Sally', - 'last_name' => 'Smith' - ), - array( - 'id' => 3, - 'first_name' => 'Jane', - 'last_name' => 'Jones' - ) - ); - - // Ensure internal array position doesn't break it - next($input); - - $this->assertEquals( - array('John', 'Sally', 'Jane'), - array_column($input, 'first_name') - ); - - $this->assertEquals( - array(1, 2, 3), - array_column($input, 'id') - ); - - $this->assertEquals( - array( - 1 => 'Doe', - 2 => 'Smith', - 3 => 'Jones' - ), - array_column($input, 'last_name', 'id') - ); - - $this->assertEquals( - array( - 'John' => 'Doe', - 'Sally' => 'Smith', - 'Jane' => 'Jones' - ), - array_column($input, 'last_name', 'first_name') - ); - - // Object key search - - $f = new Foo(); - $b = new Bar(); - - $this->assertEquals( - array('Doe', 'Smith', 'Jones'), - array_column($input, $f) - ); - - $this->assertEquals( - array( - 'John' => 'Doe', - 'Sally' => 'Smith', - 'Jane' => 'Jones' - ), - array_column($input, $f, $b) - ); - - // NULL parameters - - $input = array( - 456 => array( - 'id' => '3', - 'title' => 'Foo', - 'date' => '2013-03-25' - ), - 457 => array( - 'id' => '5', - 'title' => 'Bar', - 'date' => '2012-05-20' - ) - ); - - $this->assertEquals( - array( - 3 => array( - 'id' => '3', - 'title' => 'Foo', - 'date' => '2013-03-25' - ), - 5 => array( - 'id' => '5', - 'title' => 'Bar', - 'date' => '2012-05-20' - ) - ), - array_column($input, NULL, 'id') - ); - - $this->assertEquals( - array( - array( - 'id' => '3', - 'title' => 'Foo', - 'date' => '2013-03-25' - ), - array( - 'id' => '5', - 'title' => 'Bar', - 'date' => '2012-05-20' - ) - ), - array_column($input, NULL, 'foo') - ); - - $this->assertEquals( - array( - array( - 'id' => '3', - 'title' => 'Foo', - 'date' => '2013-03-25' - ), - array( - 'id' => '5', - 'title' => 'Bar', - 'date' => '2012-05-20' - ) - ), - array_column($input, NULL) - ); - - // Data types - - $fh = fopen(__FILE__, 'r', TRUE); - $stdClass = new stdClass(); - $input = array( - array( - 'id' => 1, - 'value' => $stdClass - ), - array( - 'id' => 2, - 'value' => 34.2345 - ), - array( - 'id' => 3, - 'value' => TRUE - ), - array( - 'id' => 4, - 'value' => FALSE - ), - array( - 'id' => 5, - 'value' => NULL - ), - array( - 'id' => 6, - 'value' => 1234 - ), - array( - 'id' => 7, - 'value' => 'Foo' - ), - array( - 'id' => 8, - 'value' => $fh - ) - ); - - $this->assertEquals( - array( - $stdClass, - 34.2345, - TRUE, - FALSE, - NULL, - 1234, - 'Foo', - $fh - ), - array_column($input, 'value') - ); - - $this->assertEquals( - array( - 1 => $stdClass, - 2 => 34.2345, - 3 => TRUE, - 4 => FALSE, - 5 => NULL, - 6 => 1234, - 7 => 'Foo', - 8 => $fh - ), - array_column($input, 'value', 'id') - ); - - // Numeric column keys - - $input = array( - array('aaa', '111'), - array('bbb', '222'), - array('ccc', '333', -1 => 'ddd') - ); - - $this->assertEquals( - array('111', '222', '333'), - array_column($input, 1) - ); - - $this->assertEquals( - array( - 'aaa' => '111', - 'bbb' => '222', - 'ccc' => '333' - ), - array_column($input, 1, 0) - ); - - $this->assertEquals( - array( - 'aaa' => '111', - 'bbb' => '222', - 'ccc' => '333' - ), - array_column($input, 1, 0.123) - ); - - $this->assertEquals( - array( - 0 => '111', - 1 => '222', - 'ddd' => '333' - ), - array_column($input, 1, -1) - ); - - // Non-existing columns - - $this->assertEquals(array(), array_column($input, 2)); - $this->assertEquals(array(), array_column($input, 'foo')); - $this->assertEquals( - array('aaa', 'bbb', 'ccc'), - array_column($input, 0, 'foo') - ); - $this->assertEquals(array(), array_column($input, 3.14)); - - // One-dimensional array - $this->assertEquals(array(), array_column(array('foo', 'bar', 'baz'), 1)); - - // Columns not present in all rows - - $input = array( - array('a' => 'foo', 'b' => 'bar', 'e' => 'bbb'), - array('a' => 'baz', 'c' => 'qux', 'd' => 'aaa'), - array('a' => 'eee', 'b' => 'fff', 'e' => 'ggg') - ); - - $this->assertEquals( - array('qux'), - array_column($input, 'c') - ); - - $this->assertEquals( - array('baz' => 'qux'), - array_column($input, 'c', 'a') - ); - - $this->assertEquals( - array( - 0 => 'foo', - 'aaa' => 'baz', - 1 => 'eee' - ), - array_column($input, 'a', 'd') - ); - - $this->assertEquals( - array( - 'bbb' => 'foo', - 0 => 'baz', - 'ggg' => 'eee' - ), - array_column($input, 'a', 'e') - ); - - $this->assertEquals( - array('bar', 'fff'), - array_column($input, 'b') - ); - - $this->assertEquals( - array( - 'foo' => 'bar', - 'eee' => 'fff' - ), - array_column($input, 'b', 'a') - ); - } - - // ------------------------------------------------------------------------ - - /** - * hex2bin() tests - * - * @depends test_bootstrap - */ - public function test_hex2bin() - { - if (is_php('5.4')) - { - return $this->markTestSkipped('hex2bin() is already available on PHP 5.4'); - } - - $this->assertEquals("\x03\x04", hex2bin("0304")); - $this->assertEquals('', hex2bin('')); - $this->assertEquals("\x01\x02\x03", hex2bin(new FooHex())); - } -} - -// ------------------------------------------------------------------------ - -class Foo { - - public function __toString() - { - return 'last_name'; - } -} - -class Bar { - - public function __toString() - { - return 'first_name'; - } -} - -class FooHex { - - public function __toString() - { - return '010203'; - } -} -- cgit v1.2.3-24-g4f1b