From 61866cf4221f9680e2feeffe8b1a2b8050bb2002 Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Fri, 3 Nov 2017 13:38:29 +0100 Subject: [PATCH] initial import --- t/samlmetadata.t | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 t/samlmetadata.t diff --git a/t/samlmetadata.t b/t/samlmetadata.t new file mode 100644 index 0000000..a28ecd8 --- /dev/null +++ b/t/samlmetadata.t @@ -0,0 +1,76 @@ +#!/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 => 6; + +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+: Empty Stream/, +'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+: Entity: line 1: parser error/, +'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); + +throws_ok { + $metadata = IdPAccountManager::SAMLMetadata->new( + file => $file3->filename() + ); +} qr/^incorrect root element type 'root'/, +'instanciation: incorrect xml file'; -- GitLab