Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Passwordless.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function sendSession(string $sessionId): void
{
$this->client->request(
method: 'POST',
path: "passwordless/sessions/{$sessionId}/send",
path: 'passwordless/sessions/' . rawurlencode($sessionId) . '/send',
body: [],
);
}
Expand Down
28 changes: 28 additions & 0 deletions tests/PasswordlessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,34 @@ public function testSendSession(): void
);
}

public function testSendSessionEncodesSessionIdAsSinglePathSegment(): void
{
$cases = [
'session/other' => 'session%2Fother',
'../other' => '..%2Fother',
'session/../../other' => 'session%2F..%2F..%2Fother',
'session?query=value#fragment' => 'session%3Fquery%3Dvalue%23fragment',
'session%2Fother' => 'session%252Fother',
'session with spaces' => 'session%20with%20spaces',
'session+other' => 'session%2Bother',
];

foreach ($cases as $sessionId => $encodedSessionId) {
$client = $this->createMockClient([['status' => 204]]);
$client->passwordless()->sendSession($sessionId);
$request = $this->getLastRequest();
$this->assertSame('POST', $request->getMethod());
$this->assertSame(
'/passwordless/sessions/' . $encodedSessionId . '/send',
$request->getUri()->getPath(),
$sessionId,
);
$this->assertSame('', $request->getUri()->getQuery());
$this->assertSame('', $request->getUri()->getFragment());
$this->assertSame('{}', (string) $request->getBody());
}
}

public function testPasswordlessAccessibleFromClient(): void
{
$client = $this->createMockClient([]);
Expand Down
Loading