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'); $params = []; $data = '{"event":"Account.create"}'; $this->expectException(\Espo\Core\Exceptions\Forbidden::class); $request = $this->createRequest('POST', $params, ['CONTENT_TYPE' => 'application/json']); $result = $controllerManager->process('Webhook', 'create', $params, $data, $request); } public function testApiUserNoAccess1() { $this->createUser( [ 'userName' => 'api', 'type' => 'api', 'authMethod' => 'ApiKey', 'apiKey' => 'test-key', ], [ 'data' => [ 'Webhook' => false, ], ] ); $this->auth('test-key', null, null, 'ApiKey'); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $data = '{"event":"Account.create", "url": "https://test"}'; $params = []; $this->expectException(\Espo\Core\Exceptions\Forbidden::class); $request = $this->createRequest('POST', $params, ['CONTENT_TYPE' => 'application/json']); $result = $controllerManager->process('Webhook', 'create', $params, $data, $request); } public function testApiUserNoAccess2() { $this->createUser( [ 'userName' => 'api', 'type' => 'api', 'authMethod' => 'ApiKey', 'apiKey' => 'test-key', ], [ 'data' => [ 'Webhook' => false, 'Account' => false, ], ] ); $this->auth('test-key', null, null, 'ApiKey'); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $data = '{"event":"Account.create", "url": "https://test"}'; $params = []; $this->expectException(\Espo\Core\Exceptions\Forbidden::class); $request = $this->createRequest('POST', $params, ['CONTENT_TYPE' => 'application/json']); $result = $controllerManager->process('Webhook', 'create', $params, $data, $request); } public function testApiUserHasAccess1() { $this->createUser( [ 'userName' => 'api', 'type' => 'api', 'authMethod' => 'ApiKey', 'apiKey' => 'test-key', ], [ 'data' => [ 'Webhook' => true, 'Account' => ['create'=> true, 'read' => 'own'], ], ] ); $this->auth('test-key', null, null, 'ApiKey'); $app = $this->createApplication(); $controllerManager = $app->getContainer()->get('controllerManager'); $data = '{"event":"Account.create", "url": "https://test"}'; $params = []; $request = $this->createRequest('POST', $params, ['CONTENT_TYPE' => 'application/json']); $result = $controllerManager->process('Webhook', 'create', $params, $data, $request); $this->assertTrue(!empty($result)); } }