public function testPublicList() { $client = new Client(['token' => 'token is not required for this api all', 'url' => getenv('KBC_MANAGE_API_URL'), 'backoffMaxTries' => 1]); $apps = $client->listUiApps(); $app = reset($apps); $this->assertNotEmpty($app['name']); $this->assertNotEmpty($app['version']); $this->assertNotEmpty($app['basePath']); $this->assertNotEmpty($app['styles']); $this->assertNotEmpty($app['scripts']); }
public function testVerifySuperToken() { $client = new Client(['token' => getenv('KBC_SUPER_API_TOKEN'), 'url' => getenv('KBC_MANAGE_API_URL'), 'backoffMaxTries' => 1]); $token = $client->verifyToken(); $this->assertInternalType('int', $token['id']); $this->assertNotEmpty($token['description']); $this->assertNotEmpty($token['created']); $this->assertFalse($token['isDisabled']); $this->assertFalse($token['isExpired']); $this->assertInternalType('array', $token['scopes']); $this->assertEquals($token['type'], 'super'); $this->assertFalse($token['isSessionToken']); }
protected function initManageApi(Request $request) { if (!$request->headers->get("X-KBC-ManageApiToken")) { throw new UserException("Token not set."); } $client = new Client(["token" => $request->headers->get("X-KBC-ManageApiToken"), "url" => $this->container->getParameter("storage_api.url")]); $this->manageApiClient = $client; try { $this->tokenInfo = $client->verifyToken(); } catch (ClientException $e) { throw new UserException($e->getMessage()); } }
public function testUserShouldNotReceiveOldNotificationsOnProjectEnter() { $this->markTestSkipped('must be revisited.'); $organization = $this->client->createOrganization($this->testMaintainerId, ['name' => 'My org']); $project = $this->client->createProject($organization['id'], ['name' => 'My test']); $msg1 = 'notificationBeforeAdminEnters' . microtime(); $notification = $this->client->addNotification(['type' => 'common', 'projectId' => $project['id'], 'title' => 'notificationBeforeAdminEnters', 'message' => $msg1]); // ensure that current admin which is member of project will receive notification $this->getNotificationById($notification['id']); // add new user to project $adminEmail = getenv('KBC_TEST_ADMIN_EMAIL'); $this->client->addUserToProject($project['id'], ['email' => $adminEmail]); $newAdminClient = new Client(['token' => getenv('KBC_TEST_ADMIN_TOKEN'), 'url' => getenv('KBC_MANAGE_API_URL')]); $notifications = $newAdminClient->getNotifications(); $received = array_filter($notifications, function ($iteratedNotification) use($notification) { return $iteratedNotification['id'] === $notification['id']; }); $this->assertCount(0, $received, 'New project admin should not receive old notifications'); }
/** * @param string $scope * @param Request $request * @return bool */ protected function checkScope($scope, Request $request) { if (!$request->headers->get("X-KBC-ManageApiToken")) { throw new UserException("Manage API Token not set."); } $client = new Client(["token" => $request->headers->get("X-KBC-ManageApiToken"), "url" => $this->container->getParameter('storage_api.url')]); try { $token = $client->verifyToken(); } catch (ClientException $e) { throw new UserException("Error validating Manage token: " . $e->getMessage()); } return is_array($token['scopes']) && in_array($scope, $token['scopes']); }