Skip to content

Commit 0830063

Browse files
dsztankoknagy
andcommitted
SECURITY-10331: add getSessionData to cache client
ROAD-4845 Co-authored-by: Krisztian <[email protected]>
1 parent 359bc88 commit 0830063

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/CachedClient.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,27 @@ public function __construct(ClientInterface $client, CacheInterface $cache)
2323
$this->cache = $cache;
2424
}
2525

26-
public function isValid(string $msid): bool
26+
public function isValid(string $id): bool
2727
{
28-
$cachedResult = $this->cache->get($msid);
28+
$cachedResult = $this->cache->get($id);
2929
if ($cachedResult) {
3030
return $cachedResult;
3131
}
3232

33-
$result = $this->client->isValid($msid);
34-
$this->cache->set($msid, $result);
33+
$result = $this->client->isValid($id);
34+
$this->cache->set($id, $result);
3535

3636
return $result;
3737
}
3838

39+
public function getSessionData(string $sessionDataToken): array
40+
{
41+
return $this->client->getSessionData($sessionDataToken);
42+
}
43+
44+
/**
45+
* @deprecated - this functionality will be removed in the future
46+
*/
3947
public function filterInvalid(array $msids): array
4048
{
4149
$result = $this->client->filterInvalid($msids);

src/ClientInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
interface ClientInterface
66
{
7-
public function isValid(string $msid): bool;
7+
public function isValid(string $id): bool;
88

99
public function filterInvalid(array $msids): array;
1010
}

tests/CachedClientTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class CachedClientTest extends TestCase
1515

1616
private CacheInterface|MockObject $cacheMock;
1717

18-
private string $msid;
18+
private string $id;
1919

2020
private bool $value;
2121

@@ -32,7 +32,7 @@ protected function setUp(): void
3232

3333
$this->client = new CachedClient($this->clientMock, $this->cacheMock);
3434

35-
$this->msid = 'msid';
35+
$this->id = 'msid';
3636
$this->value = true;
3737

3838
$this->msids = ['msid1', 'msid2', 'msid3'];
@@ -45,24 +45,24 @@ public function isValidShouldReturnTheCachedResultIfExists()
4545
$this->mockCachedValue();
4646
$this->expectClientIsValidNotCalled();
4747

48-
$this->assertEquals($this->value, $this->client->isValid($this->msid));
48+
$this->assertEquals($this->value, $this->client->isValid($this->id));
4949
}
5050

5151
#[Test]
5252
public function isValidShouldReturnTheClientsResponseIfThereIsNoCache()
5353
{
5454
$this->mockClientValue();
5555

56-
$this->assertEquals($this->value, $this->client->isValid($this->msid));
56+
$this->assertEquals($this->value, $this->client->isValid($this->id));
5757
}
5858

5959
#[Test]
6060
public function isValidShouldCacheTheClientsResponse()
6161
{
6262
$this->mockClientValue();
63-
$this->expectValueCached($this->msid, $this->value);
63+
$this->expectValueCached($this->id, $this->value);
6464

65-
$this->client->isValid($this->msid);
65+
$this->client->isValid($this->id);
6666
}
6767

6868
#[Test]
@@ -87,7 +87,7 @@ private function mockCachedValue()
8787
$this->cacheMock
8888
->expects($this->once())
8989
->method('get')
90-
->with($this->msid)
90+
->with($this->id)
9191
->willReturn($this->value);
9292
}
9393

@@ -96,7 +96,7 @@ private function mockClientValue()
9696
$this->clientMock
9797
->expects($this->once())
9898
->method('isValid')
99-
->with($this->msid)
99+
->with($this->id)
100100
->willReturn($this->value);
101101
}
102102

0 commit comments

Comments
 (0)