浏览代码

check if session is initialized

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
tags/v11.0RC2
Bjoern Schiessle 7 年前
父节点
当前提交
8a401ee156
没有帐户链接到提交者的电子邮件

+ 8
- 0
apps/encryption/lib/Crypto/Encryption.php 查看文件

@@ -177,6 +177,14 @@ class Encryption implements IEncryptionModule {
$this->isWriteOperation = false;
$this->writeCache = '';

if($this->session->isReady() === false) {
// if the master key is enabled we can initialize encryption
// with a empty password and user name
if ($this->util->isMasterKeyEnabled()) {
$this->keyManager->init('', '');
}
}

if ($this->session->decryptAllModeActivated()) {
$encryptedFileKey = $this->keyManager->getEncryptedFileKey($this->path);
$shareKey = $this->keyManager->getShareKey($this->path, $this->session->getDecryptAllUid());

+ 0
- 3
apps/encryption/lib/KeyManager.php 查看文件

@@ -406,9 +406,6 @@ class KeyManager {
}

if ($this->util->isMasterKeyEnabled()) {
if ($this->session->getStatus() === Session::NOT_INITIALIZED)
$this->init('', '');
$uid = $this->getMasterKeyId();
}


+ 10
- 0
apps/encryption/lib/Session.php 查看文件

@@ -67,6 +67,16 @@ class Session {
return $status;
}

/**
* check if encryption was initialized successfully
*
* @return bool
*/
public function isReady() {
$status = $this->getStatus();
return $status === self::INIT_SUCCESSFUL;
}

/**
* Gets user or public share private key from session
*

+ 15
- 0
apps/encryption/tests/Crypto/EncryptionTest.php 查看文件

@@ -279,6 +279,21 @@ class EncryptionTest extends TestCase {
);
}

/**
* test begin() if encryption is not initialized but the master key is enabled
* in this case we can initialize the encryption without a username/password
* and continue
*/
public function testBeginInitMasterKey() {

$this->sessionMock->expects($this->once())->method('isReady')->willReturn(false);
$this->utilMock->expects($this->once())->method('isMasterKeyEnabled')
->willReturn(true);
$this->keyManagerMock->expects($this->once())->method('init')->with('', '');

$this->instance->begin('/user/files/welcome.txt', 'user', 'r', [], []);
}

/**
* @dataProvider dataTestUpdate
*

+ 26
- 0
apps/encryption/tests/SessionTest.php 查看文件

@@ -133,6 +133,32 @@ class SessionTest extends TestCase {
$this->assertEquals(2, $this->instance->getStatus());
}

/**
* @dataProvider dataTestIsReady
*
* @param int $status
* @param bool $expected
*/
public function testIsReady($status, $expected) {
/** @var Session | \PHPUnit_Framework_MockObject_MockObject $instance */
$instance = $this->getMockBuilder(Session::class)
->setConstructorArgs([$this->sessionMock])
->setMethods(['getStatus'])->getMock();

$instance->expects($this->once())->method('getStatus')
->willReturn($status);

$this->assertSame($expected, $instance->isReady());
}

public function dataTestIsReady() {
return [
[Session::INIT_SUCCESSFUL, true],
[Session::INIT_EXECUTED, false],
[Session::NOT_INITIALIZED, false],
];
}

/**
* @param $key
* @param $value

正在加载...
取消
保存