Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

GP-1173 - Check that Notification data is supplied as a string #16

Merged
merged 2 commits into from
Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Omnipay/WorldpayCGHosted/Message/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public function __construct($data, $notificationOriginIp)
throw new InvalidResponseException();
}

if (!is_string($data)) {
throw new InvalidResponseException('Data must be provided as a string');
}

$responseDom = new DOMDocument;
if (!@$responseDom->loadXML($data)) {
throw new InvalidResponseException('Non-XML notification body received');
Expand Down
24 changes: 12 additions & 12 deletions tests/Omnipay/WorldpayCGHosted/Message/NotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testAuthorisedValid()
$http = $this->getMockHttpResponse('NotificationAuthorised.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -37,7 +37,7 @@ public function testSentForAuthorisationValid()
$http = $this->getMockHttpResponse('NotificationSentForAuth.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -57,7 +57,7 @@ public function testAuthorisedFromBadIp()
$http = $this->getMockHttpResponse('NotificationAuthorised.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_BAD
);

Expand All @@ -77,7 +77,7 @@ public function testAuthorisedFromInvalidIp()
$http = $this->getMockHttpResponse('NotificationAuthorised.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
'not-a-real-ip'
);

Expand All @@ -97,7 +97,7 @@ public function testAuthorisedFromMissingIp()
$http = $this->getMockHttpResponse('NotificationAuthorised.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
'' // no origin IP
);

Expand All @@ -120,7 +120,7 @@ public function testAuthorisedMissingOrderCode()
$http = $this->getMockHttpResponse('NotificationAuthorisedMissingOrderCode.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -143,7 +143,7 @@ public function testCaptured()
$http = $this->getMockHttpResponse('NotificationCaptured.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -163,7 +163,7 @@ public function testRefused()
$http = $this->getMockHttpResponse('NotificationRefused.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -183,7 +183,7 @@ public function testCancelled()
$http = $this->getMockHttpResponse('NotificationCancelled.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -203,7 +203,7 @@ public function testRefundRequest()
$http = $this->getMockHttpResponse('NotificationRefundRequest.txt');

$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand All @@ -226,7 +226,7 @@ public function testNonXmlResponse()
{
$http = $this->getMockHttpResponse('NotificationNonXml.txt');
new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);
}
Expand All @@ -235,7 +235,7 @@ public function testUnexpectedXmlBody()
{
$http = $this->getMockHttpResponse('NotificationUnexpectedXml.txt');
$notification = new Notification(
$http->getBody(),
$http->getBody(true),
self::ORIGIN_IP_VALID
);

Expand Down