diff --git a/phpmyfaq/admin/dashboard.php b/phpmyfaq/admin/dashboard.php index 58fe752869..3e928ab7e9 100644 --- a/phpmyfaq/admin/dashboard.php +++ b/phpmyfaq/admin/dashboard.php @@ -21,7 +21,6 @@ use phpMyFAQ\Database; use phpMyFAQ\Enums\PermissionType; use phpMyFAQ\Filter; -use phpMyFAQ\Session; use phpMyFAQ\System; use phpMyFAQ\Template\TwigWrapper; use phpMyFAQ\Translation; diff --git a/phpmyfaq/index.php b/phpmyfaq/index.php index 5ab833fb51..f539d75957 100755 --- a/phpmyfaq/index.php +++ b/phpmyfaq/index.php @@ -34,7 +34,6 @@ use phpMyFAQ\Language; use phpMyFAQ\Link; use phpMyFAQ\Seo; -use phpMyFAQ\Session; use phpMyFAQ\Session\Token; use phpMyFAQ\Strings; use phpMyFAQ\System; @@ -44,6 +43,7 @@ use phpMyFAQ\User\CurrentUser; use phpMyFAQ\User\TwoFactor; use phpMyFAQ\User\UserAuthentication; +use phpMyFAQ\User\UserSession; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; @@ -248,9 +248,9 @@ // // Found a session ID in _GET or _COOKIE? // -$sidGet = Filter::filterVar($request->query->get(Session::KEY_NAME_SESSION_ID), FILTER_VALIDATE_INT); -$sidCookie = Filter::filterVar($request->cookies->get(Session::COOKIE_NAME_SESSION_ID), FILTER_VALIDATE_INT); -$faqSession = new Session($faqConfig); +$sidGet = Filter::filterVar($request->query->get(UserSession::KEY_NAME_SESSION_ID), FILTER_VALIDATE_INT); +$sidCookie = Filter::filterVar($request->cookies->get(UserSession::COOKIE_NAME_SESSION_ID), FILTER_VALIDATE_INT); +$faqSession = new UserSession($faqConfig); $faqSession->setCurrentUser($user); // Note: do not track internal calls @@ -277,7 +277,7 @@ $sids = ''; if ($faqConfig->get('main.enableUserTracking')) { if ($faqSession->getCurrentSessionId() > 0) { - $faqSession->setCookie(Session::COOKIE_NAME_SESSION_ID, $faqSession->getCurrentSessionId()); + $faqSession->setCookie(UserSession::COOKIE_NAME_SESSION_ID, $faqSession->getCurrentSessionId()); if (is_null($sidCookie)) { $sids = sprintf('sid=%d&lang=%s&', $faqSession->getCurrentSessionId(), $faqLangCode); } @@ -288,7 +288,7 @@ } } else { $faqSession->setCookie( - Session::COOKIE_NAME_SESSION_ID, + UserSession::COOKIE_NAME_SESSION_ID, $faqSession->getCurrentSessionId(), $request->server->get('REQUEST_TIME') + 3600 ); diff --git a/phpmyfaq/services/azure/callback.php b/phpmyfaq/services/azure/callback.php index 403e9ec83c..b5105903ba 100644 --- a/phpmyfaq/services/azure/callback.php +++ b/phpmyfaq/services/azure/callback.php @@ -16,12 +16,12 @@ */ use phpMyFAQ\Auth\AuthEntraId; +use phpMyFAQ\Auth\Azure\OAuth; use phpMyFAQ\Configuration; use phpMyFAQ\Enums\AuthenticationSourceType; use phpMyFAQ\Filter; -use phpMyFAQ\Session; -use phpMyFAQ\Auth\Azure\OAuth; use phpMyFAQ\User\CurrentUser; +use phpMyFAQ\User\UserSession; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; @@ -48,7 +48,7 @@ $code = Filter::filterInput(INPUT_GET, 'code', FILTER_SANITIZE_SPECIAL_CHARS); $error = Filter::filterInput(INPUT_GET, 'error_description', FILTER_SANITIZE_SPECIAL_CHARS); -$session = new Session($faqConfig); +$session = new UserSession($faqConfig); $oAuth = new OAuth($faqConfig, $session); $auth = new AuthEntraId($faqConfig, $oAuth); @@ -81,7 +81,7 @@ $user->setTokenData([ 'refresh_token' => $oAuth->getRefreshToken(), 'access_token' => $oAuth->getAccessToken(), - 'code_verifier' => $session->get(Session::ENTRA_ID_OAUTH_VERIFIER), + 'code_verifier' => $session->get(UserSession::ENTRA_ID_OAUTH_VERIFIER), 'jwt' => $oAuth->getToken() ]); $user->setSuccess(true); diff --git a/phpmyfaq/services/azure/index.php b/phpmyfaq/services/azure/index.php index 7442dee9bf..d766a6eaf7 100644 --- a/phpmyfaq/services/azure/index.php +++ b/phpmyfaq/services/azure/index.php @@ -18,7 +18,7 @@ use phpMyFAQ\Auth\AuthEntraId; use phpMyFAQ\Auth\Azure\OAuth; use phpMyFAQ\Configuration; -use phpMyFAQ\Session; +use phpMyFAQ\User\UserSession; // // Prepend and start the PHP session @@ -34,7 +34,7 @@ $faqConfig = Configuration::getConfigurationInstance(); -$session = new Session($faqConfig); +$session = new UserSession($faqConfig); $oAuth = new OAuth($faqConfig, $session); $auth = new AuthEntraId($faqConfig, $oAuth); diff --git a/phpmyfaq/services/azure/logout.php b/phpmyfaq/services/azure/logout.php index bd37960247..69dd0c531a 100644 --- a/phpmyfaq/services/azure/logout.php +++ b/phpmyfaq/services/azure/logout.php @@ -18,7 +18,7 @@ use phpMyFAQ\Auth\AuthEntraId; use phpMyFAQ\Auth\Azure\OAuth; use phpMyFAQ\Configuration; -use phpMyFAQ\Session; +use phpMyFAQ\User\UserSession; // // Prepend and start the PHP session @@ -34,7 +34,7 @@ $faqConfig = Configuration::getConfigurationInstance(); -$session = new Session($faqConfig); +$session = new UserSession($faqConfig); $oAuth = new OAuth($faqConfig, $session); $auth = new AuthEntraId($faqConfig, $oAuth); diff --git a/phpmyfaq/src/phpMyFAQ/Auth/AuthEntraId.php b/phpmyfaq/src/phpMyFAQ/Auth/AuthEntraId.php index 5166438dfa..2543cf0959 100644 --- a/phpmyfaq/src/phpMyFAQ/Auth/AuthEntraId.php +++ b/phpmyfaq/src/phpMyFAQ/Auth/AuthEntraId.php @@ -22,8 +22,8 @@ use phpMyFAQ\Configuration; use phpMyFAQ\Core\Exception; use phpMyFAQ\Enums\AuthenticationSourceType; -use phpMyFAQ\Session; use phpMyFAQ\User; +use phpMyFAQ\User\UserSession; use SensitiveParameter; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -34,7 +34,7 @@ */ class AuthEntraId extends Auth implements AuthDriverInterface { - private readonly Session $session; + private readonly UserSession $session; private string $oAuthVerifier = ''; @@ -52,7 +52,7 @@ class AuthEntraId extends Auth implements AuthDriverInterface public function __construct(Configuration $configuration, private readonly OAuth $oAuth) { $this->configuration = $configuration; - $this->session = new Session($configuration); + $this->session = new UserSession($configuration); parent::__construct($configuration); } @@ -129,8 +129,8 @@ public function authorize(): void { $this->createOAuthChallenge(); $this->session->setCurrentSessionKey(); - $this->session->set(Session::ENTRA_ID_OAUTH_VERIFIER, $this->oAuthVerifier); - $this->session->setCookie(Session::ENTRA_ID_OAUTH_VERIFIER, $this->oAuthVerifier, 7200, false); + $this->session->set(UserSession::ENTRA_ID_OAUTH_VERIFIER, $this->oAuthVerifier); + $this->session->setCookie(UserSession::ENTRA_ID_OAUTH_VERIFIER, $this->oAuthVerifier, 7200, false); $oAuthURL = sprintf( 'https://login.microsoftonline.com/%s/oauth2/v2.0/authorize' . diff --git a/phpmyfaq/src/phpMyFAQ/Auth/Azure/OAuth.php b/phpmyfaq/src/phpMyFAQ/Auth/Azure/OAuth.php index c4c5a9e4d1..57a94a6e98 100644 --- a/phpmyfaq/src/phpMyFAQ/Auth/Azure/OAuth.php +++ b/phpmyfaq/src/phpMyFAQ/Auth/Azure/OAuth.php @@ -18,7 +18,7 @@ namespace phpMyFAQ\Auth\Azure; use phpMyFAQ\Configuration; -use phpMyFAQ\Session; +use phpMyFAQ\User\UserSession; use stdClass; use Symfony\Component\HttpClient\HttpClient; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; @@ -43,7 +43,7 @@ class OAuth /** * Constructor. */ - public function __construct(private readonly Configuration $configuration, private readonly Session $session) + public function __construct(private readonly Configuration $configuration, private readonly UserSession $session) { $this->client = HttpClient::create(); } @@ -66,10 +66,10 @@ public function getOAuthToken(string $code): stdClass { $url = 'https://login.microsoftonline.com/' . AAD_OAUTH_TENANTID . '/oauth2/v2.0/token'; - if ($this->session->get(Session::ENTRA_ID_OAUTH_VERIFIER) !== '') { - $codeVerifier = $this->session->get(Session::ENTRA_ID_OAUTH_VERIFIER); + if ($this->session->get(UserSession::ENTRA_ID_OAUTH_VERIFIER) !== '') { + $codeVerifier = $this->session->get(UserSession::ENTRA_ID_OAUTH_VERIFIER); } else { - $codeVerifier = $this->session->getCookie(Session::ENTRA_ID_OAUTH_VERIFIER); + $codeVerifier = $this->session->getCookie(UserSession::ENTRA_ID_OAUTH_VERIFIER); } $response = $this->client->request('POST', $url, [ @@ -118,7 +118,7 @@ public function setToken(stdClass $token): OAuth { $idToken = base64_decode(explode('.', (string) $token->id_token)[1]); $this->token = json_decode($idToken, null, 512, JSON_THROW_ON_ERROR); - $this->session->set(Session::ENTRA_ID_JWT, json_encode($this->token, JSON_THROW_ON_ERROR)); + $this->session->set(UserSession::ENTRA_ID_JWT, json_encode($this->token, JSON_THROW_ON_ERROR)); return $this; } diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Administration/SessionController.php b/phpmyfaq/src/phpMyFAQ/Controller/Administration/SessionController.php index d9cd853f40..17bf55775b 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Administration/SessionController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Administration/SessionController.php @@ -22,12 +22,11 @@ use phpMyFAQ\Controller\AbstractController; use phpMyFAQ\Enums\PermissionType; use phpMyFAQ\Session\Token; -use phpMyFAQ\Session; use phpMyFAQ\Translation; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\ResponseHeaderBag; use Symfony\Component\Routing\Annotation\Route; diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/CommentController.php b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/CommentController.php index 503ef4e857..6642d003f1 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/CommentController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/CommentController.php @@ -26,12 +26,12 @@ use phpMyFAQ\Filter; use phpMyFAQ\News; use phpMyFAQ\Notification; -use phpMyFAQ\Session; use phpMyFAQ\Session\Token; use phpMyFAQ\StopWords; use phpMyFAQ\Translation; use phpMyFAQ\User; use phpMyFAQ\User\CurrentUser; +use phpMyFAQ\User\UserSession; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -51,7 +51,7 @@ public function create(Request $request): JsonResponse $faq = new Faq($this->configuration); $comment = new Comments($this->configuration); $stopWords = new StopWords($this->configuration); - $session = new Session($this->configuration); + $session = new UserSession($this->configuration); $session->setCurrentUser($user); $language = $this->container->get('phpmyfaq.language'); diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/FaqController.php b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/FaqController.php index 97261500df..ebabc0365a 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/FaqController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/FaqController.php @@ -22,18 +22,16 @@ use phpMyFAQ\Core\Exception; use phpMyFAQ\Entity\FaqEntity; use phpMyFAQ\Enums\PermissionType; -use phpMyFAQ\Faq; use phpMyFAQ\Faq\MetaData; use phpMyFAQ\Filter; use phpMyFAQ\Helper\CategoryHelper; use phpMyFAQ\Helper\FaqHelper; -use phpMyFAQ\Language; use phpMyFAQ\Notification; use phpMyFAQ\Question; -use phpMyFAQ\Session; use phpMyFAQ\StopWords; use phpMyFAQ\Translation; use phpMyFAQ\User\CurrentUser; +use phpMyFAQ\User\UserSession; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -53,7 +51,7 @@ public function create(Request $request): JsonResponse $category = new Category($this->configuration); $question = new Question($this->configuration); $stopWords = new StopWords($this->configuration); - $session = new Session($this->configuration); + $session = new UserSession($this->configuration); $session->setCurrentUser($user); $language = $this->container->get('phpmyfaq.language'); diff --git a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/VotingController.php b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/VotingController.php index 1e9ebf6a63..001590201e 100644 --- a/phpmyfaq/src/phpMyFAQ/Controller/Frontend/VotingController.php +++ b/phpmyfaq/src/phpMyFAQ/Controller/Frontend/VotingController.php @@ -22,9 +22,9 @@ use phpMyFAQ\Entity\Vote; use phpMyFAQ\Filter; use phpMyFAQ\Rating; -use phpMyFAQ\Session; use phpMyFAQ\Translation; use phpMyFAQ\User\CurrentUser; +use phpMyFAQ\User\UserSession; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -38,7 +38,7 @@ public function create(Request $request): JsonResponse { $user = CurrentUser::getCurrentUser($this->configuration); $rating = new Rating($this->configuration); - $session = new Session($this->configuration); + $session = new UserSession($this->configuration); $session->setCurrentUser($user); $data = json_decode($request->getContent()); diff --git a/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php b/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php index 1f236da549..7a4a0b26dc 100644 --- a/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php +++ b/phpmyfaq/src/phpMyFAQ/User/CurrentUser.php @@ -27,7 +27,6 @@ use phpMyFAQ\Database; use phpMyFAQ\Filter; use phpMyFAQ\Permission\MediumPermission; -use phpMyFAQ\Session; use phpMyFAQ\User; use Symfony\Component\HttpFoundation\Request; @@ -62,7 +61,7 @@ class CurrentUser extends User /** * The Session class object */ - private readonly Session $session; + private readonly UserSession $session; /** * Specifies the timeout for the session-ID in minutes. If the session ID @@ -96,7 +95,7 @@ class CurrentUser extends User public function __construct(Configuration $configuration) { parent::__construct($configuration); - $this->session = new Session($configuration); + $this->session = new UserSession($configuration); } /** @@ -172,7 +171,7 @@ public function login(string $login, string $password): bool $rememberMe = sha1(session_id()); $this->setRememberMe($rememberMe); $this->session->setCookie( - Session::COOKIE_NAME_REMEMBER_ME, + UserSession::COOKIE_NAME_REMEMBER_ME, $rememberMe, Request::createFromGlobals()->server->get('REQUEST_TIME') + self::PMF_REMEMBER_ME_EXPIRED_TIME ); @@ -434,7 +433,7 @@ public function deleteFromSession(bool $deleteCookie = false): bool } if ($deleteCookie) { - $this->session->setCookie(Session::COOKIE_NAME_REMEMBER_ME, ''); + $this->session->setCookie(UserSession::COOKIE_NAME_REMEMBER_ME, ''); } session_destroy(); @@ -566,13 +565,13 @@ public static function getFromSession(Configuration $configuration): ?CurrentUse public static function getFromCookie(Configuration $configuration): ?CurrentUser { $request = Request::createFromGlobals(); - if ($request->cookies->get(Session::COOKIE_NAME_REMEMBER_ME) === null) { + if ($request->cookies->get(UserSession::COOKIE_NAME_REMEMBER_ME) === null) { return null; } // create a new CurrentUser object $user = new self($configuration); - $user->getUserByCookie($request->cookies->get(Session::COOKIE_NAME_REMEMBER_ME)); + $user->getUserByCookie($request->cookies->get(UserSession::COOKIE_NAME_REMEMBER_ME)); if (-1 === $user->getUserId()) { return null; diff --git a/phpmyfaq/src/phpMyFAQ/User/Tracking.php b/phpmyfaq/src/phpMyFAQ/User/Tracking.php new file mode 100644 index 0000000000..ea2975af9d --- /dev/null +++ b/phpmyfaq/src/phpMyFAQ/User/Tracking.php @@ -0,0 +1,150 @@ +configuration->get('main.enableUserTracking')) { + return; + } + + $bots = 0; + $banned = false; + $this->currentSessionId = Filter::filterVar( + $this->request->query->get(UserSession::KEY_NAME_SESSION_ID), + FILTER_VALIDATE_INT + ); + $cookieId = Filter::filterVar( + $this->request->query->get(UserSession::COOKIE_NAME_SESSION_ID), + FILTER_VALIDATE_INT + ); + + if (!is_null($cookieId)) { + $this->userSession->setCurrentSessionId($cookieId); + } + + if ($action === SessionActionType::OLD_SESSION->value) { + $this->userSession->setCurrentSessionId(0); + } + + foreach ($this->getBotIgnoreList() as $bot) { + if (Strings::strstr($this->request->headers->get('user-agent'), $bot)) { + ++$bots; + } + } + + // if we're running behind a reverse proxy like nginx/varnish, fix the client IP + $remoteAddress = $this->request->getClientIp(); + $localAddresses = ['127.0.0.1', '::1']; + + if (in_array($remoteAddress, $localAddresses) && $this->request->headers->has('X-Forwarded-For')) { + $remoteAddress = $this->request->headers->get('X-Forwarded-For'); + } + + // clean up as well + $remoteAddress = preg_replace('([^0-9a-z:.]+)i', '', (string) $remoteAddress); + + // Anonymize IP address + $remoteAddress = IpUtils::anonymize($remoteAddress); + + $network = new Network($this->configuration); + if ($network->isBanned($remoteAddress)) { + $banned = true; + } + + if (0 === $bots && false === $banned) { + if ($this->currentSessionId === null) { + $this->currentSessionId = $this->configuration->getDb()->nextId( + Database::getTablePrefix() . 'faqsessions', + 'sid' + ); + // Check: force the session cookie to contains the current $sid + if (!is_null($cookieId) && (!$cookieId != $this->userSession->getCurrentSessionId())) { + $this->userSession->setCookie( + UserSession::COOKIE_NAME_SESSION_ID, + $this->userSession->getCurrentSessionId() + ); + } + + $query = sprintf( + "INSERT INTO %sfaqsessions (sid, user_id, ip, time) VALUES (%d, %d, '%s', %d)", + Database::getTablePrefix(), + $this->userSession->getCurrentSessionId(), + CurrentUser::getCurrentUser($this->configuration)->getUserId(), + $remoteAddress, + $this->request->server->get('REQUEST_TIME') + ); + + $this->configuration->getDb()->query($query); + } + + $data = $this->userSession->getCurrentSessionId() . ';' . + str_replace(';', ',', $action) . ';' . + $data . ';' . + $remoteAddress . ';' . + str_replace(';', ',', $this->request->server->get('QUERY_STRING') ?? '') . ';' . + str_replace(';', ',', $this->request->server->get('HTTP_REFERER') ?? '') . ';' . + str_replace(';', ',', urldecode((string) $this->request->server->get('HTTP_USER_AGENT'))) . ';' . + $this->request->server->get('REQUEST_TIME') . ";\n"; + + $file = PMF_ROOT_DIR . '/content/core/data/tracking' . date('dmY'); + + if (!is_file($file)) { + touch($file); + } + + if (!is_writable($file)) { + $this->configuration->getLogger()->error('Cannot write to ' . $file); + } + + file_put_contents($file, $data, FILE_APPEND | LOCK_EX); + } + } + + /** + * Returns the botIgnoreList as an array. + * @return array + */ + private function getBotIgnoreList(): array + { + return explode(',', (string) $this->configuration->get('main.botIgnoreList')); + } +} diff --git a/phpmyfaq/src/phpMyFAQ/Session.php b/phpmyfaq/src/phpMyFAQ/User/UserSession.php similarity index 97% rename from phpmyfaq/src/phpMyFAQ/Session.php rename to phpmyfaq/src/phpMyFAQ/User/UserSession.php index 929c77774b..f4d75522b8 100644 --- a/phpmyfaq/src/phpMyFAQ/Session.php +++ b/phpmyfaq/src/phpMyFAQ/User/UserSession.php @@ -15,11 +15,15 @@ * @since 2007-03-31 */ -namespace phpMyFAQ; +namespace phpMyFAQ\User; use Exception; +use phpMyFAQ\Configuration; +use phpMyFAQ\Database; use phpMyFAQ\Enums\SessionActionType; -use phpMyFAQ\User\CurrentUser; +use phpMyFAQ\Filter; +use phpMyFAQ\Network; +use phpMyFAQ\Strings; use Random\RandomException; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\IpUtils; @@ -30,7 +34,7 @@ * * @package phpMyFAQ */ -class Session +class UserSession { /** @var string Name of the "remember me" cookie */ final public const COOKIE_NAME_REMEMBER_ME = 'pmf-remember-me'; @@ -72,7 +76,7 @@ public function getCurrentSessionId(): ?int /** * Sets the current session ID. */ - public function setCurrentSessionId(int $currentSessionId): Session + public function setCurrentSessionId(int $currentSessionId): UserSession { $this->currentSessionId = $currentSessionId; return $this; @@ -81,7 +85,7 @@ public function setCurrentSessionId(int $currentSessionId): Session /** * Sets current User object */ - public function setCurrentUser(CurrentUser $currentUser): Session + public function setCurrentUser(CurrentUser $currentUser): UserSession { $this->currentUser = $currentUser; return $this; @@ -100,7 +104,7 @@ public function getCurrentSessionKey(): ?string * * @throws Exception */ - public function setCurrentSessionKey(): Session + public function setCurrentSessionKey(): UserSession { if (!isset($this->currentSessionKey)) { $this->createCurrentSessionKey(); diff --git a/phpmyfaq/src/services.php b/phpmyfaq/src/services.php index a2633105d1..2e58cb4dc3 100644 --- a/phpmyfaq/src/services.php +++ b/phpmyfaq/src/services.php @@ -28,10 +28,10 @@ use phpMyFAQ\Instance; use phpMyFAQ\Language; use phpMyFAQ\Services\Gravatar; -use phpMyFAQ\Session; use phpMyFAQ\Sitemap; use phpMyFAQ\Tags; use phpMyFAQ\User\CurrentUser; +use phpMyFAQ\User\UserSession; use phpMyFAQ\Visits; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symfony\Component\DependencyInjection\Reference; @@ -104,7 +104,7 @@ new Reference('phpmyfaq.configuration') ]); - $services->set('phpmyfaq.session', Session::class) + $services->set('phpmyfaq.session', UserSession::class) ->args([ new Reference('phpmyfaq.configuration') ]); diff --git a/tests/phpMyFAQ/Auth/Azure/OAuthTest.php b/tests/phpMyFAQ/Auth/Azure/OAuthTest.php index 4c20cdea47..0feae8caa8 100644 --- a/tests/phpMyFAQ/Auth/Azure/OAuthTest.php +++ b/tests/phpMyFAQ/Auth/Azure/OAuthTest.php @@ -2,14 +2,14 @@ namespace phpMyFAQ\Auth\Azure; +use phpMyFAQ\Configuration; +use phpMyFAQ\User\UserSession; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\TestCase; +use stdClass; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; -use phpMyFAQ\Configuration; -use phpMyFAQ\Session; -use stdClass; const AAD_OAUTH_TENANTID = 'fake_tenant_id'; const AAD_OAUTH_CLIENTID = 'fake_client_id'; @@ -20,7 +20,7 @@ class OAuthTest extends TestCase { private HttpClientInterface $mockClient; private Configuration $mockConfiguration; - private Session $mockSession; + private UserSession $mockSession; private OAuth $oAuth; /** @@ -30,7 +30,7 @@ protected function setUp(): void { $this->mockClient = $this->createMock(HttpClientInterface::class); $this->mockConfiguration = $this->createMock(Configuration::class); - $this->mockSession = $this->createMock(Session::class); + $this->mockSession = $this->createMock(UserSession::class); $this->oAuth = new OAuth($this->mockConfiguration, $this->mockSession); } @@ -50,7 +50,7 @@ public function testGetOAuthTokenSuccess(): void $this->mockSession->expects($this->exactly(1)) ->method('get') - ->with(Session::ENTRA_ID_OAUTH_VERIFIER) + ->with(UserSession::ENTRA_ID_OAUTH_VERIFIER) ->willReturnOnConsecutiveCalls('', 'code_verifier'); $this->mockClient->expects($this->once()) @@ -115,7 +115,7 @@ public function testSetToken(): void $this->mockSession->expects($this->once()) ->method('set') - ->with(Session::ENTRA_ID_JWT, $this->stringContains('John Doe')); + ->with(UserSession::ENTRA_ID_JWT, $this->stringContains('John Doe')); $this->oAuth->setToken($token);