Skip to content

Commit 3cbc6a8

Browse files
authored
Add validation for brand (#490)
1 parent 2b0131c commit 3cbc6a8

File tree

8 files changed

+43
-4
lines changed

8 files changed

+43
-4
lines changed

src/Verify2/Request/BaseVerifyRequest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,13 @@ public function getBaseVerifyUniversalOutputArray(): array
170170

171171
return $returnArray;
172172
}
173+
174+
public static function isBrandValid(string $brand): bool
175+
{
176+
if (!strlen($brand) < 16) {
177+
return true;
178+
}
179+
180+
return false;
181+
}
173182
}

src/Verify2/Request/EmailRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Vonage\Verify2\Request;
44

5+
use InvalidArgumentException;
56
use Vonage\Verify2\VerifyObjects\VerificationLocale;
67
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;
78

@@ -13,6 +14,10 @@ public function __construct(
1314
protected string $from,
1415
protected ?VerificationLocale $locale = null,
1516
) {
17+
if (!self::isBrandValid($this->brand)) {
18+
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
19+
}
20+
1621
if (!$this->locale) {
1722
$this->locale = new VerificationLocale();
1823
}

src/Verify2/Request/SMSRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Vonage\Verify2\Request;
44

5+
use InvalidArgumentException;
56
use Vonage\Verify2\VerifyObjects\VerificationLocale;
67
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;
78

@@ -15,6 +16,10 @@ public function __construct(
1516
protected string $entityId = '',
1617
protected string $contentId = ''
1718
) {
19+
if (!self::isBrandValid($this->brand)) {
20+
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
21+
}
22+
1823
if (!$this->locale) {
1924
$this->locale = new VerificationLocale();
2025
}

src/Verify2/Request/SilentAuthRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Vonage\Verify2\Request;
44

5+
use InvalidArgumentException;
56
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;
67

78
class SilentAuthRequest extends BaseVerifyRequest
@@ -11,6 +12,10 @@ public function __construct(
1112
protected string $brand,
1213
protected ?string $redirectUrl = null
1314
) {
15+
if (!self::isBrandValid($this->brand)) {
16+
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
17+
}
18+
1419
$workflow = new VerificationWorkflow(VerificationWorkflow::WORKFLOW_SILENT_AUTH, $to);
1520

1621
if ($this->redirectUrl) {

src/Verify2/Request/VoiceRequest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Vonage\Verify2\Request;
44

5+
use InvalidArgumentException;
56
use Vonage\Verify2\VerifyObjects\VerificationLocale;
67
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;
78

@@ -12,6 +13,10 @@ public function __construct(
1213
protected string $brand,
1314
protected ?VerificationLocale $locale = null,
1415
) {
16+
if (!self::isBrandValid($this->brand)) {
17+
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
18+
}
19+
1520
if (!$this->locale) {
1621
$this->locale = new VerificationLocale();
1722
}
@@ -29,4 +34,4 @@ public function toArray(): array
2934
{
3035
return $this->getBaseVerifyUniversalOutputArray();
3136
}
32-
}
37+
}

src/Verify2/Request/WhatsAppInteractiveRequest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Vonage\Verify2\Request;
44

5+
use InvalidArgumentException;
56
use Vonage\Verify2\VerifyObjects\VerificationLocale;
67
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;
78

@@ -12,6 +13,10 @@ public function __construct(
1213
protected string $brand,
1314
protected ?VerificationLocale $locale = null
1415
) {
16+
if (!self::isBrandValid($this->brand)) {
17+
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
18+
}
19+
1520
if (!$this->locale) {
1621
$this->locale = new VerificationLocale();
1722
}
@@ -24,4 +29,4 @@ public function toArray(): array
2429
{
2530
return $this->getBaseVerifyUniversalOutputArray();
2631
}
27-
}
32+
}

src/Verify2/Request/WhatsAppRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Vonage\Verify2\Request;
44

5+
use InvalidArgumentException;
56
use Vonage\Verify2\VerifyObjects\VerificationLocale;
67
use Vonage\Verify2\VerifyObjects\VerificationWorkflow;
78

@@ -13,6 +14,10 @@ public function __construct(
1314
protected string $from,
1415
protected ?VerificationLocale $locale = null,
1516
) {
17+
if (!self::isBrandValid($this->brand)) {
18+
throw new InvalidArgumentException('The brand name cannot be longer than 16 characters.');
19+
}
20+
1621
if (!$this->locale) {
1722
$this->locale = new VerificationLocale();
1823
}

test/Verify2/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Laminas\Diactoros\Response;
99
use Prophecy\Argument;
1010
use Prophecy\Prophecy\ObjectProphecy;
11+
use Vonage\Messages\Channel\Messenger\InvalidCategoryException;
1112
use VonageTest\Traits\Psr7AssertionTrait;
1213
use Vonage\Client;
1314
use Vonage\Client\APIResource;
@@ -500,8 +501,7 @@ public function testCannotSendConcurrentVerifications(): void
500501

501502
public function testCannotSendWithoutBrand(): void
502503
{
503-
$this->expectException(Client\Exception\Request::class);
504-
$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');
504+
$this->expectException(\InvalidArgumentException::class);
505505

506506
$payload = [
507507
'to' => '07785254785',

0 commit comments

Comments
 (0)