Skip to content

Commit

Permalink
Fix Upload API signature
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed Mar 10, 2021
1 parent 7ef9bd4 commit 11a307c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Api/Utils/ApiUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,10 @@ public static function serializeResponsiveBreakpoints($breakpoints)
*/
public static function serializeQueryParams($parameters = [])
{
return ArrayUtils::safeImplodeAssoc(
return ArrayUtils::implodeAssoc(
$parameters,
self::QUERY_STRING_OUTER_DELIMITER,
self::QUERY_STRING_INNER_DELIMITER,
true
self::QUERY_STRING_INNER_DELIMITER
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Upload/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
final class ContextTest extends IntegrationTestCase
{
const CONTEXT_DATA = ['k1' => 'v2', 'k2' => 'v2'];
const CONTEXT_DATA = ['k1' => 'v2', 'k2' => 'vשаß = & | ? !@#$%^&*()_+{}:">?/.,\']['];

/**
* @throws ApiError
Expand Down
61 changes: 52 additions & 9 deletions tests/Unit/Utils/ApiUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
namespace Cloudinary\Test\Unit\Utils;

use Cloudinary\Api\ApiUtils;
use Cloudinary\Test\Unit\UnitTestCase;
use Cloudinary\Transformation\Format;
use Cloudinary\Transformation\Transformation;
use PHPUnit\Framework\TestCase;

/**
* Class ApiUtilsTest
*/
final class ApiUtilsTest extends TestCase
final class ApiUtilsTest extends UnitTestCase
{
/**
* Data provider for the method `testSerializeArrayOfArrays()`.
Expand Down Expand Up @@ -153,31 +153,31 @@ public function dataProviderSerializeContext()
{
return [
[
'value' => '',
'value' => '',
'result' => '',
],
[
'value' => null,
'value' => null,
'result' => '',
],
[
'value' => 0,
'value' => 0,
'result' => '0',
],
[
'value' => [],
'value' => [],
'result' => '',
],
[
'value' => ['!@#$%^&?*-+=[]{}()' => '!@#$%^&?*-+=[]{}()'],
'value' => ['!@#$%^&?*-+=[]{}()' => '!@#$%^&?*-+=[]{}()'],
'result' => '!@#$%^&?*-+\=[]{}()=!@#$%^&?*-+\=[]{}()',
],
[
'value' => ['caption' => 'cap=caps', 'alt' => 'alternative|alt=a'],
'value' => ['caption' => 'cap=caps', 'alt' => 'alternative|alt=a'],
'result' => 'caption=cap\=caps|alt=alternative\|alt\=a',
],
[
'value' => ['caption' => ['cap1', 'cap2'], 'alt' => ['a|"a"', 'b="b"']],
'value' => ['caption' => ['cap1', 'cap2'], 'alt' => ['a|"a"', 'b="b"']],
'result' => 'caption=["cap1","cap2"]|alt=["a\|\"a\"","b\=\"b\""]',
],
];
Expand All @@ -198,4 +198,47 @@ public function testSerializeContext($value, $result)
ApiUtils::serializeContext($value)
);
}

/**
* Data provider for the method `testSignParameters()`.
*
* @return array[]
*/
public function dataProviderSignParameters()
{
return [
[
'value' => ['p1' => 'v1'],
'result' => '4cdcfc973f12ab6a9a6ba56595a9c2897bdb8f32',
],
[
'value' => ['p1' => 'v1,v2'],
'result' => '9e06ad20c8a98319b00503edc4053be120017905',
],
[
'value' => ['p1' => ['v1', 'v2']],
'result' => '9e06ad20c8a98319b00503edc4053be120017905',
],
[
'value' => ['p1' => 'v1=v2*|}{ & !@#$%^&*()_;/.,?><\\/|_+a'],
'result' => 'bbdc631f4b490c0ba65722d8dbf9300d1fd98e86',
],
];
}

/**
* Verifies that context data is correctly serialized.
*
* @param $value
* @param $result
*
* @dataProvider dataProviderSignParameters
*/
public function testSignParameters($value, $result)
{
self::assertEquals(
$result,
ApiUtils::signParameters($value, self::API_SECRET)
);
}
}

0 comments on commit 11a307c

Please sign in to comment.