Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
tighten json schema for incoming device reports
Browse files Browse the repository at this point in the history
Invalid "disks" entries were not being rejected, e.g. as seen in
https://rollbar.com/joyent_buildops/conch/items/64/occurrences/111200659371/
  • Loading branch information
karenetheridge committed Jan 3, 2020
1 parent a7c88a9 commit 7e9b518
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions json-schema/device_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ definitions:
- type: 'null'
disks:
type: object
additionalProperties: false
propertyNames:
$ref: common.yaml#/definitions/disk_serial_number
additionalProperties:
Expand Down
15 changes: 12 additions & 3 deletions t/json-validation.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,25 @@ subtest 'device report validation' => sub {
->load_and_validate_schema('json-schema/device_report.yaml',
{ schema => 'http://json-schema.org/draft-07/schema#' });

my $schema = $validator->get('/definitions/DeviceReport_v3.0.0/properties/system_uuid');

cmp_deeply(
[ $validator->validate('00000000-0000-0000-0000-000000000000', $schema) ],
[ $validator->validate('00000000-0000-0000-0000-000000000000',
$validator->get('/definitions/DeviceReport_v3.0.0/properties/system_uuid')) ],
[ methods(
path => '/',
message => re(qr/should not match/i),
) ],
'all-zero system_uuids are rejected',
);

cmp_deeply(
[ $validator->validate({ '' => {} },
$validator->get('/definitions/DeviceReport_v3.0.0/properties/disks')) ],
[ methods(
path => '/',
message => re(qr{/propertyName/ String does not match '?\^\\S\+\$'?}i),
) ],
'bad disk entries are rejected',
);
};

done_testing;

0 comments on commit 7e9b518

Please sign in to comment.