Skip to content

EspoCRM – Open Source CRM Application

Entry points metadata

Yuriic3743bc43184
diff --git a/.idea/jsonSchemas.xml b/.idea/jsonSchemas.xml
index db2a0435fb..05f120bfeb 100644
--- a/.idea/jsonSchemas.xml
+++ b/.idea/jsonSchemas.xml
@@ -664,6 +664,25 @@
</SchemaInfo>
</value>
</entry>
+ <entry key="metadata/app/entryPoints">
+ <value>
+ <SchemaInfo>
+ <option name="generatedName" value="New Schema" />
+ <option name="name" value="metadata/app/entryPoints" />
+ <option name="relativePathToSchema" value="schema/metadata/app/entryPoints.json" />
+ <option name="schemaVersion" value="JSON Schema version 7" />
+ <option name="patterns">
+ <list>
+ <Item>
+ <option name="pattern" value="true" />
+ <option name="path" value="*/Resources/metadata/app/entryPoints.json" />
+ <option name="mappingKind" value="Pattern" />
+ </Item>
+ </list>
+ </option>
+ </SchemaInfo>
+ </value>
+ </entry>
<entry key="metadata/app/export">
<value>
<SchemaInfo>
diff --git a/.vscode/settings.json b/.vscode/settings.json
index c17c9f67ec..cceef9108b 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -292,6 +292,12 @@
],
"url": "./schema/metadata/app/entityTemplates.json"
},
+ {
+ "fileMatch": [
+ "*/Resources/metadata/app/entryPoints.json"
+ ],
+ "url": "./schema/metadata/app/entryPoints.json"
+ },
{
"fileMatch": [
"*/Resources/metadata/app/export.json"
diff --git a/application/Espo/Core/ApplicationRunners/EntryPoint.php b/application/Espo/Core/ApplicationRunners/EntryPoint.php
index 691ea558ae..48a99e589a 100644
--- a/application/Espo/Core/ApplicationRunners/EntryPoint.php
+++ b/application/Espo/Core/ApplicationRunners/EntryPoint.php
@@ -34,7 +34,6 @@ use Espo\Core\Application\RunnerParameterized;
use Espo\Core\Application\Runner\Params;
use Espo\Core\EntryPoint\Params as EntryPointParams;
use Espo\Core\EntryPoint\Starter;
-use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\NotFound;
use RuntimeException;
@@ -46,7 +45,6 @@ class EntryPoint implements RunnerParameterized
{
public const string PARAM_ENTRY_POINT = 'entryPoint';
public const string PARAM_FINAL = 'final';
- public const string PARAM_ALLOWED_METHODS = 'allowedMethods';
public function __construct(private Starter $starter)
{}
@@ -55,13 +53,12 @@ class EntryPoint implements RunnerParameterized
{
$entryPointParams = new EntryPointParams(
name: $this->getName($params),
- allowedMethods: $this->getAllowedMethods($params),
final: $params->get(self::PARAM_FINAL) === true,
);
try {
$this->starter->start($entryPointParams);
- } catch (BadRequest|Forbidden|NotFound $e) {
+ } catch (Forbidden|NotFound $e) {
$message = $e->getMessage();
throw new RunnerException($message, previous: $e);
@@ -78,28 +75,4 @@ class EntryPoint implements RunnerParameterized
return $name;
}
-
- /**
- * @return ?string[]
- */
- private function getAllowedMethods(Params $params): ?array
- {
- $value = $params->get(self::PARAM_ALLOWED_METHODS);
-
- if ($value === null) {
- return null;
- }
-
- if (!is_array($value)) {
- throw new RuntimeException("Bad 'allowedMethods' value.");
- }
-
- foreach ($value as $it) {
- if (!is_string($it)) {
- throw new RuntimeException("Bad 'allowedMethods' item value.");
- }
- }
-
- return $value;
- }
}
diff --git a/application/Espo/Core/EntryPoint/EntryPointManager.php b/application/Espo/Core/EntryPoint/EntryPointManager.php
index 5807e65e82..0c07e2f1cd 100644
--- a/application/Espo/Core/EntryPoint/EntryPointManager.php
+++ b/application/Espo/Core/EntryPoint/EntryPointManager.php
@@ -35,6 +35,7 @@ use Espo\Core\Api\Response;
use Espo\Core\Exceptions\NotFoundSilent;
use Espo\Core\InjectableFactory;
use Espo\Core\Utils\ClassFinder;
+use Espo\Core\Utils\Metadata;
/**
* Runs entry points.
@@ -43,7 +44,8 @@ class EntryPointManager
{
public function __construct(
private InjectableFactory $injectableFactory,
- private ClassFinder $classFinder
+ private ClassFinder $classFinder,
+ private Metadata $metadata,
) {}
/**
@@ -51,6 +53,12 @@ class EntryPointManager
*/
public function checkAuthRequired(string $name): bool
{
+ $metaParams = $this->getMetaParams($name);
+
+ if ($metaParams->noAuth) {
+ return false;
+ }
+
$className = $this->getClassName($name);
if (!$className) {
@@ -92,7 +100,33 @@ class EntryPointManager
*/
private function getClassName(string $name): ?string
{
+ $metaParams = $this->getMetaParams($name);
+
+ if ($metaParams->className) {
+ return $metaParams->className;
+ }
+
/** @var ?class-string<EntryPoint> */
return $this->classFinder->find('EntryPoints', ucfirst($name));
}
+
+ public function getMetaParams(string $name): MetaParams
+ {
+ /**
+ * @var array{
+ * className?: ?class-string<EntryPoint>,
+ * notExposed?: bool,
+ * noAuth?: bool,
+ * allowedMethods?: string[],
+ * } $params
+ */
+ $params = $this->metadata->get("app.entryPoints.$name") ?? [];
+
+ return new MetaParams(
+ className: $params['className'] ?? null,
+ notExposed: $params['notExposed'] ?? false,
+ noAuth: $params['noAuth'] ?? false,
+ allowedMethods: $params['allowedMethods'] ?? null,
+ );
+ }
}
diff --git a/application/Espo/Core/EntryPoint/MetaParams.php b/application/Espo/Core/EntryPoint/MetaParams.php
new file mode 100644
index 0000000000..6dde3bf669
--- /dev/null
+++ b/application/Espo/Core/EntryPoint/MetaParams.php
@@ -0,0 +1,47 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Core\EntryPoint;
+
+/**
+ * @since 10.1.0
+ */
+readonly class MetaParams
+{
+ /**
+ * @param ?class-string<EntryPoint> $className
+ * @param ?string[] $allowedMethods
+ */
+ public function __construct(
+ public ?string $className = null,
+ public bool $notExposed = false,
+ public bool $noAuth = false,
+ public ?array $allowedMethods = null,
+ ) {}
+}
diff --git a/application/Espo/Core/EntryPoint/OutputEmitter.php b/application/Espo/Core/EntryPoint/OutputEmitter.php
new file mode 100644
index 0000000000..8ced2c6bda
--- /dev/null
+++ b/application/Espo/Core/EntryPoint/OutputEmitter.php
@@ -0,0 +1,44 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Core\EntryPoint;
+
+use Espo\Core\Api\ResponseWrapper;
+use Slim\ResponseEmitter;
+
+/**
+ * @internal
+ */
+class OutputEmitter
+{
+ public function emit(ResponseWrapper $response): void
+ {
+ (new ResponseEmitter())->emit($response->toPsr7());
+ }
+}
diff --git a/application/Espo/Core/EntryPoint/Params.php b/application/Espo/Core/EntryPoint/Params.php
index 4a45f77247..2e640d7fea 100644
--- a/application/Espo/Core/EntryPoint/Params.php
+++ b/application/Espo/Core/EntryPoint/Params.php
@@ -34,12 +34,8 @@ namespace Espo\Core\EntryPoint;
*/
readonly class Params
{
- /**
- * @param string[] $allowedMethods
- */
public function __construct(
public ?string $name = null,
- public ?array $allowedMethods = null,
public bool $final = false,
) {}
}
diff --git a/application/Espo/Core/EntryPoint/RequestFactory.php b/application/Espo/Core/EntryPoint/RequestFactory.php
new file mode 100644
index 0000000000..07aa9ac10b
--- /dev/null
+++ b/application/Espo/Core/EntryPoint/RequestFactory.php
@@ -0,0 +1,48 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Core\EntryPoint;
+
+use Espo\Core\Api\RequestWrapper;
+use Espo\Core\Utils\Route;
+use Slim\Factory\ServerRequestCreatorFactory;
+
+/**
+ * @internal
+ */
+class RequestFactory
+{
+ public function create(): RequestWrapper
+ {
+ return new RequestWrapper(
+ ServerRequestCreatorFactory::create()->createServerRequestFromGlobals(),
+ Route::detectBasePath()
+ );
+ }
+}
diff --git a/application/Espo/Core/EntryPoint/ResponseFactory.php b/application/Espo/Core/EntryPoint/ResponseFactory.php
new file mode 100644
index 0000000000..1b45672f16
--- /dev/null
+++ b/application/Espo/Core/EntryPoint/ResponseFactory.php
@@ -0,0 +1,44 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace Espo\Core\EntryPoint;
+
+use Espo\Core\Api\ResponseWrapper;
+use Slim\Psr7\Response;
+
+/**
+ * @internal
+ */
+class ResponseFactory
+{
+ public function create(): ResponseWrapper
+ {
+ return new ResponseWrapper(new Response());
+ }
+}
diff --git a/application/Espo/Core/EntryPoint/Starter.php b/application/Espo/Core/EntryPoint/Starter.php
index 1ce1152ef5..7bbee17a31 100644
--- a/application/Espo/Core/EntryPoint/Starter.php
+++ b/application/Espo/Core/EntryPoint/Starter.php
@@ -43,14 +43,9 @@ use Espo\Core\Api\RequestWrapper;
use Espo\Core\Api\ResponseWrapper;
use Espo\Core\Api\AuthBuilderFactory;
use Espo\Core\Portal\Utils\Url;
-use Espo\Core\Utils\Route;
use Espo\Core\Utils\ClientManager;
use Espo\Core\ApplicationRunners\EntryPoint as EntryPointRunner;
-use Slim\ResponseEmitter;
-use Slim\Factory\ServerRequestCreatorFactory;
-use Slim\Psr7\Response;
-
use Exception;
/**
@@ -65,35 +60,30 @@ class Starter
private ApplicationUser $applicationUser,
private AuthTokenManager $authTokenManager,
private AuthBuilderFactory $authBuilderFactory,
+ private RequestFactory $requestFactory,
+ private ResponseFactory $responseFactory,
private ErrorOutput $errorOutput,
+ private OutputEmitter $outputEmitter,
) {}
/**
- * @throws BadRequest
* @throws Forbidden
* @throws NotFound
*/
public function start(Params $params = new Params()): void
{
- $requestWrapped = new RequestWrapper(
- ServerRequestCreatorFactory::create()->createServerRequestFromGlobals(),
- Route::detectBasePath()
- );
+ $request = $this->requestFactory->create();
+ $response = $this->responseFactory->create();
- $method = $requestWrapped->getMethod();
-
- if ($params->allowedMethods !== null) {
- if (!in_array($method, $params->allowedMethods)) {
- throw new BadRequest("Method '$method' is not allowed.");
- }
- } else if ($method !== Method::GET) {
- throw new BadRequest("Only GET requests allowed for the entry point.");
- }
+ try {
+ $name = $this->getName($params, $request);
- $name = $params->name ?? $requestWrapped->getQueryParam('entryPoint');
+ $this->checkStart($name, $params, $request->getMethod());
+ } catch (BadRequest|Forbidden $e) {
+ $this->errorOutput->processWithBodyPrinting($request, $response, $e);
+ $this->outputEmitter->emit($response);
- if (!$name) {
- throw new BadRequest("No 'entryPoint' param.");
+ return;
}
/**
@@ -109,20 +99,17 @@ class Starter
return;
}
- $responseWrapped = new ResponseWrapper(new Response());
-
try {
$authRequired = $this->entryPointManager->checkAuthRequired($name);
- } catch (NotFound $exception) {
- $this->errorOutput->processWithBodyPrinting($requestWrapped, $responseWrapped, $exception);
-
- (new ResponseEmitter())->emit($responseWrapped->toPsr7());
+ } catch (NotFound $e) {
+ $this->errorOutput->processWithBodyPrinting($request, $response, $e);
+ $this->outputEmitter->emit($response);
return;
}
if ($authRequired && !$params->final) {
- $portalId = $this->detectPortalId($requestWrapped);
+ $portalId = $this->detectPortalId($request);
if ($portalId) {
$this->runThroughPortal($portalId, $name);
@@ -133,30 +120,31 @@ class Starter
$this->processRequest(
entryPoint: $name,
- requestWrapped: $requestWrapped,
- responseWrapped: $responseWrapped,
+ request: $request,
+ response: $response,
authRequired: $authRequired,
);
- (new ResponseEmitter())->emit($responseWrapped->toPsr7());
+ $this->outputEmitter->emit($response);
}
private function processRequest(
string $entryPoint,
- RequestWrapper $requestWrapped,
- ResponseWrapper $responseWrapped,
+ RequestWrapper $request,
+ ResponseWrapper $response,
bool $authRequired,
): void {
try {
$this->processRequestInternal(
entryPoint: $entryPoint,
- request: $requestWrapped,
- response: $responseWrapped,
+ request: $request,
+ response: $response,
authRequired: $authRequired,
);
} catch (Exception $exception) {
- $this->errorOutput->processWithBodyPrinting($requestWrapped, $responseWrapped, $exception);
+ print_r($exception->getMessage());
+ $this->errorOutput->processWithBodyPrinting($request, $response, $exception);
}
}
@@ -173,8 +161,7 @@ class Starter
$authentication = $this->authenticationFactory->create();
- $apiAuth = $this->authBuilderFactory
- ->create()
+ $apiAuth = $this->authBuilderFactory->create()
->setAuthentication($authentication)
->setAuthRequired($authRequired)
->forEntryPoint()
@@ -239,4 +226,39 @@ class Starter
$app->run(EntryPointRunner::class, $params);
}
+
+ /**
+ * @throws BadRequest
+ */
+ private function getName(Params $params, RequestWrapper $request): string
+ {
+ $name = $params->name ?? $request->getQueryParam('entryPoint');
+
+ if (!$name) {
+ throw new BadRequest("No 'entryPoint' param.");
+ }
+
+ return $name;
+ }
+
+ /**
+ * @throws BadRequest
+ * @throws Forbidden
+ */
+ private function checkStart(string $name, Params $params, string $method): void
+ {
+ $metaParams = $this->entryPointManager->getMetaParams($name);
+
+ if ($metaParams->notExposed && $params->name === null) {
+ throw new Forbidden("The entry point is not exposed.");
+ }
+
+ if ($metaParams->allowedMethods !== null) {
+ if (!in_array(strtolower($method), $metaParams->allowedMethods)) {
+ throw new BadRequest("Method '$method' is not allowed.");
+ }
+ } else if ($method !== Method::GET) {
+ throw new BadRequest("Only GET requests allowed for the entry point.");
+ }
+ }
}
diff --git a/application/Espo/EntryPoints/OauthCallback.php b/application/Espo/EntryPoints/OauthCallback.php
index 70ff1dcad9..55d9114b3b 100644
--- a/application/Espo/EntryPoints/OauthCallback.php
+++ b/application/Espo/EntryPoints/OauthCallback.php
@@ -43,7 +43,11 @@ class OauthCallback implements EntryPoint
public function run(Request $request, Response $response): void
{
- echo "If this window is not closed automatically, it's probable that the URL you use to access ".
- "EspoCRM doesn't match the URL specified at Administration > Settings > Site URL.";
+ $text = <<<EOF
+ If this window is not closed automatically, it can be because the used URL
+ doesn't match the URL specified at Administration > Settings > Site URL.
+ EOF;
+
+ $response->writeBody($text);
}
}
diff --git a/application/Espo/Resources/metadata/app/entryPoints.json b/application/Espo/Resources/metadata/app/entryPoints.json
new file mode 100644
index 0000000000..323ba47d87
--- /dev/null
+++ b/application/Espo/Resources/metadata/app/entryPoints.json
@@ -0,0 +1,8 @@
+{
+ "pdf": {
+ "className": "Espo\\EntryPoints\\Pdf"
+ },
+ "oauthCallback": {
+ "className": "Espo\\EntryPoints\\OauthCallback"
+ }
+}
diff --git a/schema/metadata/app/entryPoints.json b/schema/metadata/app/entryPoints.json
new file mode 100644
index 0000000000..605d8331e9
--- /dev/null
+++ b/schema/metadata/app/entryPoints.json
@@ -0,0 +1,40 @@
+{
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
+ "$id": "https://www.espocrm.com/schema/metadata/app/scheduledJobs.json",
+ "title": "app/scheduledJobs",
+ "description": "Entry points definitions. As of v10.1.",
+ "type": "object",
+ "additionalProperties": {
+ "description": "An entry point name. Should start with a lower case letter.",
+ "type": "object",
+ "properties": {
+ "className": {
+ "type": "string",
+ "description": "An entry point implementation. Should implement Espo\\Core\\EntryPoint\\EntryPoint."
+ },
+ "notExposed": {
+ "type": "boolean",
+ "description": "If true, the entry point is not available via the regular entryPoint request – can be called only programmatically."
+ },
+ "noAuth": {
+ "type": "boolean",
+ "description": "If true, authentication is not required."
+ },
+ "allowedMethods": {
+ "type": "array",
+ "items": {
+ "enum": [
+ "get",
+ "post",
+ "put",
+ "delete",
+ "options",
+ "patch"
+ ]
+ },
+ "description": "Allowed HTTP methods.",
+ "default": ["get"]
+ }
+ }
+ }
+}
diff --git a/tests/integration/Core/BaseTestCase.php b/tests/integration/Core/BaseTestCase.php
index f69f01e597..c0cbd58c92 100644
--- a/tests/integration/Core/BaseTestCase.php
+++ b/tests/integration/Core/BaseTestCase.php
@@ -94,6 +94,7 @@ abstract class BaseTestCase extends TestCase
?string $portalId = null,
?BindingProcessor $binding = null,
bool $reuse = false,
+ bool $noUser = false,
): Application {
if (!$this->isNotCleanTest() && !$reuse) {
@@ -112,6 +113,7 @@ abstract class BaseTestCase extends TestCase
portalId: $portalId,
binding: $binding,
reuse: $reuse,
+ noUser: $noUser,
);
}
@@ -266,11 +268,15 @@ abstract class BaseTestCase extends TestCase
/**
* Re-create an application.
+ *
+ * @param bool $reuse Re-use the previous application for performance.
+ * @param bool $noUser Do not set current user. May be needed when testing authentication.
*/
- protected function reCreateApplication(bool $reuse = false): void
+ protected function reCreateApplication(bool $reuse = false, bool $noUser = false): void
{
$this->espoApplication = $this->createApplication(
reuse: $reuse,
+ noUser: $noUser,
);
}
diff --git a/tests/integration/Core/Tester.php b/tests/integration/Core/Tester.php
index cab713ba79..e687e71882 100644
--- a/tests/integration/Core/Tester.php
+++ b/tests/integration/Core/Tester.php
@@ -198,6 +198,7 @@ class Tester
?string $portalId = null,
?BindingProcessor $binding = null,
bool $reuse = false,
+ bool $noUser = false,
): Application {
if ($this->application && !$reload) {
@@ -226,10 +227,12 @@ class Tester
$this->application = new Application($applicationParams);
}
- if (isset($this->userName) || $this->authenticationMethod) {
- $this->login();
- } else {
- $this->application->setupSystemUser();
+ if (!$noUser) {
+ if (isset($this->userName) || $this->authenticationMethod) {
+ $this->login();
+ } else {
+ $this->application->setupSystemUser();
+ }
}
return $this->application;
diff --git a/tests/integration/Espo/Core/EntryPoint/EntryPointTest.php b/tests/integration/Espo/Core/EntryPoint/EntryPointTest.php
new file mode 100644
index 0000000000..ea477fe4a8
--- /dev/null
+++ b/tests/integration/Espo/Core/EntryPoint/EntryPointTest.php
@@ -0,0 +1,244 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 EspoCRM, Inc.
+ * Website: https://www.espocrm.com
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * The interactive user interfaces in modified source and object code versions
+ * of this program must display Appropriate Legal Notices, as required under
+ * Section 5 of the GNU Affero General Public License version 3.
+ *
+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
+ ************************************************************************/
+
+namespace integration\Espo\Core\EntryPoint;
+
+use Espo\Core\Api\ErrorOutput;
+use Espo\Core\Api\Method;
+use Espo\Core\Api\RequestWrapper;
+use Espo\Core\Api\ResponseWrapper;
+use Espo\Core\ApplicationState;
+use Espo\Core\Binding\BindingContainerBuilder;
+use Espo\Core\EntryPoint\OutputEmitter;
+use Espo\Core\EntryPoint\RequestFactory;
+use Espo\Core\EntryPoint\ResponseFactory;
+use Espo\Core\EntryPoint\Starter;
+use tests\integration\Core\BaseTestCase;
+
+class EntryPointTest extends BaseTestCase
+{
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function testNoAuth(): void
+ {
+ $this->reCreateApplication(reuse: true, noUser: true);
+
+ $outputEmitter = $this->createMock(OutputEmitter::class);
+ $errorOutput = $this->createMock(ErrorOutput::class);
+
+ $request = $this->createRequest(
+ method: Method::GET,
+ queryParams: [
+ 'entryPoint' => 'oauthCallback',
+ ],
+ );
+
+ $response = $this->createMock(ResponseWrapper::class);
+
+ $starter = $this->createStarter(
+ request: $request,
+ response: $response,
+ outputEmitter: $outputEmitter,
+ errorOutput: $errorOutput,
+ );
+
+ $errorOutput
+ ->expects(self::never())
+ ->method('processWithBodyPrinting');
+
+ $response
+ ->expects(self::once())
+ ->method('writeBody')
+ ->with(
+ $this->callback(function (string $body) {
+ return str_contains($body, "Site URL");
+ })
+ );
+
+ $starter->start();
+
+ $applicationState = $this->getContainer()->getByClass(ApplicationState::class);
+
+ $this->assertTrue($applicationState->hasUser());
+ }
+
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function testNoPostMethod(): void
+ {
+ $this->reCreateApplication(reuse: true, noUser: true);
+
+ $outputEmitter = $this->createMock(OutputEmitter::class);
+ $errorOutput = $this->createMock(ErrorOutput::class);
+
+ $request = $this->createRequest(
+ method: Method::POST,
+ queryParams: [
+ 'entryPoint' => 'oauthCallback',
+ ],
+ );
+
+ $response = $this->createMock(ResponseWrapper::class);
+
+ $starter = $this->createStarter(
+ request: $request,
+ response: $response,
+ outputEmitter: $outputEmitter,
+ errorOutput: $errorOutput,
+ );
+
+ $errorOutput
+ ->expects(self::once())
+ ->method('processWithBodyPrinting');
+
+ $starter->start();
+
+ $applicationState = $this->getContainer()->getByClass(ApplicationState::class);
+
+ $this->assertFalse($applicationState->hasUser());
+ }
+
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function testAllowedMethods(): void
+ {
+ $metadata = $this->getMetadata();
+ $metadata->set('app', 'entryPoints', [
+ 'oauthCallback' => [
+ 'allowedMethods' => ['get', 'post'],
+ ],
+ ]);
+ $metadata->save();
+
+ $this->reCreateApplication(reuse: true, noUser: true);
+
+ $outputEmitter = $this->createMock(OutputEmitter::class);
+ $errorOutput = $this->createMock(ErrorOutput::class);
+
+ $request = $this->createRequest(
+ method: Method::POST,
+ queryParams: [
+ 'entryPoint' => 'oauthCallback',
+ ],
+ );
+
+ $response = $this->createMock(ResponseWrapper::class);
+
+ $starter = $this->createStarter(
+ request: $request,
+ response: $response,
+ outputEmitter: $outputEmitter,
+ errorOutput: $errorOutput,
+ );
+
+ $errorOutput
+ ->expects(self::never())
+ ->method('processWithBodyPrinting');
+
+ $starter->start();
+
+ $applicationState = $this->getContainer()->getByClass(ApplicationState::class);
+
+ $this->assertTrue($applicationState->hasUser());
+ }
+
+ /**
+ * @noinspection PhpUnhandledExceptionInspection
+ */
+ public function testAuthRequired(): void
+ {
+ $this->reCreateApplication(reuse: true, noUser: true);
+
+ $outputEmitter = $this->createMock(OutputEmitter::class);
+ $errorOutput = $this->createMock(ErrorOutput::class);
+
+ $request = $this->createRequest(
+ method: Method::GET,
+ queryParams: [
+ 'entryPoint' => 'avatar',
+ ],
+ );
+
+ $response = $this->createMock(ResponseWrapper::class);
+
+ $starter = $this->createStarter(
+ request: $request,
+ response: $response,
+ outputEmitter: $outputEmitter,
+ errorOutput: $errorOutput,
+ );
+
+ $errorOutput
+ ->expects(self::never())
+ ->method('processWithBodyPrinting');
+
+ $response
+ ->expects(self::never())
+ ->method('writeBody');
+
+ $starter->start();
+
+ $applicationState = $this->getContainer()->getByClass(ApplicationState::class);
+
+ $this->assertFalse($applicationState->hasUser());
+ }
+
+ private function createStarter(
+ RequestWrapper $request,
+ ResponseWrapper $response,
+ OutputEmitter $outputEmitter,
+ ErrorOutput $errorOutput,
+ ): Starter {
+
+ $requestFactory = $this->createMock(RequestFactory::class);
+ $responseFactory = $this->createMock(ResponseFactory::class);
+
+ $requestFactory
+ ->expects(self::once())
+ ->method('create')
+ ->willReturn($request);
+
+ $responseFactory
+ ->expects(self::once())
+ ->method('create')
+ ->willReturn($response);
+
+ $binding = BindingContainerBuilder::create()
+ ->bindInstance(RequestFactory::class, $requestFactory)
+ ->bindInstance(ResponseFactory::class, $responseFactory)
+ ->bindInstance(OutputEmitter::class, $outputEmitter)
+ ->bindInstance(ErrorOutput::class, $errorOutput)
+ ->build();
+
+ return $this->getInjectableFactory()->createWithBinding(Starter::class, $binding);
+ }
+}