Skip to content

Commit 2b88d4f

Browse files
authored
PLAT-3884 Add extra logging (#27)
1 parent 30bc9b7 commit 2b88d4f

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ php:
1212
- 5.6
1313
- 5.5
1414
install:
15+
- composer self-update
1516
- composer install
1617
script: |
1718
set -xe

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "talis/talis-php",
33
"description": "This is a php client library for talis APIs",
4-
"version": "0.6.1",
4+
"version": "0.6.2",
55
"keywords": [
66
"persona",
77
"echo",

src/Talis/Persona/Client/Login.php

+13-7
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ public function validateAuth()
7979
throw new \Exception('Payload not json');
8080
}
8181

82-
if (
83-
!isset($_SESSION[self::LOGIN_PREFIX . ':loginState'])
84-
|| !isset($payload['state'])
85-
|| $payload['state'] !== $_SESSION[self::LOGIN_PREFIX . ':loginState']
86-
) {
87-
// Error with state - not authenticated
88-
$this->getLogger()->error('Login state does not match');
82+
if (!isset($_SESSION[self::LOGIN_PREFIX . ':loginState'])) {
83+
$this->getLogger()->error('Login state not found on Session');
84+
throw new \Exception('Login state does not match');
85+
}
86+
87+
if (!isset($payload['state'])) {
88+
$this->getLogger()->error('Payload does not contain login state');
89+
unset($_SESSION[self::LOGIN_PREFIX . ':loginState']);
90+
throw new \Exception('Login state does not match');
91+
}
92+
93+
if ($payload['state'] !== $_SESSION[self::LOGIN_PREFIX . ':loginState']) {
94+
$this->getLogger()->error('Session login state does not match payload state');
8995
unset($_SESSION[self::LOGIN_PREFIX . ':loginState']);
9096
throw new \Exception('Login state does not match');
9197
}

test/unit/Persona/LoginTest.php

+38
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,44 @@ public function testValidateAuthThrowsExceptionWhenPayloadIsMissingState()
204204
$personaClient->validateAuth();
205205
}
206206

207+
public function testValidateAuthThrowsExceptionWhenSessionIsMissingState()
208+
{
209+
$this->setExpectedException('Exception', 'Login state does not match');
210+
$personaClient = new Login(
211+
[
212+
'userAgent' => 'unittest',
213+
'persona_host' => 'localhost',
214+
'cacheBackend' => $this->cacheBackend,
215+
]
216+
);
217+
$_SESSION = [];
218+
$_POST['persona:signature'] = 'DummySignature';
219+
$_POST['persona:payload'] = base64_encode(json_encode([
220+
'test' => 'YouShallNotPass',
221+
'state' => 'Tennessee'
222+
]));
223+
$personaClient->validateAuth();
224+
}
225+
226+
public function testValidateAuthThrowsExceptionWhenSessionStateDoNotMatchPayloadState()
227+
{
228+
$this->setExpectedException('Exception', 'Login state does not match');
229+
$personaClient = new Login(
230+
[
231+
'userAgent' => 'unittest',
232+
'persona_host' => 'localhost',
233+
'cacheBackend' => $this->cacheBackend,
234+
]
235+
);
236+
$_SESSION[Login::LOGIN_PREFIX . ':loginState'] = 'Alabama';
237+
$_POST['persona:signature'] = 'DummySignature';
238+
$_POST['persona:payload'] = base64_encode(json_encode([
239+
'test' => 'YouShallNotPass',
240+
'state' => 'Tennessee'
241+
]));
242+
$personaClient->validateAuth();
243+
}
244+
207245
public function testValidateAuthPayloadMismatchingSignature()
208246
{
209247
$this->setExpectedException('Exception', 'Signature does not match');

0 commit comments

Comments
 (0)