Skip to content

Commit cf0e0ce

Browse files
Added acceptance authorization tests and fixed auth_redirect
1 parent 234fd6b commit cf0e0ce

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

app/library/Github/OAuth.php

100644100755
Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class OAuth extends Injectable
4646
*/
4747
public function __construct(Config $config)
4848
{
49-
$this->redirectUriAuthorize = $config->get('redirectUri');
49+
$this->logger = $this->getDI()->get('logger', ['auth']);
50+
$this->redirectUriAuthorize = $this->getRedirectGitPath($config->get('redirectUri'));
5051
$this->clientId = $config->get('clientId');
5152
$this->clientSecret = $config->get('clientSecret');
52-
$this->logger = $this->getDI()->get('logger', ['auth']);
5353
}
5454

5555
public function authorize()
@@ -132,4 +132,26 @@ public function send($url, $parameters, $method = 'post')
132132
return false;
133133
}
134134
}
135+
136+
/**
137+
* @param string $url
138+
*
139+
* @return string
140+
*/
141+
protected function getRedirectGitPath($url)
142+
{
143+
if (empty($url)) {
144+
$this->logger->error("Parameter GITHUB_REDIRECT_URI in .env file doesn't exist");
145+
}
146+
147+
$redirectUrl = rtrim($url, '/');
148+
if (stristr($redirectUrl, '://')) {
149+
$redirectUrl = stristr($redirectUrl, '://');
150+
$redirectUrl = $_SERVER['REQUEST_SCHEME'] . $redirectUrl . '/';
151+
} else {
152+
$redirectUrl = $_SERVER['REQUEST_SCHEME'] . '://' . $redirectUrl . '/';
153+
}
154+
155+
return $redirectUrl;
156+
}
135157
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
/*
4+
+------------------------------------------------------------------------+
5+
| Phalcon forum |
6+
+------------------------------------------------------------------------+
7+
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
8+
+------------------------------------------------------------------------+
9+
| This source file is subject to the New BSD License that is bundled |
10+
| with this package in the file LICENSE.txt. |
11+
| |
12+
| If you did not receive a copy of the license and are unable to |
13+
| obtain it through the world-wide-web, please send an email |
14+
| to license@phalconphp.com so we can send you a copy immediately. |
15+
+------------------------------------------------------------------------+
16+
| Authors: Sergii Svyrydenko <sergey.v.sviridenko@gmail.com> |
17+
+------------------------------------------------------------------------+
18+
*/
19+
20+
class AuthorizationCest
21+
{
22+
public function shouldCheckAutorizationOnForumWithGit(AcceptanceTester $I)
23+
{
24+
$I->wantTo('check authorization on the forum with github');
25+
26+
$I->amOnPage('/discussions/hot');
27+
$I->click('Log In');
28+
$I->fillField('login', 'test_application@ukr.net');
29+
$I->fillField('password', 'test123456');
30+
$I->click('Sign in');
31+
32+
if (in_array('Reauthorization required', $I->grabMultiple('h2'))) {
33+
$I->click('#js-oauth-authorize-btn');
34+
}
35+
36+
$I->see('Welcome');
37+
$I->canSeeInCurrentUrl('/discussions');
38+
39+
$I->amOnPage('/discussions/hot');
40+
$I->click(".//*[@id='forum-navbar-collapse']/ul/li[8]/a");
41+
$I->see('Goodbye!');
42+
}
43+
44+
public function shouldAuthorizationOnGitAndForum(AcceptanceTester $I)
45+
{
46+
$I->wantTo('check authorization on the github after that on the forum');
47+
48+
$I->amOnUrl('https://github.com');
49+
$I->amOnPage('/login');
50+
$I->fillField('login', 'test_application@ukr.net');
51+
$I->fillField('password', 'test123456');
52+
$I->click('commit');
53+
$I->see('Learn Git and GitHub without any code!');
54+
55+
$I->amOnUrl($_SERVER['APP_URL']);
56+
$I->amOnPage('/');
57+
$I->see('Hot');
58+
$I->amOnPage('/discussions/hot');
59+
$I->canSeeInCurrentUrl('/discussions/hot');
60+
61+
$I->click('Log In');
62+
if (in_array('Reauthorization required', $I->grabMultiple('h2'))) {
63+
$I->click('#js-oauth-authorize-btn');
64+
$I->see('Welcome');
65+
} else {
66+
$I->see('Welcome');
67+
$I->canSeeInCurrentUrl('/discussions');
68+
}
69+
70+
$I->amOnPage('/discussions/hot');
71+
$I->click(".//*[@id='forum-navbar-collapse']/ul/li[8]/a");
72+
$I->see('Goodbye!');
73+
}
74+
}

0 commit comments

Comments
 (0)