Skip to content
Snippets Groups Projects
Commit cdfb3a80 authored by omkar podey's avatar omkar podey Committed by Ted Bowman
Browse files

Issue #3360763 by omkar.podey, tedbow, Wim Leers: Switch failure marker file...

Issue #3360763 by omkar.podey, tedbow, Wim Leers: Switch failure marker file from *.json to *.yml to prevent it from being readable from the web
parent 414dd683
No related branches found
No related tags found
No related merge requests found
...@@ -4,7 +4,8 @@ declare(strict_types = 1); ...@@ -4,7 +4,8 @@ declare(strict_types = 1);
namespace Drupal\package_manager; namespace Drupal\package_manager;
use Drupal\Component\Serialization\Json; use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\package_manager\Exception\StageFailureMarkerException; use Drupal\package_manager\Exception\StageFailureMarkerException;
...@@ -40,7 +41,7 @@ final class FailureMarker { ...@@ -40,7 +41,7 @@ final class FailureMarker {
* The absolute path of the marker file. * The absolute path of the marker file.
*/ */
public function getPath(): string { public function getPath(): string {
return $this->pathLocator->getProjectRoot() . '/PACKAGE_MANAGER_FAILURE.json'; return $this->pathLocator->getProjectRoot() . '/PACKAGE_MANAGER_FAILURE.yml';
} }
/** /**
...@@ -62,9 +63,9 @@ final class FailureMarker { ...@@ -62,9 +63,9 @@ final class FailureMarker {
$data = [ $data = [
'stage_class' => get_class($stage), 'stage_class' => get_class($stage),
'stage_file' => (new \ReflectionObject($stage))->getFileName(), 'stage_file' => (new \ReflectionObject($stage))->getFileName(),
'message' => $message, 'message' => $message->render(),
]; ];
file_put_contents($this->getPath(), Json::encode($data)); file_put_contents($this->getPath(), Yaml::dump($data));
} }
/** /**
...@@ -79,9 +80,9 @@ final class FailureMarker { ...@@ -79,9 +80,9 @@ final class FailureMarker {
if (file_exists($path)) { if (file_exists($path)) {
$data = file_get_contents($path); $data = file_get_contents($path);
try { try {
$data = json_decode($data, TRUE, flags: JSON_THROW_ON_ERROR); $data = Yaml::parse($data);
} }
catch (\JsonException $exception) { catch (ParseException $exception) {
throw new StageFailureMarkerException('Failure marker file exists but cannot be decoded.', $exception->getCode(), $exception); throw new StageFailureMarkerException('Failure marker file exists but cannot be decoded.', $exception->getCode(), $exception);
} }
......
...@@ -29,14 +29,14 @@ class FailureMarkerTest extends PackageManagerKernelTestBase { ...@@ -29,14 +29,14 @@ class FailureMarkerTest extends PackageManagerKernelTestBase {
} }
/** /**
* Tests that an exception is thrown if the marker file contains invalid JSON. * Tests that an exception is thrown if the marker file contains invalid YAML.
* *
* @covers ::assertNotExists * @covers ::assertNotExists
*/ */
public function testExceptionForInvalidJson(): void { public function testExceptionForInvalidYaml(): void {
$failure_marker = $this->container->get(FailureMarker::class); $failure_marker = $this->container->get(FailureMarker::class);
// Write the failure marker with invalid JSON. // Write the failure marker with invalid YAML.
file_put_contents($failure_marker->getPath(), '{}}'); file_put_contents($failure_marker->getPath(), 'message : something message : something1');
$this->expectException(StageFailureMarkerException::class); $this->expectException(StageFailureMarkerException::class);
$this->expectExceptionMessage('Failure marker file exists but cannot be decoded.'); $this->expectExceptionMessage('Failure marker file exists but cannot be decoded.');
......
...@@ -75,7 +75,7 @@ trait AssertPreconditionsTrait { ...@@ -75,7 +75,7 @@ trait AssertPreconditionsTrait {
// If the failure marker exists, it will be in the project root. The project // If the failure marker exists, it will be in the project root. The project
// root is defined as the directory containing the `vendor` directory. // root is defined as the directory containing the `vendor` directory.
// @see \Drupal\package_manager\FailureMarker::getPath() // @see \Drupal\package_manager\FailureMarker::getPath()
$failure_marker = static::getProjectRoot() . '/PACKAGE_MANAGER_FAILURE.json'; $failure_marker = static::getProjectRoot() . '/PACKAGE_MANAGER_FAILURE.yml';
if (file_exists($failure_marker)) { if (file_exists($failure_marker)) {
$suffix = $when === 'before' $suffix = $when === 'before'
? 'Remove it to continue.' ? 'Remove it to continue.'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment