Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mficzel committed Mar 22, 2022
2 parents ebcde87 + 301391d commit 023b6f5
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 45 deletions.
10 changes: 8 additions & 2 deletions Neos.Eel/Classes/Helper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,21 @@ public function pop(iterable $array): array
*
* Array.push(array, e1, e2)
*
* @param iterable $array
* @param iterable|scalar $array
* @param mixed $element
* @return array The array with the inserted elements
*/
public function push(iterable $array, $element): array
public function push($array, $element): array
{
if ($array instanceof \Traversable) {
$array = iterator_to_array($array);
}
if (is_scalar($array)) {
$array = [$array];
}
if (is_array($array) === false) {
throw new \InvalidArgumentException('$array must be of type iterable|scalar got: ' . gettype($array), 1647595715);
}
$elements = func_get_args();
array_shift($elements);
foreach ($elements as $element) {
Expand Down
3 changes: 3 additions & 0 deletions Neos.Eel/Tests/Unit/Helper/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ public function pushExamples()
'string keys' => [['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz'], 42, 'foo', ['foo' => 'bar', 'baz' => 'foo', 'bar' => 'baz', 42, 'foo']],
'mixed keys' => [['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53], 42, 'foo', ['bar', '24' => 'foo', 'i' => 181.84, 'foo' => 'abc', '84216', 76, 'k' => 53, 42, 'foo']],
'traversable' => [TestArrayIterator::fromArray(['a']), 'b', 'c', ['a', 'b', 'c']],
# expect cast scalar (as arg $array) to array
'string' => ['a', 'b', 'c', ['a', 'b', 'c']],
'int' => [123, 'b', 'c', [123, 'b', 'c']],
];
}

Expand Down
2 changes: 1 addition & 1 deletion Neos.Flow/Classes/Http/Client/InternalRequestEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,6 @@ protected function prepareErrorResponse($exception, ResponseInterface $response)
->withStatus($statusCode)
->withBody($this->contentFactory->createStream($content))
->withHeader('X-Flow-ExceptionCode', $exception->getCode())
->withHeader('X-Flow-ExceptionMessage', $exception->getMessage());
->withHeader('X-Flow-ExceptionMessage', base64_encode($exception->getMessage()));
}
}
11 changes: 9 additions & 2 deletions Neos.Flow/Classes/Mvc/Controller/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Neos\Flow\Mvc\Exception\InvalidActionVisibilityException;
use Neos\Flow\Mvc\Exception\InvalidArgumentTypeException;
use Neos\Flow\Mvc\Exception\NoSuchActionException;
use Neos\Flow\Mvc\Exception\RequiredArgumentMissingException;
use Neos\Flow\Mvc\Exception\UnsupportedRequestTypeException;
use Neos\Flow\Mvc\Exception\ViewNotFoundException;
use Neos\Flow\Mvc\View\ViewInterface;
Expand Down Expand Up @@ -231,10 +232,16 @@ public function processRequest(ActionRequest $request, ActionResponse $response)
} catch (InvalidArgumentForHashGenerationException|InvalidHashException $e) {
$message = $this->throwableStorage->logThrowable($e);
$this->logger->notice('Property mapping configuration failed due to HMAC errors. ' . $message, LogEnvironment::fromMethodName(__METHOD__));
$this->throwStatus(400, '400 Bad Request', 'Invalid HMAC submitted');
$this->throwStatus(400, null, 'Invalid HMAC submitted');
}

$this->mapRequestArgumentsToControllerArguments();
try {
$this->mapRequestArgumentsToControllerArguments();
} catch (RequiredArgumentMissingException $e) {
$message = $this->throwableStorage->logThrowable($e);
$this->logger->notice('Request argument mapping failed due to a missing required argument. ' . $message, LogEnvironment::fromMethodName(__METHOD__));
$this->throwStatus(400, null, 'Required argument is missing');
}
if ($this->enableDynamicTypeValidation === true) {
$this->initializeActionMethodValidators();
}
Expand Down
79 changes: 39 additions & 40 deletions Neos.Flow/Tests/Functional/Mvc/ActionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,45 +399,42 @@ public function validatedGroupModelRelationIsValidated()
*/
public function argumentTestsDataProvider()
{
$requiredArgumentExceptionText = 'Uncaught Exception in Flow #1298012500: Required argument "argument" is not set.';
$data = [
'required string ' => ['requiredString', 'some String', '\'some String\''],
'required string - missing value' => ['requiredString', null, $requiredArgumentExceptionText],
'optional string' => ['optionalString', '123', '\'123\''],
'optional string - default' => ['optionalString', null, '\'default\''],
'optional string - nullable' => ['optionalNullableString', null, 'NULL'],
'required integer' => ['requiredInteger', '234', 234],
'required integer - missing value' => ['requiredInteger', null, $requiredArgumentExceptionText],
'required integer - mapping error' => ['requiredInteger', 'not an integer', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredIntegerAction().'],
'required integer - empty value' => ['requiredInteger', '', 'NULL'],
'optional integer' => ['optionalInteger', 456, 456],
'optional integer - default value' => ['optionalInteger', null, 123],
'optional integer - mapping error' => ['optionalInteger', 'not an integer', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalIntegerAction().'],
'optional integer - empty value' => ['optionalInteger', '', 123],
'optional integer - nullable' => ['optionalNullableInteger', null, 'NULL'],
'required float' => ['requiredFloat', 34.56, 34.56],
'required float - integer' => ['requiredFloat', 485, '485'],
'required float - integer2' => ['requiredFloat', '888', '888'],
'required float - missing value' => ['requiredFloat', null, $requiredArgumentExceptionText],
'required float - mapping error' => ['requiredFloat', 'not a float', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredFloatAction().'],
'required float - empty value' => ['requiredFloat', '', 'NULL'],
'optional float' => ['optionalFloat', 78.90, 78.9],
'optional float - default value' => ['optionalFloat', null, 112.34],
'optional float - mapping error' => ['optionalFloat', 'not a float', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalFloatAction().'],
'optional float - empty value' => ['optionalFloat', '', 112.34],
'optional float - nullable' => ['optionalNullableFloat', null, 'NULL'],
'required date' => ['requiredDate', ['date' => '1980-12-13', 'dateFormat' => 'Y-m-d'], '1980-12-13'],
'required date string' => ['requiredDate', '1980-12-13T14:22:12+02:00', '1980-12-13'],
'required date - missing value' => ['requiredDate', null, $requiredArgumentExceptionText],
'required date - mapping error' => ['requiredDate', 'no date', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredDateAction().'],
'optional date string' => ['optionalDate', '1980-12-13T14:22:12+02:00', '1980-12-13'],
'optional date - default value' => ['optionalDate', null, 'null'],
'optional date - mapping error' => ['optionalDate', 'no date', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalDateAction().'],
'optional date - missing value' => ['optionalDate', null, 'null'],
'optional date - empty value' => ['optionalDate', '', 'null'],
return [
'required string ' => ['requiredString', 'some String', '\'some String\'', 200],
'required string - missing value' => ['requiredString', null, 'Required argument is missing', 400],
'optional string' => ['optionalString', '123', '\'123\'', 200],
'optional string - default' => ['optionalString', null, '\'default\'', 200],
'optional string - nullable' => ['optionalNullableString', null, 'NULL', 200],
'required integer' => ['requiredInteger', '234', 234, 200],
'required integer - missing value' => ['requiredInteger', null, 'Required argument is missing', 400],
'required integer - mapping error' => ['requiredInteger', 'not an integer', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredIntegerAction().', 200],
'required integer - empty value' => ['requiredInteger', '', 'NULL', 200],
'optional integer' => ['optionalInteger', 456, 456, 200],
'optional integer - default value' => ['optionalInteger', null, 123, 200],
'optional integer - mapping error' => ['optionalInteger', 'not an integer', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalIntegerAction().', 200],
'optional integer - empty value' => ['optionalInteger', '', 123, 200],
'optional integer - nullable' => ['optionalNullableInteger', null, 'NULL', 200],
'required float' => ['requiredFloat', 34.56, 34.56, 200],
'required float - integer' => ['requiredFloat', 485, '485', 200],
'required float - integer2' => ['requiredFloat', '888', '888', 200],
'required float - missing value' => ['requiredFloat', null, 'Required argument is missing', 400],
'required float - mapping error' => ['requiredFloat', 'not a float', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredFloatAction().', 200],
'required float - empty value' => ['requiredFloat', '', 'NULL', 200],
'optional float' => ['optionalFloat', 78.90, 78.9, 200],
'optional float - default value' => ['optionalFloat', null, 112.34, 200],
'optional float - mapping error' => ['optionalFloat', 'not a float', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalFloatAction().', 200],
'optional float - empty value' => ['optionalFloat', '', 112.34, 200],
'optional float - nullable' => ['optionalNullableFloat', null, 'NULL', 200],
'required date' => ['requiredDate', ['date' => '1980-12-13', 'dateFormat' => 'Y-m-d'], '1980-12-13', 200],
'required date string' => ['requiredDate', '1980-12-13T14:22:12+02:00', '1980-12-13', 200],
'required date - missing value' => ['requiredDate', null, 'Required argument is missing', 400],
'required date - mapping error' => ['requiredDate', 'no date', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->requiredDateAction().', 200],
'optional date string' => ['optionalDate', '1980-12-13T14:22:12+02:00', '1980-12-13', 200],
'optional date - default value' => ['optionalDate', null, 'null', 200],
'optional date - mapping error' => ['optionalDate', 'no date', 'Validation failed while trying to call Neos\Flow\Tests\Functional\Mvc\Fixtures\Controller\ActionControllerTestBController->optionalDateAction().', 200],
'optional date - missing value' => ['optionalDate', null, 'null', 200],
'optional date - empty value' => ['optionalDate', '', 'null', 200],
];

return $data;
}

/**
Expand All @@ -446,18 +443,20 @@ public function argumentTestsDataProvider()
* @param string $action
* @param mixed $argument
* @param string $expectedResult
* @param int $expectedStatusCode
* @test
* @dataProvider argumentTestsDataProvider
*/
public function argumentTests($action, $argument, $expectedResult)
public function argumentTests($action, $argument, $expectedResult, $expectedStatusCode)
{
$arguments = [
'argument' => $argument,
];

$uri = str_replace('{@action}', strtolower($action), 'http://localhost/test/mvc/actioncontrollertestb/{@action}');
$response = $this->browser->request($uri, 'POST', $arguments);
self::assertTrue(strpos(trim($response->getBody()->getContents()), (string)$expectedResult) === 0, sprintf('The resulting string did not start with the expected string. Expected: "%s", Actual: "%s"', $expectedResult, $response->getBody()->getContents()));
self::assertEquals($expectedStatusCode, $response->getStatusCode());
self::assertStringStartsWith((string)$expectedResult, trim($response->getBody()->getContents()));
}

/**
Expand Down

0 comments on commit 023b6f5

Please sign in to comment.