Merge pull request #813 from binxio/persistence-into-data
removed json encoding from get/setValue
This commit is contained in:
commit
b72994f2e0
@ -253,14 +253,12 @@ class GoogleCloudStorage extends AbstractData
|
|||||||
$key = 'config/' . $namespace . '/' . $key;
|
$key = 'config/' . $namespace . '/' . $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = Json::encode($value);
|
|
||||||
|
|
||||||
$metadata = array('namespace' => $namespace);
|
$metadata = array('namespace' => $namespace);
|
||||||
if ($namespace != 'salt') {
|
if ($namespace != 'salt') {
|
||||||
$metadata['value'] = strval($value);
|
$metadata['value'] = strval($value);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$this->_bucket->upload($data, array(
|
$this->_bucket->upload($value, array(
|
||||||
'name' => $key,
|
'name' => $key,
|
||||||
'chunkSize' => 262144,
|
'chunkSize' => 262144,
|
||||||
'predefinedAcl' => 'private',
|
'predefinedAcl' => 'private',
|
||||||
@ -288,9 +286,8 @@ class GoogleCloudStorage extends AbstractData
|
|||||||
$key = 'config/' . $namespace . '/' . $key;
|
$key = 'config/' . $namespace . '/' . $key;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
$o = $this->_bucket->object($key);
|
$o = $this->_bucket->object($key);
|
||||||
$data = $o->downloadAsString();
|
return $o->downloadAsString();
|
||||||
return (string) Json::decode($data);
|
|
||||||
} catch (NotFoundException $e) {
|
} catch (NotFoundException $e) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -143,20 +143,21 @@ class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$client = hash_hmac('sha512', '127.0.0.1', $salt);
|
$client = hash_hmac('sha512', '127.0.0.1', $salt);
|
||||||
$expire = time();
|
$expire = time();
|
||||||
$this->_model->setValue($expire, 'traffic_limiter', $client);
|
$this->_model->setValue(strval($expire), 'traffic_limiter', $client);
|
||||||
$storedExpired = $this->_model->getValue('traffic_limiter', $client);
|
$storedExpired = $this->_model->getValue('traffic_limiter', $client);
|
||||||
$this->assertEquals($expire, $storedExpired);
|
$this->assertEquals(strval($expire), $storedExpired);
|
||||||
$this->assertEquals($expire, $storedExpired);
|
|
||||||
$this->_model->purgeValues('traffic_limiter', time() - 60);
|
$this->_model->purgeValues('traffic_limiter', time() - 60);
|
||||||
$this->assertEquals($storedExpired, $this->_model->getValue('traffic_limiter', $client));
|
$this->assertEquals($storedExpired, $this->_model->getValue('traffic_limiter', $client));
|
||||||
$this->_model->purgeValues('traffic_limiter', time() + 60);
|
$this->_model->purgeValues('traffic_limiter', time() + 60);
|
||||||
$this->assertEquals('', $this->_model->getValue('traffic_limiter', $client));
|
$this->assertEquals('', $this->_model->getValue('traffic_limiter', $client));
|
||||||
|
|
||||||
$purgeAt = $expire + (15 * 60);
|
$purgeAt = $expire + (15 * 60);
|
||||||
$this->_model->setValue($purgeAt, 'purge_limiter', '');
|
$this->_model->setValue(strval($purgeAt), 'purge_limiter', '');
|
||||||
$storedPurgedAt = $this->_model->getValue('purge_limiter', '');
|
$storedPurgedAt = $this->_model->getValue('purge_limiter', '');
|
||||||
$this->assertEquals($purgeAt, $storedPurgedAt);
|
$this->assertEquals(strval($purgeAt), $storedPurgedAt);
|
||||||
$this->_model->purgeValues('purge_limiter', time() + 60);
|
$this->_model->purgeValues('purge_limiter', $purgeAt + 60);
|
||||||
|
$this->assertEquals('', $this->_model->getValue('purge_limiter', ''));
|
||||||
$this->assertEquals('', $this->_model->getValue('purge_limiter', 'at'));
|
$this->assertEquals('', $this->_model->getValue('purge_limiter', 'at'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,25 +169,9 @@ class GoogleCloudStorageTest extends PHPUnit_Framework_TestCase
|
|||||||
$salt = bin2hex(random_bytes(256));
|
$salt = bin2hex(random_bytes(256));
|
||||||
$client = hash_hmac('sha512', '127.0.0.1', $salt);
|
$client = hash_hmac('sha512', '127.0.0.1', $salt);
|
||||||
$expire = time();
|
$expire = time();
|
||||||
$this->_model->setValue($expire, 'traffic_limiter', $client);
|
$this->_model->setValue(strval($expire), 'traffic_limiter', $client);
|
||||||
$storedExpired = $this->_model->getValue('traffic_limiter', $client);
|
$storedExpired = $this->_model->getValue('traffic_limiter', $client);
|
||||||
$this->assertEquals($expire, $storedExpired);
|
$this->assertEquals(strval($expire), $storedExpired);
|
||||||
|
|
||||||
$this->_model->purgeValues('traffic_limiter', time() - 60);
|
|
||||||
$this->assertEquals($storedExpired, $this->_model->getValue('traffic_limiter', $client));
|
|
||||||
|
|
||||||
$this->_model->purgeValues('traffic_limiter', time() + 60);
|
|
||||||
$this->assertEquals('', $this->_model->getValue('traffic_limiter', $client));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testKeyValuePurgeTrafficLimiterWithKey()
|
|
||||||
{
|
|
||||||
$salt = bin2hex(random_bytes(256));
|
|
||||||
$client = hash_hmac('sha512', '127.0.0.1', $salt);
|
|
||||||
$expire = time();
|
|
||||||
$this->_model->setValue($expire, 'traffic_limiter', $client);
|
|
||||||
$storedExpired = $this->_model->getValue('traffic_limiter', $client);
|
|
||||||
$this->assertEquals($expire, $storedExpired);
|
|
||||||
|
|
||||||
$this->_model->purgeValues('traffic_limiter', time() - 60);
|
$this->_model->purgeValues('traffic_limiter', time() - 60);
|
||||||
$this->assertEquals($storedExpired, $this->_model->getValue('traffic_limiter', $client));
|
$this->assertEquals($storedExpired, $this->_model->getValue('traffic_limiter', $client));
|
||||||
|
Loading…
Reference in New Issue
Block a user