Skip to content

Commit

Permalink
SDK-2420 Added test and updated tests for Advanced Identity Profile S…
Browse files Browse the repository at this point in the history
…hare V2
  • Loading branch information
mehmet-yoti committed Jul 2, 2024
1 parent 272c8cc commit 374f730
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,30 @@ class AdvancedIdentityController extends BaseController
public function generateSession(DigitalIdentityClient $client)
{
try {
$advancedIdentityProfileJson = '
{
"profiles": [
{
"trust_framework": "YOTI_GLOBAL",
"schemes": [
{
"label": "identity-AL-L1",
"type": "IDENTITY",
"objective": "AL_L1"
},
{
"label": "identity-AL-M1",
"type": "IDENTITY",
"objective": "AL_M1"
}
$advancedIdentityProfileJson =
(object)[
"profiles" => [(object)[

"trust_framework" => "YOTI_GLOBAL",
"schemes" => [(object)[

"label" => "identity-AL-L1",
"type" => "IDENTITY",
"objective"=> "AL_L1"
],
[
"label" => "identity-AL-M1",
"type" => "IDENTITY",
"objective" => "AL_M1"
]
]
}
]
]
]
}';
;

$policy = (new PolicyBuilder())
->withAdvancedIdentityProfileRequirements($advancedIdentityProfileJson)
->withAdvancedIdentityProfileRequirements((object)$advancedIdentityProfileJson)
->build();

$redirectUri = 'https://host/redirect/';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
alt="Yoti"/>
</a>
</div>
<h1 class="yoti-top-header">Digital Identity(Advanced)4 Share Example</h1>
<h1 class="yoti-top-header">Digital Identity(Advanced) Share Example</h1>

<div class="yoti-sdk-integration-section">
<div id="webshare-target"></div>
Expand Down
21 changes: 20 additions & 1 deletion src/Identity/Policy/Policy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,26 @@ class Policy implements \JsonSerializable
*/
private $identityProfileRequirements;

/**
* @var object|null
*/
private $advancedIdentityProfileRequirements;

/**
* @param WantedAttribute[] $wantedAttributes
* Array of attributes to be requested.
* @param int[] $wantedAuthTypes
* Auth types represents the authentication type to be used.
* @param object $identityProfileRequirements
* @param object $advancedidentityProfileRequirements
*/
public function __construct(
array $wantedAttributes,
array $wantedAuthTypes,
bool $wantedRememberMe = false,
bool $wantedRememberMeOptional = false,
$identityProfileRequirements = null
$identityProfileRequirements = null,
$advancedIdentityProfileRequirements = null
) {
Validation::isArrayOfType($wantedAttributes, [WantedAttribute::class], 'wantedAttributes');
$this->wantedAttributes = $wantedAttributes;
Expand All @@ -49,6 +56,7 @@ public function __construct(
$this->wantedRememberMe = $wantedRememberMe;
$this->wantedRememberMeOptional = $wantedRememberMeOptional;
$this->identityProfileRequirements = $identityProfileRequirements;
$this->advancedIdentityProfileRequirements = $advancedIdentityProfileRequirements;
}


Expand All @@ -60,6 +68,7 @@ public function jsonSerialize(): stdClass
'wanted_remember_me' => $this->wantedRememberMe,
'wanted_remember_me_optional' => $this->wantedRememberMeOptional,
'identity_profile_requirements' => $this->identityProfileRequirements,
'advanced_identity_profile_requirements' => $this->advancedIdentityProfileRequirements,
];
}

Expand All @@ -72,4 +81,14 @@ public function getIdentityProfileRequirements()
{
return $this->identityProfileRequirements;
}

/**
* AdvancedIdentityProfileRequirements requested in the policy
*
* @return object|null
*/
public function getAdvancedIdentityProfileRequirements()
{
return $this->advancedIdentityProfileRequirements;
}
}
5 changes: 2 additions & 3 deletions src/Identity/Policy/PolicyBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,16 +331,15 @@ public function withAdvancedIdentityProfileRequirements($advancedIdentityProfile
return $this;
}



public function build(): Policy
{
return new Policy(
array_values($this->wantedAttributes),
array_values($this->wantedAuthTypes),
$this->wantedRememberMe,
$this->wantedRememberMeOptional,
$this->identityProfileRequirements
$this->identityProfileRequirements,
$this->advancedIdentityProfileRequirements
);
}
}
76 changes: 72 additions & 4 deletions tests/Identity/Policy/PolicyBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function testBuildWithAttributes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand Down Expand Up @@ -124,6 +125,7 @@ public function testWithWantedAttributeByNameWithConstraints()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertJsonStringEqualsJsonString(
Expand Down Expand Up @@ -151,6 +153,7 @@ public function testWithDuplicateAttribute()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand Down Expand Up @@ -205,6 +208,7 @@ public function testWithWantedAttributeByName()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand Down Expand Up @@ -238,6 +242,7 @@ public function testWithAttributeObjects()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand Down Expand Up @@ -269,6 +274,7 @@ public function testWithAgeDerivedAttributes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand Down Expand Up @@ -314,6 +320,7 @@ public function testWithAgeDerivedAttributesWithConstraints()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertJsonStringEqualsJsonString(
Expand Down Expand Up @@ -343,6 +350,7 @@ public function testWithDuplicateAgeDerivedAttributes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -367,6 +375,7 @@ public function testWithAuthTypes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -390,7 +399,8 @@ public function testWithAuthTypesTrue()
'wanted_auth_types' => [self::SELFIE_AUTH_TYPE, self::PIN_AUTH_TYPE, 99],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -415,6 +425,7 @@ public function testWithAuthTypesFalse()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -439,6 +450,7 @@ public function testWithAuthEnabledThenDisabled()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -461,6 +473,7 @@ public function testWithSameAuthTypeAddedOnlyOnce()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -482,6 +495,7 @@ public function testWithOnlyTwoAuthTypes()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -503,6 +517,7 @@ public function testWithNoSelfieAuthAfterRemoval()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -524,6 +539,7 @@ public function testWithNoPinAuthAfterRemoval()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -545,6 +561,7 @@ public function testWithRememberMe()
'wanted_remember_me' => true,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -564,7 +581,8 @@ public function testWithoutRememberMe()
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -585,6 +603,7 @@ public function testWithRememberMeOptional()
'wanted_remember_me' => false,
'wanted_remember_me_optional' => true,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -604,7 +623,8 @@ public function testWithoutRememberMeOptional()
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => null
];

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
Expand All @@ -631,7 +651,8 @@ public function testWithIdentityProfileRequirements()
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => $identityProfileSample
'identity_profile_requirements' => $identityProfileSample,
'advanced_identity_profile_requirements' => null
];

$policy = (new PolicyBuilder())
Expand All @@ -641,4 +662,51 @@ public function testWithIdentityProfileRequirements()
$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
$this->assertEquals($identityProfileSample, $policy->getIdentityProfileRequirements());
}

/**
* @covers ::withAdvancedIdentityProfileRequirements
* @covers \Yoti\Identity\Policy\Policy::__construct
* @covers \Yoti\Identity\Policy\Policy::getAdvancedIdentityProfileRequirements
* @covers \Yoti\Identity\Policy\Policy::jsonSerialize
*/
public function testWithAdvancedIdentityProfileRequirements()
{
$advancedIdentityProfileSample =
(object)[
"profiles" => [(object)[

"trust_framework" => "YOTI_GLOBAL",
"schemes" => [(object)[

"label" => "identity-AL-L1",
"type" => "IDENTITY",
"objective"=> "AL_L1"
],
[
"label" => "identity-AL-M1",
"type" => "IDENTITY",
"objective" => "AL_M1"
]
]
]
]
]
;

$expectedWantedAttributeData = [
'wanted' => [],
'wanted_auth_types' => [],
'wanted_remember_me' => false,
'wanted_remember_me_optional' => false,
'identity_profile_requirements' => null,
'advanced_identity_profile_requirements' => $advancedIdentityProfileSample
];

$policy = (new PolicyBuilder())
->withAdvancedIdentityProfileRequirements($advancedIdentityProfileSample)
->build();

$this->assertEquals(json_encode($expectedWantedAttributeData), json_encode($policy));
$this->assertEquals($advancedIdentityProfileSample, $policy->getAdvancedIdentityProfileRequirements());
}
}

0 comments on commit 374f730

Please sign in to comment.