<commit_before><?php

namespace Tests\Unit\Signer;

use ByteArk\Signer\ByteArkV2UrlSigner;
use Tests\TestCase;

class ByteArkV2UrlSignerTest extends TestCase
{
    public function testSignUrl_withCredentials_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=<KEY>'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_expires=1514764800'
                . '&x_ark_signature=cLwtn96a-YPY7jt8ZKSf_Q',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withCustomHttpMethod_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'method' => 'HEAD',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_expires=1514764800'
                . '&x_ark_signature=QULE8DQ08f8fhFC-1gDUWQ',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withSignClientIpOption_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'client_ip' => '172.16.17.32',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_client_ip=1'
                . '&x_ark_expires=1514764800'
                . '&x_ark_signature=Gr9T_ZdHDy8l8CCPxpFjNg',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withSignClientIpOption_evenWithDashInsteadOfUnderscore_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '2Aj6Wkge4hi1ZYLp0DBG',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'client_ip' => '172.16.17.32',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_client_ip=1'
                . '&x_ark_expires=1514764800'
                . '&x_ark_signature=Gr9T_ZdHDy8l8CCPxpFjNg',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withSignClientIpOption_withPathPrefixOption_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '2Aj6Wkge4hi1ZYLp0DBG',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'client_ip' => '172.16.17.32',
                'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_client_ip=1'
                . '&x_ark_expires=1514764800'
                . '&x_ark_path_prefix=%2Fvideo-objects%2FQDuxJm02TYqJ%2F'
                . '&x_ark_signature=2bkwVFSu6CzW7KmzXkwDbA',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withSignClientIpOption_withPathPrefixOption_withSkipUrlEncodingOptions_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '2Aj6Wkge4hi1ZYLp0DBG',
            'access_secret' => '<KEY>',
            'skip_url_encoding' => true,
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'client_ip' => '172.16.17.32',
                'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_client_ip=1'
                . '&x_ark_expires=1514764800'
                . '&x_ark_path_prefix=/video-objects/QDuxJm02TYqJ/'
                . '&x_ark_signature=2bkwVFSu6CzW7KmzXkwDbA',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withSignClientIpOption_withSignUserAgentOption_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'client_ip' => '172.16.17.32',
                'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.68 Safari/537.36',<commit_msg>Remove legacy test cases<commit_after><?php

namespace Tests\Unit\Signer;

use ByteArk\Signer\ByteArkV2UrlSigner;
use Tests\TestCase;

class ByteArkV2UrlSignerTest extends TestCase
{
    public function testSignUrl_withCredentials_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_expires=1514764800'
                . '&x_ark_signature=cLwtn96a-YPY7jt8ZKSf_Q',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withCustomHttpMethod_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'method' => 'HEAD',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=2Aj6Wkge4hi1ZYLp0DBG'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_expires=1514764800'
                . '&x_ark_signature=QULE8DQ08f8fhFC-1gDUWQ',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withPathPrefixOption_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=<KEY>'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_expires=1514764800'
                . '&x_ark_path_prefix=%2Fvideo-objects%2FQDuxJm02TYqJ%2F'
                . '&x_ark_signature=334wInm0jKfC6LCm23zndA',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withPathPrefixOption_withSkipUrlEncodingOptions_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
            'skip_url_encoding' => true,
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'path_prefix' => '/video-objects/QDuxJm02TYqJ/',
            ]
        );

        $this->assertEquals(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8'
                . '?x_ark_access_id=<KEY>'
                . '&x_ark_auth_type=ark-v2'
                . '&x_ark_expires=1514764800'
                . '&x_ark_path_prefix=/video-objects/QDuxJm02TYqJ/'
                . '&x_ark_signature=334wInm0jKfC6LCm23zndA',
            $signedUrl
        );
    }

    public function testSignUrl_withCredentials_withSignClientIpOption_withSignUserAgentOption_shouldGenerateValidSignedUrl()
    {
        $signer = new ByteArkV2UrlSigner([
            'access_id' => '<KEY>',
            'access_secret' => '<KEY>',
        ]);

        $signedUrl = $signer->sign(
            'http://inox.qoder.byteark.com/video-objects/QDuxJm02TYqJ/playlist.m3u8',
            1514764800,
            [
                'client_ip' => '172.16.17.32',
                'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.68 Safari/537.36',
{'fraction_non_alphanumeric': 0.12456223379081874, 'fraction_numerical': 0.053005205868433505, 'mean_word_length': 1.9027472527472526, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, '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': '3823563', 'n_tokens_mistral': 4116, 'n_tokens_neox': 3807, 'n_words': 326}