Browse Source

Separate settings for remote share expiration

Added separate settings for default and enforced expiration date for
remote shares.

Signed-off-by: Vincent Petry <vincent@nextcloud.com>
tags/v22.0.0beta1
Vincent Petry 3 years ago
parent
commit
af61486aea
No account linked to committer's email address

+ 3
- 3
apps/files_sharing/js/dist/files_sharing_tab.js
File diff suppressed because it is too large
View File


+ 1
- 1
apps/files_sharing/js/dist/files_sharing_tab.js.map
File diff suppressed because it is too large
View File


+ 7
- 0
apps/files_sharing/lib/Capabilities.php View File

@@ -86,6 +86,13 @@ class Capabilities implements ICapability {
$public['expire_date_internal']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
}

$public['expire_date_remote'] = [];
$public['expire_date_remote']['enabled'] = $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
if ($public['expire_date_remote']['enabled']) {
$public['expire_date_remote']['days'] = $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
$public['expire_date_remote']['enforced'] = $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
}

$public['send_mail'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no') === 'yes';
$public['upload'] = $this->config->getAppValue('core', 'shareapi_allow_public_upload', 'yes') === 'yes';
$public['upload_files_drop'] = $public['upload'];

+ 13
- 4
apps/files_sharing/src/components/SharingEntry.vue View File

@@ -222,8 +222,12 @@ export default {
},

canHaveNote() {
return this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE
&& this.share.type !== this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
return !this.isRemote
},

isRemote() {
return this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE
|| this.share.type === this.SHARE_TYPES.SHARE_TYPE_REMOTE_GROUP
},

/**
@@ -348,8 +352,13 @@ export default {
},

dateMaxEnforced() {
return this.config.isDefaultInternalExpireDateEnforced
&& moment().add(1 + this.config.defaultInternalExpireDate, 'days')
if (!this.isRemote) {
return this.config.isDefaultInternalExpireDateEnforced
&& moment().add(1 + this.config.defaultInternalExpireDate, 'days')
} else {
return this.config.isDefaultRemoteExpireDateEnforced
&& moment().add(1 + this.config.defaultRemoteExpireDate, 'days')
}
},

/**

+ 40
- 0
apps/files_sharing/src/services/ConfigService.js View File

@@ -95,6 +95,24 @@ export default class Config {
return expireDateString
}

/**
* Get the default remote expiration date as string
*
* @returns {string}
* @readonly
* @memberof Config
*/
get defaultRemoteExpirationDateString() {
let expireDateString = ''
if (this.isDefaultRemoteExpireDateEnabled) {
const date = window.moment.utc()
const expireAfterDays = this.defaultRemoteExpireDate
date.add(expireAfterDays, 'days')
expireDateString = date.format('YYYY-MM-DD')
}
return expireDateString
}

/**
* Are link shares password-enforced ?
*
@@ -150,6 +168,17 @@ export default class Config {
return OC.appConfig.core.defaultInternalExpireDateEnforced === true
}

/**
* Is remote shares expiration enforced ?
*
* @returns {boolean}
* @readonly
* @memberof Config
*/
get isDefaultRemoteExpireDateEnforced() {
return OC.appConfig.core.defaultRemoteExpireDateEnforced === true
}

/**
* Is there a default expiration date for new internal shares ?
*
@@ -209,6 +238,17 @@ export default class Config {
return OC.appConfig.core.defaultInternalExpireDate
}

/**
* Get the default days to remote shares expiration
*
* @returns {int}
* @readonly
* @memberof Config
*/
get defaultRemoteExpireDate() {
return OC.appConfig.core.defaultRemoteExpireDate
}

/**
* Is resharing allowed ?
*

+ 4
- 0
apps/settings/js/admin.js View File

@@ -90,6 +90,10 @@ window.addEventListener('DOMContentLoaded', function(){
$("#setDefaultInternalExpireDate").toggleClass('hidden', !this.checked);
});

$('#shareapiDefaultRemoteExpireDate').change(function() {
$("#setDefaultRemoteExpireDate").toggleClass('hidden', !this.checked);
});

$('#publicShareDisclaimer').change(function() {
$("#publicShareDisclaimerText").toggleClass('hidden', !this.checked);
if(!this.checked) {

+ 3
- 0
apps/settings/lib/Settings/Admin/Sharing.php View File

@@ -90,6 +90,9 @@ class Sharing implements ISettings {
'shareDefaultInternalExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no'),
'shareInternalExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7'),
'shareInternalEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no'),
'shareDefaultRemoteExpireDateSet' => $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no'),
'shareRemoteExpireAfterNDays' => $this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7'),
'shareRemoteEnforceExpireDate' => $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no'),
];

return new TemplateResponse('settings', 'settings/admin/sharing', $parameters, '');

+ 23
- 0
apps/settings/templates/settings/admin/sharing.php View File

@@ -63,6 +63,29 @@
<label for="shareapiInternalEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/>
</p>

<p id="remoteShareSettings" class="indent <?php if ($_['shareAPIEnabled'] === 'no') {
p('hidden');
} ?>">
<input type="checkbox" name="shareapi_default_remote_expire_date" id="shareapiDefaultRemoteExpireDate" class="checkbox"
value="1" <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'yes') {
print_unescaped('checked="checked"');
} ?> />
<label for="shareapiDefaultRemoteExpireDate"><?php p($l->t('Set default expiration date for shares to other servers'));?></label><br/>
</p>
<p id="setDefaultRemoteExpireDate" class="double-indent <?php if ($_['shareDefaultRemoteExpireDateSet'] === 'no' || $_['shareAPIEnabled'] === 'no') {
p('hidden');
}?>">
<?php p($l->t('Expire after ')); ?>
<input type="text" name='shareapi_remote_expire_after_n_days' id="shareapiRemoteExpireAfterNDays" placeholder="<?php p('7')?>"
value='<?php p($_['shareRemoteExpireAfterNDays']) ?>' />
<?php p($l->t('days')); ?>
<input type="checkbox" name="shareapi_enforce_remote_expire_date" id="shareapiRemoteEnforceExpireDate" class="checkbox"
value="1" <?php if ($_['shareRemoteEnforceExpireDate'] === 'yes') {
print_unescaped('checked="checked"');
} ?> />
<label for="shareapiRemoteEnforceExpireDate"><?php p($l->t('Enforce expiration date'));?></label><br/>
</p>

<p class="<?php if ($_['shareAPIEnabled'] === 'no') {
p('hidden');
}?>">

+ 12
- 0
apps/settings/tests/Settings/Admin/SharingTest.php View File

@@ -86,6 +86,9 @@ class SharingTest extends TestCase {
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
]);

$expected = new TemplateResponse(
@@ -115,6 +118,9 @@ class SharingTest extends TestCase {
'shareDefaultInternalExpireDateSet' => 'no',
'shareInternalExpireAfterNDays' => '7',
'shareInternalEnforceExpireDate' => 'no',
'shareDefaultRemoteExpireDateSet' => 'no',
'shareRemoteExpireAfterNDays' => '7',
'shareRemoteEnforceExpireDate' => 'no',
],
''
);
@@ -146,6 +152,9 @@ class SharingTest extends TestCase {
['core', 'shareapi_default_internal_expire_date', 'no', 'no'],
['core', 'shareapi_internal_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_internal_expire_date', 'no', 'no'],
['core', 'shareapi_default_remote_expire_date', 'no', 'no'],
['core', 'shareapi_remote_expire_after_n_days', '7', '7'],
['core', 'shareapi_enforce_remote_expire_date', 'no', 'no'],
]);

$expected = new TemplateResponse(
@@ -175,6 +184,9 @@ class SharingTest extends TestCase {
'shareDefaultInternalExpireDateSet' => 'no',
'shareInternalExpireAfterNDays' => '7',
'shareInternalEnforceExpireDate' => 'no',
'shareDefaultRemoteExpireDateSet' => 'no',
'shareRemoteExpireAfterNDays' => '7',
'shareRemoteEnforceExpireDate' => 'no',
],
''
);

+ 47
- 8
lib/private/Share20/Manager.php View File

@@ -385,6 +385,8 @@ class Manager implements IManager {
* @throws \Exception
*/
protected function validateExpirationDateInternal(IShare $share) {
$isRemote = $share->getShareType() === IShare::TYPE_REMOTE || $share->getShareType() === IShare::TYPE_REMOTE_GROUP;

$expirationDate = $share->getExpirationDate();

if ($expirationDate !== null) {
@@ -407,28 +409,39 @@ class Manager implements IManager {
// This is a new share
}

if ($fullId === null && $expirationDate === null && $this->shareApiInternalDefaultExpireDate()) {
if ($isRemote) {
$defaultExpireDate = $this->shareApiRemoteDefaultExpireDate();
$defaultExpireDays = $this->shareApiRemoteDefaultExpireDays();
$configProp = 'remote_defaultExpDays';
$isEnforced = $this->shareApiRemoteDefaultExpireDateEnforced();
} else {
$defaultExpireDate = $this->shareApiInternalDefaultExpireDate();
$defaultExpireDays = $this->shareApiInternalDefaultExpireDays();
$configProp = 'internal_defaultExpDays';
$isEnforced = $this->shareApiInternalDefaultExpireDateEnforced();
}
if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
$expirationDate = new \DateTime();
$expirationDate->setTime(0,0,0);

$days = (int)$this->config->getAppValue('core', 'internal_defaultExpDays', (string)$this->shareApiInternalDefaultExpireDays());
if ($days > $this->shareApiInternalDefaultExpireDays()) {
$days = $this->shareApiInternalDefaultExpireDays();
$days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays);
if ($days > $defaultExpireDays) {
$days = $defaultExpireDays;
}
$expirationDate->add(new \DateInterval('P'.$days.'D'));
}

// If we enforce the expiration date check that is does not exceed
if ($this->shareApiInternalDefaultExpireDateEnforced()) {
if ($isEnforced) {
if ($expirationDate === null) {
throw new \InvalidArgumentException('Expiration date is enforced');
}

$date = new \DateTime();
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P' . $this->shareApiInternalDefaultExpireDays() . 'D'));
$date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
if ($date < $expirationDate) {
$message = $this->l->t('Can’t set expiration date more than %s days in the future', [$this->shareApiInternalDefaultExpireDays()]);
$message = $this->l->t('Can’t set expiration date more than %s days in the future', [$defaultExpireDays]);
throw new GenericShareException($message, $message, 404);
}
}
@@ -1792,9 +1805,18 @@ class Manager implements IManager {
return $this->config->getAppValue('core', 'shareapi_default_internal_expire_date', 'no') === 'yes';
}

/**
* Is default remote expire date enabled
*
* @return bool
*/
public function shareApiRemoteDefaultExpireDate(): bool {
return $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
}

/**
* Is default expire date enforced
*`
*
* @return bool
*/
public function shareApiInternalDefaultExpireDateEnforced(): bool {
@@ -1802,6 +1824,15 @@ class Manager implements IManager {
$this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
}

/**
* Is default expire date enforced for remote shares
*
* @return bool
*/
public function shareApiRemoteDefaultExpireDateEnforced(): bool {
return $this->shareApiRemoteDefaultExpireDate() &&
$this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
}

/**
* Number of default expire days
@@ -1811,6 +1842,14 @@ class Manager implements IManager {
return (int)$this->config->getAppValue('core', 'shareapi_internal_expire_after_n_days', '7');
}

/**
* Number of default expire days for remote shares
* @return int
*/
public function shareApiRemoteDefaultExpireDays(): int {
return (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
}

/**
* Allow public upload on link shares
*

+ 10
- 0
lib/private/Template/JSConfigHelper.php View File

@@ -165,6 +165,13 @@ class JSConfigHelper {
$defaultInternalExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_internal_expire_date', 'no') === 'yes';
}

$defaultRemoteExpireDateEnabled = $this->config->getAppValue('core', 'shareapi_default_remote_expire_date', 'no') === 'yes';
$defaultRemoteExpireDate = $defaultRemoteExpireDateEnforced = null;
if ($defaultRemoteExpireDateEnabled) {
$defaultRemoteExpireDate = (int)$this->config->getAppValue('core', 'shareapi_remote_expire_after_n_days', '7');
$defaultRemoteExpireDateEnforced = $this->config->getAppValue('core', 'shareapi_enforce_remote_expire_date', 'no') === 'yes';
}

$countOfDataLocation = 0;
$dataLocation = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValue('datadirectory', ''), $countOfDataLocation);
if ($countOfDataLocation !== 1 || $uid === null || !$this->groupManager->isAdmin($uid)) {
@@ -278,6 +285,9 @@ class JSConfigHelper {
'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled,
'defaultInternalExpireDate' => $defaultInternalExpireDate,
'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced,
'defaultRemoteExpireDateEnabled' => $defaultRemoteExpireDateEnabled,
'defaultRemoteExpireDate' => $defaultRemoteExpireDate,
'defaultRemoteExpireDateEnforced' => $defaultRemoteExpireDateEnforced,
]
]),
"_theme" => json_encode([

+ 207
- 70
tests/lib/Share20/ManagerTest.php View File

@@ -772,7 +772,14 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'generalCreateChecks', [$share]);
}

public function testValidateExpirationDateInternalInPast() {
public function validateExpirationDateInternalProvider() {
return [[IShare::TYPE_USER], [IShare::TYPE_REMOTE], [IShare::TYPE_REMOTE_GROUP]];
}

/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalInPast($shareType) {
$this->expectException(\OCP\Share\Exceptions\GenericShareException::class);
$this->expectExceptionMessage('Expiration date is in the past');

@@ -781,51 +788,88 @@ class ManagerTest extends \Test\TestCase {
$past->sub(new \DateInterval('P1D'));

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($past);

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}

public function testValidateExpirationDateInternalEnforceButNotSet() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalEnforceButNotSet($shareType) {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Expiration date is enforced');

$share = $this->manager->newShare();
$share->setProviderId('foo')->setId('bar');

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
]);
$share->setShareType($shareType);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
]);
}

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}

public function testValidateExpirationDateInternalEnforceButNotEnabledAndNotSet() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalEnforceButNotEnabledAndNotSet($shareType) {
$share = $this->manager->newShare();
$share->setProviderId('foo')->setId('bar');
$share->setShareType($shareType);

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
]);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
]);
}

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);

$this->assertNull($share->getExpirationDate());
}

public function testValidateExpirationDateInternalEnforceButNotSetNewShare() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalEnforceButNotSetNewShare($shareType) {
$share = $this->manager->newShare();

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'internal_defaultExpDays', '3', '3'],
]);
$share->setShareType($shareType);

if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'internal_defaultExpDays', '3', '3'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
['core', 'remote_defaultExpDays', '3', '3'],
]);
}

$expected = new \DateTime();
$expected->setTime(0,0,0);
@@ -837,16 +881,30 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSetNewShare() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalEnforceRelaxedDefaultButNotSetNewShare($shareType) {
$share = $this->manager->newShare();

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'internal_defaultExpDays', '3', '1'],
]);
$share->setShareType($shareType);

if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'internal_defaultExpDays', '3', '1'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
['core', 'remote_defaultExpDays', '3', '1'],
]);
}

$expected = new \DateTime();
$expected->setTime(0,0,0);
@@ -858,7 +916,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalEnforceTooFarIntoFuture() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalEnforceTooFarIntoFuture($shareType) {
$this->expectException(\OCP\Share\Exceptions\GenericShareException::class);
$this->expectExceptionMessage('Can’t set expiration date more than 3 days in the future');

@@ -866,19 +927,32 @@ class ManagerTest extends \Test\TestCase {
$future->add(new \DateInterval('P7D'));

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($future);

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
]);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
]);
}

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}

public function testValidateExpirationDateInternalEnforceValid() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalEnforceValid($shareType) {
$future = new \DateTime();
$future->add(new \DateInterval('P2D'));
$future->setTime(1,2,3);
@@ -887,14 +961,24 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0);

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($future);

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
]);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_enforce_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
]);
}

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
@@ -907,7 +991,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalNoDefault() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalNoDefault($shareType) {
$date = new \DateTime();
$date->add(new \DateInterval('P5D'));
$date->setTime(1,2,3);
@@ -916,6 +1003,7 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0);

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($date);

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
@@ -929,7 +1017,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalNoDateNoDefault() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalNoDateNoDefault($shareType) {
$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
$hookListener->expects($this->once())->method('listener')->with($this->callback(function ($data) {
@@ -937,6 +1028,7 @@ class ManagerTest extends \Test\TestCase {
}));

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setPassword('password');

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -944,19 +1036,32 @@ class ManagerTest extends \Test\TestCase {
$this->assertNull($share->getExpirationDate());
}

public function testValidateExpirationDateInternalNoDateDefault() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalNoDateDefault($shareType) {
$share = $this->manager->newShare();
$share->setShareType($shareType);

$expected = new \DateTime();
$expected->add(new \DateInterval('P3D'));
$expected->setTime(0,0,0);

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'internal_defaultExpDays', '3', '3'],
]);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'internal_defaultExpDays', '3', '3'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
['core', 'remote_defaultExpDays', '3', '3'],
]);
}

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
@@ -969,7 +1074,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalDefault() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalDefault($shareType) {
$future = new \DateTime();
$future->add(new \DateInterval('P5D'));
$future->setTime(1,2,3);
@@ -978,14 +1086,24 @@ class ManagerTest extends \Test\TestCase {
$expected->setTime(0,0,0);

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($future);

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'internal_defaultExpDays', '3', '1'],
]);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '3'],
['core', 'internal_defaultExpDays', '3', '1'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '3'],
['core', 'remote_defaultExpDays', '3', '1'],
]);
}

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
\OCP\Util::connectHook('\OC\Share', 'verifyExpirationDate', $hookListener, 'listener');
@@ -998,7 +1116,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($expected, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalHookModification() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalHookModification($shareType) {
$nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
@@ -1012,6 +1133,7 @@ class ManagerTest extends \Test\TestCase {
});

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($nextWeek);

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
@@ -1020,7 +1142,10 @@ class ManagerTest extends \Test\TestCase {
$this->assertEquals($save, $share->getExpirationDate());
}

public function testValidateExpirationDateInternalHookException() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalHookException($shareType) {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Invalid date!');

@@ -1029,6 +1154,7 @@ class ManagerTest extends \Test\TestCase {
$nextWeek->setTime(0,0,0);

$share = $this->manager->newShare();
$share->setShareType($shareType);
$share->setExpirationDate($nextWeek);

$hookListener = $this->getMockBuilder('Dummy')->setMethods(['listener'])->getMock();
@@ -1041,16 +1167,27 @@ class ManagerTest extends \Test\TestCase {
self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
}

public function testValidateExpirationDateInternalExistingShareNoDefault() {
/**
* @dataProvider validateExpirationDateInternalProvider
*/
public function testValidateExpirationDateInternalExistingShareNoDefault($shareType) {
$share = $this->manager->newShare();

$share->setShareType($shareType);
$share->setId('42')->setProviderId('foo');

$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '6'],
]);
if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_internal_expire_date', 'no', 'yes'],
['core', 'shareapi_internal_expire_after_n_days', '7', '6'],
]);
} else {
$this->config->method('getAppValue')
->willReturnMap([
['core', 'shareapi_default_remote_expire_date', 'no', 'yes'],
['core', 'shareapi_remote_expire_after_n_days', '7', '6'],
]);
}

self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);


Loading…
Cancel
Save