Skip to content

Commit

Permalink
Merge pull request #2636 from CachetHQ/command-validation-bug
Browse files Browse the repository at this point in the history
Fix lack of Command Validating middleware
  • Loading branch information
jbrooksuk committed Jul 17, 2017
2 parents 3ad2382 + 39718c7 commit c77e5df
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/Bus/Commands/Component/CreateComponentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class CreateComponentCommand
/**
* JSON meta data for the component.
*
* @var string|null
* @var array|null
*/
public $meta;

Expand All @@ -87,7 +87,7 @@ final class CreateComponentCommand
'order' => 'nullable|int',
'group_id' => 'nullable|int',
'enabled' => 'nullable|bool',
'meta' => 'nullable|string',
'meta' => 'nullable|array',
];

/**
Expand All @@ -100,7 +100,7 @@ final class CreateComponentCommand
* @param int $order
* @param int $group_id
* @param bool $enabled
* @param string|null $meta
* @param array|null $meta
*
* @return void
*/
Expand Down
6 changes: 3 additions & 3 deletions app/Bus/Commands/Component/UpdateComponentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class UpdateComponentCommand
/**
* JSON meta data for the component.
*
* @var string|null
* @var array|null
*/
public $meta;

Expand All @@ -98,7 +98,7 @@ final class UpdateComponentCommand
'order' => 'nullable|int',
'group_id' => 'nullable|int',
'enabled' => 'nullable|bool',
'meta' => 'nullable|string',
'meta' => 'nullable|array',
'silent' => 'nullable|bool',
];

Expand All @@ -113,7 +113,7 @@ final class UpdateComponentCommand
* @param int $order
* @param int $group_id
* @param bool $enabled
* @param string|null $meta
* @param array|null $meta
* @param bool $silent
*
* @return void
Expand Down
4 changes: 2 additions & 2 deletions app/Bus/Commands/Incident/CreateIncidentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ final class CreateIncidentCommand
public $rules = [
'name' => 'required|string',
'status' => 'required|int|min:0|max:4',
'message' => 'required|string',
'message' => 'nullable|string',
'visible' => 'nullable|bool',
'component_id' => 'nullable|required_with:component_status|int',
'component_status' => 'nullable|required_with:component_id|int|min:0|max:4',
'notify' => 'nullable|bool',
'stickied' => 'required|bool',
'occurred_at' => 'nullable|string',
'template' => 'nullable|string',
'meta' => 'required|array',
'meta' => 'nullable|array',
];

/**
Expand Down
6 changes: 3 additions & 3 deletions app/Bus/Commands/Metric/CreateMetricPointCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class CreateMetricPointCommand
/**
* The metric point created at.
*
* @var string
* @var int
*/
public $created_at;

Expand All @@ -49,15 +49,15 @@ final class CreateMetricPointCommand
*/
public $rules = [
'value' => 'required|numeric',
'created_at' => 'required|string',
'created_at' => 'nullable|int',
];

/**
* Create a new add metric point command instance.
*
* @param \CachetHQ\Cachet\Models\Metric $metric
* @param int $value
* @param string $created_at
* @param int $created_at
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion app/Bus/Commands/Metric/UpdateMetricCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ final class UpdateMetricCommand
'default_view' => 'nullable|numeric|between:0,4',
'threshold' => 'nullable|int',
'order' => 'nullable|int',
'visible' => 'required|int|between:0,2',
'visible' => 'nullable|int|between:0,2',
];

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Bus/Commands/Schedule/CreateScheduleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class CreateScheduleCommand
'status' => 'required|int|min:0|max:2',
'scheduled_at' => 'required|string',
'completed_at' => 'nullable|string',
'components' => 'required|array',
'components' => 'nullable|array',
];

/**
Expand All @@ -86,7 +86,7 @@ final class CreateScheduleCommand
*
* @return void
*/
public function __construct($name, $message, $status, $scheduled_at, $completed_at, array $components)
public function __construct($name, $message, $status, $scheduled_at, $completed_at, array $components = [])
{
$this->name = $name;
$this->message = $message;
Expand Down
3 changes: 2 additions & 1 deletion app/Foundation/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace CachetHQ\Cachet\Foundation\Providers;

use AltThree\Bus\Dispatcher;
use AltThree\Validator\ValidatingMiddleware;
use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions;
use CachetHQ\Cachet\Services\Dates\DateFactory;
use Illuminate\Database\Eloquent\Relations\Relation;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function boot(Dispatcher $dispatcher)
return Dispatcher::simpleMapping($command, 'CachetHQ\Cachet\Bus', 'CachetHQ\Cachet\Bus\Handlers');
});

$dispatcher->pipeThrough([UseDatabaseTransactions::class]);
$dispatcher->pipeThrough([UseDatabaseTransactions::class, ValidatingMiddleware::class]);

Str::macro('canonicalize', function ($url) {
return preg_replace('/([^\/])$/', '$1/', $url);
Expand Down
6 changes: 4 additions & 2 deletions tests/Api/MetricPointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public function testPostMetricPointTimestamp()

$metric = factory('CachetHQ\Cachet\Models\Metric')->create();
$timestamp = 1434369116;
$datetime = '2015-06-15 11:51:56';
$metricPoint = factory('CachetHQ\Cachet\Models\MetricPoint')->make([
'metric_id' => $metric->id,
]);
Expand All @@ -79,7 +78,10 @@ public function testPostMetricPointTimestamp()

$this->post("/api/v1/metrics/{$metric->id}/points", $postData);

$this->seeJsonContains(['value' => $metricPoint->value, 'created_at' => $datetime]);
$this->seeJsonContains([
'value' => $metricPoint->value,
'created_at' => date('Y-m-d H:i:s', 1434369116),
]);

$this->assertResponseOk();
}
Expand Down

0 comments on commit c77e5df

Please sign in to comment.