Skip to content

Commit

Permalink
Fix bug with AuthParams defined on SessionHandlerParams not migrating…
Browse files Browse the repository at this point in the history
… to Client AuthParams causing Security_Authenticate message to fail when using SoapHeader 2. (#40)
  • Loading branch information
DerMika committed Mar 6, 2017
1 parent e208aef commit 0c1d390
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 21 deletions.
30 changes: 15 additions & 15 deletions docs/about-get-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ Soap Header 4 example:
//Set up the client with necessary parameters:
$params = new Params([
'authParams' => [
'officeId' => 'BRUXX1111', //The Amadeus Office Id you want to sign in to - must be open on your WSAP.
'userId' => 'WSBENXXX', //Also known as 'Originator' for Soap Header 1 & 2 WSDL's
'passwordData' => 'dGhlIHBhc3N3b3Jk' // **base 64 encoded** password
],
'sessionHandlerParams' => [
'soapHeaderVersion' => Client::HEADER_V4, //This is the default value, can be omitted.
'wsdl' => '/home/user/mytestproject/data/amadeuswsdl/1ASIWXXXXXX_PDT_20160101_080000.wsdl', //Points to the location of the WSDL file for your WSAP. Make sure the associated XSD's are also available.
'stateful' => false, //Enable stateful messages by default - can be changed at will to switch between stateless & stateful.
'logger' => new Psr\Log\NullLogger(),
'authParams' => [
'officeId' => 'BRUXX1111', //The Amadeus Office Id you want to sign in to - must be open on your WSAP.
'userId' => 'WSBENXXX', //Also known as 'Originator' for Soap Header 1 & 2 WSDL's
'passwordData' => 'dGhlIHBhc3N3b3Jk' // **base 64 encoded** password
]
'logger' => new Psr\Log\NullLogger()
],
'requestCreatorParams' => [
'receivedFrom' => 'my test project' // The "Received From" string that will be visible in PNR History
Expand Down Expand Up @@ -104,18 +104,18 @@ Soap Header 2 example:
//Set up the client with necessary parameters:
$params = new Params([
'authParams' => [
'officeId' => 'BRUXX1111', //The Amadeus Office Id you want to sign in to - must be open on your WSAP.
'userId' => 'WSBENXXX', //Also known as 'Originator' for Soap Header 1 & 2 WSDL's
'passwordData' => 'dGhlIHBhc3N3b3Jk' // **base 64 encoded** password
'passwordLength' => 12,
'dutyCode' => 'SU',
'organizationId' => 'DUMMY-ORG',
]
'sessionHandlerParams' => [
'soapHeaderVersion' => Client::HEADER_V2,
'wsdl' => '/home/user/mytestproject/data/amadeuswsdl/1ASIWXXXXXX_PDT_20110101_080000.wsdl', //Points to the location of the WSDL file for your WSAP. Make sure the associated XSD's are also available.
'logger' => new Psr\Log\NullLogger(),
'authParams' => [
'officeId' => 'BRUXX1111', //The Amadeus Office Id you want to sign in to - must be open on your WSAP.
'userId' => 'WSBENXXX', //Also known as 'Originator' for Soap Header 1 & 2 WSDL's
'passwordData' => 'dGhlIHBhc3N3b3Jk' // **base 64 encoded** password
'passwordLength' => 12,
'dutyCode' => 'SU',
'organizationId' => 'DUMMY-ORG',
]
'logger' => new Psr\Log\NullLogger()
],
'requestCreatorParams' => [
'receivedFrom' => 'my test project' // The "Received From" string that will be visible in PNR History
Expand Down
12 changes: 6 additions & 6 deletions docs/how-to.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ You can provide all the WSDL's in your WSAP by passing an array of wsdl's in the
//Set up the client with necessary parameters:
$params = new Params([
'authParams' => [
'officeId' => 'BRUXX1111',
'userId' => 'WSBENXXX',
'passwordData' => 'dGhlIHBhc3N3b3Jk'
]
'sessionHandlerParams' => [
'soapHeaderVersion' => Client::HEADER_V4,
'wsdl' => [
'/home/user/mytestproject/data/amadeuswsdl/1ASIWXXXXXX_PDT_20160101_080000.wsdl',
'/home/user/mytestproject/data/amadeuswsdl/1ASIWXXXXXX_PDT_MediaServer_1.0_4.0.wsdl'
],
'logger' => new Psr\Log\NullLogger(),
'authParams' => [
'officeId' => 'BRUXX1111',
'userId' => 'WSBENXXX',
'passwordData' => 'dGhlIHBhc3N3b3Jk'
]
'logger' => new Psr\Log\NullLogger()
]
]);
Expand Down
6 changes: 6 additions & 0 deletions src/Amadeus/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ public function __construct($params)
) {
$params->sessionHandlerParams->authParams = $this->authParams;
}
} elseif (isset($params->sessionHandlerParams) &&
$params->sessionHandlerParams->authParams instanceof Params\AuthParams
) {
//@deprecated - Provide backwards compatibility with old authparams structure.
//Github Issue 40 - retrieve AuthParams from sessionhandlerparams if not generally available
$this->authParams = $params->sessionHandlerParams->authParams;
}

$this->sessionHandler = $this->loadSessionHandler(
Expand Down
61 changes: 61 additions & 0 deletions tests/Amadeus/Client/ParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function testCanMakeParamsFromArray()

$params = new Params($theParamArray);

$this->assertNull($params->authParams);

$this->assertNull($params->requestCreator);
$this->assertNull($params->sessionHandler);

Expand Down Expand Up @@ -84,6 +86,65 @@ public function testCanMakeParamsFromArray()
$this->assertEquals('some RF string', $params->requestCreatorParams->receivedFrom);
}

/**
* Auth params New location
*/
public function testCanMakeParamsFromArraySupportForAuthParamsSoapHeader2()
{
$theParamArray = [
'authParams' => [
'officeId' => 'BRUXXXXXX',
'originatorTypeCode' => 'U',
'userId' => 'WSXXXXXX',
'organizationId' => 'NMC-XXXXXX',
'passwordLength' => '4',
'passwordData' => base64_encode('TEST')
],
'sessionHandlerParams' => [
'wsdl' => '/var/fake/file/path',
'stateful' => true,
'logger' => new NullLogger(),

],
'requestCreatorParams' => [
'originatorOfficeId' => 'BRUXXXXXX',
'receivedFrom' => 'some RF string'
]
];

$params = new Params($theParamArray);

$this->assertNull($params->requestCreator);
$this->assertNull($params->sessionHandler);

$this->assertInstanceOf('Amadeus\Client\Params\SessionHandlerParams', $params->sessionHandlerParams);
$this->assertTrue($params->sessionHandlerParams->stateful);
$this->assertInstanceOf('Psr\Log\LoggerInterface', $params->sessionHandlerParams->logger);
$this->assertInternalType('array', $params->sessionHandlerParams->wsdl);
$this->assertCount(1, $params->sessionHandlerParams->wsdl);
$this->assertEquals('/var/fake/file/path', $params->sessionHandlerParams->wsdl[0]);

//No Auth params on sessionhandlerparams level:
$this->assertNull($params->sessionHandlerParams->authParams);

//Auth Params on highest level:
$this->assertInstanceOf('Amadeus\Client\Params\AuthParams', $params->authParams);
$this->assertEquals('BRUXXXXXX', $params->authParams->officeId);
$this->assertEquals('NMC-XXXXXX', $params->authParams->organizationId);
$this->assertEquals('WSXXXXXX', $params->authParams->userId);
$this->assertEquals('U', $params->authParams->originatorTypeCode);
$this->assertEquals(base64_encode('TEST'), $params->authParams->passwordData);
$this->assertEquals(4, $params->authParams->passwordLength);

//Defaults:
$this->assertEquals('SU', $params->authParams->dutyCode);
$this->assertNull($params->authParams->nonceBase);

$this->assertInstanceOf('Amadeus\Client\Params\RequestCreatorParams', $params->requestCreatorParams);
$this->assertEquals('BRUXXXXXX', $params->requestCreatorParams->originatorOfficeId);
$this->assertEquals('some RF string', $params->requestCreatorParams->receivedFrom);
}

public function testCanMakeParamsWithBaseNonceFromArray()
{
$theParamArray = [
Expand Down
91 changes: 91 additions & 0 deletions tests/Amadeus/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3449,6 +3449,97 @@ public function testCanDoAuthenticateCall()
$this->assertEquals($messageResult, $response);
}

/**
* Github issue #40
* backwards compatibility for AuthParams at SessionHandlerParams level which must fall back to client authparams
*
* to be deprecated with version 2.0
*
* @deprecated To be removed with version 2.0
*/
public function testCanDoAuthenticateCallWithAuthParamsOnSessionHandlerSoapHeader2()
{
$sessionHandlerParams = new Params\SessionHandlerParams([
'authParams' => [
'officeId' => 'BRUXXXXXX',
'originatorTypeCode' => 'U',
'userId' => 'WSXXXXXX',
'passwordData' => base64_encode('TEST'),
'passwordLength' => 4,
'dutyCode' => 'SU',
'organizationId' => 'DUMMY-ORG',
]
]);

$authParams = new Params\AuthParams([
'officeId' => 'BRUXXXXXX',
'originatorTypeCode' => 'U',
'userId' => 'WSXXXXXX',
'passwordData' => base64_encode('TEST'),
'passwordLength' => 4,
'dutyCode' => 'SU',
'organizationId' => 'DUMMY-ORG',
]);

$mockedSendResult = new Client\Session\Handler\SendResult();
$mockedSendResult->responseXml = 'dummy auth response xml';
$mockedSendResult->responseObject = new \stdClass();
$mockedSendResult->responseObject->processStatus = new \stdClass();
$mockedSendResult->responseObject->processStatus->statusCode = 'P';

$messageResult = new Client\Result($mockedSendResult);

$expectedMessageResult = new Client\Struct\Security\Authenticate(
new Client\RequestOptions\SecurityAuthenticateOptions(
$authParams
)
);

$mockSessionHandler = $this->getMock(
'Amadeus\Client\Session\Handler\SoapHeader2',
['Security_Authenticate', 'getLastResponse', 'getMessagesAndVersions', 'sendMessage'],
[$sessionHandlerParams],
'',
true
);

$mockSessionHandler
->expects($this->once())
->method('sendMessage')
->with('Security_Authenticate', $expectedMessageResult, ['endSession' => false, 'returnXml' => true])
->will($this->returnValue($mockedSendResult));
$mockSessionHandler
->expects($this->never())
->method('getLastResponse');
$mockSessionHandler
->expects($this->atLeastOnce())
->method('getMessagesAndVersions')
->will($this->returnValue(['Security_Authenticate' => "6.1"]));

$mockResponseHandler = $this->getMockBuilder('Amadeus\Client\ResponseHandler\ResponseHandlerInterface')->getMock();

$mockResponseHandler
->expects($this->once())
->method('analyzeResponse')
->with($mockedSendResult, 'Security_Authenticate')
->will($this->returnValue($messageResult));

$par = new Params();
$par->sessionHandler = $mockSessionHandler;
$par->sessionHandlerParams = $sessionHandlerParams;
$par->requestCreatorParams = new Params\RequestCreatorParams([
'receivedFrom' => 'some RF string',
'originatorOfficeId' => 'BRUXXXXXX'
]);
$par->responseHandler = $mockResponseHandler;

$client = new Client($par);

$response = $client->securityAuthenticate();

$this->assertEquals($messageResult, $response);
}

public function testCanSetSessionData()
{
$mockSessionHandler = $this->getMockBuilder('Amadeus\Client\Session\Handler\HandlerInterface')->getMock();
Expand Down

0 comments on commit 0c1d390

Please sign in to comment.