Skip to content

Commit 63eb230

Browse files
fix(responsetranslator): to return empty description case also as invalid template; patched tests
1 parent 2e66cdc commit 63eb230

File tree

4 files changed

+45
-40
lines changed

4 files changed

+45
-40
lines changed

.github/workflows/test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ jobs:
6363
env:
6464
TESTS_USER_HEXONET: ${{ secrets.TESTS_USER_HEXONET }}
6565
TESTS_USERPASSWORD_HEXONET: ${{ secrets.TESTS_USERPASSWORD_HEXONET }}
66-
TESTS_USER_CNR: ${{ secrets.TESTS_USER_RRPPROXY }}
67-
TESTS_USERPASSWORD_CNR: ${{ secrets.TESTS_USERPASSWORD_RRPPROXY }}
66+
TESTS_USER_CNR: ${{ secrets.TESTS_USER_CNR }}
67+
TESTS_USERPASSWORD_CNR: ${{ secrets.TESTS_USERPASSWORD_CNR }}
6868
run: composer run-script test

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" stopOnFailure="false" bootstrap="./vendor/autoload.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" stopOnFailure="true" bootstrap="./vendor/autoload.php" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
33
<coverage processUncoveredFiles="true">
44
<include>
55
<directory suffix=".php">src</directory>

src/HEXONET/ResponseTranslator.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ class ResponseTranslator
2323
* @var array
2424
*/
2525
private static $descriptionRegexMap = [
26-
"Authorization failed; Operation forbidden by ACL" => "Authorization failed; Used Command `{COMMAND}` not white-listed by your Access Control List",
27-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (clientTransferProhibited)/WRONG AUTH" => "This Domain is locked and the given Authorization Code is wrong. Initiating a Transfer is therefore impossible.",
28-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (clientTransferProhibited)" => "This Domain is locked. Initiating a Transfer is therefore impossible.",
29-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (requested)" => "Registration of this Domain Name has not yet completed. Initiating a Transfer is therefore impossible.",
30-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (requestedcreate)" => "Registration of this Domain Name has not yet completed. Initiating a Transfer is therefore impossible.",
31-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (requesteddelete)" => "Deletion of this Domain Name has been requested. Initiating a Transfer is therefore impossible.",
32-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (pendingdelete)" => "Deletion of this Domain Name is pending. Initiating a Transfer is therefore impossible.",
33-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY WRONG AUTH" => "The given Authorization Code is wrong. Initiating a Transfer is therefore impossible.",
34-
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY AGE OF THE DOMAIN" => "This Domain Name is within 60 days of initial registration. Initiating a Transfer is therefore impossible."
26+
"Authorization failed; Operation forbidden by ACL" => "Authorization failed; Used Command `{COMMAND}` not white-listed by your Access Control List",
27+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (clientTransferProhibited)/WRONG AUTH" => "This Domain is locked and the given Authorization Code is wrong. Initiating a Transfer is therefore impossible.",
28+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (clientTransferProhibited)" => "This Domain is locked. Initiating a Transfer is therefore impossible.",
29+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (requested)" => "Registration of this Domain Name has not yet completed. Initiating a Transfer is therefore impossible.",
30+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (requestedcreate)" => "Registration of this Domain Name has not yet completed. Initiating a Transfer is therefore impossible.",
31+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (requesteddelete)" => "Deletion of this Domain Name has been requested. Initiating a Transfer is therefore impossible.",
32+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY STATUS (pendingdelete)" => "Deletion of this Domain Name is pending. Initiating a Transfer is therefore impossible.",
33+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY WRONG AUTH" => "The given Authorization Code is wrong. Initiating a Transfer is therefore impossible.",
34+
"Request is not available; DOMAIN TRANSFER IS PROHIBITED BY AGE OF THE DOMAIN" => "This Domain Name is within 60 days of initial registration. Initiating a Transfer is therefore impossible."
3535
];
3636

3737
/**
@@ -55,9 +55,9 @@ public static function translate($raw, $cmd, $ph = [])
5555

5656
// Missing CODE or DESCRIPTION in API Response
5757
if (
58-
(
59-
!preg_match("/description[\s]*=/i", $newraw)
60-
|| !preg_match("/code[\s]*=/i", $newraw)
58+
(!preg_match("/description[\s]*=/i", $newraw) // missing description
59+
|| preg_match("/description[\s]*=\r\n/i", $newraw) // empty description
60+
|| !preg_match("/code[\s]*=/i", $newraw) // missing code
6161
)
6262
&& RTM::hasTemplate("invalid")
6363
) {

tests/HEXONET/ClientTest.php

+30-25
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ public function testGetPOSTDataSecured(): void
4141
"SUBUSER" => self::$user,
4242
"PASSWORD" => self::$pw
4343
], true);
44-
$pwenc = urlencode(self::$pw);
4544
self::$cl->setCredentials();
4645
$this->assertEquals(
47-
"s_entity=54cd&s_login=" . self::$user . "&s_pw=" . $pwenc .
48-
"&s_command=COMMAND%3DCheckAuthentication%0ASUBUSER%3D" . self::$user . "%0APASSWORD%3D" . $pwenc,
46+
http_build_query([
47+
"s_entity" => "54cd",
48+
"s_login" => self::$user,
49+
"s_pw" => "***",
50+
"s_command" => "COMMAND=CheckAuthentication\nSUBUSER=" . self::$user . "\nPASSWORD=***"
51+
]),
4952
$enc
5053
);
5154
}
@@ -148,7 +151,7 @@ public function testSetOTPSet(): void
148151
self::$cl->settings["parameters"]["otp"] = "s_otp";
149152
self::$cl->setOTP("12345678");
150153
$tmp = self::$cl->getPOSTData([
151-
"COMMAND" => "StatusAccount"
154+
"COMMAND" => "StatusAccount"
152155
]);
153156
$this->assertEquals($tmp, "s_entity=54cd&s_otp=12345678&s_command=COMMAND%3DStatusAccount");
154157
}
@@ -157,7 +160,7 @@ public function testSetOTPReset(): void
157160
{
158161
self::$cl->setOTP();
159162
$tmp = self::$cl->getPOSTData([
160-
"COMMAND" => "StatusAccount"
163+
"COMMAND" => "StatusAccount"
161164
]);
162165
$this->assertEquals($tmp, "s_entity=54cd&s_command=COMMAND%3DStatusAccount");
163166
}
@@ -166,7 +169,7 @@ public function testSetSessionSet(): void
166169
{
167170
self::$cl->setSession("12345678");
168171
$tmp = self::$cl->getPOSTData([
169-
"COMMAND" => "StatusAccount"
172+
"COMMAND" => "StatusAccount"
170173
]);
171174
$this->assertEquals($tmp, "s_entity=54cd&s_session=12345678&s_command=COMMAND%3DStatusAccount");
172175
}
@@ -175,8 +178,8 @@ public function testSetSessionCredentials(): void
175178
{
176179
// credentials and otp code have to be unset when session id is set
177180
self::$cl->setRoleCredentials("myaccountid", "myrole", "mypassword")
178-
->setOTP("12345678")
179-
->setSession("12345678");
181+
->setOTP("12345678")
182+
->setSession("12345678");
180183
$tmp = self::$cl->getPOSTData([
181184
"COMMAND" => "StatusAccount"
182185
]);
@@ -187,15 +190,15 @@ public function testSetSessionReset(): void
187190
{
188191
self::$cl->setSession();
189192
$tmp = self::$cl->getPOSTData([
190-
"COMMAND" => "StatusAccount"
193+
"COMMAND" => "StatusAccount"
191194
]);
192195
$this->assertEquals($tmp, "s_entity=54cd&s_command=COMMAND%3DStatusAccount");
193196
}
194197

195198
public function testSaveReuseSession(): void
196199
{
197200
self::$cl->setSession("12345678")
198-
->saveSession($_SESSION);
201+
->saveSession($_SESSION);
199202
$cl2 = CF::getClient([
200203
"registrar" => "HEXONET"
201204
]);
@@ -221,7 +224,7 @@ public function testSetRemoteIPAddressSet(): void
221224
self::$cl->settings["parameters"]["ipfilter"] = "s_remoteaddr";
222225
self::$cl->setRemoteIPAddress("10.10.10.10");
223226
$tmp = self::$cl->getPOSTData([
224-
"COMMAND" => "StatusAccount"
227+
"COMMAND" => "StatusAccount"
225228
]);
226229
$this->assertEquals($tmp, "s_entity=54cd&s_remoteaddr=10.10.10.10&s_command=COMMAND%3DStatusAccount");
227230
}
@@ -239,7 +242,7 @@ public function testSetCredentialsSet(): void
239242
{
240243
self::$cl->setCredentials("myaccountid", "mypassword");
241244
$tmp = self::$cl->getPOSTData([
242-
"COMMAND" => "StatusAccount"
245+
"COMMAND" => "StatusAccount"
243246
]);
244247
$this->assertEquals($tmp, "s_entity=54cd&s_login=myaccountid&s_pw=mypassword&s_command=COMMAND%3DStatusAccount");
245248
}
@@ -257,7 +260,7 @@ public function testSetRoleCredentialsSet(): void
257260
{
258261
self::$cl->setRoleCredentials("myaccountid", "myroleid", "mypassword");
259262
$tmp = self::$cl->getPOSTData([
260-
"COMMAND" => "StatusAccount"
263+
"COMMAND" => "StatusAccount"
261264
]);
262265
$this->assertEquals($tmp, "s_entity=54cd&s_login=myaccountid%21myroleid&s_pw=mypassword&s_command=COMMAND%3DStatusAccount");
263266
}
@@ -274,7 +277,7 @@ public function testSetRoleCredentialsReset(): void
274277
public function testLoginCredsOK(): void
275278
{
276279
self::$cl->useOTESystem()
277-
->setCredentials(self::$user, self::$pw);
280+
->setCredentials(self::$user, self::$pw);
278281
$r = self::$cl->login();
279282
$this->assertInstanceOf(R::class, $r);
280283
$this->assertEquals($r->isSuccess(), true);
@@ -310,7 +313,7 @@ public function testLoginCredsFAIL(): void
310313
public function testLoginExtendedCredsOK(): void
311314
{
312315
self::$cl->useOTESystem()
313-
->setCredentials(self::$user, self::$pw);
316+
->setCredentials(self::$user, self::$pw);
314317
$r = self::$cl->loginExtended([
315318
"TIMEOUT" => 60
316319
]);
@@ -358,9 +361,9 @@ public function testRequestCurlExecFail2(): void
358361
{
359362
self::$cl->settings["env"]["ote"]["url"] = "http://gregeragregaegaegag.com/geragaerg/call.cgi";
360363
self::$cl->setCredentials(self::$user, self::$pw)
361-
->useOTESystem();
364+
->useOTESystem();
362365
$r = self::$cl->request([
363-
"COMMAND" => "StatusAccount"
366+
"COMMAND" => "StatusAccount"
364367
]);
365368
$this->assertInstanceOf(R::class, $r);
366369
$this->assertEquals($r->isSuccess(), false);
@@ -370,10 +373,12 @@ public function testRequestCurlExecFail2(): void
370373

371374
public function testRequestFlattenCommand(): void
372375
{
376+
$cfgpath = implode(DIRECTORY_SEPARATOR, ["src", "HEXONET", "config.json"]);
377+
$orgsettings = json_decode(file_get_contents($cfgpath), true);
373378
// restore
374-
self::$cl->settings["env"]["ote"]["url"] = "https://api.ispapi.net/api/call.cgi";
379+
self::$cl->settings["env"]["ote"]["url"] = $orgsettings["env"]["ote"]["url"];
375380
self::$cl->setCredentials(self::$user, self::$pw)
376-
->useOTESystem();
381+
->useOTESystem();
377382
$r = self::$cl->request([
378383
"COMMAND" => "CheckDomains",
379384
"DOMAIN" => ["example.com", "example.net"]
@@ -394,7 +399,7 @@ public function testRequestFlattenCommand(): void
394399
public function testRequestAUTOIdnConvert(): void
395400
{
396401
self::$cl->setCredentials(self::$user, self::$pw)
397-
->useOTESystem();
402+
->useOTESystem();
398403
$r = self::$cl->request([
399404
"COMMAND" => "CheckDomains",
400405
"DOMAIN" => ["example.com", "dömäin.example", "example.net"]
@@ -417,7 +422,7 @@ public function testRequestAUTOIdnConvert(): void
417422
public function testRequestAUTOIdnConvert2(): void
418423
{
419424
self::$cl->setCredentials(self::$user, self::$pw)
420-
->useOTESystem();
425+
->useOTESystem();
421426
$r = self::$cl->request([
422427
"COMMAND" => "QueryObjectlogList",
423428
"OBJECTID" => "dömäin.example",
@@ -440,7 +445,7 @@ public function testRequestAUTOIdnConvert2(): void
440445
public function testRequestAUTOIdnConvert3(): void
441446
{
442447
self::$cl->setCredentials(self::$user, self::$pw)
443-
->useOTESystem();
448+
->useOTESystem();
444449
$r = self::$cl->request([
445450
"COMMAND" => "QueryObjectlogList",
446451
"OBJECTID" => "dömäin.example",
@@ -463,8 +468,8 @@ public function testRequestAUTOIdnConvert3(): void
463468
public function testRequestCodeTmpErrorDbg(): void
464469
{
465470
self::$cl->enableDebugMode()
466-
->setCredentials(self::$user, self::$pw)
467-
->useOTESystem();
471+
->setCredentials(self::$user, self::$pw)
472+
->useOTESystem();
468473
$r = self::$cl->request(["COMMAND" => "GetUserIndex"]);
469474
$this->assertInstanceOf(R::class, $r);
470475
$this->assertEquals($r->isSuccess(), true);
@@ -476,7 +481,7 @@ public function testRequestCodeTmpErrorDbg(): void
476481
public function testRequestCodeTmpErrorNoDbg(): void
477482
{
478483
self::$cl->disableDebugMode();
479-
$r = self::$cl->request([ "COMMAND" => "GetUserIndex" ]);
484+
$r = self::$cl->request(["COMMAND" => "GetUserIndex"]);
480485
$this->assertInstanceOf(R::class, $r);
481486
$this->assertEquals($r->isSuccess(), true);
482487
$this->assertEquals($r->getCode(), 200);

0 commit comments

Comments
 (0)