Skip to content

Commit d14f22c

Browse files
authored
Update glpi inventory library, add test (#18958)
* Revert "Allow extra nodes in inventory file" This reverts commit a8e8bdb. * Update glpi inventory library
1 parent 1bee128 commit d14f22c

File tree

3 files changed

+5
-57
lines changed

3 files changed

+5
-57
lines changed

composer.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit/functional/Glpi/Inventory/InventoryTest.php

-16
Original file line numberDiff line numberDiff line change
@@ -9417,24 +9417,8 @@ public function testAdditionalProperty()
94179417

94189418
//initial import
94199419
$inventory = new \Glpi\Inventory\Inventory();
9420-
$this->assertFalse($inventory->isSchemaStrict());
94219420
$inventory->setData($json);
94229421
$inventory->doInventory();
94239422
$this->assertTrue($computer->getFromDBByCrit(['name' => 'pc_with_additional_prop']));
9424-
9425-
//enable strict schema checks; an error is thrown
9426-
$inventory = new \Glpi\Inventory\Inventory();
9427-
$inventory->setStrictSchema();
9428-
$this->assertTrue($inventory->isSchemaStrict());
9429-
$inventory->setData($json);
9430-
9431-
$this->assertTrue($inventory->inError());
9432-
$this->assertSame(
9433-
['JSON does not validate. Violations:
9434-
Additional properties not allowed: unknown_property at #->properties:content
9435-
'
9436-
],
9437-
$inventory->getErrors()
9438-
);
94399423
}
94409424
}

src/Glpi/Inventory/Inventory.php

-36
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class Inventory
8787
private $request_query;
8888
/** @var bool */
8989
private bool $is_discovery = false;
90-
private bool $strict_schema = false;
9190

9291
/**
9392
* @param mixed $data Inventory data, optional
@@ -130,9 +129,6 @@ public function setData($data, $format = Request::JSON_MODE): bool
130129
$converter = new Converter();
131130

132131
$schema = $converter->getSchema();
133-
if (!$this->strict_schema) {
134-
$schema->setFlexible(); //allow extra nodes in inventory file
135-
}
136132

137133
$schema->setExtraItemtypes($this->getExtraItemtypes());
138134

@@ -1023,36 +1019,4 @@ protected function getExtraItemtypes(): array
10231019
}
10241020
return $itemtypes;
10251021
}
1026-
1027-
/**
1028-
* Set schema validation strict (no additional properties allowed anywhere)
1029-
*
1030-
* @return self
1031-
*/
1032-
public function setFlexibleSchema(): self
1033-
{
1034-
$this->strict_schema = false;
1035-
return $this;
1036-
}
1037-
1038-
/**
1039-
* Set schema validation strict (no additional properties allowed anywhere)
1040-
*
1041-
* @return self
1042-
*/
1043-
public function setStrictSchema(): self
1044-
{
1045-
$this->strict_schema = true;
1046-
return $this;
1047-
}
1048-
1049-
/**
1050-
* Is scheam validation strict?
1051-
*
1052-
* @return bool
1053-
*/
1054-
public function isSchemaStrict(): bool
1055-
{
1056-
return $this->strict_schema;
1057-
}
10581022
}

0 commit comments

Comments
 (0)