Skip to content

Commit e13bedf

Browse files
committed
update
1 parent 766f49f commit e13bedf

4 files changed

Lines changed: 61 additions & 24 deletions

File tree

‎src/Encryption.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public function getAvailableMethods(): array
8686
$methods = array_merge($ciphers, $cipherAliases);
8787

8888
$methods = array_filter($methods, function ($c) {
89-
return $c !== 'AES-128-CBC-HMAC-SHA1';
89+
return !in_array($c, ['AES-128-CBC-HMAC-SHA1', 'AES-256-CBC-HMAC-SHA1'], true);
9090
});
91-
91+
9292
return $methods;
9393
}
9494

‎tests/DefaultEncryptionTest.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class DefaultEncryptionTest extends TestCase
1616
private function foundSessionFile()
1717
{
1818
$path = ini_get('session.save_path');
19+
if (empty($path)) {
20+
$path = DIRECTORY_SEPARATOR . 'tmp';
21+
}
1922
$id = session_id();
2023

2124
$files = scandir($path);
@@ -46,7 +49,7 @@ public function testWrite()
4649
$encryptionTrait->setKey('randomKey');
4750
$endData = $encryptionTrait->decrypt($data);
4851
var_dump($endData);
49-
static::assertEquals('b', $endData['a']);
52+
static::assertEquals('a|s:1:"b";', $endData);
5053
}
5154

5255
/*
@@ -58,7 +61,7 @@ public function testRead()
5861
$data = $defaultEncryption->read($sessionId);
5962
static::assertTrue(!empty($data));
6063
static::assertTrue(is_string($data));
61-
64+
6265
$sessionId = '';
6366
$data = $defaultEncryption->read($sessionId);
6467
static::assertTrue(empty($data));

‎tests/FileEncryptionTest.php‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,35 @@
1212
*/
1313
class FileEncryptionTest extends TestCase
1414
{
15-
public static function setUpBeforeClass()
15+
private function getPath()
1616
{
17-
if (file_exists(__DIR__ . '/toto')) {
18-
rmdir(__DIR__ . '/toto');
17+
$path = ini_get('session.save_path');
18+
if (empty($path)) {
19+
return DIRECTORY_SEPARATOR . 'tmp';
1920
}
21+
22+
return $path;
2023
}
2124

22-
public static function setUpAfterClass()
25+
private function openSessionForSavingSavePath(FileEncryption $fileEncryption)
2326
{
24-
if (file_exists(__DIR__ . '/toto')) {
25-
rmdir(__DIR__ . '/toto');
26-
}
27+
$success = $fileEncryption->open($this->getPath(), '');
28+
static::assertTrue($success);
2729
}
2830

2931
public function testOpen()
3032
{
3133
$fileEncryption = new FileEncryption();
3234
$fileEncryption->setKey('randomKey');
33-
$savePath = __DIR__;
35+
36+
$savePath = $this->getPath();
3437
$sessionName = '';
3538
$success = $fileEncryption->open($savePath, $sessionName);
3639
static::assertTrue($success);
3740

38-
$success = $fileEncryption->open($savePath . '/toto', $sessionName);
41+
$success = $fileEncryption->open($savePath . '/tests', $sessionName);
3942
static::assertTrue($success);
40-
$success = file_exists($savePath . '/toto');
43+
$success = file_exists($savePath . '/tests');
4144
static::assertTrue($success);
4245
}
4346

@@ -53,6 +56,9 @@ public function testWrite()
5356
{
5457
$fileEncryption = new FileEncryption();
5558
$fileEncryption->setKey('randomKey');
59+
60+
$this->openSessionForSavingSavePath($fileEncryption);
61+
5662
$sessionId = 'test';
5763
$data = 'azerty';
5864
$success = $fileEncryption->write($sessionId, $data);
@@ -63,6 +69,9 @@ public function testRead()
6369
{
6470
$fileEncryption = new FileEncryption();
6571
$fileEncryption->setKey('randomKey');
72+
73+
$this->openSessionForSavingSavePath($fileEncryption);
74+
6675
$sessionId = 'test';
6776
$data = $fileEncryption->read($sessionId);
6877
static::assertTrue(!empty($data));
@@ -78,13 +87,19 @@ public function testDestroy()
7887
{
7988
$fileEncryption = new FileEncryption();
8089
$fileEncryption->setKey('randomKey');
90+
91+
$this->openSessionForSavingSavePath($fileEncryption);
92+
8193
$sessionId = 'todelete';
8294
$data = '';
8395
$success = $fileEncryption->write($sessionId, $data);
8496
static::assertTrue($success);
8597

8698
$fileEncryption = new FileEncryption();
8799
$fileEncryption->setKey('randomKey');
100+
101+
$this->openSessionForSavingSavePath($fileEncryption);
102+
88103
$sessionId = 'todelete';
89104
$fileEncryption->destroy($sessionId);
90105
static::assertTrue(true);
@@ -94,6 +109,9 @@ public function testGc()
94109
{
95110
$fileEncryption = new FileEncryption();
96111
$fileEncryption->setKey('randomKey');
112+
113+
$this->openSessionForSavingSavePath($fileEncryption);
114+
97115
$lifetime = -1000;
98116
$fileEncryption->gc($lifetime);
99117
static::assertTrue(true);

‎tests/FileTest.php‎

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,33 @@
1212
*/
1313
class FileTest extends TestCase
1414
{
15-
public static function setUpBeforeClass()
15+
private function getPath()
1616
{
17-
if (file_exists(__DIR__ . '/toto')) {
18-
rmdir(__DIR__ . '/toto');
17+
$path = ini_get('session.save_path');
18+
if (empty($path)) {
19+
return DIRECTORY_SEPARATOR . 'tmp';
1920
}
21+
22+
return $path;
2023
}
2124

22-
public static function setUpAfterClass()
25+
private function openSessionForSavingSavePath(File $file)
2326
{
24-
if (file_exists(__DIR__ . '/toto')) {
25-
rmdir(__DIR__ . '/toto');
26-
}
27+
$success = $file->open($this->getPath(), '');
28+
static::assertTrue($success);
2729
}
2830

2931
public function testOpen()
3032
{
3133
$file = new File();
32-
$savePath = __DIR__;
34+
$savePath = $this->getPath();
3335
$sessionName = '';
3436
$success = $file->open($savePath, $sessionName);
3537
static::assertTrue($success);
3638

37-
$success = $file->open($savePath . '/toto', $sessionName);
39+
$success = $file->open($savePath . '/tests', $sessionName);
3840
static::assertTrue($success);
39-
$success = file_exists($savePath . '/toto');
41+
$success = file_exists($savePath . '/tests');
4042
static::assertTrue($success);
4143
}
4244

@@ -50,6 +52,9 @@ public function testClose()
5052
public function testWrite()
5153
{
5254
$file = new File();
55+
56+
$this->openSessionForSavingSavePath($file);
57+
5358
$sessionId = 'test';
5459
$data = 'azerty';
5560
$success = $file->write($sessionId, $data);
@@ -59,6 +64,9 @@ public function testWrite()
5964
public function testRead()
6065
{
6166
$file = new File();
67+
68+
$this->openSessionForSavingSavePath($file);
69+
6270
$sessionId = 'test';
6371
$data = $file->read($sessionId);
6472
static::assertTrue(!empty($data));
@@ -73,12 +81,17 @@ public function testRead()
7381
public function testDestroy()
7482
{
7583
$file = new File();
84+
85+
$this->openSessionForSavingSavePath($file);
86+
7687
$sessionId = 'todelete';
7788
$data = '';
7889
$success = $file->write($sessionId, $data);
7990
static::assertTrue($success);
8091

8192
$file = new File();
93+
$this->openSessionForSavingSavePath($file);
94+
8295
$sessionId = 'todelete';
8396
$file->destroy($sessionId);
8497
static::assertTrue(true);
@@ -87,6 +100,9 @@ public function testDestroy()
87100
public function testGc()
88101
{
89102
$file = new File();
103+
104+
$this->openSessionForSavingSavePath($file);
105+
90106
$lifetime = -1000;
91107
$file->gc($lifetime);
92108
static::assertTrue(true);

0 commit comments

Comments
 (0)