diff options
author | VirtualTam <virtualtam@flibidi.net> | 2015-11-11 22:49:58 +0100 |
---|---|---|
committer | VirtualTam <virtualtam@flibidi.net> | 2015-11-24 01:12:35 +0100 |
commit | 2e28269baed195d58bbe169841eed176b171db76 (patch) | |
tree | f743e785edf708454ab53efa13f38e35f10447e6 /tests/ApplicationUtilsTest.php | |
parent | c580024cfbe5f0d290b09157b9665d1b4131d7f4 (diff) | |
download | Shaarli-2e28269baed195d58bbe169841eed176b171db76.tar.gz Shaarli-2e28269baed195d58bbe169841eed176b171db76.tar.zst Shaarli-2e28269baed195d58bbe169841eed176b171db76.zip |
install: check file/directory permissions for Shaarli resources
Relates to #40
Relates to #372
Additions:
- FileUtils: IOException
- ApplicationUtils:
- check if Shaarli resources are accessible with sufficient permissions
- basic test coverage
- index.php:
- check access permissions and redirect to an error page if needed:
- before running the first installation
Modifications:
- LinkDB:
- factorize datastore write code
- check if the datastore
(exists AND is writeable) OR (doesn't exist AND its parent dir is writable)
- raise an IOException if needed
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'tests/ApplicationUtilsTest.php')
-rw-r--r-- | tests/ApplicationUtilsTest.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/ApplicationUtilsTest.php b/tests/ApplicationUtilsTest.php new file mode 100644 index 00000000..9a99c6c6 --- /dev/null +++ b/tests/ApplicationUtilsTest.php | |||
@@ -0,0 +1,69 @@ | |||
1 | <?php | ||
2 | /** | ||
3 | * ApplicationUtils' tests | ||
4 | */ | ||
5 | |||
6 | require_once 'application/ApplicationUtils.php'; | ||
7 | |||
8 | |||
9 | /** | ||
10 | * Unitary tests for Shaarli utilities | ||
11 | */ | ||
12 | class ApplicationUtilsTest extends PHPUnit_Framework_TestCase | ||
13 | { | ||
14 | /** | ||
15 | * Checks resource permissions for the current Shaarli installation | ||
16 | */ | ||
17 | public function testCheckCurrentResourcePermissions() | ||
18 | { | ||
19 | $config = array( | ||
20 | 'CACHEDIR' => 'cache', | ||
21 | 'CONFIG_FILE' => 'data/config.php', | ||
22 | 'DATADIR' => 'data', | ||
23 | 'DATASTORE' => 'data/datastore.php', | ||
24 | 'IPBANS_FILENAME' => 'data/ipbans.php', | ||
25 | 'LOG_FILE' => 'data/log.txt', | ||
26 | 'PAGECACHE' => 'pagecache', | ||
27 | 'RAINTPL_TMP' => 'tmp', | ||
28 | 'RAINTPL_TPL' => 'tpl', | ||
29 | 'UPDATECHECK_FILENAME' => 'data/lastupdatecheck.txt' | ||
30 | ); | ||
31 | $this->assertEquals( | ||
32 | array(), | ||
33 | ApplicationUtils::checkResourcePermissions($config) | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | /** | ||
38 | * Checks resource permissions for a non-existent Shaarli installation | ||
39 | */ | ||
40 | public function testCheckCurrentResourcePermissionsErrors() | ||
41 | { | ||
42 | $config = array( | ||
43 | 'CACHEDIR' => 'null/cache', | ||
44 | 'CONFIG_FILE' => 'null/data/config.php', | ||
45 | 'DATADIR' => 'null/data', | ||
46 | 'DATASTORE' => 'null/data/store.php', | ||
47 | 'IPBANS_FILENAME' => 'null/data/ipbans.php', | ||
48 | 'LOG_FILE' => 'null/data/log.txt', | ||
49 | 'PAGECACHE' => 'null/pagecache', | ||
50 | 'RAINTPL_TMP' => 'null/tmp', | ||
51 | 'RAINTPL_TPL' => 'null/tpl', | ||
52 | 'UPDATECHECK_FILENAME' => 'null/data/lastupdatecheck.txt' | ||
53 | ); | ||
54 | $this->assertEquals( | ||
55 | array( | ||
56 | '"null/tpl" directory is not readable', | ||
57 | '"null/cache" directory is not readable', | ||
58 | '"null/cache" directory is not writable', | ||
59 | '"null/data" directory is not readable', | ||
60 | '"null/data" directory is not writable', | ||
61 | '"null/pagecache" directory is not readable', | ||
62 | '"null/pagecache" directory is not writable', | ||
63 | '"null/tmp" directory is not readable', | ||
64 | '"null/tmp" directory is not writable' | ||
65 | ), | ||
66 | ApplicationUtils::checkResourcePermissions($config) | ||
67 | ); | ||
68 | } | ||
69 | } | ||