public function createJsonRequest($method, array $params = [])
 {
     $this->request = new Request(Arr::get($params, 'getParams', []), [], Arr::get($params, 'attributes', []), [], [], [], Arr::get($params, 'content') !== null ? json_encode($params['content']) : '');
     $this->request->setMethod($method);
     $this->request->headers->set('CONTENT_TYPE', 'application/json');
     return $this->request;
 }
Example #2
0
 /**
  * {@inheritDoc}
  */
 public function checkClientCredentials($clientId, $clientSecret = null)
 {
     $select = new Select($this->config['client_table']);
     $select->where(array('client_id' => $clientId));
     $result = $this->execute($select)->current();
     return Arr::get($result, 'client_secret', null) === $clientSecret;
 }
 public function withUserFoundHavingPassword($password, $attributes = [])
 {
     $hashedPassword = password_hash($password, PASSWORD_BCRYPT);
     $attributes['enabled'] = Arr::get($attributes, 'enabled', '1');
     $attributes['verified'] = Arr::get($attributes, 'verified', '1');
     $attributes['password'] = $hashedPassword;
     $user = new UserEntity($attributes);
     $this->mockUserService->expects($this->any())->method('findByEmail')->will($this->returnValue($user));
 }
 public function setMockInputWithArguments(array $args = [])
 {
     $this->mocks['input'] = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\ArrayInput')->disableOriginalConstructor()->getMock();
     $this->mocks['input']->expects($this->any())->method('getArguments')->will($this->returnValue($args));
     $getter = function ($field) use($args) {
         return Arr::get($args, $field);
     };
     $this->mocks['input']->expects($this->any())->method('getArgument')->will($this->returnCallback($getter));
 }
Example #5
0
 /**
  * @param RollbarNotifier  $rollbarNotifier RollbarNotifier object constructed with valid token
  * @param string           $environment
  * @param boolean          $bubble          Whether the messages that are handled can bubble up the stack or not
  */
 public function __construct($config, $environment, $bubble = true)
 {
     $token = Arr::get($config, 'post_server_item_access_token');
     if (!$token) {
         throw new ConfigException('Rollbar is enabled but the post server item access token is not set.');
     }
     $this->rollbarNotifier = new RollbarNotifier(['access_token' => $token, 'environment' => $environment, 'batched' => false, 'root' => Arr::get($config, 'root')]);
     $level = Arr::path($config, 'level') ?: Logger::ERROR;
     parent::__construct($level, $bubble);
 }
 public function setUpMockUrlGenerator()
 {
     $captured = $this->captured;
     $this->mockUrlGenerator = $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface');
     $this->mockUrlGenerator->expects($this->any())->method('generate')->will($this->returnCallback(function ($name, $params, $refType) use($captured) {
         $generatedUrl = '/users/' . Arr::get($params, 'id');
         $captured->generatedUrl = $generatedUrl;
         return $generatedUrl;
     }));
     $this->captured = $captured;
 }
 /**
  * Verify user registration with token and user id
  *
  * @param  Request $request
  * @return array
  */
 public function post(Request $request)
 {
     $id = $request->attributes->get('id');
     $token = Arr::get($this->getContentAsArray($request), 'token');
     if (!$token) {
         return $this->createSimpleResponse(422, 'Token not specified.');
     }
     $conditions = ['user_id' => $id, 'token' => $token, 'token_type_id' => TokenEntity::TYPE_VERIFY_REGISTRATION];
     $token = $this->userService->findTokenBy($conditions);
     if (!$token) {
         return $this->createNotFoundResponse();
     }
     try {
         $user = $this->userService->verifyRegistration($token);
     } catch (OutOfBoundsException $e) {
         $httpCodes = [UserService::INCORRECT_TOKEN_TYPE => 422, UserService::TOKEN_EXPIRED => 410, UserService::TOKEN_NOT_FOUND => 404];
         return $this->createErrorResponse(['token' => ['INVALID']], $httpCodes[$e->getCode()]);
     }
     $user = $user->getArrayCopy();
     unset($user['password']);
     return $user;
 }
 /**
  * Reset password using token and new password
  *
  * @param  Request $request
  * @return array
  */
 public function put(Request $request)
 {
     $token = Arr::get($this->getContentAsArray($request), 'token');
     // Ensure token is valid
     $token = $this->userService->findTokenBy(['token' => $token, 'token_type_id' => TokenEntity::TYPE_RESET_PASSWORD]);
     if (!$token) {
         return $this->createNotFoundResponse();
     }
     if ($token->getExpires() < time()) {
         return $this->createNotFoundResponse();
     }
     $user = $this->userService->findById($token->getUserId());
     if (!$user) {
         return $this->createNotFoundResponse();
     }
     $password = Arr::get($this->getContentAsArray($request), 'password');
     // Ensure user input is valid
     if (!$password) {
         return $this->createErrorResponse(['password' => ['EMPTY']], 422);
     }
     $this->userService->resetPassword($user, $password);
     $this->userService->deleteToken($token);
     return $this->userArrayWithoutPassword($user);
 }
Example #9
0
 /**
  * Get the count of results from a given query
  *
  * @param  Select $query
  * @return int
  */
 protected function getQueryResultCount(Select $query)
 {
     $queryString = $this->getSqlObject()->getSqlStringForSqlObject($query, $this->dbAdapter->getPlatform());
     $format = 'Select count(*) as `count` from (%s) as `query_count`';
     $countQueryString = sprintf($format, $queryString);
     $countQuery = $this->dbAdapter->query($countQueryString);
     $result = $countQuery->execute()->current();
     return (int) Arr::get($result, 'count');
 }
Example #10
0
 /**
  * Get the query parameters given for the SQL query provided
  *
  * @param  integer $key Key of the SQL query run (0 = the first query run, 1 = the second, etc)
  * @return array|null   List of parameters or null if none found
  */
 protected function getQueryParams($key = 0)
 {
     return Arr::get($this->queryParameters, $key);
 }
 /**
  * Register log handler for Rollbar
  *
  * @return RollbarHandler
  */
 protected function getRollbarHandler($environment)
 {
     $rollbarConfig = Arr::get($this->config, 'rollbar', []);
     return new RollbarHandler($rollbarConfig, $environment);
 }
Example #12
0
 /**
  * Tests Arr::get()
  *
  * @test
  * @dataProvider providerGet()
  * @param array          $array      Array to look in
  * @param string|integer $key        Key to look for
  * @param mixed          $default    What to return if $key isn't set
  * @param mixed          $expected   The expected value returned
  */
 public function testGet(array $array, $key, $default, $expected)
 {
     $this->assertSame($expected, Arr::get($array, $key, $default));
 }
Example #13
0
 /**
  * Handle logout request
  *
  * @param  Request $request
  * @return Response
  */
 public function logout(Request $request)
 {
     $content = json_decode($request->getContent(), true);
     $securityToken = $this->security->getToken();
     $user = $securityToken->getUser();
     $accessToken = $securityToken->getOAuthToken();
     $refreshToken = Arr::get($content, 'refresh_token');
     $this->session->set('user', null);
     if (!$refreshToken) {
         return new Response('Refresh token not provided', 422);
     }
     try {
         $this->expireAccessToken($accessToken);
         $this->expireRefreshToken($refreshToken, $user);
     } catch (OutOfBoundsException $e) {
         return new Response($e->getMessage(), 422);
     }
     return new Response('', 200);
 }
 /**
  * Export database data to dbData install file
  *
  * @param  string $outputPath Path where file should be exported
  */
 protected function dumpData($outputPath)
 {
     $tables = Arr::get($this->installConfig, 'dataTables', []);
     /**
      *  Do not attempt to create an empty data install file if no tables are to be exported.
      *  Otherwise all tables will be exported.
      */
     if (!count($tables)) {
         return;
     }
     $command = sprintf('mysqldump %s %s -u %s -p%s --no-create-info > %s', escapeshellarg($this->dbConfig['database']), implode(' ', $tables), escapeshellarg($this->dbConfig['username']), escapeshellarg($this->dbConfig['password']), escapeshellarg($outputPath . '/' . self::DATA_FILE));
     return shell_exec($command);
 }
Example #15
0
 /**
  * Initialize Resque
  *
  * @param array $config
  */
 public function __construct($config = [])
 {
     ResqueLib::setBackend(Arr::get($config, 'host'));
 }
 public function testPutReturns200AndUserEntityWithPasswordRemoved()
 {
     $this->withUserServiceFindTokenByReturningToken();
     $this->withUserServiceFindByIdReturningUser();
     $response = $this->performPutRequest();
     $this->assertEquals(200, $response->getStatusCode());
     $responseBody = json_decode($response->getContent(), true);
     $this->assertEquals(null, Arr::get($responseBody, 'content'));
 }