fix: [attribute] IP address was considered as valid AS number

pull/8613/head
Jakub Onderka 2022-09-27 10:33:27 +02:00
parent f57ea8ef21
commit c8bda8b66f
2 changed files with 15 additions and 1 deletions

View File

@ -202,7 +202,7 @@ class AttributeValidationTool
$value = substr($value, 2); // remove 'AS'
}
if (strpos($value, '.') !== false) { // maybe value is in asdot notation
$parts = explode('.', $value);
$parts = explode('.', $value, 2);
if (self::isPositiveInteger($parts[0]) && self::isPositiveInteger($parts[1])) {
return $parts[0] * 65536 + $parts[1];
}

View File

@ -110,6 +110,20 @@ class AttributeValidationToolTest extends TestCase
]);
}
public function testValidateAs(): void
{
$this->shouldBeValid('AS', [
'0',
0,
1,
'1',
4294967295,
]);
$this->shouldBeInvalid('AS', [
'1.2.3.4',
]);
}
public function testCompressIpv6(): void
{
$this->assertEquals('1234:fd2:5621:1:89::4500', AttributeValidationTool::modifyBeforeValidation('ip-src', '1234:0fd2:5621:0001:0089:0000:0000:4500'));