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

fix errors for scope #351

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* fix [add helper metods isError for registerCallResult fortelephony](https://github.com/mesilov/bitrix24-php-sdk/issues/335)
* fix [add return type for crm multifields phone, email, im](https://github.com/mesilov/bitrix24-php-sdk/issues/338)
* fix errors in `ShowFieldsDescriptionCommand` metadata reader CLI command
* fix errors for `ApplicationProfile` with empty scope

### etc
* move CLI entry point to `bin/console`
Expand Down
16 changes: 8 additions & 8 deletions src/Core/Credentials/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

use Bitrix24\SDK\Core\Exceptions\UnknownScopeCodeException;

/**
* Class Scope
*
* @package Bitrix24\SDK\Core\Credentials
*/
class Scope
{
/**
Expand Down Expand Up @@ -84,9 +79,14 @@ class Scope
public function __construct(array $scope = [])
{
$scope = array_unique(array_map('strtolower', $scope));
foreach ($scope as $item) {
if (!in_array($item, $this->availableScope, true)) {
throw new UnknownScopeCodeException(sprintf('unknown application scope code - %s', $item));

if (count($scope) === 1 && $scope[0] === '') {
$scope = [];
} else {
foreach ($scope as $item) {
if (!in_array($item, $this->availableScope, true)) {
throw new UnknownScopeCodeException(sprintf('unknown application scope code - %s', $item));
}
}
}

Expand Down
28 changes: 18 additions & 10 deletions tests/Unit/Core/Credentials/ApplicationProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class ApplicationProfileTest extends TestCase
{
/**
*
* @param array $arr
* @param array $arr
* @param string|null $expectedException
*
* @return void
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
* @throws InvalidArgumentException
* @dataProvider arrayDataProvider
*/
public function testFromArray(array $arr, ?string $expectedException): void
Expand All @@ -35,35 +35,43 @@ public function arrayDataProvider(): Generator
{
yield 'valid' => [
[
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user',
],
null,
];
yield 'without client id' => [
[
'' => '1',
'' => '1',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user',
],
InvalidArgumentException::class,
];
yield 'without client secret' => [
[
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1',
'' => '2',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user',
'' => '2',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => 'user',
],
InvalidArgumentException::class,
];
yield 'without client application scope' => [
[
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2',
'' => 'user',
'' => 'user',
],
InvalidArgumentException::class,
];
yield 'with empty scope' => [
[
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_ID' => '1',
'BITRIX24_PHP_SDK_APPLICATION_CLIENT_SECRET' => '2',
'BITRIX24_PHP_SDK_APPLICATION_SCOPE' => '',
],
null
];
}
}
9 changes: 9 additions & 0 deletions tests/Unit/Core/Credentials/ScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public function testUnknownScope(): void
$scope = new Scope(['fooo']);
}

/**
* @throws UnknownScopeCodeException
*/
public function testEmptyScope(): void
{
$scope = new Scope(['']);
$this->assertEquals([], $scope->getScopeCodes());
}

/**
* @throws UnknownScopeCodeException
*/
Expand Down
Loading