From 9625fa3e0112aa22631622e1f87f3d42b8871416 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 29 May 2020 15:47:32 +0100 Subject: [PATCH 01/10] Bump minor version --- composer.json | 2 +- sonar-project.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index ce4315f..d688d8c 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yoti/yoti-php-sdk-sandbox", "description": "Yoti PHP SDK Sandbox", - "version": "1.1.0", + "version": "1.2.0", "keywords": [ "yoti", "sdk" diff --git a/sonar-project.properties b/sonar-project.properties index a6c70eb..d4d3cf1 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,7 +3,7 @@ sonar.organization = getyoti sonar.projectKey = getyoti:php-sandbox sonar.projectName = PHP SDK Sandbox -sonar.projectVersion = 1.1.0 +sonar.projectVersion = 1.2.0 sonar.language = php sonar.sources=src From 5c68626f7cc182e15ffe0bfb11b457487ea88b88 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 12 Jun 2020 17:55:00 +0100 Subject: [PATCH 02/10] SDK-1395: Add SonarCloud to Travis --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 1a939c3..a38ff3c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,14 @@ jobs: php: "7.2" - <<: *compatibility php: "7.3" + - <<: *test + stage: Analyze + name: Sonarcloud + dist: trusty + addons: + sonarcloud: + organization: "getyoti" + if: type == pull_request OR branch = master + script: + - composer coverage-clover + - sonar-scanner From 44bcccc6650ecea102d05bcf84c88bdc7a4b77a7 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 12 Jun 2020 18:19:31 +0100 Subject: [PATCH 03/10] SDK-1395: Add badges to README --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 2f6a5b6..fe51043 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ # Yoti PHP Sandbox SDK +[![Build Status](https://travis-ci.com/getyoti/yoti-php-sdk-sandbox.svg?branch=master)](https://travis-ci.com/getyoti/yoti-php-sdk-sandbox) +[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=coverage)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) +[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=bugs)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) +[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=code_smells)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) +[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=getyoti%3Aphp-sandbox&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=getyoti%3Aphp-sandbox) + This repository contains the tools you need to test your Yoti integration. ## Installing the Sandbox From 89fa12bfff8f465f40c2e70934fecee764e048e6 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Mon, 15 Jun 2020 15:27:23 +0100 Subject: [PATCH 04/10] NA: Update PHPUnit for new PHP versions --- composer.json | 2 +- tests/DocScan/SandboxClientTest.php | 4 ++-- tests/TestCase.php | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index d688d8c..120b46e 100755 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "yoti/yoti-php-sdk": "^3.1" }, "require-dev": { - "phpunit/phpunit": "^7.5 || ^8.5", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.2", "squizlabs/php_codesniffer": "^3.4", "friendsofphp/php-cs-fixer": "^2.15", "brainmaestro/composer-git-hooks": "^2.8", diff --git a/tests/DocScan/SandboxClientTest.php b/tests/DocScan/SandboxClientTest.php index 4f1809c..b0479a2 100644 --- a/tests/DocScan/SandboxClientTest.php +++ b/tests/DocScan/SandboxClientTest.php @@ -46,7 +46,7 @@ function (RequestInterface $requestMessage) { ); $this->assertEquals('PUT', $requestMessage->getMethod()); - $this->assertRegExp($expectedPathPattern, (string)$requestMessage->getUri()); + $this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri()); return true; } ) @@ -89,7 +89,7 @@ function (RequestInterface $requestMessage) { ); $this->assertEquals('PUT', $requestMessage->getMethod()); - $this->assertRegExp($expectedPathPattern, (string)$requestMessage->getUri()); + $this->assertMatchesRegularExpression($expectedPathPattern, (string)$requestMessage->getUri()); return true; } ) diff --git a/tests/TestCase.php b/tests/TestCase.php index 914e030..49626e3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -8,4 +8,21 @@ abstract class TestCase extends PHPUnitTestCase { + /** + * Override assertMatchesRegularExpression to support older versions of PHPUnit. + * + * @param string $pattern + * @param string $string + * @param string $message + * + * @return void + */ + public static function assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void + { + if (method_exists(parent::class, __FUNCTION__)) { + parent::{__FUNCTION__}(...\func_get_args()); + } else { + parent::assertRegExp(...\func_get_args()); + } + } } From bd4b161d9ef1831abc9b61d4d5426e4fd44af9df Mon Sep 17 00:00:00 2001 From: David Grayston Date: Tue, 28 Apr 2020 13:47:26 +0100 Subject: [PATCH 05/10] SDK-1412: Implement ExtraData --- .../Request/ExtraData/SandboxDataEntry.php | 39 ++++++++++ .../Request/ExtraData/SandboxExtraData.php | 31 ++++++++ .../ExtraData/SandboxExtraDataBuilder.php | 32 +++++++++ .../SandboxAttributeIssuanceDetails.php | 20 ++++++ ...SandboxAttributeIssuanceDetailsBuilder.php | 72 +++++++++++++++++++ .../SandboxAttributeIssuanceDetailsValue.php | 39 ++++++++++ .../ThirdParty/SandboxDefinition.php | 34 +++++++++ .../ThirdParty/SandboxIssuingAttributes.php | 44 ++++++++++++ src/Profile/Request/TokenRequest.php | 16 ++++- src/Profile/Request/TokenRequestBuilder.php | 19 ++++- .../ExtraData/SandboxDataEntryTest.php | 41 +++++++++++ .../ExtraData/SandboxExtraDataBuilderTest.php | 40 +++++++++++ ...boxAttributeIssuanceDetailsBuilderTest.php | 59 +++++++++++++++ ...ndboxAttributeIssuanceDetailsValueTest.php | 41 +++++++++++ .../ThirdParty/SandboxDefinitionTest.php | 34 +++++++++ .../SandboxIssuingAttributesTest.php | 47 ++++++++++++ .../Request/TokenRequestBuilderTest.php | 27 +++++-- 17 files changed, 624 insertions(+), 11 deletions(-) create mode 100644 src/Profile/Request/ExtraData/SandboxDataEntry.php create mode 100644 src/Profile/Request/ExtraData/SandboxExtraData.php create mode 100644 src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php create mode 100644 src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php create mode 100644 src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilder.php create mode 100644 src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php create mode 100644 src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php create mode 100644 src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php create mode 100644 tests/Profile/Request/ExtraData/SandboxDataEntryTest.php create mode 100644 tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php create mode 100644 tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php create mode 100644 tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php create mode 100644 tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php create mode 100644 tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php diff --git a/src/Profile/Request/ExtraData/SandboxDataEntry.php b/src/Profile/Request/ExtraData/SandboxDataEntry.php new file mode 100644 index 0000000..174c11d --- /dev/null +++ b/src/Profile/Request/ExtraData/SandboxDataEntry.php @@ -0,0 +1,39 @@ +type = $type; + $this->value = $value; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'type' => $this->type, + 'value' => $this->value, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/SandboxExtraData.php b/src/Profile/Request/ExtraData/SandboxExtraData.php new file mode 100644 index 0000000..e29057a --- /dev/null +++ b/src/Profile/Request/ExtraData/SandboxExtraData.php @@ -0,0 +1,31 @@ +dataEntries = $dataEntries; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'data_entry' => $this->dataEntries, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php b/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php new file mode 100644 index 0000000..ba2055b --- /dev/null +++ b/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php @@ -0,0 +1,32 @@ +dataEntries[] = $dataEntry; + return $this; + } + + /** + * @return SandboxExtraData + */ + public function build(): SandboxExtraData + { + return new SandboxExtraData($this->dataEntries); + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php new file mode 100644 index 0000000..da5ac5b --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetails.php @@ -0,0 +1,20 @@ +issuanceToken = $issuanceToken; + return $this; + } + + /** + * @param \DateTime $expiryDate + * + * @return $this + */ + public function withExpiryDate(\DateTime $expiryDate): self + { + $this->expiryDate = $expiryDate; + return $this; + } + + /** + * @param string $definition + * + * @return self + */ + public function withDefinition(string $definition): self + { + Validation::notEmptyString($definition, 'definition'); + $this->definitions[] = new SandboxDefinition($definition); + return $this; + } + + /** + * @return SandboxAttributeIssuanceDetails + */ + public function build(): SandboxAttributeIssuanceDetails + { + $value = new SandboxAttributeIssuanceDetailsValue( + $this->issuanceToken, + new SandboxIssuingAttributes($this->expiryDate, $this->definitions) + ); + return new SandboxAttributeIssuanceDetails($value); + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php new file mode 100644 index 0000000..01d1dcf --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValue.php @@ -0,0 +1,39 @@ +issuanceToken = $issuanceToken; + $this->issuingAttributes = $issuingAttributes; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'issuance_token' => $this->issuanceToken, + 'issuing_attributes' => $this->issuingAttributes, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php new file mode 100644 index 0000000..3304680 --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxDefinition.php @@ -0,0 +1,34 @@ +name = $name; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'name' => $this->name, + ]; + } +} diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php new file mode 100644 index 0000000..d6c0de4 --- /dev/null +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php @@ -0,0 +1,44 @@ +expiryDate = $expiryDate; + + Validation::isArrayOfType($definitions, [SandboxDefinition::class], 'definitions'); + $this->definitions = $definitions; + } + + /** + * @return \stdClass + */ + public function jsonSerialize(): \stdClass + { + return (object) [ + 'expiry_date' => $this->expiryDate->format(DateTime::RFC3339), + 'definitions' => $this->definitions, + ]; + } +} diff --git a/src/Profile/Request/TokenRequest.php b/src/Profile/Request/TokenRequest.php index 4d7c6c1..9c054bd 100644 --- a/src/Profile/Request/TokenRequest.php +++ b/src/Profile/Request/TokenRequest.php @@ -6,6 +6,8 @@ use Yoti\Http\Payload; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAttribute; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraData; +use Yoti\Util\Json; use Yoti\Util\Validation; class TokenRequest implements \JsonSerializable @@ -20,16 +22,23 @@ class TokenRequest implements \JsonSerializable */ private $sandboxAttributes; + /** + * @var SandboxExtraData|null + */ + private $extraData; + /** * @param string|null $rememberMeId * @param SandboxAttribute[] $sandboxAttributes */ - public function __construct(?string $rememberMeId, array $sandboxAttributes) + public function __construct(?string $rememberMeId, array $sandboxAttributes, ?SandboxExtraData $extraData = null) { $this->rememberMeId = $rememberMeId; Validation::isArrayOfType($sandboxAttributes, [ SandboxAttribute::class ], 'sandboxAttributes'); $this->sandboxAttributes = $sandboxAttributes; + + $this->extraData = $extraData; } /** @@ -37,10 +46,11 @@ public function __construct(?string $rememberMeId, array $sandboxAttributes) */ public function jsonSerialize(): array { - return [ + return Json::withoutNullValues([ 'remember_me_id' => $this->rememberMeId, 'profile_attributes' => $this->sandboxAttributes, - ]; + 'extra_data' => $this->extraData, + ]); } /** diff --git a/src/Profile/Request/TokenRequestBuilder.php b/src/Profile/Request/TokenRequestBuilder.php index ee19aab..3e6aaea 100644 --- a/src/Profile/Request/TokenRequestBuilder.php +++ b/src/Profile/Request/TokenRequestBuilder.php @@ -8,6 +8,7 @@ use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAttribute; use Yoti\Sandbox\Profile\Request\Attribute\SandboxDocumentDetails; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraData; class TokenRequestBuilder { @@ -21,6 +22,11 @@ class TokenRequestBuilder */ private $sandboxAttributes = []; + /** + * @var SandboxExtraData|null + */ + private $extraData; + /** * @param string $value */ @@ -263,6 +269,17 @@ public function addAttribute(SandboxAttribute $attribute): self return $this; } + /** + * @param SandboxExtraData $extraData + * + * @return self + */ + public function setExtraData(SandboxExtraData $extraData): self + { + $this->extraData = $extraData; + return $this; + } + /** * @param string $name * @param string $value @@ -314,6 +331,6 @@ private function getAnchors($anchors, array $args, string $method): array */ public function build(): TokenRequest { - return new TokenRequest($this->rememberMeId, $this->sandboxAttributes); + return new TokenRequest($this->rememberMeId, $this->sandboxAttributes, $this->extraData); } } diff --git a/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php b/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php new file mode 100644 index 0000000..b37ab72 --- /dev/null +++ b/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php @@ -0,0 +1,41 @@ +createMock(\JsonSerializable::class); + $valueMock->method('jsonSerialize')->willReturn('some-value'); + + $sandboxDataEntry = $this->getMockBuilder(SandboxDataEntry::class) + ->setConstructorArgs([self::SOME_TYPE, $valueMock]) + ->setMethodsExcept(['jsonSerialize']) + ->getMock(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'type' => self::SOME_TYPE, + 'value' => $valueMock, + ]), + json_encode($sandboxDataEntry), + ); + } +} diff --git a/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php b/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php new file mode 100644 index 0000000..23f2b3b --- /dev/null +++ b/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php @@ -0,0 +1,40 @@ +createMock(SandboxDataEntry::class); + $dataEntryMock->method('jsonSerialize')->willReturn((object) ['some' => 'data-entry']); + + $extraData = (new SandboxExtraDataBuilder()) + ->withDataEntry($dataEntryMock) + ->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'data_entry' => [$dataEntryMock] + ]), + json_encode($extraData), + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php new file mode 100644 index 0000000..004efb6 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php @@ -0,0 +1,59 @@ +withDefinition(self::SOME_DEFINITION) + ->withExpiryDate($someDateTime) + ->withIssuanceToken(self::SOME_TOKEN) + ->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'type' => self::TYPE_THIRD_PARTY_ATTRIBUTE, + 'value' => [ + 'issuance_token' => self::SOME_TOKEN, + 'issuing_attributes' => [ + 'expiry_date' => $someDateTime->format(DateTime::RFC3339), + 'definitions' => [ + [ + 'name' => self::SOME_DEFINITION, + ], + ], + ], + ], + ]), + json_encode($sandboxAttributeIssuanceDetails), + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php new file mode 100644 index 0000000..cbabcd1 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsValueTest.php @@ -0,0 +1,41 @@ +createMock(SandboxIssuingAttributes::class); + $issuingAttributesMock + ->method('jsonSerialize') + ->willReturn((object) ['some' => 'issuing-attributes']); + + $value = new SandboxAttributeIssuanceDetailsValue(self::SOME_TOKEN, $issuingAttributesMock); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'issuance_token' => self::SOME_TOKEN, + 'issuing_attributes' => $issuingAttributesMock, + ]), + json_encode($value) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php new file mode 100644 index 0000000..92e3203 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxDefinitionTest.php @@ -0,0 +1,34 @@ +assertJsonStringEqualsJsonString( + json_encode([ + 'name' => self::SOME_NAME, + ]), + json_encode($definition) + ); + } +} diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php new file mode 100644 index 0000000..c571b77 --- /dev/null +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php @@ -0,0 +1,47 @@ +createMock(SandboxDefinition::class); + $definitionMock + ->method('jsonSerialize') + ->willReturn((object) ['some' => 'definition']); + + $someDateTime = DateTime::stringToDateTime(self::SOME_DATE_STRING); + + $sandboxIssuingAttributes = new SandboxIssuingAttributes( + $someDateTime, + [$definitionMock] + ); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'expiry_date' => $someDateTime->format(DateTime::RFC3339), + 'definitions' => [$definitionMock], + ]), + json_encode($sandboxIssuingAttributes) + ); + } +} diff --git a/tests/Profile/Request/TokenRequestBuilderTest.php b/tests/Profile/Request/TokenRequestBuilderTest.php index b2c072e..2b6ec19 100644 --- a/tests/Profile/Request/TokenRequestBuilderTest.php +++ b/tests/Profile/Request/TokenRequestBuilderTest.php @@ -7,6 +7,7 @@ use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAnchor; use Yoti\Sandbox\Profile\Request\Attribute\SandboxDocumentDetails; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraData; use Yoti\Sandbox\Profile\Request\TokenRequest; use Yoti\Sandbox\Profile\Request\TokenRequestBuilder; use Yoti\Sandbox\Test\TestCase; @@ -91,7 +92,6 @@ public function testStringAttributeSetters($setterMethod, $name) $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -217,7 +217,6 @@ public function testStringAttributeSettersWithOptionalAndAnchor($setterMethod, $ $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -263,7 +262,6 @@ public function testSetDateOfBirth() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'date_of_birth', @@ -287,7 +285,6 @@ public function testSetSelfie() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'selfie', @@ -368,7 +365,6 @@ public function testSetDocumentDetails() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -452,7 +448,6 @@ public function testSetDocumentDetailsWithStringAndAnchors() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -512,10 +507,28 @@ public function testSetAgeVerification() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [$someAgeVerification] ]), json_encode($tokenRequest) ); } + + /** + * @covers ::setExtraData + */ + public function testSetExtraData() + { + $someExtraData = $this->createMock(SandboxExtraData::class); + $someExtraData->method('jsonSerialize')->willReturn((object) ['some' => 'extra-data']); + + $tokenRequest = $this->requestBuilder->setExtraData($someExtraData)->build(); + + $this->assertJsonStringEqualsJsonString( + json_encode([ + 'profile_attributes' => [], + 'extra_data' => $someExtraData, + ]), + json_encode($tokenRequest) + ); + } } From 618bbebfaf699c259dce42463bcaeef0a331d6aa Mon Sep 17 00:00:00 2001 From: David Grayston Date: Tue, 28 Apr 2020 13:58:05 +0100 Subject: [PATCH 06/10] SDK-1412: Add ExtraData example --- examples/profile/tests/ProfileTest.php | 24 +++++++++++++++++++ .../Request/ExtraData/SandboxExtraData.php | 3 +++ .../ExtraData/SandboxExtraDataBuilder.php | 2 +- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/examples/profile/tests/ProfileTest.php b/examples/profile/tests/ProfileTest.php index cd81741..3eea8fe 100644 --- a/examples/profile/tests/ProfileTest.php +++ b/examples/profile/tests/ProfileTest.php @@ -7,6 +7,8 @@ use PHPUnit\Framework\TestCase as PHPUnitTestCase; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAgeVerification; use Yoti\Sandbox\Profile\Request\Attribute\SandboxAnchor; +use Yoti\Sandbox\Profile\Request\ExtraData\SandboxExtraDataBuilder; +use Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty\SandboxAttributeIssuanceDetailsBuilder; use Yoti\Sandbox\Profile\Request\TokenRequestBuilder; use Yoti\Sandbox\Profile\SandboxClient; use Yoti\YotiClient; @@ -54,6 +56,16 @@ public function shouldReturnUserProfile() new \DateTime('1980-01-01') ); + $extraData = (new SandboxExtraDataBuilder()) + ->withDataEntry( + (new SandboxAttributeIssuanceDetailsBuilder()) + ->withDefinition('some-definition') + ->withExpiryDate(new \DateTime('2020-01-01T00:00:00Z')) + ->withIssuanceToken('some-token') + ->build() + ) + ->build(); + $tokenRequest = (new TokenRequestBuilder()) ->setRememberMeId('Some Remember Me ID') ->setGivenNames('Some Given Names', $anchors) @@ -71,6 +83,7 @@ public function shouldReturnUserProfile() 'building_number' => 1, 'address_line1' => 'Some Address', ])) + ->setExtraData($extraData) ->build(); $token = $this->sandboxClient->setupSharingProfile($tokenRequest); @@ -104,5 +117,16 @@ public function shouldReturnUserProfile() $this->assertEquals('PASSPORT', $profile->getGivenNames()->getSources()[0]->getValue()); $this->assertEquals('YOTI_ADMIN', $profile->getGivenNames()->getVerifiers()[0]->getValue()); + + $attributeIssuanceDetails = $activityDetails->getExtraData()->getAttributeIssuanceDetails(); + $this->assertEquals(base64_encode('some-token'), $attributeIssuanceDetails->getToken()); + $this->assertEquals( + '2020-01-01T00:00:00+00:00', + $attributeIssuanceDetails->getExpiryDate()->format(DATE_RFC3339) + ); + $this->assertEquals( + 'some-definition', + $attributeIssuanceDetails->getIssuingAttributes()[0]->getName() + ); } } diff --git a/src/Profile/Request/ExtraData/SandboxExtraData.php b/src/Profile/Request/ExtraData/SandboxExtraData.php index e29057a..ed4b08c 100644 --- a/src/Profile/Request/ExtraData/SandboxExtraData.php +++ b/src/Profile/Request/ExtraData/SandboxExtraData.php @@ -4,6 +4,8 @@ namespace Yoti\Sandbox\Profile\Request\ExtraData; +use Yoti\Util\Validation; + class SandboxExtraData implements \JsonSerializable { /** @@ -16,6 +18,7 @@ class SandboxExtraData implements \JsonSerializable */ public function __construct(array $dataEntries) { + Validation::isArrayOfType($dataEntries, [SandboxDataEntry::class], 'dataEntries'); $this->dataEntries = $dataEntries; } diff --git a/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php b/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php index ba2055b..8b7f55f 100644 --- a/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php +++ b/src/Profile/Request/ExtraData/SandboxExtraDataBuilder.php @@ -16,7 +16,7 @@ class SandboxExtraDataBuilder * * @return $this */ - public function withDataEntry($dataEntry): self + public function withDataEntry(SandboxDataEntry $dataEntry): self { $this->dataEntries[] = $dataEntry; return $this; From ad44c11fb47d99b087b0fda23d9e4d64dcd808b7 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Tue, 28 Apr 2020 14:10:39 +0100 Subject: [PATCH 07/10] SDK-1412: Fix unit tests for older PHP versions --- tests/Profile/Request/ExtraData/SandboxDataEntryTest.php | 2 +- tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php | 2 +- .../ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php b/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php index b37ab72..461a384 100644 --- a/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php +++ b/tests/Profile/Request/ExtraData/SandboxDataEntryTest.php @@ -35,7 +35,7 @@ public function shouldSerializeToJson() 'type' => self::SOME_TYPE, 'value' => $valueMock, ]), - json_encode($sandboxDataEntry), + json_encode($sandboxDataEntry) ); } } diff --git a/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php b/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php index 23f2b3b..39050f6 100644 --- a/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php +++ b/tests/Profile/Request/ExtraData/SandboxExtraDataBuilderTest.php @@ -34,7 +34,7 @@ public function shouldBuildSandboxExtraData() json_encode([ 'data_entry' => [$dataEntryMock] ]), - json_encode($extraData), + json_encode($extraData) ); } } diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php index 004efb6..a769a66 100644 --- a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php @@ -53,7 +53,7 @@ public function shouldBuildSandboxAttributeIssuanceDetails() ], ], ]), - json_encode($sandboxAttributeIssuanceDetails), + json_encode($sandboxAttributeIssuanceDetails) ); } } From 2884925c49693658fcc15d61ad04aaef9e4f8775 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Thu, 30 Apr 2020 19:30:09 +0100 Subject: [PATCH 08/10] SDK-1412: Use future date in example --- examples/profile/tests/ProfileTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/profile/tests/ProfileTest.php b/examples/profile/tests/ProfileTest.php index 3eea8fe..d675010 100644 --- a/examples/profile/tests/ProfileTest.php +++ b/examples/profile/tests/ProfileTest.php @@ -56,11 +56,12 @@ public function shouldReturnUserProfile() new \DateTime('1980-01-01') ); + $expiryDate = new \DateTime('+1 day'); $extraData = (new SandboxExtraDataBuilder()) ->withDataEntry( (new SandboxAttributeIssuanceDetailsBuilder()) ->withDefinition('some-definition') - ->withExpiryDate(new \DateTime('2020-01-01T00:00:00Z')) + ->withExpiryDate($expiryDate) ->withIssuanceToken('some-token') ->build() ) @@ -121,7 +122,7 @@ public function shouldReturnUserProfile() $attributeIssuanceDetails = $activityDetails->getExtraData()->getAttributeIssuanceDetails(); $this->assertEquals(base64_encode('some-token'), $attributeIssuanceDetails->getToken()); $this->assertEquals( - '2020-01-01T00:00:00+00:00', + $expiryDate->format(DATE_RFC3339), $attributeIssuanceDetails->getExpiryDate()->format(DATE_RFC3339) ); $this->assertEquals( From e1fc8efc3a1dac5c6e7ee9cc2df5424735b32924 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 1 May 2020 18:26:12 +0100 Subject: [PATCH 09/10] SDK-1412: Remove null Remember Me ID from tests --- tests/Profile/Request/TokenRequestBuilderTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Profile/Request/TokenRequestBuilderTest.php b/tests/Profile/Request/TokenRequestBuilderTest.php index 2b6ec19..d508eca 100644 --- a/tests/Profile/Request/TokenRequestBuilderTest.php +++ b/tests/Profile/Request/TokenRequestBuilderTest.php @@ -135,7 +135,6 @@ public function testStringAttributeSettersWithOptional($setterMethod, $name) $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -173,7 +172,6 @@ public function testStringAttributeSettersWithAnchor($setterMethod, $name) $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => $name, @@ -308,7 +306,6 @@ public function testSetSelfieWithAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'selfie', @@ -338,7 +335,6 @@ public function testSetSelfieWithOptionalAndAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'selfie', @@ -391,7 +387,6 @@ public function testSetDocumentDetailsWithAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -424,7 +419,6 @@ public function testSetDocumentDetailsWithOptionalAndAnchor() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', @@ -477,7 +471,6 @@ public function testSetDocumentDetailsWithStringAndOptionalAndAnchors() $this->assertJsonStringEqualsJsonString( json_encode([ - 'remember_me_id' => null, 'profile_attributes' => [ [ 'name' => 'document_details', From 1e0d7c8bceef105ff2f3cae67ac115d808c180b5 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Fri, 29 May 2020 16:10:06 +0100 Subject: [PATCH 10/10] SDK-1412: Format expiry date with milliseconds --- .../ThirdParty/SandboxIssuingAttributes.php | 5 +++-- ...boxAttributeIssuanceDetailsBuilderTest.php | 2 +- .../SandboxIssuingAttributesTest.php | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php b/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php index d6c0de4..89bac90 100644 --- a/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php +++ b/src/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributes.php @@ -4,7 +4,6 @@ namespace Yoti\Sandbox\Profile\Request\ExtraData\ThirdParty; -use Yoti\Util\DateTime; use Yoti\Util\Validation; class SandboxIssuingAttributes implements \JsonSerializable @@ -37,7 +36,9 @@ public function __construct(\DateTime $expiryDate, array $definitions) public function jsonSerialize(): \stdClass { return (object) [ - 'expiry_date' => $this->expiryDate->format(DateTime::RFC3339), + 'expiry_date' => $this->expiryDate + ->setTimezone(new \DateTimeZone('UTC')) + ->format(\DateTime::RFC3339_EXTENDED), 'definitions' => $this->definitions, ]; } diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php index a769a66..0b5bde7 100644 --- a/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxAttributeIssuanceDetailsBuilderTest.php @@ -44,7 +44,7 @@ public function shouldBuildSandboxAttributeIssuanceDetails() 'value' => [ 'issuance_token' => self::SOME_TOKEN, 'issuing_attributes' => [ - 'expiry_date' => $someDateTime->format(DateTime::RFC3339), + 'expiry_date' => $someDateTime->format(\DateTime::RFC3339_EXTENDED), 'definitions' => [ [ 'name' => self::SOME_DEFINITION, diff --git a/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php b/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php index c571b77..65f8c9f 100644 --- a/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php +++ b/tests/Profile/Request/ExtraData/ThirdParty/SandboxIssuingAttributesTest.php @@ -14,22 +14,22 @@ */ class SandboxIssuingAttributesTest extends TestCase { - private const SOME_DATE_STRING = '2020-01-02T01:02:03.123456Z'; - /** * @test * * @covers ::__construct * @covers ::jsonSerialize + * + * @dataProvider expiryDateDataProvider */ - public function shouldSerializeToJson() + public function shouldSerializeToJson($inputDate, $outputDate) { $definitionMock = $this->createMock(SandboxDefinition::class); $definitionMock ->method('jsonSerialize') ->willReturn((object) ['some' => 'definition']); - $someDateTime = DateTime::stringToDateTime(self::SOME_DATE_STRING); + $someDateTime = DateTime::stringToDateTime($inputDate); $sandboxIssuingAttributes = new SandboxIssuingAttributes( $someDateTime, @@ -38,10 +38,22 @@ public function shouldSerializeToJson() $this->assertJsonStringEqualsJsonString( json_encode([ - 'expiry_date' => $someDateTime->format(DateTime::RFC3339), + 'expiry_date' => $outputDate, 'definitions' => [$definitionMock], ]), json_encode($sandboxIssuingAttributes) ); } + + /** + * Provides test expiry dates. + */ + public function expiryDateDataProvider() + { + return [ + ['2020-01-02T01:02:03.123456Z', '2020-01-02T01:02:03.123+00:00'], + ['2020-01-01T01:02:03.123+04:00', '2019-12-31T21:02:03.123+00:00'], + ['2020-01-02T01:02:03.123-02:00', '2020-01-02T03:02:03.123+00:00'] + ]; + } }