Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added acceptance authorization tests #391

Open
wants to merge 1 commit into
base: 3.5.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions app/library/Github/OAuth.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -46,10 +46,10 @@ class OAuth extends Injectable
*/
public function __construct(Config $config)
{
$this->redirectUriAuthorize = $config->get('redirectUri');
$this->logger = $this->getDI()->get('logger', ['auth']);
$this->redirectUriAuthorize = $this->getRedirectGitPath($config->get('redirectUri'));
$this->clientId = $config->get('clientId');
$this->clientSecret = $config->get('clientSecret');
$this->logger = $this->getDI()->get('logger', ['auth']);
}

public function authorize()
@@ -132,4 +132,26 @@ public function send($url, $parameters, $method = 'post')
return false;
}
}

/**
* @param string $url
*
* @return string
*/
protected function getRedirectGitPath($url)
{
if (empty($url)) {
$this->logger->error("Parameter GITHUB_REDIRECT_URI in .env file doesn't exist");
}

$redirectUrl = rtrim($url, '/');
if (stristr($redirectUrl, '://')) {
$redirectUrl = stristr($redirectUrl, '://');
$redirectUrl = $_SERVER['REQUEST_SCHEME'] . $redirectUrl . '/';
} else {
$redirectUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $redirectUrl . '/';
}

return $redirectUrl;
}
}
73 changes: 73 additions & 0 deletions tests/acceptance/AuthorizationCest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon forum |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to license@phalconphp.com so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Sergii Svyrydenko <sergey.v.sviridenko@gmail.com> |
+------------------------------------------------------------------------+
*/

class AuthorizationCest
{
public function shouldCheckAutorizationOnForumWithGit(AcceptanceTester $I)
{
$I->wantTo('check authorization on the forum with github');

$I->amOnPage('/discussions/hot');
$I->click('Log In');
$I->fillField('login', 'test_application@ukr.net');
$I->fillField('password', 'test123456');
$I->click('Sign in');

if (in_array('Reauthorization required', $I->grabMultiple('h2'))) {
$I->click('#js-oauth-authorize-btn');
}

$I->see('Welcome');
$I->canSeeInCurrentUrl('/discussions');

$I->amOnPage('/discussions/hot');
$I->click(".//*[@id='forum-navbar-collapse']/ul/li[8]/a");
$I->see('Goodbye!');
}

public function shouldAuthorizationOnGitAndForum(AcceptanceTester $I)
{
$I->wantTo('check authorization on the github after that on the forum');

$I->amOnUrl('https://github.com');
$I->amOnPage('/login');
$I->fillField('login', 'test_application@ukr.net');
$I->fillField('password', 'test123456');
$I->click('commit');
$I->see('Learn Git and GitHub without any code!');

$I->amOnUrl($_SERVER['APP_URL']);
$I->amOnPage('/');
$I->see('Hot');
$I->amOnPage('/discussions/hot');
$I->canSeeInCurrentUrl('/discussions/hot');

$I->click('Log In');
if (in_array('Reauthorization required', $I->grabMultiple('h2'))) {
$I->click('#js-oauth-authorize-btn');
}

$I->see('Welcome');
$I->canSeeInCurrentUrl('/discussions');

$I->amOnPage('/discussions/hot');
$I->click(".//*[@id='forum-navbar-collapse']/ul/li[8]/a");
$I->see('Goodbye!');
}
}