Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions t/01-decrypt.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use strict;
use warnings;
use Test::More tests => 6;
use XML::Enc;
use Test::More;
use MIME::Base64 qw/decode_base64/;

my $base64 = <<'BASE64AES';
Expand All @@ -10,16 +10,14 @@ BASE64AES

my $xml = decode_base64($base64);

ok($xml, "Got encrypted AES XML");

my $decrypter = XML::Enc->new(
{
key => 't/sign-private.pem',
no_xml_declaration => 1
}
);

ok($decrypter->decrypt($xml) =~ /68351fcad4f2/, "Successfully Decrypted AES");
like($decrypter->decrypt($xml), qr/68351fcad4f2/, "Successfully Decrypted AES");

$base64 = <<'BASE64DES';
PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0
Expand Down Expand Up @@ -217,16 +215,14 @@ BASE64DES

$xml = decode_base64($base64);

ok($xml, "Got encrypted DES XML");

$decrypter = XML::Enc->new(
{
key => 't/sign-private.pem',
no_xml_declaration => 1
}
);

ok($decrypter->decrypt($xml) =~ /5e08ab4870dfd2f2a/, "Successfully Decrypted DES");
like($decrypter->decrypt($xml), qr/5e08ab4870dfd2f2a/, "Successfully Decrypted DES");


$base64 = <<'FIRSTGO';
Expand Down Expand Up @@ -267,15 +263,13 @@ FIRSTGO

$xml = decode_base64($base64);

ok($xml, "Got encrypted DES XML");

$decrypter = XML::Enc->new(
{
key => 't/sign-private.pem',
no_xml_declaration => 1
}
);

ok($decrypter->decrypt($xml) =~ /XML-SIG_1/, "Successfully Decrypted DES");
like($decrypter->decrypt($xml), qr/XML-SIG_1/, "Successfully Decrypted DES");

done_testing;
8 changes: 4 additions & 4 deletions t/02-decrypt-saml.t
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ my $decrypter = XML::Enc->new(
}
);

ok($decrypter->decrypt($xml) =~ /Af49573f11706b4/, "Successfully Decrypted 3DES RSA-OAEP-MGF1P SAML2 Assertion");
like($decrypter->decrypt($xml), qr/Af49573f11706b4/, "Successfully Decrypted 3DES RSA-OAEP-MGF1P SAML2 Assertion");

$base64 = <<'SAMLAES128_RSA-OAEP-MGF1P';
PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0
Expand Down Expand Up @@ -414,7 +414,7 @@ $decrypter = XML::Enc->new(
}
);

ok($decrypter->decrypt($xml) =~ /Ac43ac806fc1e00b9f95/, "Successfully Decrypted AES128 RSA-OAEP-MGF1P Assertion");
like($decrypter->decrypt($xml), qr/Ac43ac806fc1e00b9f95/, "Successfully Decrypted AES128 RSA-OAEP-MGF1P Assertion");


$base64 = <<'SAMLAES196_RSA-OAEP-MGF1P';
Expand Down Expand Up @@ -621,7 +621,7 @@ $decrypter = XML::Enc->new(
}
);

ok($decrypter->decrypt($xml) =~ /NETSAML2_70fbdf22f456/, "Successfully Decrypted AES196 RSA-OAEP-MGF1P SAML2 Assertion");
like($decrypter->decrypt($xml), qr/NETSAML2_70fbdf22f456/, "Successfully Decrypted AES196 RSA-OAEP-MGF1P SAML2 Assertion");

$base64 = <<'SAMLAES256_RSA-OAEP-MGF1P';
PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0
Expand Down Expand Up @@ -826,6 +826,6 @@ $decrypter = XML::Enc->new(
no_xml_declaration => 1
}
);
ok($decrypter->decrypt($xml) =~ /A835657d0615aa0bfa/, "Successfully Decrypted AES256 RSA-OAEP-MGF1P SAML2 Assertion");
like($decrypter->decrypt($xml), qr/A835657d0615aa0bfa/, "Successfully Decrypted AES256 RSA-OAEP-MGF1P SAML2 Assertion");

done_testing;
5 changes: 3 additions & 2 deletions t/03-encrypt.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ my $encrypter = XML::Enc->new(
);

my $encrypted = $encrypter->encrypt($xml);
ok($encrypted =~ /EncryptedData/, "Successfully Encrypted");

ok($encrypter->decrypt($encrypted) =~ /XML-SIG_1/, "Successfully Decrypted");
like($encrypted, qr/EncryptedData/, "Successfully Encrypted");

like($encrypter->decrypt($encrypted), qr/XML-SIG_1/, "Successfully Decrypted");
done_testing;
6 changes: 3 additions & 3 deletions t/04-decrypt.t

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions t/05-invalid-xml.t
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ my $ret;
eval {
$ret = $decrypter->decrypt($xml);
};
ok($@ =~ /Opening and ending tag mismatch/,"Invalid XML");
like($@, qr/Opening and ending tag mismatch/,"Invalid XML");
ok(!$ret);
done_testing;
exit;
Expand Down Expand Up @@ -96,7 +96,7 @@ eval {
$ret = $decrypter->decrypt($xml);
};

ok($@ =~ /Opening and ending tag mismatch/,"Invalid XML");
like($@, qr/Opening and ending tag mismatch/,"Invalid XML");
ok(!$ret);

done_testing;
10 changes: 5 additions & 5 deletions t/06-test-encryption-methods.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ foreach my $km (@key_methods) {
);

my $encrypted = $encrypter->encrypt($xml);
ok($encrypted =~ /EncryptedData/, "Successfully Encrypted: Key Method $km Data Method $dm");
like($encrypted, qr/EncryptedData/, "Successfully Encrypted: Key Method $km Data Method $dm");

ok($encrypter->decrypt($encrypted) =~ /XML-SIG_1/, "Successfully Decrypted with XML::Enc");
like($encrypter->decrypt($encrypted), qr/XML-SIG_1/, "Successfully Decrypted with XML::Enc");

SKIP: {
skip "xmlsec1 not installed", 2 unless $xmlsec->{installed};
Expand All @@ -48,7 +48,7 @@ foreach my $km (@key_methods) {
print XML $encrypted;
close XML;
my $verify_response = `xmlsec1 --decrypt $lax_key_search --privkey-pem t/sign-private.pem tmp.xml 2>&1`;
ok( $verify_response =~ m/XML-SIG_1/, "Successfully decrypted with xmlsec1" )
like($verify_response, qr/XML-SIG_1/, "Successfully decrypted with xmlsec1" )
or warn "calling xmlsec1 failed: '$verify_response'\n";
unlink 'tmp.xml';
}
Expand All @@ -69,9 +69,9 @@ foreach my $om (@oaep_mgf_algs) {
);

my $encrypted = $encrypter->encrypt($xml);
ok($encrypted =~ /EncryptedData/, "Successfully Encrypted: Key Method 'rsa-oaep' with $om Data Method $dm");
like($encrypted, qr/EncryptedData/, "Successfully Encrypted: Key Method 'rsa-oaep' with $om Data Method $dm");

ok($encrypter->decrypt($encrypted) =~ /XML-SIG_1/, "Successfully Decrypted with XML::Enc");
like($encrypter->decrypt($encrypted), qr/XML-SIG_1/, "Successfully Decrypted with XML::Enc");
}
}
done_testing;
4 changes: 2 additions & 2 deletions t/07-decrypt-xmlsec.t
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ SKIP: {
);

# Decrypt using XML::Enc
ok($decrypter->decrypt($encrypted) =~ /1076 2478 0678 5589/,
like($decrypter->decrypt($encrypted), qr/1076 2478 0678 5589/,
"Decrypted xmlsec1 $dm $km Element");

# Test Encrypted Content
Expand All @@ -152,7 +152,7 @@ SKIP: {
unlink 'encrypted-content.xml';

# Decrypt using XML::Enc
ok($decrypter->decrypt($encrypted) =~ /1076 2478 0678 5589/,
like($decrypter->decrypt($encrypted), qr/1076 2478 0678 5589/,
"Decrypted $dm $km xmlsec1 Content");
}
}
Expand Down
8 changes: 4 additions & 4 deletions t/08-support-oaepparams.t
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ my $decrypter = XML::Enc->new(
}
);

ok($decrypter->decrypt($xml) =~ /4019 2445 0277 5567/, "Successfully Decrypted xmlsec1 xml using OAEPparams");
like($decrypter->decrypt($xml), qr/4019 2445 0277 5567/, "Successfully Decrypted xmlsec1 xml using OAEPparams");

$xml = <<'XML';
<?xml version="1.0"?>
Expand All @@ -75,9 +75,9 @@ my $encrypter = XML::Enc->new(
);

my $encrypted = $encrypter->encrypt($xml);
ok($encrypted =~ /CipherData/, "Successfully Encrypted with XML::Enc using OAEPparams");
like($encrypted, qr/CipherData/, "Successfully Encrypted with XML::Enc using OAEPparams");

ok($encrypter->decrypt($encrypted) =~ /<bar>123<\/bar>/, "Successfully Decrypted with XML::Enc using OAEPparams");
like($encrypter->decrypt($encrypted), qr/<bar>123<\/bar>/, "Successfully Decrypted with XML::Enc using OAEPparams");

SKIP: {
skip "xmlsec1 not installed", 2 unless $xmlsec->{installed};
Expand Down Expand Up @@ -106,7 +106,7 @@ my $ret;
eval {
$ret = $decrypter->decrypt($encrypted);
};
ok($@ =~ /FATAL: rsa_decrypt_key_ex/,"XML::Enc Unable to decrypt if XML includes incorrect OAEPparams");
like($@, qr/FATAL: rsa_decrypt_key_ex/,"XML::Enc Unable to decrypt if XML includes incorrect OAEPparams");
ok(!$ret);

done_testing;