<commit_before><?php
declare(strict_types = 1);
/**
 * /src/Utils/Tests/Auth.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Utils\Tests;

use App\Utils\JSON;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;

/**
 * Class Auth
 *
 * @package App\Utils\Tests
 * @author  TLe, <NAME> <<EMAIL>>
 */
class Auth
{
    /**
     * @var ContainerInterface
     */
    private $container;

    /**
     * JWT cache
     *
     * @var \string[]
     */
    private $cache = [];

    /**
     * Auth constructor.
     *
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * Method to get authorization headers for specified user.
     *
     * @param string $username
     * @param string $password
     *
     * @return array
     *
     * @throws \Exception
     */
    public function getAuthorizationHeadersForUser(string $username, string $password): array
    {
        $key = \hash('sha512', $username . $password);

        if (!\array_key_exists($key, $this->cache)) {
            $this->cache[$key] = $this->getToken($username, $password);
        }

        // Return valid authorization headers for user
        return $this->getAuthorizationHeaders($this->cache[$key]);
    }

    /**
     * Method to get authorization headers for specified API Key role.
     *
     * @param string $role
     *
     * @return array
     */
    public function getAuthorizationHeadersForApiKey(string $role): array
    {
        return [
            'CONTENT_TYPE'          => 'application/json',
            'HTTP_AUTHORIZATION'    => 'ApiKey ' . \str_pad($role, 40, '_'),
        ];
    }

    /**
     * Method to get authorization headers for specified token.
     *
     * @param string $token
     *
     * @return array
     */<commit_msg>tests: "small" fix, although this should affect test performance quite lot...<commit_after><?php
declare(strict_types = 1);
/**
 * /src/Utils/Tests/Auth.php
 *
 * @author  TLe, <NAME> <<EMAIL>>
 */
namespace App\Utils\Tests;

use App\Utils\JSON;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;

/**
 * Class Auth
 *
 * @package App\Utils\Tests
 * @author  TLe, <NAME> <<EMAIL>>
 */
class Auth
{
    /**
     * @var ContainerInterface
     */
    private $container;

    /**
     * JWT cache
     *
     * @var \string[]
     */
    private $cache = [];

    /**
     * Auth constructor.
     *
     * @param ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    /**
     * Method to get authorization headers for specified user.
     *
     * @param string $username
     * @param string $password
     *
     * @return array
     *
     * @throws \Exception
     */
    public function getAuthorizationHeadersForUser(string $username, string $password): array
    {
        // Return valid authorization headers for user
        return $this->getAuthorizationHeaders($this->getToken($username, $password));
    }

    /**
     * Method to get authorization headers for specified API Key role.
     *
     * @param string $role
     *
     * @return array
     */
    public function getAuthorizationHeadersForApiKey(string $role): array
    {
        return [
            'CONTENT_TYPE'          => 'application/json',
            'HTTP_AUTHORIZATION'    => 'ApiKey ' . \str_pad($role, 40, '_'),
        ];
    }

    /**
     * Method to get authorization headers for specified token.
     *
     * @param string $token
     *
     * @return array
     */
{'fraction_non_alphanumeric': 0.1289291422482685, 'fraction_numerical': 0.002397442727757059, 'mean_word_length': 2.1984667802385007, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2453826', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1069, 'n_words': 261}