Skip to content

Commit

Permalink
Add validation for brand (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK authored Jul 17, 2024
1 parent 2b0131c commit 3cbc6a8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Verify2/Request/BaseVerifyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,13 @@ public function getBaseVerifyUniversalOutputArray(): array

return $returnArray;
}

public static function isBrandValid(string $brand): bool
{
if (!strlen($brand) < 16) {
return true;
}

return false;
}
}
5 changes: 5 additions & 0 deletions src/Verify2/Request/EmailRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vonage\Verify2\Request;

use InvalidArgumentException;
use Vonage\Verify2\VerifyObjects\VerificationLocale;
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;

Expand All @@ -13,6 +14,10 @@ public function __construct(
protected string $from,
protected ?VerificationLocale $locale = null,
) {
if (!self::isBrandValid($this->brand)) {
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
}

if (!$this->locale) {
$this->locale = new VerificationLocale();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Verify2/Request/SMSRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vonage\Verify2\Request;

use InvalidArgumentException;
use Vonage\Verify2\VerifyObjects\VerificationLocale;
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;

Expand All @@ -15,6 +16,10 @@ public function __construct(
protected string $entityId = '',
protected string $contentId = ''
) {
if (!self::isBrandValid($this->brand)) {
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
}

if (!$this->locale) {
$this->locale = new VerificationLocale();
}
Expand Down
5 changes: 5 additions & 0 deletions src/Verify2/Request/SilentAuthRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vonage\Verify2\Request;

use InvalidArgumentException;
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;

class SilentAuthRequest extends BaseVerifyRequest
Expand All @@ -11,6 +12,10 @@ public function __construct(
protected string $brand,
protected ?string $redirectUrl = null
) {
if (!self::isBrandValid($this->brand)) {
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
}

$workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SILENT_AUTH, $to);

if ($this->redirectUrl) {
Expand Down
7 changes: 6 additions & 1 deletion src/Verify2/Request/VoiceRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vonage\Verify2\Request;

use InvalidArgumentException;
use Vonage\Verify2\VerifyObjects\VerificationLocale;
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;

Expand All @@ -12,6 +13,10 @@ public function __construct(
protected string $brand,
protected ?VerificationLocale $locale = null,
) {
if (!self::isBrandValid($this->brand)) {
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
}

if (!$this->locale) {
$this->locale = new VerificationLocale();
}
Expand All @@ -29,4 +34,4 @@ public function toArray(): array
{
return $this->getBaseVerifyUniversalOutputArray();
}
}
}
7 changes: 6 additions & 1 deletion src/Verify2/Request/WhatsAppInteractiveRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vonage\Verify2\Request;

use InvalidArgumentException;
use Vonage\Verify2\VerifyObjects\VerificationLocale;
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;

Expand All @@ -12,6 +13,10 @@ public function __construct(
protected string $brand,
protected ?VerificationLocale $locale = null
) {
if (!self::isBrandValid($this->brand)) {
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
}

if (!$this->locale) {
$this->locale = new VerificationLocale();
}
Expand All @@ -24,4 +29,4 @@ public function toArray(): array
{
return $this->getBaseVerifyUniversalOutputArray();
}
}
}
5 changes: 5 additions & 0 deletions src/Verify2/Request/WhatsAppRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vonage\Verify2\Request;

use InvalidArgumentException;
use Vonage\Verify2\VerifyObjects\VerificationLocale;
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;

Expand All @@ -13,6 +14,10 @@ public function __construct(
protected string $from,
protected ?VerificationLocale $locale = null,
) {
if (!self::isBrandValid($this->brand)) {
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
}

if (!$this->locale) {
$this->locale = new VerificationLocale();
}
Expand Down
4 changes: 2 additions & 2 deletions test/Verify2/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\Diactoros\Response;
use Prophecy\Argument;
use Prophecy\Prophecy\ObjectProphecy;
use Vonage\Messages\Channel\Messenger\InvalidCategoryException;
use VonageTest\Traits\Psr7AssertionTrait;
use Vonage\Client;
use Vonage\Client\APIResource;
Expand Down Expand Up @@ -500,8 +501,7 @@ public function testCannotSendConcurrentVerifications(): void

public function testCannotSendWithoutBrand(): void
{
$this->expectException(Client\Exception\Request::class);
$this->expectExceptionMessage('Invalid params: The value of one or more parameters is invalid. See https://www.developer.vonage.com/api-errors#invalid-params for more information');
$this->expectException(\InvalidArgumentException::class);

$payload = [
'to' => '07785254785',
Expand Down

0 comments on commit 3cbc6a8

Please sign in to comment.