Skip to content
Snippets Groups Projects
Commit a994df6f authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #3173321 by e0ipso: Fix tests for 5.x on D9

parent a61de6ac
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,7 @@ class JwksEntity {
// Get the public key from simple_oauth settings.
$config = \Drupal::config('simple_oauth.settings');
if (!empty($config)) {
$public_key_real = realpath($config->get('public_key'));
$public_key_real = \Drupal::service('file_system')->realpath($config->get('public_key'));
if (!empty($public_key_real)) {
$key_info = openssl_pkey_get_details(openssl_pkey_get_public(file_get_contents($public_key_real)));
$json_data = [
......
......@@ -7,6 +7,7 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\consumers\Entity\Consumer;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\File\FileSystemInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -70,6 +71,13 @@ class Oauth2GrantManager extends DefaultPluginManager implements Oauth2GrantMana
*/
protected $server;
/**
* The file system.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* Constructor for Oauth2GrantManager objects.
*
......@@ -146,7 +154,7 @@ class Oauth2GrantManager extends DefaultPluginManager implements Oauth2GrantMana
$this->clientRepository,
$this->accessTokenRepository,
$this->scopeRepository,
realpath($this->privateKeyPath),
$this->fileSystem()->realpath($this->privateKeyPath),
Core::ourSubstr($salt, 0, 32),
$this->responseType
);
......@@ -187,4 +195,17 @@ class Oauth2GrantManager extends DefaultPluginManager implements Oauth2GrantMana
}
}
/**
* Lazy loads the file system.
*
* @return \Drupal\Core\File\FileSystemInterface
* The file system service.
*/
protected function fileSystem(): FileSystemInterface {
if (!isset($this->fileSystem)) {
$this->fileSystem = \Drupal::service('file_system');
}
return $this->fileSystem;
}
}
......@@ -3,6 +3,7 @@
namespace Drupal\simple_oauth\Server;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\File\FileSystemInterface;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\ResourceServer as LeageResourceServer;
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
......@@ -35,6 +36,13 @@ class ResourceServer implements ResourceServerInterface {
*/
protected $foundationFactory;
/**
* The file system.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* ResourceServer constructor.
*/
......@@ -45,22 +53,35 @@ class ResourceServer implements ResourceServerInterface {
HttpFoundationFactoryInterface $foundation_factory
) {
try {
$public_key = $config_factory->get('simple_oauth.settings')->get('public_key');
$public_key_real = realpath($public_key);
$public_key = $config_factory->get('simple_oauth.settings')
->get('public_key');
$public_key_real = $this->fileSystem()->realpath($public_key);
if ($public_key && $public_key_real) {
$this->subject = new LeageResourceServer(
$access_token_repository,
$public_key_real
);
}
}
catch (\LogicException $exception) {
} catch (\LogicException $exception) {
trigger_error($exception, E_USER_WARNING);
}
$this->messageFactory = $message_factory;
$this->foundationFactory = $foundation_factory;
}
/**
* Lazy loads the file system.
*
* @return \Drupal\Core\File\FileSystemInterface
* The file system service.
*/
protected function fileSystem(): FileSystemInterface {
if (!isset($this->fileSystem)) {
$this->fileSystem = \Drupal::service('file_system');
}
return $this->fileSystem;
}
/**
* {@inheritdoc}
*/
......
name: Simple OAuth Test
type: module
description: Test module for Simple OAuth
core: 8.x
core_version_requirement: '^8 || ^9'
package: Testing
hidden: true
......
......@@ -87,6 +87,9 @@ class AuthCodeFunctionalTest extends TokenBearerFunctionalTestBase {
'response_type' => 'code',
'client_id' => $this->client->uuid(),
'client_secret' => $this->clientSecret,
'redirect_uri' => Url::fromRoute('oauth2_token.test_token', [], [
'absolute' => TRUE,
])->toString(),
];
// 1. Anonymous request invites the user to log in.
$this->drupalGet($this->authorizeUrl->toString(), [
......@@ -125,6 +128,9 @@ class AuthCodeFunctionalTest extends TokenBearerFunctionalTestBase {
'response_type' => 'code',
'client_id' => $this->client->uuid(),
'client_secret' => $this->clientSecret,
'redirect_uri' => Url::fromRoute('oauth2_token.test_token', [], [
'absolute' => TRUE,
])->toString(),
];
// 1. Anonymous request invites the user to log in.
$this->drupalGet($this->authorizeUrl->toString(), [
......@@ -159,6 +165,9 @@ class AuthCodeFunctionalTest extends TokenBearerFunctionalTestBase {
'response_type' => 'code',
'client_id' => $this->client->uuid(),
'client_secret' => $this->clientSecret,
'redirect_uri' => Url::fromRoute('oauth2_token.test_token', [], [
'absolute' => TRUE,
])->toString(),
];
// 1. Anonymous request invites the user to log in.
$this->drupalGet($this->authorizeUrl->toString(), [
......@@ -256,6 +265,9 @@ class AuthCodeFunctionalTest extends TokenBearerFunctionalTestBase {
'client_id' => $this->client->uuid(),
'code_challenge' => $code_challenge,
'code_challenge_method' => 'S256',
'redirect_uri' => Url::fromRoute('oauth2_token.test_token', [], [
'absolute' => TRUE,
])->toString(),
];
// 1. Anonymous request redirect to log in.
......
......@@ -19,6 +19,11 @@ class RolesNegotiationFunctionalTest extends BrowserTestBase {
use RequestHelperTrait;
use SimpleOauthTestTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
......
......@@ -49,20 +49,17 @@ AwIDAQAB
* Set up public and private keys.
*/
public function setUpKeys() {
$public_key_path = 'private:///public.key';
$private_key_path = 'private:///private.key';
$public_key_path = 'private://public.key';
$private_key_path = 'private://private.key';
file_put_contents($public_key_path, $this->publicKey);
file_put_contents($private_key_path, $this->privateKey);
chmod($public_key_path, 0660);
chmod($private_key_path, 0660);
/** @var \Drupal\Core\File\FileSystemInterface $filesystem */
$filesystem = \Drupal::service('file_system');
$settings = $this->config('simple_oauth.settings');
$settings->set('public_key', $filesystem->realpath($public_key_path));
$settings->set('private_key', $filesystem->realpath($private_key_path));
$settings->set('public_key', $public_key_path);
$settings->set('private_key',$private_key_path);
$settings->save();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment