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

Commit

Permalink
Merge pull request #16 from comicrelief/GP-1173-no-debug-log
Browse files Browse the repository at this point in the history
GP-1173 - Check that Notification data is supplied as a string
  • Loading branch information
adamclark-dev authored Jan 31, 2018
2 parents f65c08c + 276ad13 commit f199682
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
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

0 comments on commit f199682

Please sign in to comment.