From: Thiemo Mättig Date: Wed, 28 Oct 2015 15:26:37 +0000 (+0100) Subject: Add tests for MemcachedBagOStuff::validateKeyEncoding X-Git-Tag: 1.31.0-rc.0~9147^2~1 X-Git-Url: https://git.cyclocoop.org/%7B%7B%20url_for%28%27user_edit%27%2C%20userid=session.user.id%29%20%7D%7D?a=commitdiff_plain;h=e6cf3aa0b3bc4c6200616e11aba7a0a0a3481d4c;p=lhc%2Fweb%2Fwiklou.git Add tests for MemcachedBagOStuff::validateKeyEncoding If3e20c6 and the following patches introduced a breaking change and cause a regression in Wikibase because we are using the version number constant as part of a cache key prefix. Currently the Wikibase version is set to "0.5 alpha". Space characters were allowed before and encoded as "%20". This does not happen any more. Change-Id: Ia2fd4ed6738a10e02050bced947ef5d4e8b98980 --- diff --git a/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php b/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php index b0c9e4f389..3e3bac37cb 100644 --- a/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php +++ b/tests/phpunit/includes/objectcache/MemcachedBagOStuffTest.php @@ -12,7 +12,7 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase { } /** - * @covers MemcachedBagOStuff::makeKeyInternal + * @covers MemcachedBagOStuff::makeKey */ public function testKeyNormalization() { $this->assertEquals( @@ -67,4 +67,39 @@ class MemcachedBagOStuffTest extends MediaWikiTestCase { $this->cache->makeKey( 'long_key_part_hashed', str_repeat( 'y', 500 ) ) ); } + + /** + * @dataProvider validKeyProvider + */ + public function testValidateKeyEncoding( $key ) { + $this->assertSame( $key, $this->cache->validateKeyEncoding( $key ) ); + } + + public function validKeyProvider() { + return array( + 'empty' => array( '' ), + 'digits' => array( '09' ), + 'letters' => array( 'AZaz' ), + 'ASCII special characters' => array( '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' ), + ); + } + + /** + * @dataProvider invalidKeyProvider + */ + public function testValidateKeyEncodingThrowsException( $key ) { + $this->setExpectedException( 'Exception' ); + $this->cache->validateKeyEncoding( $key ); + } + + public function invalidKeyProvider() { + return array( + array( "\x00" ), + array( ' ' ), + array( "\x1F" ), + array( "\x7F" ), + array( "\x80" ), + array( "\xFF" ), + ); + } }