-
Guillaume ROUSSE authoredGuillaume ROUSSE authored
samlmetadata.t 2.89 KiB
#!/usr/bin/perl
use strict;
use warnings;
use English qw(-no_match_vars);
use File::Temp;
use Test::More;
use Test::Exception;
use IdPAccountManager::SAMLMetadata;
plan tests => 21;
my $metadata;
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new();
} qr/^missing argument 'file'/,
'instanciation: no file argument';
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
file => '/no/such/file',
);
} qr/^non-existing file/,
'instanciation: non-existing file argument';
my $file1 = File::Temp->new(UNLINK => $ENV{TEST_DEBUG} ? 0 : 1);
chmod 0000, $file1;
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
file => $file1->filename()
);
} qr/^non-readable file/,
'instanciation: non-readable file';
chmod 0644, $file1;
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
file => $file1->filename()
);
} 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);
print $file2 <<EOF;
foo
EOF
close($file2);
throws_ok {
$metadata = IdPAccountManager::SAMLMetadata->new(
file => $file2->filename()
);
} 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);
print $file3 <<EOF;
<?xml version="1.0" encoding="UTF-8" ?>
<root/>
EOF
close($file3);