Skip to content

Commit 5ea5cd7

Browse files
authored
Merge pull request 1EdTech#65 from packbackbooks/podb-612-replace-reg-error
PODB-612: Replace registration error with dynamic function.
2 parents 18c31d6 + c37baab commit 5ea5cd7

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/LtiOidcLogin.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class LtiOidcLogin
1313
public const ERROR_MSG_LAUNCH_URL = 'No launch URL configured';
1414
public const ERROR_MSG_ISSUER = 'Could not find issuer';
1515
public const ERROR_MSG_LOGIN_HINT = 'Could not find login hint';
16-
public const ERROR_MSG_REGISTRATION = 'Could not find registration details';
1716

1817
private $db;
1918
private $cache;
@@ -113,11 +112,14 @@ public function validateOidcLogin($request)
113112
}
114113

115114
// Fetch Registration Details.
116-
$registration = $this->db->findRegistrationByIssuer($request['iss'], $request['client_id'] ?? null);
115+
$clientId = $request['client_id'] ?? null;
116+
$registration = $this->db->findRegistrationByIssuer($request['iss'], $clientId);
117117

118118
// Check we got something.
119119
if (empty($registration)) {
120-
throw new OidcException(static::ERROR_MSG_REGISTRATION, 1);
120+
$errorMsg = LtiMessageLaunch::getMissingRegistrationErrorMsg($request['iss'], $clientId);
121+
122+
throw new OidcException($errorMsg, 1);
121123
}
122124

123125
// Return Registration.

tests/LtiOidcLoginTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Packback\Lti1p3\Interfaces\ICache;
77
use Packback\Lti1p3\Interfaces\ICookie;
88
use Packback\Lti1p3\Interfaces\IDatabase;
9+
use Packback\Lti1p3\LtiMessageLaunch;
910
use Packback\Lti1p3\LtiOidcLogin;
1011
use Packback\Lti1p3\OidcException;
1112

@@ -84,6 +85,10 @@ public function testValidatesFailsIfLoginHintIsNotSet()
8485
$this->oidcLogin->validateOidcLogin($request);
8586
}
8687

88+
/**
89+
* @runInSeparateProcess
90+
* @preserveGlobalState disabled
91+
*/
8792
public function testValidatesFailsIfRegistrationNotFound()
8893
{
8994
$request = [
@@ -93,8 +98,14 @@ public function testValidatesFailsIfRegistrationNotFound()
9398
$this->database->shouldReceive('findRegistrationByIssuer')
9499
->once()->andReturn(null);
95100

101+
// Use an alias to mock LtiMessageLaunch::getMissingRegistrationErrorMsg()
102+
$expectedError = 'Registration not found!';
103+
Mockery::mock('alias:'.LtiMessageLaunch::class)
104+
->shouldReceive('getMissingRegistrationErrorMsg')
105+
->andReturn($expectedError);
106+
96107
$this->expectException(OidcException::class);
97-
$this->expectExceptionMessage(LtiOidcLogin::ERROR_MSG_REGISTRATION);
108+
$this->expectExceptionMessage($expectedError);
98109

99110
$this->oidcLogin->validateOidcLogin($request);
100111
}

0 commit comments

Comments
 (0)