Skip to content

Commit

Permalink
Merge pull request mschindler83#41 from roben/nemiah
Browse files Browse the repository at this point in the history
Fix HITANS
  • Loading branch information
nemiah authored Sep 18, 2019
2 parents bf0f7ad + fb6a972 commit d9fd700
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 57 deletions.
11 changes: 8 additions & 3 deletions lib/Fhp/Response/GetVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ public function parseTanModes($segments)
$processNameIndex = $this->getTanProcessNameIndexForVersion($version);
$processParamElementCount = $this->getTanProcessParamElementCountForVersion($version);
array_splice($params, 0, $processParamsOffset);
if (count($params) % $processParamElementCount !== 0) {
throw new MT940Exception('Invalid number of params for HITANS version ' . $version . ': ' . count($params));

$paramCount = count($params);
if ($paramCount % $processParamElementCount === $processParamElementCount - 1) {
// From version 3 on, the last parameter is optional and may be omitted in the last group of HITANS parameters
// see https://github.com/nemiah/phpFinTS/pull/40#issuecomment-532362814
$paramCount++;
}
$paramBlockIterations = count($params) / $processParamElementCount;

$paramBlockIterations = $paramCount / $processParamElementCount;
for ($i = 0; $i < $paramBlockIterations; $i++) {
$blockOffset = $i * $processParamElementCount;
$num = $params[$blockOffset]; // first element in block
Expand Down
47 changes: 0 additions & 47 deletions lib/Tests/Fhp/ConnectionTest.php

This file was deleted.

45 changes: 38 additions & 7 deletions lib/Tests/Fhp/ResponseTest/GetVariablesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Fhp\ResponseTest;

use Fhp\Response\GetVariables;
use Tests\Fhp\Model\HITANSTest;

class GetVariablesTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -22,6 +23,23 @@ public function testParseTanModesSparkasse()
$this->assertEquals($modes[900], 'iTAN');
}

public function testParseTanModesSparkasseLastParamRemoved()
{
// see https://github.com/nemiah/phpFinTS/pull/40#issuecomment-532362814
$segments = array(
'HITANS:169:6:4+1+1+1+J:N:0:910:2:HHD1.3.0:::chipTAN manuell:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:0:N:1:911:2:HHD1.3.2OPT:HHDOPT1:1.3.2:chipTAN optisch:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:0:N:1:912:2:HHD1.3.2USB:HHDUSB1:1.3.2:chipTAN-USB:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:0:N:1:913:2:Q1S:Secoder_UC:1.2.0:chipTAN-QR:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:0:N:1:920:2:smsTAN:::smsTAN:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:2:N:5:921:2:pushTAN:::pushTAN:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:2:N:2:900:2:iTAN:::iTAN:6:1:TAN-Nummer:3:J:2:N:0:0:N:N:00:0:N'
);
$gv = new GetVariables(null, null);
$modes = $gv->parseTanModes($segments);
$this->assertEquals($modes[910], 'chipTAN manuell');
$this->assertEquals($modes[911], 'chipTAN optisch');
$this->assertEquals($modes[912], 'chipTAN-USB');
$this->assertEquals($modes[913], 'chipTAN-QR');
$this->assertEquals($modes[920], 'smsTAN');
$this->assertEquals($modes[921], 'pushTAN');
$this->assertEquals($modes[900], 'iTAN');
}

public function testParseTanModesPostbank()
{
// postbank provides different versions - maybe we just use the highest one?
Expand All @@ -32,12 +50,25 @@ public function testParseTanModesPostbank()
);
$gv = new GetVariables(null, null);
$modes = $gv->parseTanModes($segments);
$this->assertEquals($modes[901], "mobileTAN");
$this->assertEquals($modes[910], "chipTAN optisch HHD1.3.2");
$this->assertEquals($modes[911], "chipTAN manuell HHD1.3.2");
$this->assertEquals($modes[920], "BestSign");
$this->assertEquals($modes[930], "mobileTAN");
$this->assertEquals($modes[912], "chipTAN optisch HHD1.4");
$this->assertEquals($modes[913], "chipTAN manuell HHD1.4");
$this->assertEquals($modes[901], 'mobileTAN');
$this->assertEquals($modes[910], 'chipTAN optisch HHD1.3.2');
$this->assertEquals($modes[911], 'chipTAN manuell HHD1.3.2');
$this->assertEquals($modes[920], 'BestSign');
$this->assertEquals($modes[930], 'mobileTAN');
$this->assertEquals($modes[912], 'chipTAN optisch HHD1.4');
$this->assertEquals($modes[913], 'chipTAN manuell HHD1.4');
}

public function testParseTanModesDKB()
{
$gv = new GetVariables(null, null);
$modes = $gv->parseTanModes(HITANSTest::REAL_DKB_RESPONSE);
$this->assertEquals($modes[920], "smsTAN");
$this->assertEquals($modes[900], "iTAN");
$this->assertEquals($modes[910], "chipTAN manuell");
$this->assertEquals($modes[911], "chipTAN optisch");
$this->assertEquals($modes[912], "chipTAN-USB");
$this->assertEquals($modes[913], "chipTAN-QR");
$this->assertEquals($modes[921], "TAN2go");
}
}

0 comments on commit d9fd700

Please sign in to comment.