createUser( [ 'userName' => 'test', 'password' => '1', ], [ 'data' => [ 'Webhook' => true, 'Account' => ['create'=> true, 'read' => 'own'], ], ] ); $this->auth('test', '1'); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $this->expectException(\Espo\Core\Exceptions\Forbidden::class); $request = $this->createRequest('POST', [], ['Content-Type' => 'application/json']); $data = json_decode('{"event":"Account.create"}'); $result = $controllerManager->process('Webhook', 'POST', 'create', [], $data, $request, $this->createResponse()); } public function testApiUserNoAccess1() { $this->createUser( [ 'userName' => 'api', 'type' => 'api', 'authMethod' => 'ApiKey', 'apiKey' => 'test-key', ], [ 'data' => [ 'Webhook' => false, ], ] ); $request = $this->createRequest('POST', [], [ 'Content-Type' => 'application/json', 'X-Api-Key' => 'test-key', ]); $this->auth(null, null, null, 'ApiKey', $request); $data = json_decode('{"event":"Account.create", "url": "https://test"}'); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $this->expectException(\Espo\Core\Exceptions\Forbidden::class); $result = $controllerManager->process('Webhook', 'POST', 'create', [], $data, $request, $this->createResponse()); } public function testApiUserNoAccess2() { $this->createUser( [ 'userName' => 'api', 'type' => 'api', 'authMethod' => 'ApiKey', 'apiKey' => 'test-key', ], [ 'data' => [ 'Webhook' => false, 'Account' => false, ], ] ); $request = $this->createRequest('POST', [], [ 'Content-Type' => 'application/json', 'X-Api-Key' => 'test-key', ]); $this->auth(null, null, null, 'ApiKey', $request); $data = json_decode('{"event":"Account.create", "url": "https://test"}'); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $this->expectException(\Espo\Core\Exceptions\Forbidden::class); $result = $controllerManager->process('Webhook', 'POST', 'create', [], $data, $request, $this->createResponse()); } public function testApiUserHasAccess1() { $this->createUser( [ 'userName' => 'api', 'type' => 'api', 'authMethod' => 'ApiKey', 'apiKey' => 'test-key', ], [ 'data' => [ 'Webhook' => true, 'Account' => ['create' => true, 'read' => 'own'], ], ] ); $request = $this->createRequest('POST', [], [ 'Content-Type' => 'application/json', 'X-Api-Key' => 'test-key', ]); $this->auth(null, null, null, 'ApiKey', $request); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $data = json_decode('{"event":"Account.create", "url": "https://test"}'); $result = $controllerManager->process('Webhook', 'POST', 'create', [], $data, $request, $this->createResponse()); $this->assertTrue(!empty($result)); } }