Skip to content

Commit 1d89fd6

Browse files
authored
Merge pull request #1108 from oat-sa/backport/tr-5940/uri-provider-length
[Backport][Fix] Set the maximum allowable value for URI - 36 characters
2 parents 8a93fd3 + c093157 commit 1d89fd6

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

core/kernel/uri/Bin2HexUriProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Bin2HexUriProvider extends ConfigurableService implements UriProvider
4949
*/
5050
public function provide()
5151
{
52-
return $this->getOption(self::OPTION_NAMESPACE) . uniqid('i') . getmypid()
53-
. bin2hex(openssl_random_pseudo_bytes(8));
52+
return $this->getOption(self::OPTION_NAMESPACE) . uniqid('i') . date('YmdHis')
53+
. bin2hex(openssl_random_pseudo_bytes(4));
5454
}
5555
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation; under version 2
7+
* of the License (non-upgradable).
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
*
18+
* Copyright (c) 2024 (original work) Open Assessment Technologies SA.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
namespace oat\generis\test\unit\core\kernel\uri;
24+
25+
use oat\generis\model\kernel\uri\Bin2HexUriProvider;
26+
use PHPUnit\Framework\TestCase;
27+
28+
class Bin2HexUriProviderTest extends TestCase
29+
{
30+
private const NAMESPACE = 'test#';
31+
32+
private Bin2HexUriProvider $sut;
33+
34+
protected function setUp(): void
35+
{
36+
$this->sut = new Bin2HexUriProvider(['namespace' => self::NAMESPACE]);
37+
}
38+
39+
public function testProvide(): void
40+
{
41+
$uri = $this->sut->provide();
42+
43+
$this->assertStringContainsString(self::NAMESPACE, $uri);
44+
$this->assertEquals(36, strlen(substr($uri, strlen(self::NAMESPACE))));
45+
}
46+
}

0 commit comments

Comments
 (0)