Skip to content

Commit 086857e

Browse files
committed
SDK-1019: Ensure formatted address has structured address anchors
1 parent 08976d0 commit 086857e

File tree

4 files changed

+63
-17
lines changed

4 files changed

+63
-17
lines changed

src/Yoti/Entity/Anchor.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Anchor
1818
const TYPE_UNKNOWN_NAME = 'UNKNOWN';
1919
const TYPE_SOURCE_OID = '1.3.6.1.4.1.47127.1.1.1';
2020
const TYPE_VERIFIER_OID = '1.3.6.1.4.1.47127.1.1.2';
21-
const TYPE_UNKNOWN_OID = '';
2221

2322
/**
2423
* @var string

src/Yoti/Entity/Profile.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,27 @@ private function getFormattedAddress()
235235
$postalAddress = new Attribute(
236236
self::ATTR_POSTAL_ADDRESS,
237237
$postalAddressValue,
238-
$structuredPostalAddress->getSources(),
239-
$structuredPostalAddress->getVerifiers()
238+
$this->getAttributeAnchorMap($structuredPostalAddress)
240239
);
241240
}
242241
}
243242
return $postalAddress;
244243
}
244+
245+
/**
246+
* Get anchor map for provided anchor.
247+
*
248+
* @param Attribute $attribute
249+
* @return array attribute map
250+
*/
251+
private function getAttributeAnchorMap(Attribute $attribute)
252+
{
253+
return [
254+
Anchor::TYPE_UNKNOWN_NAME => array_filter($attribute->getAnchors(), function ($anchor) {
255+
return $anchor->getType() == Anchor::TYPE_UNKNOWN_NAME;
256+
}),
257+
Anchor::TYPE_VERIFIER_OID => $attribute->getVerifiers(),
258+
Anchor::TYPE_SOURCE_OID => $attribute->getSources(),
259+
];
260+
}
245261
}

src/Yoti/Util/Profile/AnchorConverter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ public static function convertAnchor(Anchor $protobufAnchor)
2929

3030
foreach ($certExtsArr as $extObj) {
3131
$anchorType = self::getAnchorTypeByOid($extObj->extnId);
32-
$anchorValue = '';
33-
if ($anchorType !== YotiAnchor::TYPE_UNKNOWN_NAME) {
32+
if ($anchorType === YotiAnchor::TYPE_UNKNOWN_NAME) {
33+
$anchorValue = '';
34+
} else {
3435
$anchorValue = self::decodeAnchorValue($extObj->extnValue);
3536
}
3637
$yotiAnchor = self::createYotiAnchor(
@@ -206,7 +207,7 @@ private static function getAnchorTypesMap()
206207
return [
207208
YotiAnchor::TYPE_SOURCE_OID => YotiAnchor::TYPE_SOURCE_NAME,
208209
YotiAnchor::TYPE_VERIFIER_OID => YotiAnchor::TYPE_VERIFIER_NAME,
209-
YotiAnchor::TYPE_UNKNOWN_OID => YotiAnchor::TYPE_UNKNOWN_NAME,
210+
YotiAnchor::TYPE_UNKNOWN_NAME => YotiAnchor::TYPE_UNKNOWN_NAME,
210211
];
211212
}
212213
}

tests/Entity/ProfileTest.php

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Yoti\Entity\Profile;
77
use Yoti\Entity\Attribute;
88
use Yoti\Entity\AgeVerification;
9+
use Yoti\Entity\Anchor;
10+
use Yoti\Util\Profile\AnchorListConverter;
11+
use YotiTest\Util\Profile\TestAnchors;
912

1013
/**
1114
* @coversDefaultClass \Yoti\Entity\Profile
@@ -15,22 +18,22 @@ class ProfileTest extends TestCase
1518
/**
1619
* @var \Yoti\Entity\Profile
1720
*/
18-
public $profile;
21+
private $profile;
1922

2023
/**
2124
* @var \Yoti\YotiClient
2225
*/
23-
public $yotiClient;
26+
private $yotiClient;
2427

2528
/**
2629
* @var string
2730
*/
28-
public $expectedPhoneNumber;
31+
private $expectedPhoneNumber;
2932

3033
/**
3134
* @var Array Structured Postal Address
3235
*/
33-
public $dummyStructuredPostalAddress;
36+
private $dummyStructuredPostalAddress;
3437

3538
public function setup()
3639
{
@@ -93,28 +96,43 @@ public function testGetAttributeName()
9396
*/
9497
public function testShouldReturnFormattedAddressAsPostalAddressWhenNull()
9598
{
99+
$anchorsMap = AnchorListConverter::convert(new \ArrayObject([
100+
$this->parseAnchor(TestAnchors::VERIFIER_YOTI_ADMIN_ANCHOR),
101+
$this->parseAnchor(TestAnchors::UNKNOWN_ANCHOR),
102+
$this->parseAnchor(TestAnchors::SOURCE_DL_ANCHOR),
103+
]));
104+
96105
$structuredPostalAddress = new Attribute(
97106
Profile::ATTR_STRUCTURED_POSTAL_ADDRESS,
98107
$this->dummyStructuredPostalAddress,
99-
[]
108+
$anchorsMap
100109
);
101-
$profileData = [
110+
111+
$profile = new Profile([
102112
Profile::ATTR_STRUCTURED_POSTAL_ADDRESS => $structuredPostalAddress,
103113
Profile::ATTR_GIVEN_NAMES => new Attribute(
104114
Profile::ATTR_GIVEN_NAMES,
105115
'Given Name TEST',
106116
[]
107117
),
108-
];
109-
$profile = new Profile($profileData);
110-
$expectedPostalAddress = '15a North Street CARSHALTON SM5 2HW UK';
111-
118+
]);
112119
$this->assertEquals('Given Name TEST', $profile->getGivenNames()->getValue());
113-
$this->assertEquals($expectedPostalAddress, $profile->getPostalAddress()->getValue());
114120
$this->assertEquals(
115121
json_encode($this->dummyStructuredPostalAddress),
116122
json_encode($profile->getStructuredPostalAddress()->getValue())
117123
);
124+
125+
$postalAddress = $profile->getPostalAddress();
126+
127+
$this->assertEquals('15a North Street CARSHALTON SM5 2HW UK', $postalAddress->getValue());
128+
$this->assertEquals($anchorsMap[Anchor::TYPE_SOURCE_OID], $postalAddress->getSources());
129+
$this->assertEquals($anchorsMap[Anchor::TYPE_VERIFIER_OID], $postalAddress->getVerifiers());
130+
131+
$anchors = [];
132+
array_walk($anchorsMap, function ($val) use (&$anchors) {
133+
$anchors = array_merge($anchors, array_values($val));
134+
});
135+
$this->assertEquals($anchors, $postalAddress->getAnchors());
118136
}
119137

120138
/**
@@ -223,4 +241,16 @@ public function testGetDocumentImages()
223241
$profile = new Profile($profileData);
224242
$this->assertSame($profileData['document_images'], $profile->getDocumentImages());
225243
}
244+
245+
/**
246+
* @param string $anchorString
247+
*
248+
* @return array $anchors
249+
*/
250+
private function parseAnchor($anchorString)
251+
{
252+
$anchor = new \Attrpubapi\Anchor();
253+
$anchor->mergeFromString(base64_decode($anchorString));
254+
return $anchor;
255+
}
226256
}

0 commit comments

Comments
 (0)