Skip to content

Commit 172a2d0

Browse files
authored
Merge pull request #58709 from nextcloud/backport/58128/stable32
[stable32] fix(share): Set expiration time to end of day (23:59:59)
2 parents f315c53 + c5c47fe commit 172a2d0

8 files changed

Lines changed: 59 additions & 43 deletions

File tree

‎apps/files_sharing/lib/Controller/ShareAPIController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ protected function formatShare(IShare $share, ?Node $recipientNode = null): arra
235235
$expiration = $share->getExpirationDate();
236236
if ($expiration !== null) {
237237
$expiration->setTimezone($this->dateTimeZone->getTimeZone());
238-
$result['expiration'] = $expiration->format('Y-m-d 00:00:00');
238+
$result['expiration'] = $expiration->format('Y-m-d H:i:s');
239239
}
240240

241241
$currentUserPermissions = $recipientNode?->getPermissions() ?? Constants::PERMISSION_ALL;

‎apps/files_sharing/tests/ApiTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public function testUpdateShareExpireDate(): void {
10891089
$share1 = $this->shareManager->getShareById($share1->getFullId());
10901090

10911091
// date should be changed
1092-
$dateWithinRange->setTime(0, 0, 0);
1092+
$dateWithinRange->setTime(23, 59, 59);
10931093
$dateWithinRange->setTimezone(new \DateTimeZone(date_default_timezone_get()));
10941094
$this->assertEquals($dateWithinRange, $share1->getExpirationDate());
10951095

@@ -1304,7 +1304,7 @@ public function testShareStorageMountPoint(): void {
13041304

13051305
public static function datesProvider() {
13061306
$date = new \DateTime();
1307-
$date->setTime(0, 0);
1307+
$date->setTime(23, 59, 59);
13081308
$date->add(new \DateInterval('P5D'));
13091309
$date->setTimezone(new \DateTimeZone(date_default_timezone_get()));
13101310

@@ -1369,14 +1369,14 @@ public function testCreatePublicLinkExpireDateValid(): void {
13691369

13701370
$data = $result->getData();
13711371
$this->assertTrue(is_string($data['token']));
1372-
$this->assertEquals($date->format('Y-m-d 00:00:00'), $data['expiration']);
1372+
$this->assertEquals($date->format('Y-m-d 23:59:59'), $data['expiration']);
13731373

13741374
// check for correct link
13751375
$url = Server::get(IURLGenerator::class)->getAbsoluteURL('/index.php/s/' . $data['token']);
13761376
$this->assertEquals($url, $data['url']);
13771377

13781378
$share = $this->shareManager->getShareById('ocinternal:' . $data['id']);
1379-
$date->setTime(0, 0, 0);
1379+
$date->setTime(23, 59, 59);
13801380
$this->assertEquals($date, $share->getExpirationDate());
13811381

13821382
$this->shareManager->deleteShare($share);

‎apps/files_sharing/tests/Controller/ShareAPIControllerTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ public function dataGetShare() {
774774
$data[] = [$share, $expected];
775775

776776
// File shared by link with Expire
777-
$expire = \DateTime::createFromFormat('Y-m-d h:i:s', '2000-01-02 01:02:03');
777+
$expire = \DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 23:59:59');
778778
$share = $this->createShare(
779779
101,
780780
IShare::TYPE_LINK,
@@ -808,7 +808,7 @@ public function dataGetShare() {
808808
'file_target' => 'target',
809809
'file_parent' => 3,
810810
'token' => 'token',
811-
'expiration' => '2000-01-02 00:00:00',
811+
'expiration' => '2000-01-02 23:59:59',
812812
'permissions' => 4,
813813
'attributes' => null,
814814
'stime' => 5,
@@ -4481,7 +4481,7 @@ public function dataFormatShare() {
44814481
'permissions' => 1,
44824482
'stime' => 946684862,
44834483
'parent' => null,
4484-
'expiration' => '2001-02-03 00:00:00',
4484+
'expiration' => '2001-02-03 04:05:06',
44854485
'token' => null,
44864486
'uid_file_owner' => 'owner',
44874487
'displayname_file_owner' => 'owner',
@@ -4535,7 +4535,7 @@ public function dataFormatShare() {
45354535
'permissions' => 1,
45364536
'stime' => 946684862,
45374537
'parent' => null,
4538-
'expiration' => '2001-02-03 00:00:00',
4538+
'expiration' => '2001-02-03 04:05:06',
45394539
'token' => null,
45404540
'uid_file_owner' => 'owner',
45414541
'displayname_file_owner' => 'owner',

‎apps/files_sharing/tests/SharesReminderJobTest.php‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ public static function dataSharesReminder() {
9999
$someMail = 'test@test.com';
100100
$noExpirationDate = null;
101101
$today = new \DateTime();
102-
// For expiration dates, the time is always automatically set to zero by ShareAPIController
103-
$today->setTime(0, 0);
104-
$nearFuture = new \DateTime();
105-
$nearFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
102+
// Expiration dates are set to end of day (23:59:59) by the Share Manager
103+
$today->setTime(23, 59, 59);
104+
$nearFuture = clone $today;
106105
$farFuture = new \DateTime();
107-
$farFuture->setTimestamp($today->getTimestamp() + 86400 * 2);
106+
$farFuture->setTimestamp($today->getTimestamp() + 86400 * 1);
108107
$permissionRead = Constants::PERMISSION_READ;
109108
$permissionCreate = $permissionRead | Constants::PERMISSION_CREATE;
110109
$permissionUpdate = $permissionRead | Constants::PERMISSION_UPDATE;

‎autotest.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ function execute_tests {
309309
if [ ! -z "$USEDOCKER" ] ; then
310310
echo "Fire up the postgres docker"
311311
DOCKER_CONTAINER_ID=$(docker run -e POSTGRES_DB="$DATABASENAME" -e POSTGRES_USER="$DATABASEUSER" -e POSTGRES_PASSWORD=owncloud -d postgres)
312-
DATABASEHOST=$(docker inspect --format="{{.NetworkSettings.IPAddress}}" "$DOCKER_CONTAINER_ID")
312+
DATABASEHOST=$(docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" "$DOCKER_CONTAINER_ID")
313313

314314
echo "Waiting for Postgres initialisation ..."
315315

‎build/integration/features/bootstrap/Sharing.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public function isFieldInResponse($field, $contentExpected) {
318318
$data = simplexml_load_string($this->response->getBody())->data[0];
319319
if ((string)$field == 'expiration') {
320320
if (!empty($contentExpected)) {
321-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
321+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
322322
}
323323
}
324324
if (count($data->element) > 0) {
@@ -625,7 +625,7 @@ private function assertFieldIsInReturnedShare(string $field, string $contentExpe
625625
}
626626

627627
if ($field === 'expiration' && !empty($contentExpected)) {
628-
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 00:00:00';
628+
$contentExpected = date('Y-m-d', strtotime($contentExpected)) . ' 23:59:59';
629629
}
630630

631631
if ($contentExpected === 'A_NUMBER') {

‎lib/private/Share20/Manager.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ protected function validateExpirationDateInternal(IShare $share) {
303303
if (!$share->getNoExpirationDate() || $isEnforced) {
304304
if ($expirationDate !== null) {
305305
$expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
306-
$expirationDate->setTime(0, 0, 0);
306+
$expirationDate->setTime(23, 59, 59);
307307

308308
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
309309
$date->setTime(0, 0, 0);
@@ -322,7 +322,7 @@ protected function validateExpirationDateInternal(IShare $share) {
322322

323323
if ($fullId === null && $expirationDate === null && $defaultExpireDate) {
324324
$expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
325-
$expirationDate->setTime(0, 0, 0);
325+
$expirationDate->setTime(23, 59, 59);
326326
$days = (int)$this->config->getAppValue('core', $configProp, (string)$defaultExpireDays);
327327
if ($days > $defaultExpireDays) {
328328
$days = $defaultExpireDays;
@@ -337,7 +337,7 @@ protected function validateExpirationDateInternal(IShare $share) {
337337
}
338338

339339
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
340-
$date->setTime(0, 0, 0);
340+
$date->setTime(23, 59, 59);
341341
$date->add(new \DateInterval('P' . $defaultExpireDays . 'D'));
342342
if ($date < $expirationDate) {
343343
throw new GenericShareException($this->l->n('Cannot set expiration date more than %n day in the future', 'Cannot set expiration date more than %n days in the future', $defaultExpireDays), code: 404);
@@ -381,7 +381,7 @@ protected function validateExpirationDateLink(IShare $share) {
381381
if (!($share->getNoExpirationDate() && !$isEnforced)) {
382382
if ($expirationDate !== null) {
383383
$expirationDate->setTimezone($this->dateTimeZone->getTimeZone());
384-
$expirationDate->setTime(0, 0, 0);
384+
$expirationDate->setTime(23, 59, 59);
385385

386386
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
387387
$date->setTime(0, 0, 0);
@@ -400,7 +400,7 @@ protected function validateExpirationDateLink(IShare $share) {
400400

401401
if ($fullId === null && $expirationDate === null && $this->shareApiLinkDefaultExpireDate()) {
402402
$expirationDate = new \DateTime('now', $this->dateTimeZone->getTimeZone());
403-
$expirationDate->setTime(0, 0, 0);
403+
$expirationDate->setTime(23, 59, 59);
404404

405405
$days = (int)$this->config->getAppValue('core', 'link_defaultExpDays', (string)$this->shareApiLinkDefaultExpireDays());
406406
if ($days > $this->shareApiLinkDefaultExpireDays()) {
@@ -416,7 +416,7 @@ protected function validateExpirationDateLink(IShare $share) {
416416
}
417417

418418
$date = new \DateTime('now', $this->dateTimeZone->getTimeZone());
419-
$date->setTime(0, 0, 0);
419+
$date->setTime(23, 59, 59);
420420
$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
421421
if ($date < $expirationDate) {
422422
throw new GenericShareException(

0 commit comments

Comments
 (0)