From 2dd375b9f6fb5ce29747a96d66c4422d850b4320 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Fri, 3 Nov 2017 13:44:13 +0100 Subject: [PATCH] simplification --- lib/IdPAccountManager/SAMLMetadata.pm | 14 ++------------ t/samlmetadata.t | 4 ++-- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/lib/IdPAccountManager/SAMLMetadata.pm b/lib/IdPAccountManager/SAMLMetadata.pm index ccda103..588eea7 100644 --- a/lib/IdPAccountManager/SAMLMetadata.pm +++ b/lib/IdPAccountManager/SAMLMetadata.pm @@ -15,19 +15,9 @@ sub new { die "non-existing file $args{file}" unless -f $args{file}; die "non-readable file $args{file}" unless -r $args{file}; - open(my $handle, '<', $args{file}) - or die "failed to open file $args{file}: $ERRNO"; - - my $parser = XML::LibXML->new(); - die "Failed to initialize XML parser" unless $parser; - my $doc; - eval { $doc = $parser->parse_fh($handle) }; - die "Failed to parse file $args{file}: $EVAL_ERROR" - if $EVAL_ERROR; - - die "Failed to parse file $args{file}: $EVAL_ERROR" - unless $doc; + eval { $doc = XML::LibXML->load_xml(location => $args{file}); }; + die "Failed to parse file: $EVAL_ERROR" if $EVAL_ERROR; my $root = $doc->documentElement(); my $type = $root->nodeName(); diff --git a/t/samlmetadata.t b/t/samlmetadata.t index a28ecd8..93feb91 100644 --- a/t/samlmetadata.t +++ b/t/samlmetadata.t @@ -43,7 +43,7 @@ throws_ok { $metadata = IdPAccountManager::SAMLMetadata->new( file => $file1->filename() ); -} qr/^Failed to parse file \S+: Empty Stream/, +} qr/^Failed to parse file: \S+ parser error : Document is empty/, 'instanciation: empty file'; my $file2 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); @@ -57,7 +57,7 @@ throws_ok { $metadata = IdPAccountManager::SAMLMetadata->new( file => $file2->filename() ); -} qr/^Failed to parse file \S+: Entity: line 1: parser error/, +} qr/^Failed to parse file: \S+ parser error : Start tag expected/, 'instanciation: non-xml file'; my $file3 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1); -- GitLab