Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
fix(responsetranslator): review generic replacement logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiSchwarz-cnic committed May 21, 2021
1 parent 03267e0 commit c76d2f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ResponseTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public static function translate($raw, $cmd, $ph = [])

// generic API response description rewrite
foreach (self::$descriptionRegexMap as $regex => $val) {
$qregex = "/description=" . preg_quote($regex) . "/i";
// match the response for given description
// NOTE: we match if the description starts with the given description
// it would also match if it is followed by additional text
$qregex = "/description=" . preg_quote($regex) . "[^\r]*/i";
if (preg_match($qregex, $newraw)) {
// replace command place holder with API command name used
if (isset($cmd["COMMAND"])) {
Expand Down
5 changes: 5 additions & 0 deletions tests/ResponseTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ public function testCheckDomainTransferTranslation(): void
$this->assertEquals(219, $r->getCode());
$this->assertEquals("The given Authorization Code is wrong. Initiating a Transfer is therefore impossible.", $r->getDescription());

// mixed status `locked` and Wrong Auth
$r = new R("[RESPONSE]\r\ncode=219\r\ndescription=Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (clientTransferProhibited)/WRONG AUTH\r\nEOF\r\n", $cmd);
$this->assertEquals(219, $r->getCode());
$this->assertEquals("This Domain is locked. Initiating a Transfer is therefore impossible.", $r->getDescription());

// Age of the Domain <= 60d
$r = new R("[RESPONSE]\r\ncode=219\r\ndescription=Request is not available; DOMAIN TRANSFER IS PROHIBITED BY AGE OF THE DOMAIN\r\nEOF\r\n", $cmd);
$this->assertEquals(219, $r->getCode());
Expand Down

0 comments on commit c76d2f6

Please sign in to comment.