Skip to content

Commit

Permalink
Add attribute_consuming_service to SP for metadata creation
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Schwengle <waterkip@cpan.org>
  • Loading branch information
waterkip committed Dec 20, 2023
1 parent 2ec62c0 commit a8a1eaf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
4 changes: 4 additions & 0 deletions lib/Net/SAML2/SP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ has 'slo_url_redirect' => (isa => 'Str', is => 'ro', required => 0);
has 'acs_url_post' => (isa => 'Str', is => 'ro', required => 0);
has 'acs_url_artifact' => (isa => 'Str', is => 'ro', required => 0);

has 'attribute_consuming_service' =>
(isa => 'Net::SAML2::AttributeConsumingService', is => 'ro', predicate => 'has_attribute_consuming_service');

has '_cert_text' => (isa => 'Str', is => 'ro', init_arg => undef, builder => '_build_cert_text', lazy => 1);

has '_encryption_key_text' => (isa => 'Str', is => 'ro', init_arg => undef, builder => '_build_encryption_key_text', lazy => 1);
Expand Down Expand Up @@ -588,6 +591,7 @@ sub generate_metadata {
$self->_generate_single_logout_service($x),

$self->_generate_assertion_consumer_service($x),
$self->has_attribute_consuming_service ? $self->attribute_consuming_service->to_xml : (),

),
$x->Organization(
Expand Down
60 changes: 39 additions & 21 deletions t/02-create-sp.t
Original file line number Diff line number Diff line change
Expand Up @@ -441,32 +441,50 @@ use URN::OASIS::SAML2 qw(:bindings :urn);
);
}

TODO: {
local $TODO = "Not build yet";
my $consuming_index = Net::SAML2::AttributeConsumingService->new(
service_name => 'Net::SAML2 testsuite',
index => 1,
requested_attributes => [
{
my $consuming_index = Net::SAML2::AttributeConsumingService->new(
service_name => 'Net::SAML2 testsuite',
index => 1,
attributes => [
Net::SAML2::RequestedAttribute->new(
namespace => 'bar',
friendly_name => 'foo',
name => 'urn:foo:bar',
name_format => 'xx',
required => 1,
friendly_name => 'foo',
name => 'urn:foo:bar',
name_format => 'xx',
required => 1,
),
],
);
],
);

my $sp = net_saml2_sp(
attribute_consuming_service => $consuming_index,
);
my $sp = net_saml2_sp(attribute_consuming_service => $consuming_index,);

my $xpath = get_xpath(
$sp->metadata,
md => URN_METADATA,
ds => URN_SIGNATURE,
);
my $xpath = get_xpath(
$sp->metadata,
md => URN_METADATA,
ds => URN_SIGNATURE,
);

my $node = get_single_node_ok($xpath, '//md:SPSSODescriptor');
my $acs = get_single_node_ok($node, '//md:AttributeConsumingService');

is($acs->getAttribute('index'), 1, ".. index is 1");
is($acs->getAttribute('isDefault'), 0, "Not the default");


my @child = $acs->childNodes();
is(@child, 2, "Have 2 children");
is($child[0]->nodeName, "md:ServiceName", "Service name node found");
is(
$child[0]->textContent,
'Net::SAML2 testsuite',
".. with the correct value"
);

is($child[1]->nodeName, "md:RequestedAttribute",
"Requested attribute found");
is($child[1]->getAttribute('FriendlyName'),
'foo', ".. with the correct friendly name");
is($child[1]->getAttribute('Name'), 'urn:foo:bar', ".. and name");
is($child[1]->getAttribute('isRequired'), '1', ".. and requiredness");
}

done_testing;

0 comments on commit a8a1eaf

Please sign in to comment.