From 888bb78d29af30949b7804c0a709d3dbe13b2bcd Mon Sep 17 00:00:00 2001 From: Titouan Galopin Date: Wed, 27 Jan 2021 16:07:18 +0100 Subject: [PATCH 1/2] Fix tests --- tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php b/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php index cf792b8..a0af16d 100644 --- a/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php +++ b/tests/SymfonyCorp/Connect/Tests/Api/ApiTest.php @@ -48,7 +48,7 @@ public function testGet() $api = $this->createApi(new MockHttpClient(function ($method, $url, $options) { $this->assertSame('GET', $method); $this->assertSame('http://foobar/api/', $url); - $this->assertContains('accept: application/vnd.com.symfony.connect+xml', $options['request_headers']); + $this->assertContains('accept: application/vnd.com.symfony.connect+xml', array_map('strtolower', $options['headers'])); return $this->createResponse(200, $this->rootXml); })); @@ -130,7 +130,7 @@ public function testSubmit() $this->assertSame('POST', $method); $this->assertSame('http://foobar/api/?access_token=foobar', $url); $this->assertSame('foo=bar', $options['body']); - $this->assertContains('accept: application/vnd.com.symfony.connect+xml', $options['request_headers']); + $this->assertContains('accept: application/vnd.com.symfony.connect+xml', array_map('strtolower', $options['headers'])); return $this->createResponse(200, $this->rootXml); })); From 3fb52b8ed530d63d9c17affe50d312883e149cc3 Mon Sep 17 00:00:00 2001 From: Titouan Galopin Date: Wed, 27 Jan 2021 16:09:09 +0100 Subject: [PATCH 2/2] Fix ConnectToken --- composer.json | 8 +++--- .../Authentication/Token/ConnectToken.php | 25 ++++++++----------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 3887bb1..a885c77 100644 --- a/composer.json +++ b/composer.json @@ -10,12 +10,12 @@ "php": "^7.1.3", "ext-json": "*", "psr/log": "^1.0", - "symfony/http-client": "^4.3" + "symfony/http-client": "^4.4" }, "require-dev": { - "symfony/form": "^2.1|^3.0|^4.0", - "symfony/security": "^2.3|^3.0|^4.0", - "symfony/phpunit-bridge": "^4.2" + "symfony/form": "^2.8|^3.4|^4.4", + "symfony/security": "^2.8|^3.4|^4.4", + "symfony/phpunit-bridge": "^4.4" }, "suggest": { "symfony/security": "To use in a Symfony environment" diff --git a/src/Security/Authentication/Token/ConnectToken.php b/src/Security/Authentication/Token/ConnectToken.php index 3dd7018..30a4ff3 100644 --- a/src/Security/Authentication/Token/ConnectToken.php +++ b/src/Security/Authentication/Token/ConnectToken.php @@ -52,14 +52,20 @@ public function getRoles() { $user = $this->getUser(); if ($user instanceof UserInterface) { - return $this->getUserRoles($user); + return array_map([$this, 'getObjectUserRole'], $user->getRoles()); } - if (method_exists(AbstractToken::class, 'getRoleNames')) { - return parent::getRoleNames(); + return parent::getRoles(); + } + + public function getRolesNames() + { + $user = $this->getUser(); + if ($user instanceof UserInterface) { + return array_map([$this, 'getStringUserRole'], $user->getRoles()); } - return parent::getRoles(); + return parent::getRoleNames(); } public function setScope($scope) @@ -102,17 +108,6 @@ public function getCredentials() return $this->accessToken; } - private function getUserRoles(UserInterface $user) - { - $callBackMethod = 'getObjectUserRole'; - - if (method_exists(AbstractToken::class, 'getRoleNames')) { - $callBackMethod = 'getStringUserRole'; - } - - return array_map([$this, $callBackMethod], $user->getRoles()); - } - private function getStringUserRole($role) { if (!is_string($role) && !($role instanceof Role)) {