/** * @test * @group AttributeDictionary */ public function finds_definition_when_urn_matches_urn_oid() { $oidAttributeUrn = 'urn:oid:0.0.0.0.0.0.0.0.0'; $existingOidAttributeDefinition = new AttributeDefinition('existingOidAttribute', 'urn:mace:some:attribute', $oidAttributeUrn); $attributeDictionary = new AttributeDictionary(); $attributeDictionary->addAttributeDefinition($existingOidAttributeDefinition); $foundDefinition = $attributeDictionary->findAttributeDefinitionByUrn($oidAttributeUrn); $this->assertSame($existingOidAttributeDefinition, $foundDefinition, 'Expected to find an attribute definition, but found none'); }
/** * @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); }
/** * @test * @group AttributeSet * @group AttributeDictionary */ public function attribute_set_with_fallbacks_contains_an_attribute_with_an_existing_definition() { $attributeMaceUrn = 'urn:mace:some-attribute'; $attributeValue = ['someValue']; $attributeDefinition = new AttributeDefinition('some-attribute', $attributeMaceUrn); $assertion = Mockery::mock(SAML2_Assertion::class); $assertion->shouldReceive('getAttributes')->andReturn([$attributeMaceUrn => $attributeValue]); $dictionary = new AttributeDictionary(); $dictionary->addAttributeDefinition($attributeDefinition); $attributeSet = AttributeSetWithFallbacks::createFrom($assertion, $dictionary); $attributeIsInSet = $attributeSet->contains(new Attribute($attributeDefinition, $attributeValue)); $this->assertTrue($attributeIsInSet); }
/** * @test * @group AssertionAdapter */ public function attribute_set_has_no_duplicate_attribute_definitions_when_same_attributes_found() { $oidAttributeUrn = 'urn:oid:0.0.0.0.0.0.0.0.0'; $maceAttributeUrn = 'urn:mace:some:attribute'; $attributeValue = ['oid-attribute-value']; $existingAttributeDefinition = new AttributeDefinition('existingOidAttribute', $maceAttributeUrn, $oidAttributeUrn); $assertion = m::mock('\\SAML2_Assertion'); $assertion->shouldReceive('getAttributes')->andReturn([$oidAttributeUrn => $attributeValue, $maceAttributeUrn => $attributeValue]); $dictionary = new AttributeDictionary(); $dictionary->addAttributeDefinition($existingAttributeDefinition); $adapter = new AssertionAdapter($assertion, $dictionary); $attributeSet = $adapter->getAttributeSet(); $this->assertCount(1, $attributeSet, 'Expected attribute AttributeSet to have exactly one attribute'); }
private function getAttributeDictionary() { $attributeDictionary = new AttributeDictionary(); $attributeDictionary->addAttributeDefinition(new AttributeDefinition('displayName', 'urn:mace:dir:attribute-def:displayName')); $attributeDictionary->addAttributeDefinition(new AttributeDefinition('eduPersonTargetedID', 'urn:mace:dir:attribute-def:eduPersonTargetedID')); return $attributeDictionary; }