Skip to content

Commit

Permalink
Merge pull request #18 from crawly/danielfs/issues/1259/corrige-antec…
Browse files Browse the repository at this point in the history
…edentes-criminais

Define cfuvid como nullable.
  • Loading branch information
danielfs authored Sep 12, 2024
2 parents c45fbb0 + 1d5ff2c commit f1f6209
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function resolveChallenge(): CloudflareChallengeResponse

return new CloudflareChallengeResponse(
$this->taskInfo->solution->cf_clearance,
$this->taskInfo->solution->_cfuvid
$this->taskInfo->solution->_cfuvid ?? null
);
}

Expand Down
13 changes: 4 additions & 9 deletions src/ValueObject/CloudflareChallengeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@

class CloudflareChallengeResponse implements ChallengeResponseContract
{
private string $cloudflareClearance;
private $cloudflareClearance;
private $cfuvid;

public function __construct(string $cloudflareClearance, string $cfuvid)
public function __construct(string $cloudflareClearance, ?string $cfuvid)
{
if (empty(trim($cloudflareClearance))) {
throw new \InvalidArgumentException(
"Cloudflare clearance cannot be empty"
);
}

if (empty(trim($cfuvid))) {
throw new \InvalidArgumentException(
"cfuvid cannot be empty"
);
}

$this->cloudflareClearance = $cloudflareClearance;
$this->cfuvid = $cfuvid;
}
Expand All @@ -29,7 +24,7 @@ public function getCloudflareClearance(): string
return $this->cloudflareClearance;
}

public function getCfuvid(): string
public function getCfuvid(): ?string
{
return $this->cfuvid;
}
Expand Down
24 changes: 17 additions & 7 deletions tests/ValueObject/CloudflareChallengeResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ public function validationProvider(): array
["\r", "", "Cloudflare clearance cannot be empty"],
["\0", "", "Cloudflare clearance cannot be empty"],
["\x0B", "", "Cloudflare clearance cannot be empty"],
["cloudflare-clearance", "", "cfuvid cannot be empty"],
["cloudflare-clearance", " ", "cfuvid cannot be empty"],
["cloudflare-clearance", "\t", "cfuvid cannot be empty"],
["cloudflare-clearance", "\n", "cfuvid cannot be empty"],
["cloudflare-clearance", "\r", "cfuvid cannot be empty"],
["cloudflare-clearance", "\0", "cfuvid cannot be empty"],
["cloudflare-clearance", "\x0B", "cfuvid cannot be empty"],
];
}

Expand All @@ -59,4 +52,21 @@ public function testValidation(
$this->expectExceptionMessage($expectedMessage);
new CloudflareChallengeResponse($cloudflareClearance, $cfuvid);
}

public function testNullableCfuvidCookie(): void
{
$cloudflareChallengeResponse = new CloudflareChallengeResponse(
"cloudflare-clearance",
null
);
$this->assertEquals(
"cloudflare-clearance",
$cloudflareChallengeResponse->getCloudflareClearance()
);

$this->assertEquals(
null,
$cloudflareChallengeResponse->getCfuvid()
);
}
}

0 comments on commit f1f6209

Please # to comment.