Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
d22795d6
Commit
d22795d6
authored
12 years ago
by
Florin Peter
Browse files
Options
Downloads
Patches
Plain Diff
fixed test for crypt and keymanager
disabled encryption file proxy in test/lib/cache/file.php
parent
c52fe125
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/files_encryption/test/crypt.php
+49
-38
49 additions, 38 deletions
apps/files_encryption/test/crypt.php
apps/files_encryption/test/keymanager.php
+25
-12
25 additions, 12 deletions
apps/files_encryption/test/keymanager.php
tests/lib/cache/file.php
+4
-3
4 additions, 3 deletions
tests/lib/cache/file.php
with
78 additions
and
53 deletions
apps/files_encryption/test/crypt.php
+
49
−
38
View file @
d22795d6
...
...
@@ -34,6 +34,8 @@ use OCA\Encryption;
class
Test_Crypt
extends
\PHPUnit_Framework_TestCase
{
function
setUp
()
{
// reset backend
\OC_User
::
useBackend
(
'database'
);
// set content for encrypting / decrypting in tests
$this
->
dataLong
=
file_get_contents
(
realpath
(
dirname
(
__FILE__
)
.
'/../lib/crypt.php'
)
);
...
...
@@ -54,13 +56,10 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
$this
->
pass
=
'admin'
;
$userHome
=
\OC_User
::
getHome
(
$this
->
userId
);
if
(
!
file_exists
(
$userHome
))
{
mkdir
(
$userHome
,
0777
,
true
);
}
$dataDir
=
str_replace
(
'/'
.
$this
->
userId
,
''
,
$userHome
);
$this
->
dataDir
=
str_replace
(
'/'
.
$this
->
userId
,
''
,
$userHome
);
\OC\Files\Filesystem
::
mount
(
'OC_Filestorage_Local'
,
array
(
'datadir'
=>
$dataDir
),
'/'
);
\OC\Files\Filesystem
::
init
(
$this
->
userId
,
'/'
);
\OC\Files\Filesystem
::
mount
(
'OC_Filestorage_Local'
,
array
(
'datadir'
=>
$this
->
dataDir
),
'/'
);
}
function
tearDown
()
{
...
...
@@ -234,9 +233,15 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Test that data was successfully written
$this
->
assertTrue
(
is_int
(
$cryptedFile
)
);
// Disable encryption proxy to prevent recursive calls
$proxyStatus
=
\OC_FileProxy
::
$enabled
;
\OC_FileProxy
::
$enabled
=
false
;
// Get file contents without using any wrapper to get it's actual contents on disk
$absolutePath
=
\OC\Files\Filesystem
::
getLocalFile
(
$this
->
userId
.
'/files/'
.
$filename
);
$retreivedCryptedFile
=
file_get_contents
(
$absolutePath
);
$retreivedCryptedFile
=
$this
->
view
->
file_get_contents
(
$this
->
userId
.
'/files/'
.
$filename
);
// Re-enable proxy - our work is done
\OC_FileProxy
::
$enabled
=
$proxyStatus
;
// Check that the file was encrypted before being written to disk
$this
->
assertNotEquals
(
$this
->
dataShort
,
$retreivedCryptedFile
);
...
...
@@ -262,6 +267,10 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Check that decrypted data matches
$this
->
assertEquals
(
$this
->
dataShort
,
$manualDecrypt
);
// Teardown
$this
->
view
->
unlink
(
$filename
);
Encryption\Keymanager
::
deleteFileKey
(
$this
->
view
,
$this
->
userId
,
$filename
);
}
/**
...
...
@@ -273,7 +282,7 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
function
testSymmetricStreamEncryptLongFileContent
()
{
// Generate a a random filename
$filename
=
'tmp-'
.
time
();
$filename
=
'tmp-'
.
time
()
.
'.test'
;
// Save long data as encrypted file using stream wrapper
$cryptedFile
=
file_put_contents
(
'crypt://'
.
$filename
,
$this
->
dataLong
.
$this
->
dataLong
);
...
...
@@ -281,10 +290,16 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Test that data was successfully written
$this
->
assertTrue
(
is_int
(
$cryptedFile
)
);
// Disable encryption proxy to prevent recursive calls
$proxyStatus
=
\OC_FileProxy
::
$enabled
;
\OC_FileProxy
::
$enabled
=
false
;
// Get file contents without using any wrapper to get it's actual contents on disk
$retreivedCryptedFile
=
$this
->
view
->
file_get_contents
(
$this
->
userId
.
'/files/'
.
$filename
);
// echo "\n\n\$retreivedCryptedFile = $retreivedCryptedFile\n\n";
// Re-enable proxy - our work is done
\OC_FileProxy
::
$enabled
=
$proxyStatus
;
// Check that the file was encrypted before being written to disk
$this
->
assertNotEquals
(
$this
->
dataLong
.
$this
->
dataLong
,
$retreivedCryptedFile
);
...
...
@@ -299,18 +314,20 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
//print_r($e);
// Get the encrypted keyfile
$encKeyfile
=
Encryption\Keymanager
::
getFileKey
(
$this
->
view
,
$this
->
userId
,
$filename
);
// Get private key
$encryptedPrivateKey
=
Encryption\Keymanager
::
getPrivateKey
(
$this
->
view
,
$this
->
userId
);
$decryptedPrivateKey
=
Encryption\Crypt
::
symmetricDecryptFileContent
(
$encryptedPrivateKey
,
$this
->
pass
);
// Attempt to fetch the user's shareKey
$shareKey
=
Encryption\Keymanager
::
getShareKey
(
$this
->
view
,
$this
->
userId
,
$filename
);
//
G
et
keyfile
$encryptedKeyfile
=
Encryption\Keymanager
::
getFileKey
(
$this
->
view
,
$this
->
userId
,
$filename
);
//
g
et
session
$session
=
new
Encryption\Session
(
$this
->
view
);
$decryptedKeyfile
=
Encryption\Crypt
::
keyDecrypt
(
$encryptedKeyfile
,
$decryptedPrivateKey
);
// get private key
$privateKey
=
$session
->
getPrivateKey
(
$this
->
userId
);
// Decrypt keyfile with shareKey
$plainKeyfile
=
Encryption\Crypt
::
multiKeyDecrypt
(
$encKeyfile
,
$shareKey
,
$privateKey
);
// Set var for reassembling decrypted content
$decrypt
=
''
;
...
...
@@ -318,19 +335,13 @@ class Test_Crypt extends \PHPUnit_Framework_TestCase {
// Manually decrypt chunk
foreach
(
$e
as
$e
)
{
// echo "\n\$e = $e";
$chunkDecrypt
=
Encryption\Crypt
::
symmetricDecryptFileContent
(
$e
,
$decryptedKeyfile
);
$chunkDecrypt
=
Encryption\Crypt
::
symmetricDecryptFileContent
(
$e
,
$plainKeyfile
);
// Assemble decrypted chunks
$decrypt
.
=
$chunkDecrypt
;
// echo "\n\$chunkDecrypt = $chunkDecrypt";
}
// echo "\n\$decrypt = $decrypt";
$this
->
assertEquals
(
$this
->
dataLong
.
$this
->
dataLong
,
$decrypt
);
// Teardown
...
...
This diff is collapsed.
Click to expand it.
apps/files_encryption/test/keymanager.php
+
25
−
12
View file @
d22795d6
...
...
@@ -24,6 +24,8 @@ use OCA\Encryption;
class
Test_Keymanager
extends
\PHPUnit_Framework_TestCase
{
function
setUp
()
{
// reset backend
\OC_User
::
useBackend
(
'database'
);
\OC_FileProxy
::
$enabled
=
false
;
...
...
@@ -45,8 +47,11 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$this
->
userId
=
'admin'
;
$this
->
pass
=
'admin'
;
\OC_Filesystem
::
init
(
'/'
);
\OC_Filesystem
::
mount
(
'OC_Filestorage_Local'
,
array
(
'datadir'
=>
\OC_User
::
getHome
(
$this
->
userId
)),
'/'
);
$userHome
=
\OC_User
::
getHome
(
$this
->
userId
);
$this
->
dataDir
=
str_replace
(
'/'
.
$this
->
userId
,
''
,
$userHome
);
\OC_Filesystem
::
init
(
$this
->
userId
,
'/'
);
\OC_Filesystem
::
mount
(
'OC_Filestorage_Local'
,
array
(
'datadir'
=>
$this
->
dataDir
),
'/'
);
}
...
...
@@ -61,7 +66,7 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$key
=
Encryption\Keymanager
::
getPrivateKey
(
$this
->
view
,
$this
->
userId
);
// Will this length vary? Perhaps we should use a range instead
$this
->
assertEquals
(
2296
,
strlen
(
$key
)
);
$this
->
assertEquals
(
4388
,
strlen
(
$key
)
);
}
...
...
@@ -69,7 +74,7 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$key
=
Encryption\Keymanager
::
getPublicKey
(
$this
->
view
,
$this
->
userId
);
$this
->
assertEquals
(
451
,
strlen
(
$key
)
);
$this
->
assertEquals
(
800
,
strlen
(
$key
)
);
$this
->
assertEquals
(
'-----BEGIN PUBLIC KEY-----'
,
substr
(
$key
,
0
,
26
)
);
}
...
...
@@ -81,11 +86,19 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$key
=
Encryption\Crypt
::
symmetricEncryptFileContentKeyfile
(
$this
->
randomKey
,
'hat'
);
$
path
=
'unittest-'
.
time
()
.
'txt'
;
$
file
=
'unittest-'
.
time
()
.
'
.
txt'
;
//$view = new \OC_FilesystemView( '/' . $this->userId . '/files_encryption/keyfiles' );
// Disable encryption proxy to prevent recursive calls
$proxyStatus
=
\OC_FileProxy
::
$enabled
;
\OC_FileProxy
::
$enabled
=
false
;
Encryption\Keymanager
::
setFileKey
(
$this
->
view
,
$path
,
$this
->
userId
,
$key
[
'key'
]
);
$this
->
view
->
file_put_contents
(
$this
->
userId
.
'/files/'
.
$file
,
$key
[
'encrypted'
]);
// Re-enable proxy - our work is done
\OC_FileProxy
::
$enabled
=
$proxyStatus
;
//$view = new \OC_FilesystemView( '/' . $this->userId . '/files_encryption/keyfiles' );
Encryption\Keymanager
::
setFileKey
(
$this
->
view
,
$file
,
$this
->
userId
,
$key
[
'key'
]
);
}
...
...
@@ -109,9 +122,9 @@ class Test_Keymanager extends \PHPUnit_Framework_TestCase {
$keys
=
Encryption\Keymanager
::
getUserKeys
(
$this
->
view
,
$this
->
userId
);
$this
->
assertEquals
(
451
,
strlen
(
$keys
[
'publicKey'
]
)
);
$this
->
assertEquals
(
800
,
strlen
(
$keys
[
'publicKey'
]
)
);
$this
->
assertEquals
(
'-----BEGIN PUBLIC KEY-----'
,
substr
(
$keys
[
'publicKey'
],
0
,
26
)
);
$this
->
assertEquals
(
2296
,
strlen
(
$keys
[
'privateKey'
]
)
);
$this
->
assertEquals
(
4388
,
strlen
(
$keys
[
'privateKey'
]
)
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/lib/cache/file.php
+
4
−
3
View file @
d22795d6
...
...
@@ -33,9 +33,10 @@ class Test_Cache_File extends Test_Cache {
OC_Hook
::
clear
(
'OC_Filesystem'
);
//enable only the encryption hook if needed
if
(
OC_App
::
isEnabled
(
'files_encryption'
))
{
OC_FileProxy
::
register
(
new
OC_FileProxy_Encryption
());
}
//not used right now
//if(OC_App::isEnabled('files_encryption')) {
// OC_FileProxy::register(new OCA\Encryption\Proxy());
//}
//set up temporary storage
\OC\Files\Filesystem
::
clearMounts
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment