From e17e7ffeeabed7192fd13b1a973edc4ae1efcefb Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Sun, 20 Dec 2020 10:28:34 +0100 Subject: [PATCH 1/9] Version 1.2.x needs PHP at least 7.2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 131426f..898cd3c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Nette addon for login with social networks | Version | Facebook App API | PHP | Recommended Nette | | --- | --- | --- | --- | | dev-master | 8.0 or own | \>= 7.2 | Nette 3.0 | -| 1.2.x | 8.0 or own | \>= 7.1 | Nette 3.0 | +| 1.2.x | 8.0 or own | \>= 7.2 | Nette 3.0 | | 1.1.x | 2.6 | \>= 7.0 | Nette 2.4 (Nette\SmartObject) | | 1.0.x | 2.6 | \>= 5.5 | Nette 2.4, 2.3 (Nette\Object) | From 4da5871cdcec194d83ae8773faf20e29fe857c62 Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Sun, 20 Dec 2020 13:53:05 +0100 Subject: [PATCH 2/9] Fix code coverage --- .travis.yml | 6 ++---- tests/tests/Bootstrap.php | 36 +++++++++++++++++++++++++++++++++++ tests/tests/InstanceTest.phpt | 21 +++++++++++++++----- tests/tests/bootstrap.php | 22 --------------------- 4 files changed, 54 insertions(+), 31 deletions(-) create mode 100644 tests/tests/Bootstrap.php delete mode 100644 tests/tests/bootstrap.php diff --git a/.travis.yml b/.travis.yml index 2494b07..f2f7956 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,20 +32,18 @@ jobs: - travis_retry composer create-project nette/code-checker temp/code-checker --no-progress # Install Nette Coding Standard - travis_retry composer create-project nette/coding-standard temp/coding-standard --no-progress - script: - php temp/code-checker/code-checker -d src -d tests --short-arrays --strict-types - php temp/coding-standard/ecs check src tests --preset php71 - - stage: Code Coverage + php: 7.4 script: - vendor/bin/tester -p phpdbg tests -s --coverage ./coverage.xml --coverage-src ./src after_script: - - wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar + - wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.1/coveralls.phar - php coveralls.phar --verbose --config tests/.coveralls.yml - allow_failures: - stage: Code Coverage - env: title="Lowest Dependencies" diff --git a/tests/tests/Bootstrap.php b/tests/tests/Bootstrap.php new file mode 100644 index 0000000..153e7c8 --- /dev/null +++ b/tests/tests/Bootstrap.php @@ -0,0 +1,36 @@ +setTimeZone('Europe/Prague'); + $configurator->setTempDirectory(__DIR__ . '/temp'); + + $configurator->createRobotLoader() + ->addDirectory(__DIR__ . '/../../src/') + ->register(); + + $configurator + ->addConfig(__DIR__ . '/config/config.neon'); + + return $configurator; + } + + + public static function bootForTests(): Configurator + { + $configurator = self::boot(); + \Tester\Environment::setup(); + return $configurator; + } +} diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index 4e8044d..c8ad931 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -3,22 +3,28 @@ declare(strict_types=1); namespace Test; +use Nette; use Tester; use Tester\Assert; -use VencaX; require __DIR__ . '/../../vendor/autoload.php'; class InstanceTest extends Tester\TestCase { - /** @var VencaX\SocialLogin */ + private $container; + private $socialLogin; + public function __construct(Nette\DI\Container $container) + { + $this->container = $container; + } + + public function setUp() { - $container = require __DIR__ . '/bootstrap.php'; - $this->socialLogin = $container->getByType('VencaX\SocialLogin'); + $this->socialLogin = $this->container->getByType('VencaX\SocialLogin'); } @@ -72,5 +78,10 @@ class InstanceTest extends Tester\TestCase } } -$test = new InstanceTest; +require __DIR__ . '/Bootstrap.php'; + +$container = \Test\Bootstrap::bootForTests() + ->createContainer(); + +$test = new InstanceTest($container); $test->run(); diff --git a/tests/tests/bootstrap.php b/tests/tests/bootstrap.php deleted file mode 100644 index 7dbdc79..0000000 --- a/tests/tests/bootstrap.php +++ /dev/null @@ -1,22 +0,0 @@ -setDebugMode(false); -$configurator->setTempDirectory(__DIR__ . '/temp'); -$configurator->createRobotLoader() - ->addDirectory(__DIR__ . '/../../src/') - ->register(); - -$configurator->addConfig(__DIR__ . '/config/config.neon'); - -return $configurator->createContainer(); From 925e8aad736629e356c89eb5dc30ecba312486ed Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Sun, 20 Dec 2020 14:36:25 +0100 Subject: [PATCH 3/9] Improve test - scopes --- src/FacebookLogin.php | 3 +-- src/TwitterLogin.php | 13 ------------- tests/tests/InstanceTest.phpt | 6 ++++++ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/FacebookLogin.php b/src/FacebookLogin.php index 2731aaf..90d8710 100644 --- a/src/FacebookLogin.php +++ b/src/FacebookLogin.php @@ -194,8 +194,7 @@ public function setState($state) */ public function getLoginUrl() { - $loginUrl = $this->helper->getLoginUrl($this->callBackUrl, $this->scope); - return $loginUrl; + return $this->helper->getLoginUrl($this->callBackUrl, $this->scope); } diff --git a/src/TwitterLogin.php b/src/TwitterLogin.php index 975f64b..e6ec3b9 100644 --- a/src/TwitterLogin.php +++ b/src/TwitterLogin.php @@ -21,9 +21,6 @@ class TwitterLogin extends BaseLogin /** @var array Request token */ private $requestToken; - /** @var string scope */ - private $scope = ''; - /** @var Nette\Http\Session session */ private $session; @@ -51,16 +48,6 @@ public function __construct( } - /** - * Set scope - * @param $scope - */ - public function setScope($scope) - { - $this->scope = $scope; - } - - /** * Get URL for login * @param string $callbackURL diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index c8ad931..bf2ee6f 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -30,6 +30,8 @@ class InstanceTest extends Tester\TestCase public function testFacebookLoginUrl() { + $this->socialLogin->facebook->setScope( ['email'] ); + $url = $this->socialLogin->facebook->getLoginUrl(); $urlParseArray = parse_url($url); @@ -45,12 +47,15 @@ class InstanceTest extends Tester\TestCase Assert::same('123456789', $urlParseQueryArray['client_id']); Assert::same('code', $urlParseQueryArray['response_type']); Assert::same('http://www.muj-web.cz/homepage/facebook-login', $urlParseQueryArray['redirect_uri']); + Assert::same('email', $urlParseQueryArray['scope']); //Assert::same('', $urlParseQueryArray['scope']); } public function testGoogleLoginUrl() { + $this->socialLogin->google->setScope( array( "https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/userinfo.email" ) ); + $url = $this->socialLogin->google->getLoginUrl(); $urlParseArray = parse_url($url); @@ -67,6 +72,7 @@ class InstanceTest extends Tester\TestCase Assert::same('online', $urlParseQueryArray['access_type']); Assert::same('123456789', $urlParseQueryArray['client_id']); Assert::same('http://www.muj-web.cz/homepage/google-login', $urlParseQueryArray['redirect_uri']); + Assert::same('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email', $urlParseQueryArray['scope']); } From a3b66571d144ce00c331a92bf70613e01a312647 Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Sun, 20 Dec 2020 14:46:40 +0100 Subject: [PATCH 4/9] add tests for state --- tests/tests/InstanceTest.phpt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index bf2ee6f..fb1e597 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -31,6 +31,7 @@ class InstanceTest extends Tester\TestCase public function testFacebookLoginUrl() { $this->socialLogin->facebook->setScope( ['email'] ); + $this->socialLogin->facebook->setState('https://www.mypage.cz/sign/facebook'); $url = $this->socialLogin->facebook->getLoginUrl(); @@ -48,13 +49,14 @@ class InstanceTest extends Tester\TestCase Assert::same('code', $urlParseQueryArray['response_type']); Assert::same('http://www.muj-web.cz/homepage/facebook-login', $urlParseQueryArray['redirect_uri']); Assert::same('email', $urlParseQueryArray['scope']); - //Assert::same('', $urlParseQueryArray['scope']); + Assert::same('https://www.mypage.cz/sign/facebook', $urlParseQueryArray['state']); } public function testGoogleLoginUrl() { $this->socialLogin->google->setScope( array( "https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/userinfo.email" ) ); + $this->socialLogin->google->setState('https://www.mypage.cz/sign/google'); $url = $this->socialLogin->google->getLoginUrl(); @@ -73,6 +75,7 @@ class InstanceTest extends Tester\TestCase Assert::same('123456789', $urlParseQueryArray['client_id']); Assert::same('http://www.muj-web.cz/homepage/google-login', $urlParseQueryArray['redirect_uri']); Assert::same('https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/userinfo.email', $urlParseQueryArray['scope']); + Assert::same('https://www.mypage.cz/sign/google', $urlParseQueryArray['state']); } From cfedaa44013b19e9e7567752c75c5d55b8bc738c Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Sun, 20 Dec 2020 14:53:31 +0100 Subject: [PATCH 5/9] cs --- tests/tests/InstanceTest.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index fb1e597..87b082c 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -30,7 +30,7 @@ class InstanceTest extends Tester\TestCase public function testFacebookLoginUrl() { - $this->socialLogin->facebook->setScope( ['email'] ); + $this->socialLogin->facebook->setScope(['email']); $this->socialLogin->facebook->setState('https://www.mypage.cz/sign/facebook'); $url = $this->socialLogin->facebook->getLoginUrl(); @@ -55,7 +55,7 @@ class InstanceTest extends Tester\TestCase public function testGoogleLoginUrl() { - $this->socialLogin->google->setScope( array( "https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/userinfo.email" ) ); + $this->socialLogin->google->setScope(['https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/userinfo.email']); $this->socialLogin->google->setState('https://www.mypage.cz/sign/google'); $url = $this->socialLogin->google->getLoginUrl(); From 1ebd3b46ac0eef6ce9281fcda14e6a8e72ca6c91 Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Fri, 12 Mar 2021 21:46:42 +0100 Subject: [PATCH 6/9] Fix TwitterOAuth to Abraham\TwitterOAuth\TwitterOAuth --- src/TwitterLogin.php | 14 ++++++++++---- tests/tests/InstanceTest.phpt | 7 +++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/TwitterLogin.php b/src/TwitterLogin.php index e6ec3b9..638f9b9 100644 --- a/src/TwitterLogin.php +++ b/src/TwitterLogin.php @@ -3,6 +3,7 @@ namespace VencaX; +use Abraham; use Exception; use Nette; @@ -15,7 +16,7 @@ class TwitterLogin extends BaseLogin { public const SOCIAL_NAME = 'twitter'; - /** @var \TwitterOAuth */ + /** @var Abraham\TwitterOAuth\TwitterOAuth */ private $twitterOAuth; /** @var array Request token */ @@ -55,8 +56,13 @@ public function __construct( */ public function getLoginUrl() { - $this->twitterOAuth = new \TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret']); - $this->requestToken = $this->twitterOAuth->getRequestToken($this->params['callbackURL']); + $this->twitterOAuth = new Abraham\TwitterOAuth\TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret']); + $this->requestToken = $this->twitterOAuth->oauth( + 'oauth/request_token', + [ + 'oauth_callback' => $this->params['callbackURL'], + ] + ); $sessionSection = $this->session->getSection('twitter'); $sessionSection->oauth_token = $token = $this->requestToken['oauth_token']; @@ -84,7 +90,7 @@ public function getMe($oauthToken, $oauthVerifier) } //Create TwitteroAuth object with app key/secret and token key/secret from default phase - $this->twitterOAuth = new \TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret'], $sessionSection->oauth_token, $sessionSection->oauth_token_secret); + $this->twitterOAuth = new Abraham\TwitterOAuth\TwitterOAuth($this->params['consumerKey'], $this->params['consumerSecret'], $sessionSection->oauth_token, $sessionSection->oauth_token_secret); //Request access tokens from twitter $access_token = $this->twitterOAuth->getAccessToken($oauthVerifier); diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index 87b082c..1963d93 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Test; +use Abraham; use Nette; use Tester; use Tester\Assert; @@ -81,8 +82,10 @@ class InstanceTest extends Tester\TestCase public function testTwitterLoginUrl() { - //$url = $this->socialLogin->twitter->getLoginUrl(); - //Assert::same(false, $this->socialLogin->twitter->getSocialLoginCookie()); + Assert::exception(function () { + $this->socialLogin->twitter->getLoginUrl(); + }, Abraham\TwitterOAuth\TwitterOAuthException::class, '{"errors":[{"code":32,"message":"Could not authenticate you."}]}'); + Assert::same(false, $this->socialLogin->twitter->isThisServiceLastLogin()); } } From e1892f93a64dc77ed33e8bc8a64039edae937ee5 Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Fri, 12 Mar 2021 21:55:48 +0100 Subject: [PATCH 7/9] Refctoring getAuthorizeURL to url --- src/TwitterLogin.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/TwitterLogin.php b/src/TwitterLogin.php index 638f9b9..f2bc3e3 100644 --- a/src/TwitterLogin.php +++ b/src/TwitterLogin.php @@ -68,7 +68,12 @@ public function getLoginUrl() $sessionSection->oauth_token = $token = $this->requestToken['oauth_token']; $sessionSection->oauth_token_secret = $this->requestToken['oauth_token_secret']; - $loginUrl = $this->twitterOAuth->getAuthorizeURL($this->requestToken); // Use Sign in with Twitter + $loginUrl = $this->twitterOAuth->url( + 'oauth/authorize', + [ + 'oauth_token' => $this->params['callbackURL'], + ] + ); return $loginUrl; } From 8261aff381a321ead2737fdca3d3b4ae6b221a39 Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Fri, 12 Mar 2021 22:00:01 +0100 Subject: [PATCH 8/9] Improve test --- tests/tests/InstanceTest.phpt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tests/InstanceTest.phpt b/tests/tests/InstanceTest.phpt index 1963d93..7e2859b 100644 --- a/tests/tests/InstanceTest.phpt +++ b/tests/tests/InstanceTest.phpt @@ -86,6 +86,10 @@ class InstanceTest extends Tester\TestCase $this->socialLogin->twitter->getLoginUrl(); }, Abraham\TwitterOAuth\TwitterOAuthException::class, '{"errors":[{"code":32,"message":"Could not authenticate you."}]}'); + Assert::exception(function () { + $this->socialLogin->twitter->getMe('oauthToken', 'oauthVerifier'); + }, \Exception::class, 'Twitter token is old. Try again login'); + Assert::same(false, $this->socialLogin->twitter->isThisServiceLastLogin()); } } From bda6eea1729785a81dc957d589e97b9d6ebcdc67 Mon Sep 17 00:00:00 2001 From: vEnCa-X Date: Fri, 12 Mar 2021 22:09:26 +0100 Subject: [PATCH 9/9] Add php 8.0 testing. allow_failures --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f2f7956..d204b80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0 before_install: # turn off XDebug @@ -45,8 +46,9 @@ jobs: - php coveralls.phar --verbose --config tests/.coveralls.yml allow_failures: - - stage: Code Coverage - - env: title="Lowest Dependencies" + - stage: Code Coverage + - env: title="Lowest Dependencies" + - php: 8.0 sudo: false