public function LTIAuthTest::testSuccessfulAuthenticationNewUser in LTI Tool Provider 8
Same name and namespace in other branches
- 2.x tests/src/Functional/LTIAuthTest.php \Drupal\Tests\lti_tool_provider\Functional\LTIAuthTest::testSuccessfulAuthenticationNewUser()
Test successful authentication and account creation with new user.
Throws
OAuthException
Exception
File
- tests/
src/ Functional/ LTIAuthTest.php, line 277
Class
- LTIAuthTest
- Functional tests for LTI authentication.
Namespace
Drupal\Tests\lti_tool_provider\FunctionalCode
public function testSuccessfulAuthenticationNewUser() {
$oauth = new OAuth($this->consumer
->get('consumer_key')->value, $this->consumer
->get('consumer_secret')->value, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_URI);
$timestamp = time();
$nonce = md5($timestamp);
$oauth
->setTimestamp($timestamp);
$oauth
->setNonce($nonce);
$url = Url::fromRoute('lti_tool_provider.lti');
$params = [
'oauth_version' => '1.0',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_consumer_key' => 'consumer_key',
'oauth_timestamp' => $timestamp,
'oauth_nonce' => $nonce,
'lti_message_type' => 'basic-lti-launch-request',
'lti_version' => 'LTI-1p0',
'resource_link_id' => 'resource_link_id',
'lis_person_contact_email_primary' => 'user@lms.edu',
];
$signature = $oauth
->generateSignature('POST', $url
->setAbsolute()
->toString(), $params);
$params['oauth_signature'] = $signature;
$response = $this
->request('POST', $url, [
'form_params' => $params,
]);
// $userStorage = $this->container->get('entity_type.manager')->getStorage('user');
$ids = $this->userStorage
->getQuery()
->condition('name', 'user@lms.edu', '=')
->condition('mail', 'user@lms.edu', '=')
->execute();
$this
->assertEquals(200, $response
->getStatusCode());
$this
->assertCount(1, $ids);
}