Skip to content

Commit 255f511

Browse files
authored
Merge pull request #32 from silverstripeltd/task/add-github-actions-workflow
2 parents a44b789 + 2a33cce commit 255f511

File tree

6 files changed

+74
-15
lines changed

6 files changed

+74
-15
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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
"source": "https://github.com/madmatt/silverstripe-encrypt-at-rest"
1717
},
1818
"require": {
19+
"php": "^8.0",
1920
"silverstripe/framework": "^4.9.0",
2021
"defuse/php-encryption": "^2.2"
2122
},
2223
"require-dev": {
23-
"phpunit/phpunit": "^5.7"
24+
"phpunit/phpunit": "^9.6"
2425
},
2526
"autoload": {
2627
"psr-4": {
@@ -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: 20 additions & 13 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->applyPathPrefix(
93+
$oldFilename = $adapter->$prefixPath(
8894
$strategy->buildFileID(
8995
new ParsedFileID(
9096
$file->getFilename(),
@@ -102,9 +108,9 @@ public function testEncryptFile($filename, $contents, $visibility)
102108
$this->assertEquals($originalFilename, $file->getFilename());
103109

104110
if ($visibility === AssetStore::VISIBILITY_PROTECTED) {
105-
$this->assertContains('assets/.protected/', $oldFilename);
111+
$this->assertStringContainsString('assets/.protected/', $oldFilename);
106112
} elseif ($visibility === AssetStore::VISIBILITY_PUBLIC) {
107-
$this->assertNotContains('assets/.protected/', $oldFilename);
113+
$this->assertStringNotContainsString('assets/.protected/', $oldFilename);
108114
}
109115

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

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

119-
$encryptedFilename = $adapter->applyPathPrefix(
125+
$encryptedFilename = $adapter->$prefixPath(
120126
$strategy->buildFileID(
121127
new ParsedFileID(
122128
$encryptedFile->getFilename(),
@@ -130,20 +136,21 @@ public function testEncryptFile($filename, $contents, $visibility)
130136
$this->assertFileExists($encryptedFilename);
131137

132138
if ($visibility === AssetStore::VISIBILITY_PROTECTED) {
133-
$this->assertContains('assets/.protected/', $encryptedFilename);
139+
$this->assertStringContainsString('assets/.protected/', $encryptedFilename);
134140
} elseif ($visibility === AssetStore::VISIBILITY_PUBLIC) {
135-
$this->assertNotContains('assets/.protected/', $encryptedFilename);
141+
$this->assertStringNotContainsString('assets/.protected/', $encryptedFilename);
136142
}
137143

144+
$encryptedFileString = $encryptedFile->getString() ?: '';
138145
// Confirm the new file is encrypted
139-
$this->assertFalse(ctype_print($encryptedFile->getString()));
140-
$this->assertNotEquals($originalText, $encryptedFile->getString());
146+
$this->assertFalse(ctype_print($encryptedFileString));
147+
$this->assertNotEquals($originalText, $encryptedFileString);
141148
$this->assertEquals($originalFilename, $encryptedFile->Name);
142149
$this->assertEquals($originalFilename . '.enc', $file->getFilename());
143150

144151
// Now decrypt the file back
145152
$decryptedFile = $service->decryptFile($encryptedFile, null, $visibility);
146-
$decryptedFilename = $adapter->applyPathPrefix(
153+
$decryptedFilename = $adapter->$prefixPath(
147154
$strategy->buildFileID(
148155
new ParsedFileID(
149156
$decryptedFile->getFilename(),
@@ -160,16 +167,16 @@ public function testEncryptFile($filename, $contents, $visibility)
160167
$this->assertEquals($originalFilename, $decryptedFile->getFilename());
161168

162169
if ($visibility === AssetStore::VISIBILITY_PROTECTED) {
163-
$this->assertContains('assets/.protected/', $decryptedFilename);
170+
$this->assertStringContainsString('assets/.protected/', $decryptedFilename);
164171
} elseif ($visibility === AssetStore::VISIBILITY_PUBLIC) {
165-
$this->assertNotContains('assets/.protected/', $decryptedFilename);
172+
$this->assertStringNotContainsString('assets/.protected/', $decryptedFilename);
166173
}
167174

168175
// Confirm that original text has been decoded properly
169176
$this->assertEquals($originalText, $decryptedFile->getString());
170177

171178
// Confirm that encrypted file has been deleted
172-
$this->assertFileNotExists($encryptedFilename);
179+
$this->assertFileDoesNotExist($encryptedFilename);
173180
}
174181

175182
/**

0 commit comments

Comments
 (0)