Skip to content

Commit

Permalink
Enhance certification id error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
badraxas committed Jan 20, 2024
1 parent 25d513b commit 54fb8a4
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Lines/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public function getRelationship(): Relationship

private function validateCertificationId(): void
{
if (isset($this->certificationId) && !preg_match('/^[a-f0-9]+$/i', $this->certificationId)) {
throw new RecordArgumentException(sprintf('Invalid certification ID "%s".', $this->certificationId));
if (isset($this->certificationId) && !preg_match('/^[a-f0-9]{9,16}$/', $this->certificationId)) {
throw new RecordArgumentException(sprintf('Certification authority ID "%s" is invalid. It may only contain numbers and lowercase letters, and must be 9 or 16 characters.', $this->certificationId));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/AdsTxtParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testParseFromFile(): void
$adsTxt = $adsTxtParser->fromFile(__DIR__.'/test_files/ads.txt');
$adsTxtReference = (new AdsTxt())
->addLine(new Comment(' ads.txt file for divisionone.example.com:'))
->addLine(new Record('silverssp.com', 5569, Relationship::DIRECT, 'f496211'))
->addLine(new Record('silverssp.com', 5569, Relationship::DIRECT, 'f496211f496211'))
->addLine(new Record('orangeexchange.com', 'AB345', Relationship::RESELLER))
;

Expand Down
6 changes: 3 additions & 3 deletions tests/AdsTxtTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public function testDiffMethodReturnsMissingLines(): void
$adsTxt1 = new AdsTxt();
$adsTxt2 = new AdsTxt();

$line1 = new Record('example.com', 'pub-123456789', Relationship::DIRECT, 'abc123');
$line2 = new Record('example.com', 'pub-987654321', Relationship::RESELLER, 'afe456');
$line3 = new Record('example.com', 'pub-444555666', Relationship::DIRECT, 'def789');
$line1 = new Record('example.com', 'pub-123456789', Relationship::DIRECT, 'abcdef12345');
$line2 = new Record('example.com', 'pub-987654321', Relationship::RESELLER, '12345abcdef');
$line3 = new Record('example.com', 'pub-444555666', Relationship::DIRECT, 'abcddef789');

$adsTxt1->addLine($line1)->addLine($line2);

Expand Down
4 changes: 2 additions & 2 deletions tests/Lines/RecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ class RecordTest extends TestCase
{
public function testGetters(): void
{
$record = new Record('domain.com', 1034, Relationship::DIRECT, 'ae45', new Comment(' a nice comment!'));
$record = new Record('domain.com', 1034, Relationship::DIRECT, 'aed12b962', new Comment(' a nice comment!'));

$this->assertEquals('domain.com', $record->getDomain());
$this->assertEquals(1034, $record->getPublisherId());
$this->assertEquals(Relationship::DIRECT, $record->getRelationship());
$this->assertEquals('ae45', $record->getCertificationId());
$this->assertEquals('aed12b962', $record->getCertificationId());
$this->assertEquals(new Comment(' a nice comment!'), $record->getComment());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_files/ads.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# ads.txt file for divisionone.example.com:
silverssp.com, 5569, DIRECT, f496211
silverssp.com, 5569, DIRECT, f496211f496211
orangeexchange.com, AB345, RESELLER

0 comments on commit 54fb8a4

Please sign in to comment.