-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Yoti\Test\Identity\Content; | ||
|
||
use Yoti\Identity\Content\ApplicationContent; | ||
use Yoti\Profile\ApplicationProfile; | ||
use Yoti\Profile\ExtraData; | ||
use Yoti\Test\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Yoti\Identity\Content\ApplicationContent | ||
*/ | ||
class ApplicationContentTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::getExtraData | ||
* @covers ::getProfile | ||
* @covers ::__construct | ||
*/ | ||
public function testBuildCorrectly() | ||
{ | ||
$applicationProfile = $this->createMock(ApplicationProfile::class); | ||
$extraData = $this->createMock(ExtraData::class); | ||
|
||
$applicationContent = new ApplicationContent($applicationProfile, $extraData); | ||
|
||
$this->assertInstanceOf(ApplicationProfile::class, $applicationContent->getProfile()); | ||
$this->assertInstanceOf(ExtraData::class, $applicationContent->getExtraData()); | ||
|
||
$applicationContent2 = new ApplicationContent(); | ||
|
||
$this->assertNull($applicationContent2->getProfile()); | ||
$this->assertNull($applicationContent2->getExtraData()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Yoti\Test\Identity\Content; | ||
|
||
use Yoti\Exception\EncryptedDataException; | ||
use Yoti\Identity\Content\Content; | ||
use Yoti\Test\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Yoti\Identity\Content\Content | ||
*/ | ||
class ContentTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::getExtraData | ||
* @covers ::getProfile | ||
* @covers ::__construct | ||
*/ | ||
public function testBuildCorrectly() | ||
{ | ||
$someString = 'SOME_STRING_11111'; | ||
$someString2 = 'f439fh9347h43uhfo34uhf'; | ||
|
||
$content = new Content(base64_encode($someString), base64_encode($someString2)); | ||
|
||
$this->assertEquals($someString, $content->getProfile()); | ||
$this->assertEquals($someString2, $content->getExtraData()); | ||
|
||
$content = new Content($someString, $someString2); | ||
|
||
$this->expectException(EncryptedDataException::class); | ||
|
||
$content->getProfile(); | ||
$content->getExtraData(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Yoti\Test\Identity\Content; | ||
|
||
use Yoti\Identity\Content\UserContent; | ||
use Yoti\Profile\ExtraData; | ||
use Yoti\Profile\UserProfile; | ||
use Yoti\Test\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Yoti\Identity\Content\UserContent | ||
*/ | ||
class UserContentTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::getExtraData | ||
* @covers ::getProfile | ||
* @covers ::__construct | ||
*/ | ||
public function testBuildCorrectly() | ||
{ | ||
$userProfile = $this->createMock(UserProfile::class); | ||
$extraData = $this->createMock(ExtraData::class); | ||
|
||
$userContent = new UserContent($userProfile, $extraData); | ||
|
||
$this->assertInstanceOf(UserProfile::class, $userContent->getProfile()); | ||
$this->assertInstanceOf(ExtraData::class, $userContent->getExtraData()); | ||
|
||
$userContent2 = new UserContent(); | ||
|
||
$this->assertNull($userContent2->getProfile()); | ||
$this->assertNull($userContent2->getExtraData()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Yoti\Test\Identity; | ||
|
||
use Yoti\Exception\EncryptedDataException; | ||
use Yoti\Identity\ReceiptItemKey; | ||
use Yoti\Test\TestCase; | ||
use Yoti\Test\TestData; | ||
|
||
/** | ||
* @coversDefaultClass \Yoti\Identity\ReceiptItemKey | ||
*/ | ||
class ReceiptItemKeyTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::getId | ||
* @covers ::getIv | ||
* @covers ::getValue | ||
* @covers ::setIv | ||
* @covers ::__construct | ||
*/ | ||
public function testShouldBuildCorrectly() | ||
{ | ||
$someId = 'SOME_ID'; | ||
$someIv = TestData::YOTI_CONNECT_TOKEN_DECRYPTED; | ||
$someValue = 'weofmwrfmwrkfmwepkfmwprekmf'; | ||
|
||
$sessionData = [ | ||
'id' => $someId, | ||
'iv' => $someIv, | ||
'value' => base64_encode($someValue) | ||
]; | ||
|
||
$this->expectException(EncryptedDataException::class); | ||
|
||
$receiptItemKey = new ReceiptItemKey($sessionData); | ||
|
||
$this->assertEquals($someId, $receiptItemKey->getId()); | ||
$this->assertEquals($someValue, $receiptItemKey->getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Yoti\Test\Identity; | ||
|
||
use Yoti\Identity\Content\ApplicationContent; | ||
use Yoti\Identity\Content\UserContent; | ||
use Yoti\Identity\Receipt; | ||
use Yoti\Identity\ReceiptBuilder; | ||
use Yoti\Profile\ApplicationProfile; | ||
use Yoti\Profile\UserProfile; | ||
use Yoti\Test\TestCase; | ||
|
||
/** | ||
* @coversDefaultClass \Yoti\Identity\Receipt | ||
*/ | ||
class ReceiptTest extends TestCase | ||
{ | ||
/** | ||
* @covers ::getExtraData | ||
* @covers ::getProfile | ||
* @covers ::getId | ||
* @covers ::getError | ||
* @covers ::getApplicationContent | ||
* @covers ::getTimestamp | ||
* @covers ::getParentRememberMeId | ||
* @covers ::getRememberMeId | ||
* @covers ::getSessionId | ||
* @covers ::getUserContent | ||
* @covers ::__construct | ||
*/ | ||
public function testShouldBuildCorrectly() | ||
{ | ||
$someId = 'SOME_ID'; | ||
$sessionId = 'SESSION_ID'; | ||
$someTime = new \DateTime('2021-08-11 13:11:17'); | ||
$applicationContent = $this->createMock(ApplicationContent::class); | ||
$userContent = $this->createMock(UserContent::class); | ||
$rememberId = 'SOME_REMEMBER_ID'; | ||
$parentRememberId = 'SOME_PARENT_REMEMBER_ID'; | ||
$someError = 'SOME_ERROR'; | ||
|
||
$receipt = new Receipt( | ||
$someId, | ||
$sessionId, | ||
$someTime, | ||
$applicationContent, | ||
$userContent, | ||
$rememberId, | ||
$parentRememberId, | ||
$someError | ||
); | ||
|
||
$this->assertEquals($someId, $receipt->getId()); | ||
$this->assertEquals($sessionId, $receipt->getSessionId()); | ||
$this->assertEquals($someTime, $receipt->getTimestamp()); | ||
$this->assertEquals($applicationContent, $receipt->getApplicationContent()); | ||
$this->assertEquals($userContent, $receipt->getUserContent()); | ||
$this->assertEquals($rememberId, $receipt->getRememberMeId()); | ||
$this->assertEquals($parentRememberId, $receipt->getParentRememberMeId()); | ||
$this->assertEquals($someError, $receipt->getError()); | ||
} | ||
|
||
/** | ||
* @covers \Yoti\Identity\ReceiptBuilder::withError | ||
* @covers \Yoti\Identity\ReceiptBuilder::withApplicationContent | ||
* @covers \Yoti\Identity\ReceiptBuilder::withId | ||
* @covers \Yoti\Identity\ReceiptBuilder::withTimestamp | ||
* @covers \Yoti\Identity\ReceiptBuilder::withSessionId | ||
* @covers \Yoti\Identity\ReceiptBuilder::withParentRememberMeId | ||
* @covers \Yoti\Identity\ReceiptBuilder::withRememberMeId | ||
* @covers \Yoti\Identity\ReceiptBuilder::withUserContent | ||
* @covers \Yoti\Identity\ReceiptBuilder::build | ||
*/ | ||
public function testShouldBuildCorrectlyThroughBuilder() | ||
{ | ||
$someId = 'SOME_ID'; | ||
$sessionId = 'SESSION_ID'; | ||
$someTime = new \DateTime('2021-08-11 13:11:17'); | ||
$userProfile = $this->createMock(UserProfile::class); | ||
$applicationProfile = $this->createMock(ApplicationProfile::class); | ||
$rememberId = 'SOME_REMEMBER_ID'; | ||
$parentRememberId = 'SOME_PARENT_REMEMBER_ID'; | ||
$someError = 'SOME_ERROR'; | ||
|
||
$receipt = (new ReceiptBuilder()) | ||
->withId($someId) | ||
->withSessionId($sessionId) | ||
->withTimestamp($someTime) | ||
->withUserContent($userProfile) | ||
->withApplicationContent($applicationProfile) | ||
->withRememberMeId($rememberId) | ||
->withParentRememberMeId($parentRememberId) | ||
->withError($someError) | ||
->build(); | ||
|
||
|
||
$this->assertEquals($someId, $receipt->getId()); | ||
$this->assertEquals($sessionId, $receipt->getSessionId()); | ||
$this->assertEquals($someTime, $receipt->getTimestamp()); | ||
$this->assertInstanceOf(ApplicationContent::class, $receipt->getApplicationContent()); | ||
$this->assertInstanceOf(UserContent::class, $receipt->getUserContent()); | ||
$this->assertEquals($rememberId, $receipt->getRememberMeId()); | ||
$this->assertEquals($parentRememberId, $receipt->getParentRememberMeId()); | ||
$this->assertEquals($someError, $receipt->getError()); | ||
} | ||
} |