|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | +use Test::Lib; |
| 4 | +use Test::Net::SAML2; |
| 5 | +use Net::SAML2::Types qw(XsdID SAMLRequestType signingAlgorithm); |
| 6 | + |
| 7 | +subtest 'XsdID' => sub { |
| 8 | + my @xsdidok = qw(thisiscorrect _so_it_this THISTOO _YES this.-123.correct); |
| 9 | + foreach (@xsdidok) { |
| 10 | + ok(XsdID->check($_), "$_ is correct as an xsd:ID"); |
| 11 | + } |
| 12 | + |
| 13 | + ok(!XsdID->check("1abc"), "... and this is not a correct xsd:ID"); |
| 14 | + like( |
| 15 | + XsdID->get_message("1abc"), |
| 16 | + qr/is not a valid xsd:ID/, |
| 17 | + ".. with the correct error message" |
| 18 | + ); |
| 19 | + |
| 20 | + ok(!XsdID->check('asb#'), "... not an allowed character"); |
| 21 | + |
| 22 | +}; |
| 23 | + |
| 24 | +subtest 'SAMLRequestType' => sub { |
| 25 | + |
| 26 | + foreach (qw(SAMLRequest SAMLResponse)) { |
| 27 | + ok(SAMLRequestType->check($_), "$_ is correct SAMLRequestType"); |
| 28 | + } |
| 29 | + ok(!SAMLRequestType->check("foo"), ".. and this is not"); |
| 30 | + like( |
| 31 | + SAMLRequestType->get_message("foo"), |
| 32 | + qr/is not a SAML Request type/, |
| 33 | + ".. with the correct error message" |
| 34 | + ); |
| 35 | +}; |
| 36 | + |
| 37 | +subtest 'signingAlgorithm' => sub { |
| 38 | + |
| 39 | + foreach (qw(sha244 sha256 sha384 sha512 sha1)) { |
| 40 | + ok(signingAlgorithm->check($_), "$_ is correct signingAlgorithm"); |
| 41 | + } |
| 42 | + |
| 43 | + ok(!signingAlgorithm->check("shafake"), ".. and this is not"); |
| 44 | + like( |
| 45 | + signingAlgorithm->get_message("shafake"), |
| 46 | + qr/is not a supported signingAlgorithm/, |
| 47 | + ".. with the correct error message" |
| 48 | + ); |
| 49 | +}; |
| 50 | + |
| 51 | +done_testing; |
0 commit comments