Skip to content

Commit 68fe0bf

Browse files
authored
Merge branch 'main' into feature/silverstripe-5.x-compatibility
2 parents 2839e51 + 255f511 commit 68fe0bf

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

.github/workflows/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Module CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 1 * *'
8+
9+
jobs:
10+
ci:
11+
name: CI
12+
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
13+
with:
14+
endtoend: false
15+
phpcoverage_force_off: true
16+
js: false

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.phpunit.result.cache
3+
/vendor/
4+
/resources
5+
/app
6+
/themes
7+
.test-output
8+
/composer.lock
9+
*.log

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# silverstripe-encrypt-at-rest
22

3+
![github actions](https://github.com/madmatt/silverstripe-encrypt-at-rest/actions/workflows/main.yml/badge.svg)
4+
35
This module allows Silverstripe CMS ORM data to be encrypted before being stored in the database, and automatically decrypted before using within your application. To do this, we use a secret key known only by the web server.
46

57

composer.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"source": "https://github.com/madmatt/silverstripe-encrypt-at-rest"
1717
},
1818
"require": {
19+
"php": "^8.0",
1920
"silverstripe/framework": "^5",
2021
"defuse/php-encryption": "^2.2"
2122
},
@@ -29,5 +30,11 @@
2930
}
3031
},
3132
"minimum-stability": "dev",
32-
"prefer-stable": true
33+
"prefer-stable": true,
34+
"config": {
35+
"allow-plugins": {
36+
"composer/installers": true,
37+
"silverstripe/vendor-plugin": true
38+
}
39+
}
3340
}

phpunit.xml.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage includeUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
<exclude>
8+
<directory suffix=".php">tests/</directory>
9+
</exclude>
10+
</coverage>
11+
<php>
12+
<!-- An example key for testing purposes, created with vendor/bin/generate-defuse-key -->
13+
<env name="ENCRYPT_AT_REST_KEY" value="def000001ae7b3baf85422b623b0c0236d5c5c389049b4a277a413a2481fd4ebbc153cdf3c52bd3f97e599ca5094e04e52c3cebbab039d7514fa2e449794fdd1217c0ce9" />
14+
</php>
15+
<testsuite name="silverstripe-encrypt-at-rest">
16+
<directory>tests/</directory>
17+
</testsuite>
18+
</phpunit>

tests/AtRestCryptoServiceTest.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public function testEncryptFile($filename, $contents, $visibility)
7474
? $assetStore->getProtectedFilesystem()->getAdapter()
7575
: $assetStore->getPublicFilesystem()->getAdapter();
7676

77+
// Check for existence of $adaptor->prefixPath() showing we are using SS5.0+
78+
$prefixPath = 'applyPathPrefix';
79+
if (method_exists($adapter, 'prefixPath')) {
80+
$prefixPath = 'prefixPath';
81+
}
82+
7783
$file = File::create();
7884
$file->setFromString($originalText, $originalFilename);
7985
$file->write();
@@ -84,7 +90,7 @@ public function testEncryptFile($filename, $contents, $visibility)
8490
$file->publishFile();
8591
}
8692

87-
$oldFilename = $adapter->prefixPath(
93+
$oldFilename = $adapter->$prefixPath(
8894
$strategy->buildFileID(
8995
new ParsedFileID(
9096
$file->getFilename(),
@@ -116,7 +122,7 @@ public function testEncryptFile($filename, $contents, $visibility)
116122
// Confirm the old file has been deleted
117123
$this->assertFileDoesNotExist($oldFilename);
118124

119-
$encryptedFilename = $adapter->prefixPath(
125+
$encryptedFilename = $adapter->$prefixPath(
120126
$strategy->buildFileID(
121127
new ParsedFileID(
122128
$encryptedFile->getFilename(),
@@ -144,7 +150,7 @@ public function testEncryptFile($filename, $contents, $visibility)
144150

145151
// Now decrypt the file back
146152
$decryptedFile = $service->decryptFile($encryptedFile, null, $visibility);
147-
$decryptedFilename = $adapter->prefixPath(
153+
$decryptedFilename = $adapter->$prefixPath(
148154
$strategy->buildFileID(
149155
new ParsedFileID(
150156
$decryptedFile->getFilename(),

0 commit comments

Comments
 (0)