Skip to content

Commit 04734fc

Browse files
committed
Change weird regexp ok to like
This changes the way how the output is returned when a test fails because like() will show the needle and the haystack unlike the ok(foo =~ /bar/) construction previously used. perl -p -i -e 's#ok\((\S+) =~ #like($1, qr#' t/*.t Signed-off-by: Wesley Schwengle <waterkip@cpan.org>
1 parent 95fd5b9 commit 04734fc

File tree

8 files changed

+27
-32
lines changed

8 files changed

+27
-32
lines changed

t/01-decrypt.t

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use strict;
22
use warnings;
3-
use Test::More tests => 6;
43
use XML::Enc;
4+
use Test::More;
55
use MIME::Base64 qw/decode_base64/;
66

77
my $base64 = <<'BASE64AES';
@@ -10,16 +10,14 @@ BASE64AES
1010

1111
my $xml = decode_base64($base64);
1212

13-
ok($xml, "Got encrypted AES XML");
14-
1513
my $decrypter = XML::Enc->new(
1614
{
1715
key => 't/sign-private.pem',
1816
no_xml_declaration => 1
1917
}
2018
);
2119

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

2422
$base64 = <<'BASE64DES';
2523
PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0
@@ -217,16 +215,14 @@ BASE64DES
217215

218216
$xml = decode_base64($base64);
219217

220-
ok($xml, "Got encrypted DES XML");
221-
222218
$decrypter = XML::Enc->new(
223219
{
224220
key => 't/sign-private.pem',
225221
no_xml_declaration => 1
226222
}
227223
);
228224

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

231227

232228
$base64 = <<'FIRSTGO';
@@ -267,15 +263,13 @@ FIRSTGO
267263

268264
$xml = decode_base64($base64);
269265

270-
ok($xml, "Got encrypted DES XML");
271-
272266
$decrypter = XML::Enc->new(
273267
{
274268
key => 't/sign-private.pem',
275269
no_xml_declaration => 1
276270
}
277271
);
278272

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

281275
done_testing;

t/02-decrypt-saml.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ my $decrypter = XML::Enc->new(
208208
}
209209
);
210210

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

213213
$base64 = <<'SAMLAES128_RSA-OAEP-MGF1P';
214214
PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWw9InVybjpvYXNpczpuYW1lczp0
@@ -414,7 +414,7 @@ $decrypter = XML::Enc->new(
414414
}
415415
);
416416

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

419419

420420
$base64 = <<'SAMLAES196_RSA-OAEP-MGF1P';
@@ -621,7 +621,7 @@ $decrypter = XML::Enc->new(
621621
}
622622
);
623623

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

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

831831
done_testing;

t/03-encrypt.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ my $encrypter = XML::Enc->new(
2020
);
2121

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

25-
ok($encrypter->decrypt($encrypted) =~ /XML-SIG_1/, "Successfully Decrypted");
24+
like($encrypted, qr/EncryptedData/, "Successfully Encrypted");
25+
26+
like($encrypter->decrypt($encrypted), qr/XML-SIG_1/, "Successfully Decrypted");
2627
done_testing;

t/04-decrypt.t

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

t/05-invalid-xml.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ my $ret;
4848
eval {
4949
$ret = $decrypter->decrypt($xml);
5050
};
51-
ok($@ =~ /Opening and ending tag mismatch/,"Invalid XML");
51+
like($@, qr/Opening and ending tag mismatch/,"Invalid XML");
5252
ok(!$ret);
5353
done_testing;
5454
exit;
@@ -96,7 +96,7 @@ eval {
9696
$ret = $decrypter->decrypt($xml);
9797
};
9898

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

102102
done_testing;

t/06-test-encryption-methods.t

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ foreach my $km (@key_methods) {
3333
);
3434

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

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

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

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

74-
ok($encrypter->decrypt($encrypted) =~ /XML-SIG_1/, "Successfully Decrypted with XML::Enc");
74+
like($encrypter->decrypt($encrypted), qr/XML-SIG_1/, "Successfully Decrypted with XML::Enc");
7575
}
7676
}
7777
done_testing;

t/07-decrypt-xmlsec.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ SKIP: {
135135
);
136136

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

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

154154
# Decrypt using XML::Enc
155-
ok($decrypter->decrypt($encrypted) =~ /1076 2478 0678 5589/,
155+
like($decrypter->decrypt($encrypted), qr/1076 2478 0678 5589/,
156156
"Decrypted $dm $km xmlsec1 Content");
157157
}
158158
}

t/08-support-oaepparams.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ my $decrypter = XML::Enc->new(
5656
}
5757
);
5858

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

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

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

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

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

112112
done_testing;

0 commit comments

Comments
 (0)