/**
  * @test
  * @group Entity
  * @group Value
  */
 public function the_same_entity_types_are_considered_equal()
 {
     $base = EntityType::SP();
     $theSame = EntityType::SP();
     $different = EntityType::IdP();
     $this->assertTrue($base->equals($theSame));
     $this->assertFalse($base->equals($different));
 }
 /**
  * @test
  * @group Consent
  */
 public function it_can_create_a_consent_list()
 {
     $firstEntityId = 'http://profile.vm.openconext.invalid/authentication/metadata';
     $secondEntityId = 'https://serviceregistry.vm.openconext.invalid/simplesaml/module.php/saml/sp/metadata.php/default-sp';
     $firstEula = 'https://domain.invalid';
     $secondSupportEmail = '*****@*****.**';
     $givenFirstConsentTypeValue = 'explicit';
     $expectedFirstConsentType = ConsentType::explicit();
     $givenSecondConsentTypeValue = 'implicit';
     $expectedSecondConsentType = ConsentType::implicit();
     $given = [['service_provider' => ['entity_id' => $firstEntityId, 'display_name' => ['en' => '', 'nl' => ''], 'eula_url' => $firstEula, 'support_email' => null], 'consent_given_on' => '2015-11-05T08:43:01+01:00', 'last_used_on' => '2015-11-05T08:43:01+01:00', 'consent_type' => $givenFirstConsentTypeValue], ['service_provider' => ['entity_id' => $secondEntityId, 'display_name' => ['en' => 'OpenConext ServiceRegistry', 'nl' => 'OpenConext ServiceRegistry'], 'eula_url' => null, 'support_email' => $secondSupportEmail], 'consent_given_on' => '2015-11-05T08:17:04+01:00', 'last_used_on' => '2015-11-05T08:17:04+01:00', 'consent_type' => $givenSecondConsentTypeValue]];
     $expectedConsentList = new ConsentList([new Consent(new ServiceProvider(new Entity(new EntityId($firstEntityId), EntityType::SP()), new DisplayName(['nl' => '', 'en' => '']), new Url($firstEula), null), new DateTimeImmutable('2015-11-05T08:43:01+01:00'), new DateTimeImmutable('2015-11-05T08:43:01+01:00'), $expectedFirstConsentType), new Consent(new ServiceProvider(new Entity(new EntityId($secondEntityId), EntityType::SP()), new DisplayName(['nl' => 'OpenConext ServiceRegistry', 'en' => 'OpenConext ServiceRegistry']), null, new ContactEmailAddress($secondSupportEmail)), new DateTimeImmutable('2015-11-05T08:17:04+01:00'), new DateTimeImmutable('2015-11-05T08:17:04+01:00'), $expectedSecondConsentType)]);
     $this->assertEquals($expectedConsentList, ConsentListFactory::createListFromMetadata($given));
 }
 /**
  * @test
  * @group Entity
  * @group Value
  */
 public function two_entities_with_the_same_entity_id_and_entity_type_are_equal()
 {
     $entityIdOne = new EntityId('one');
     $entityIdTwo = new EntityId('two');
     $sp = EntityType::SP();
     $idp = EntityType::IdP();
     $base = new Entity($entityIdOne, $sp);
     $theSame = new Entity($entityIdOne, $sp);
     $differentType = new Entity($entityIdOne, $idp);
     $differentId = new Entity($entityIdTwo, $sp);
     $differentIdAndType = new Entity($entityIdTwo, $idp);
     $this->assertTrue($base->equals($theSame));
     $this->assertFalse($base->equals($differentType));
     $this->assertFalse($base->equals($differentId));
     $this->assertFalse($base->equals($differentIdAndType));
 }
 /**
  * @param mixed $data
  * @return ServiceProvider
  */
 private static function createServiceProvider($data)
 {
     Assert::keyExists($data, 'entity_id', 'Consent JSON structure must contain key "entity_id"');
     Assert::keyExists($data, 'display_name', 'Consent JSON structure must contain key "display_name"');
     Assert::keyExists($data, 'eula_url', 'Consent JSON structure must contain key "eula_url"');
     Assert::keyExists($data, 'support_email', 'Consent JSON structure must contain key "support_email"');
     $entity = new Entity(new EntityId($data['entity_id']), EntityType::SP());
     $displayName = new DisplayName($data['display_name']);
     $eulaUrl = null;
     $supportEmail = null;
     if ($data['eula_url'] !== null) {
         $eulaUrl = new Url($data['eula_url']);
     }
     if ($data['support_email'] !== null) {
         $supportEmail = new ContactEmailAddress($data['support_email']);
     }
     return new ServiceProvider($entity, $displayName, $eulaUrl, $supportEmail);
 }
 /**
  * @test
  * @group AttributeReleasePolicy
  */
 public function consent_list_and_attributes_are_correctly_converted_to_a_request_and_the_response_is_mapped_correctly_to_a_result()
 {
     $someAttributeDefinition = new AttributeDefinition('someAttribute', 'urn:mace:some-attribute', 'urn:oid:0.0.0.0.0.1');
     $anotherAttributeDefinition = new AttributeDefinition('anotherAttribute', null, 'urn:oid:0.0.0.0.0.2');
     $attributeDictionary = new AttributeDictionary();
     $attributeDictionary->addAttributeDefinition($someAttributeDefinition);
     $attributeDictionary->addAttributeDefinition($anotherAttributeDefinition);
     $client = Mockery::mock(JsonApiClient::class);
     $arpService = new AttributeReleasePolicyService($client, $attributeDictionary);
     $client->shouldReceive('post')->withArgs([['entityIds' => ['some-entity-id', 'another-entity-id'], 'attributes' => ['urn:mace:some-attribute' => ['some-value'], 'urn:oid:0.0.0.0.0.1' => ['some-value'], 'urn:oid:0.0.0.0.0.2' => ['another-value']]], '/arp'])->andReturn(['some-entity-id' => ['urn:mace:some-attribute' => ['some-value'], 'urn:oid:0.0.0.0.0.1' => ['some-value'], 'urn:oid:0.0.0.0.0.2' => ['another-value']], 'another-entity-id' => ['urn:oid:0.0.0.0.0.2' => ['another-value']]]);
     $someConsent = new Consent(new ServiceProvider(new Entity(new EntityId('some-entity-id'), EntityType::SP()), new DisplayName(['en' => 'Some display name']), new Url('http://some-eula-url.example'), new ContactEmailAddress('*****@*****.**')), new DateTimeImmutable(), new DateTimeImmutable(), ConsentType::explicit());
     $anotherConsent = new Consent(new ServiceProvider(new Entity(new EntityId('another-entity-id'), EntityType::SP()), new DisplayName(['en' => 'Another display name']), new Url('http://another-eula-url.example'), new ContactEmailAddress('*****@*****.**')), new DateTimeImmutable(), new DateTimeImmutable(), ConsentType::explicit());
     $consentList = new ConsentList([$someConsent, $anotherConsent]);
     $someAttribute = new Attribute($someAttributeDefinition, ['some-value']);
     $anotherAttribute = new Attribute($anotherAttributeDefinition, ['another-value']);
     $attributeSet = AttributeSet::create([$someAttribute, $anotherAttribute]);
     $expectedResult = SpecifiedConsentList::createWith([SpecifiedConsent::specifies($someConsent, AttributeSetWithFallbacks::create([$someAttribute, $anotherAttribute])), SpecifiedConsent::specifies($anotherConsent, AttributeSetWithFallbacks::create([$anotherAttribute]))]);
     $result = $arpService->applyAttributeReleasePolicies($consentList, $attributeSet);
     $this->assertEquals($expectedResult, $result);
 }
Example #6
0
 /**
  * @param Entity $other
  * @return bool
  */
 public function equals(Entity $other)
 {
     return $this->entityId->equals($other->entityId) && $this->entityType->equals($other->entityType);
 }