Skip to content

Commit

Permalink
Merge pull request #14 from giansalex/wssecurity-password-type
Browse files Browse the repository at this point in the history
Add Type attribute to password (Security Header)
  • Loading branch information
giansalex authored Jul 7, 2019
2 parents 689bc91 + 0cbb8c2 commit b45798f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
.php_cs.dist export-ignore
.travis.yml export-ignore
phpstan.neon export-ignore
phpunit.xml export-ignore
phpunit.xml.dist export-ignore
README.md export-ignore
33 changes: 16 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
language: php

php:
- 5.6
- 7.1
git:
depth: 1

matrix:
include:
- php: '5.6'
env:
- COVERAGE=true
- php: '7.1'
env:
- RUN_ANALYZER=true

before_script:
- composer install --prefer-source --no-interaction

install:
- |
if [ $(phpenv version-name) = "7.1" ]; then
composer require php-coveralls/php-coveralls;
composer require --dev phpstan/phpstan;
fi
- if [ $COVERAGE ]; then composer require php-coveralls/php-coveralls; fi
- if [ $RUN_ANALYZER ]; then composer require --dev phpstan/phpstan; fi

script:
- mkdir -p build/logs
- |
if [ $(phpenv version-name) = "7.1" ]; then
vendor/bin/phpstan analyse src --level 1 -c phpstan.neon;
fi
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml
- if [ $RUN_ANALYZER ]; then vendor/bin/phpstan analyse src --level 1 -c phpstan.neon; fi
- vendor/bin/phpunit --exclude-group manual --coverage-clover build/logs/clover.xml

after_success:
- |
if [ $(phpenv version-name) = "7.1" ]; then
travis_retry php vendor/bin/php-coveralls -v;
fi
- if [ $COVERAGE ]; then travis_retry php vendor/bin/php-coveralls -v; fi
3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
parameters:
ignoreErrors:
- '#Greenter\\Ws\\Header\\WSSESecurityHeader::__construct\(\) does not call parent constructor from SoapHeader.#'
- '#Greenter\\Ws\\Header\\WSSESecurityHeader::__construct\(\) does not call parent constructor from SoapHeader.#'
- '#Call to an undefined static method SoapClient::__construct().#'
File renamed without changes.
5 changes: 4 additions & 1 deletion src/Ws/Header/WSSESecurityHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
class WSSESecurityHeader extends SoapHeader
{
const WSS_NAMESPACE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
const PASSWORD_TYPE = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
const PASSWORD_FORMAT = '<o:Password xmlns:o="%s" Type="%s">%s</o:Password>';

public function __construct($username, $password)
{
$passwordXml = sprintf(self::PASSWORD_FORMAT, self::WSS_NAMESPACE, self::PASSWORD_TYPE, $password);
$security = new SoapVar(
[new SoapVar(
[
new SoapVar($username, XSD_STRING, null, null, 'Username', self::WSS_NAMESPACE),
new SoapVar($password, XSD_STRING, null, null, 'Password', self::WSS_NAMESPACE),
new SoapVar($passwordXml, XSD_ANYXML),
],
SOAP_ENC_OBJECT,
null,
Expand Down
15 changes: 8 additions & 7 deletions src/Ws/Services/SoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
namespace Greenter\Ws\Services;

use Greenter\Ws\Header\WSSESecurityHeader;
use SoapFault;

/**
* Class SoapClient.
*/
class SoapClient implements WsClientInterface
class SoapClient extends \SoapClient implements WsClientInterface
{
private $client;

/**
* SoapClient constructor.
*
* @param string $wsdl Url of WSDL
* @param array $parameters Soap's parameters
*
* @throws SoapFault
*/
public function __construct($wsdl = '', $parameters = [])
{
if (empty($wsdl)) {
$wsdl = WsdlProvider::getBillPath();
}
$this->client = new \SoapClient($wsdl, $parameters);
parent::__construct($wsdl, $parameters);
}

/**
Expand All @@ -37,7 +38,7 @@ public function __construct($wsdl = '', $parameters = [])
*/
public function setCredentials($user, $password)
{
$this->client->__setSoapHeaders(new WSSESecurityHeader($user, $password));
$this->__setSoapHeaders(new WSSESecurityHeader($user, $password));
}

/**
Expand All @@ -47,7 +48,7 @@ public function setCredentials($user, $password)
*/
public function setService($url)
{
$this->client->__setLocation($url);
$this->__setLocation($url);
}

/**
Expand All @@ -58,6 +59,6 @@ public function setService($url)
*/
public function call($function, $arguments)
{
return $this->client->__soapCall($function, $arguments);
return $this->__soapCall($function, $arguments);
}
}
Binary file modified tests/Resources/cdr-rechazo.zip
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/Ws/Services/FeSunatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function testSendInvoice()
);
}

/**
* @group manual
*/
public function testSendInvoiceBillSender()
{
$nameXml = '20600055519-01-F001-00000001';
Expand Down Expand Up @@ -112,6 +115,9 @@ public function testSendInvalidVoided()
$this->assertEquals('2001', $result->getError()->getCode());
}

/**
* @group manual
*/
public function testSendSummaryV2()
{
$nameXml = '20000000001-RC-20171119-001';
Expand All @@ -138,6 +144,17 @@ public function testGetStatus()
$this->assertContains('aceptada', $result->getCdrResponse()->getDescription());
}

public function testGetStatusWithExceptionCode()
{
$wss = $this->getExtServiceMock();
$result = $wss->getStatus('667123123214');

$this->assertFalse($result->isSuccess());
$this->assertNull($result->getCdrResponse());
$this->assertGreaterThanOrEqual(100, intval($result->getCode()));
$this->assertLessThanOrEqual(1999, intval($result->getCode()));
}

public function testGetStatusPending()
{
$service = $this->getExtServiceMock();
Expand Down
3 changes: 3 additions & 0 deletions tests/Ws/Services/FeSunatTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ private function getExtServiceMock()

if ('223123123213' === $ticket) {
$obj->status->statusCode = '98';
} elseif ('667123123214' === $ticket){
$obj->status->statusCode = '1002';
$obj->status->statusMessage = 'ERROR Z';
} else {
$obj->status->statusCode = '0';
$obj->status->content = file_get_contents(__DIR__.'/../../Resources/cdrBaja.zip');
Expand Down

2 comments on commit b45798f

@KhanMaytok
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Para usar estos cambios, habrá un nuevo release?

@giansalex
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola, se libero la versión 2.2.2

Please sign in to comment.