Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Report and test for invalid password formats correctly

  • Loading branch information...
commit 076c6147988fa688969e7c93588fcd2ae13269e0 1 parent 8076773
@avar authored
Showing with 18 additions and 2 deletions.
  1. +2 −0  Changes
  2. +4 −1 lib/Crypt/CVS.pm
  3. +12 −1 t/scramble.t
View
2  Changes
@@ -2,6 +2,8 @@ Revision history for CVS::Password
{{$NEXT}}
+ - Report and test for invalid password formats correctly.
+
0.01 2010-05-15 14:34:07
- Initial release.
View
5 lib/Crypt/CVS.pm
@@ -43,7 +43,10 @@ sub descramble
# This should never happen, the same password format (A) bas been
# used by CVS since the beginning of time
- die "invalid password format $1" unless substr($str, 0, 1) eq 'A';
+ {
+ my $fmt = substr($str, 0, 1);
+ die "invalid password format `$fmt'" unless $fmt eq 'A';
+ }
my @str = unpack "C*", substr($str, 1);
my $ret = join '', map { chr $SHIFTS[$_] } @str;
View
13 t/scramble.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 2 + 1 + 1_000 * 3;
+use Test::More tests => 2 + 1 + (1_000 * 3) + (26 * 2 + 10);
use Crypt::CVS qw(:all);
my %sanity = (
@@ -38,6 +38,17 @@ for my $str (map { random_string() } 1 .. 1_000) {
is $descrambled, $str, "descramble(scramble('$str') = '$str'";
}
+# Invalid password formats
+for my $chr ("A" .. "Z", "a" .. "z", 0 .. 9) {
+ local $@;
+ eval { descramble("${chr}foobar") };
+ if ($chr eq 'A') {
+ is $@, '', "A is a valid password format";
+ } else {
+ like $@, qr/invalid password format `$chr'/, "$chr isn't a valid password format";
+ }
+}
+
sub random_string
{
my $from = 32;
Please sign in to comment.
Something went wrong with that request. Please try again.