Skip to content

Commit 2839e51

Browse files
committed
Updates for Silverstripe 5.x
Includes Unit test changes for PHPUnit 9.6
1 parent a44b789 commit 2839e51

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This module allows Silverstripe CMS ORM data to be encrypted before being stored
1010

1111

1212
## Requirements
13-
* SilverStripe CMS 4.9
13+
* SilverStripe CMS 5.0
1414

1515
## Installation
1616
Install via Composer:

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"source": "https://github.com/madmatt/silverstripe-encrypt-at-rest"
1717
},
1818
"require": {
19-
"silverstripe/framework": "^4.9.0",
19+
"silverstripe/framework": "^5",
2020
"defuse/php-encryption": "^2.2"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^5.7"
23+
"phpunit/phpunit": "^9.6"
2424
},
2525
"autoload": {
2626
"psr-4": {

src/AtRestCryptoService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected function getFullPath($file, $visibility = AssetStore::VISIBILITY_PROTE
182182
$fileID = rtrim($filename, '\\/');
183183
}
184184

185-
return $adapter->applyPathPrefix($fileID);
185+
return $adapter->prefixPath($fileID);
186186
}
187187

188188
}

src/Extension/DecryptDataObjectFieldsExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ class DecryptDataObjectFieldsExtension extends DataExtension
2626
* if so, we decrypt these and inject them into the object during hydration so that the rest of the application only
2727
* has to deal with the decrypted values everywhere.
2828
*
29-
* @param $record
3029
* @return array
3130
*/
32-
public function augmentHydrateFields($record)
31+
public function augmentHydrateFields()
3332
{
3433
// Look at $this->owner to determine if it has any encrypted database fields
3534
$schema = DataObject::getSchema();

tests/AtRestCryptoServiceTest.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testEncryptFile($filename, $contents, $visibility)
8484
$file->publishFile();
8585
}
8686

87-
$oldFilename = $adapter->applyPathPrefix(
87+
$oldFilename = $adapter->prefixPath(
8888
$strategy->buildFileID(
8989
new ParsedFileID(
9090
$file->getFilename(),
@@ -102,9 +102,9 @@ public function testEncryptFile($filename, $contents, $visibility)
102102
$this->assertEquals($originalFilename, $file->getFilename());
103103

104104
if ($visibility === AssetStore::VISIBILITY_PROTECTED) {
105-
$this->assertContains('assets/.protected/', $oldFilename);
105+
$this->assertStringContainsString('assets/.protected/', $oldFilename);
106106
} elseif ($visibility === AssetStore::VISIBILITY_PUBLIC) {
107-
$this->assertNotContains('assets/.protected/', $oldFilename);
107+
$this->assertStringNotContainsString('assets/.protected/', $oldFilename);
108108
}
109109

110110
/** @var AtRestCryptoService $service */
@@ -114,9 +114,9 @@ public function testEncryptFile($filename, $contents, $visibility)
114114
$this->assertEquals($originalFilename . '.enc', $encryptedFile->getFilename());
115115

116116
// Confirm the old file has been deleted
117-
$this->assertFileNotExists($oldFilename);
117+
$this->assertFileDoesNotExist($oldFilename);
118118

119-
$encryptedFilename = $adapter->applyPathPrefix(
119+
$encryptedFilename = $adapter->prefixPath(
120120
$strategy->buildFileID(
121121
new ParsedFileID(
122122
$encryptedFile->getFilename(),
@@ -130,20 +130,21 @@ public function testEncryptFile($filename, $contents, $visibility)
130130
$this->assertFileExists($encryptedFilename);
131131

132132
if ($visibility === AssetStore::VISIBILITY_PROTECTED) {
133-
$this->assertContains('assets/.protected/', $encryptedFilename);
133+
$this->assertStringContainsString('assets/.protected/', $encryptedFilename);
134134
} elseif ($visibility === AssetStore::VISIBILITY_PUBLIC) {
135-
$this->assertNotContains('assets/.protected/', $encryptedFilename);
135+
$this->assertStringNotContainsString('assets/.protected/', $encryptedFilename);
136136
}
137137

138+
$encryptedFileString = $encryptedFile->getString() ?: '';
138139
// Confirm the new file is encrypted
139-
$this->assertFalse(ctype_print($encryptedFile->getString()));
140-
$this->assertNotEquals($originalText, $encryptedFile->getString());
140+
$this->assertFalse(ctype_print($encryptedFileString));
141+
$this->assertNotEquals($originalText, $encryptedFileString);
141142
$this->assertEquals($originalFilename, $encryptedFile->Name);
142143
$this->assertEquals($originalFilename . '.enc', $file->getFilename());
143144

144145
// Now decrypt the file back
145146
$decryptedFile = $service->decryptFile($encryptedFile, null, $visibility);
146-
$decryptedFilename = $adapter->applyPathPrefix(
147+
$decryptedFilename = $adapter->prefixPath(
147148
$strategy->buildFileID(
148149
new ParsedFileID(
149150
$decryptedFile->getFilename(),
@@ -160,16 +161,16 @@ public function testEncryptFile($filename, $contents, $visibility)
160161
$this->assertEquals($originalFilename, $decryptedFile->getFilename());
161162

162163
if ($visibility === AssetStore::VISIBILITY_PROTECTED) {
163-
$this->assertContains('assets/.protected/', $decryptedFilename);
164+
$this->assertStringContainsString('assets/.protected/', $decryptedFilename);
164165
} elseif ($visibility === AssetStore::VISIBILITY_PUBLIC) {
165-
$this->assertNotContains('assets/.protected/', $decryptedFilename);
166+
$this->assertStringNotContainsString('assets/.protected/', $decryptedFilename);
166167
}
167168

168169
// Confirm that original text has been decoded properly
169170
$this->assertEquals($originalText, $decryptedFile->getString());
170171

171172
// Confirm that encrypted file has been deleted
172-
$this->assertFileNotExists($encryptedFilename);
173+
$this->assertFileDoesNotExist($encryptedFilename);
173174
}
174175

175176
/**

0 commit comments

Comments
 (0)