summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/001compile.t141
-rw-r--r--t/002goodperl.t288
-rw-r--r--t/004template.t161
-rw-r--r--t/005whitespace.t66
-rw-r--r--t/006spellcheck.t104
-rw-r--r--t/007util.t66
-rw-r--r--t/008filter.t288
-rw-r--r--t/009bugwords.t74
-rw-r--r--t/010dependencies.t76
-rw-r--r--t/011pod.t40
-rw-r--r--t/012throwables.t281
-rw-r--r--t/901-secure-mail-loop.t20
-rw-r--r--t/902-crypt-openpgp-random.t18
-rw-r--r--t/903-passwdqc-conf.t30
-rw-r--r--t/Support/Files.pm60
-rw-r--r--t/Support/Templates.pm91
-rw-r--r--t/bmo/comments.t75
-rw-r--r--t/bmo/passwords.t407
-rw-r--r--t/critic.t2
-rw-r--r--t/css.t27
-rw-r--r--t/daemon-control-catch-signal.t88
-rw-r--r--t/docker.t24
-rw-r--r--t/extract-nicks.t29
-rw-r--r--t/hash-sig.t9
-rw-r--r--t/json-boxes.t2
-rw-r--r--t/markdown.t36
-rw-r--r--t/mock-db.t24
-rw-r--r--t/mock-params.t6
-rw-r--r--t/mojo-example.t29
-rw-r--r--t/security-risk.t231
-rw-r--r--t/sqlite-memory.t95
31 files changed, 1503 insertions, 1385 deletions
diff --git a/t/001compile.t b/t/001compile.t
index 3d8d82bf4..ae609d5ba 100644
--- a/t/001compile.t
+++ b/t/001compile.t
@@ -18,58 +18,59 @@ use lib qw(. lib local/lib/perl5 t);
use Config;
use Support::Files;
use Test::More;
-BEGIN {
- if ($ENV{CI}) {
- plan skip_all => 'Not running compile tests in CI.';
- exit;
- }
- plan tests => @Support::Files::testitems + @Support::Files::test_files;
- use_ok('Bugzilla::Constants');
- use_ok('Bugzilla::Install::Requirements');
- use_ok('Bugzilla');
+BEGIN {
+ if ($ENV{CI}) {
+ plan skip_all => 'Not running compile tests in CI.';
+ exit;
+ }
+ plan tests => @Support::Files::testitems + @Support::Files::test_files;
+
+ use_ok('Bugzilla::Constants');
+ use_ok('Bugzilla::Install::Requirements');
+ use_ok('Bugzilla');
}
Bugzilla->usage_mode(USAGE_MODE_TEST);
sub compile_file {
- my ($file) = @_;
-
- # Don't allow CPAN.pm to modify the global @INC, which the version
- # shipped with Perl 5.8.8 does. (It gets loaded by
- # Bugzilla::Install::CPAN.)
- local @INC = @INC;
-
- if ($file =~ /extensions/) {
- skip "$file: extensions not tested", 1;
- return;
- }
-
- if ($file =~ s/\.pm$//) {
- $file =~ s{/}{::}g;
- use_ok($file);
- return;
- }
-
- open(my $fh, $file);
- my $bang = <$fh>;
- close $fh;
-
- my $T = "";
- if ($bang =~ m/#!\S*perl\s+-.*T/) {
- $T = "T";
- }
-
- my $libs = '-It ';
- if ($ENV{PERL5LIB}) {
- $libs .= join " ", map { "-I\"$_\"" } split /$Config{path_sep}/, $ENV{PERL5LIB};
- }
- my $perl = qq{"$^X"};
- my $output = `$perl $libs -c$T -MSupport::Systemexec $file 2>&1`;
- chomp($output);
- my $return_val = $?;
- $output =~ s/^\Q$file\E syntax OK$//ms;
- diag($output) if $output;
- ok(!$return_val, $file) or diag('--ERROR');
+ my ($file) = @_;
+
+ # Don't allow CPAN.pm to modify the global @INC, which the version
+ # shipped with Perl 5.8.8 does. (It gets loaded by
+ # Bugzilla::Install::CPAN.)
+ local @INC = @INC;
+
+ if ($file =~ /extensions/) {
+ skip "$file: extensions not tested", 1;
+ return;
+ }
+
+ if ($file =~ s/\.pm$//) {
+ $file =~ s{/}{::}g;
+ use_ok($file);
+ return;
+ }
+
+ open(my $fh, $file);
+ my $bang = <$fh>;
+ close $fh;
+
+ my $T = "";
+ if ($bang =~ m/#!\S*perl\s+-.*T/) {
+ $T = "T";
+ }
+
+ my $libs = '-It ';
+ if ($ENV{PERL5LIB}) {
+ $libs .= join " ", map {"-I\"$_\""} split /$Config{path_sep}/, $ENV{PERL5LIB};
+ }
+ my $perl = qq{"$^X"};
+ my $output = `$perl $libs -c$T -MSupport::Systemexec $file 2>&1`;
+ chomp($output);
+ my $return_val = $?;
+ $output =~ s/^\Q$file\E syntax OK$//ms;
+ diag($output) if $output;
+ ok(!$return_val, $file) or diag('--ERROR');
}
my @testitems = (@Support::Files::testitems, @Support::Files::test_files);
@@ -77,28 +78,28 @@ my $file_features = map_files_to_features();
# Test the scripts by compiling them
foreach my $file (@testitems) {
- # These were already compiled, above.
- next if ($file eq 'Bugzilla.pm'
- or $file eq 'Bugzilla/Constants.pm'
- or $file eq 'Bugzilla/Install/Requirements.pm');
- SKIP: {
- if ($file eq 'mod_perl.pl') {
- skip 'mod_perl.pl cannot be compiled from the command line', 1;
- }
- my $feature = $file_features->{$file};
- if ($feature and !Bugzilla->feature($feature)) {
- skip "$file: $feature not enabled", 1;
- }
-
- # Check that we have a DBI module to support the DB, if this
- # is a database module (but not Schema)
- if ($file =~ m{Bugzilla/DB/([^/]+)\.pm$}
- and $file ne "Bugzilla/DB/Schema.pm")
- {
- my $module = lc($1);
- Bugzilla->feature($module) or skip "$file: Driver for $module not installed", 1;
- }
-
- compile_file($file);
+
+ # These were already compiled, above.
+ next
+ if ($file eq 'Bugzilla.pm'
+ or $file eq 'Bugzilla/Constants.pm'
+ or $file eq 'Bugzilla/Install/Requirements.pm');
+SKIP: {
+ if ($file eq 'mod_perl.pl') {
+ skip 'mod_perl.pl cannot be compiled from the command line', 1;
}
+ my $feature = $file_features->{$file};
+ if ($feature and !Bugzilla->feature($feature)) {
+ skip "$file: $feature not enabled", 1;
+ }
+
+ # Check that we have a DBI module to support the DB, if this
+ # is a database module (but not Schema)
+ if ($file =~ m{Bugzilla/DB/([^/]+)\.pm$} and $file ne "Bugzilla/DB/Schema.pm") {
+ my $module = lc($1);
+ Bugzilla->feature($module) or skip "$file: Driver for $module not installed", 1;
+ }
+
+ compile_file($file);
+ }
}
diff --git a/t/002goodperl.t b/t/002goodperl.t
index 80d7cf2b9..b2a9d5751 100644
--- a/t/002goodperl.t
+++ b/t/002goodperl.t
@@ -18,169 +18,185 @@ use lib qw(. lib local/lib/perl5 t);
use Support::Files;
-use Test::More tests => (scalar(@Support::Files::testitems)
- + scalar(@Support::Files::test_files)) * 6;
+use Test::More tests =>
+ (scalar(@Support::Files::testitems) + scalar(@Support::Files::test_files))
+ * 6;
my @testitems = (@Support::Files::test_files, @Support::Files::testitems);
my @require_taint = qw(email_in.pl importxml.pl mod_perl.pl whine.pl);
foreach my $file (@testitems) {
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next if (!$file); # skip null entries
- if (! open (FILE, $file)) {
- ok(0,"could not open $file --WARNING");
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next if (!$file); # skip null entries
+ if (!open(FILE, $file)) {
+ ok(0, "could not open $file --WARNING");
+ }
+ my $file_line1 = <FILE>;
+ close(FILE);
+
+ $file =~ m/.*\.(.*)/;
+ my $ext = $1;
+
+ if ($file_line1 !~ m/^#\!/) {
+ ok(1, "$file does not have a shebang");
+ }
+ else {
+ my $flags;
+ if (!defined $ext || $ext eq 'pl' || $ext eq 'psgi') {
+
+ # standalone programs aren't taint checked yet
+ if (grep { $file eq $_ } @require_taint) {
+ $flags = 'T';
+ }
+ else {
+ $flags = '';
+ }
}
- my $file_line1 = <FILE>;
- close (FILE);
-
- $file =~ m/.*\.(.*)/;
- my $ext = $1;
-
- if ($file_line1 !~ m/^#\!/) {
- ok(1,"$file does not have a shebang");
- } else {
- my $flags;
- if (!defined $ext || $ext eq 'pl' || $ext eq 'psgi') {
- # standalone programs aren't taint checked yet
- if (grep { $file eq $_ } @require_taint) {
- $flags = 'T';
- }
- else {
- $flags = '';
- }
- } elsif ($ext eq "pm") {
- ok(0, "$file is a module, but has a shebang");
- next;
- } elsif ($ext eq "cgi") {
- # cgi files must be taint checked
- $flags = 'T';
- } elsif ($ext eq 't') {
- $flags = '';
- } else {
- ok(0, "$file has shebang but unknown extension");
- next;
- }
-
- if ($file_line1 =~ m#^\#\!/usr/bin/perl(?:\s-(\w+))?$#) {
- my $file_flags = $1 || '';
- if ($flags eq $file_flags) {
- ok(1, "$file uses standard perl location" . ($flags ? " and -$flags flag" : ""));
- }
- elsif ($flags) {
- ok(0, "$file is MISSING -$flags flag --WARNING");
- }
- else {
- ok(0, "$file has unexpected -$file_flags flag --WARNING");
- }
- } else {
- ok(0,"$file uses non-standard perl location");
- }
+ elsif ($ext eq "pm") {
+ ok(0, "$file is a module, but has a shebang");
+ next;
}
-}
+ elsif ($ext eq "cgi") {
-foreach my $file (@testitems) {
- my $found_use_perl = 0;
- my $found_use_strict = 0;
- my $found_use_warnings = 0;
- my $found_modern_perl = 0;
- my $found_mojo = 0;
-
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next if (!$file); # skip null entries
- if (! open (FILE, $file)) {
- ok(0,"could not open $file --WARNING");
- next;
+ # cgi files must be taint checked
+ $flags = 'T';
}
- while (my $file_line = <FILE>) {
- $found_modern_perl = 1 if $file_line =~ m/^use\s*(?:Moo|Role::Tiny)/;
- $found_mojo = 1 if $file_line =~ m/^use\s(?:Mojo(?:licious::Lite|::Base)\b)/;
- $found_use_perl = 1 if $file_line =~ m/^\s*use 5.10.1/;
- $found_use_strict = 1 if $file_line =~ m/^\s*use strict/;
- $found_use_warnings = 1 if $file_line =~ m/^\s*use warnings/;
- if ($found_modern_perl || $found_mojo) {
- $found_use_strict = 1;
- $found_use_warnings = 1;
- }
- if ($found_mojo) {
- $found_use_perl = 1;
- }
- last if ($found_use_perl && $found_use_strict && $found_use_warnings);
+ elsif ($ext eq 't') {
+ $flags = '';
}
- close (FILE);
- if ($found_use_perl) {
- ok(1,"$file requires Perl 5.10.1");
- } else {
- ok(0,"$file DOES NOT require Perl 5.10.1 --WARNING");
+ else {
+ ok(0, "$file has shebang but unknown extension");
+ next;
}
- if ($found_use_strict) {
- ok(1,"$file uses strict");
- } else {
- ok(0,"$file DOES NOT use strict --WARNING");
+ if ($file_line1 =~ m#^\#\!/usr/bin/perl(?:\s-(\w+))?$#) {
+ my $file_flags = $1 || '';
+ if ($flags eq $file_flags) {
+ ok(1,
+ "$file uses standard perl location" . ($flags ? " and -$flags flag" : ""));
+ }
+ elsif ($flags) {
+ ok(0, "$file is MISSING -$flags flag --WARNING");
+ }
+ else {
+ ok(0, "$file has unexpected -$file_flags flag --WARNING");
+ }
+ }
+ else {
+ ok(0, "$file uses non-standard perl location");
}
+ }
+}
- if ($found_use_warnings) {
- ok(1,"$file uses warnings");
- } else {
- ok(0,"$file DOES NOT use warnings --WARNING");
+foreach my $file (@testitems) {
+ my $found_use_perl = 0;
+ my $found_use_strict = 0;
+ my $found_use_warnings = 0;
+ my $found_modern_perl = 0;
+ my $found_mojo = 0;
+
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next if (!$file); # skip null entries
+ if (!open(FILE, $file)) {
+ ok(0, "could not open $file --WARNING");
+ next;
+ }
+ while (my $file_line = <FILE>) {
+ $found_modern_perl = 1 if $file_line =~ m/^use\s*(?:Moo|Role::Tiny)/;
+ $found_mojo = 1 if $file_line =~ m/^use\s(?:Mojo(?:licious::Lite|::Base)\b)/;
+ $found_use_perl = 1 if $file_line =~ m/^\s*use 5.10.1/;
+ $found_use_strict = 1 if $file_line =~ m/^\s*use strict/;
+ $found_use_warnings = 1 if $file_line =~ m/^\s*use warnings/;
+ if ($found_modern_perl || $found_mojo) {
+ $found_use_strict = 1;
+ $found_use_warnings = 1;
+ }
+ if ($found_mojo) {
+ $found_use_perl = 1;
}
+ last if ($found_use_perl && $found_use_strict && $found_use_warnings);
+ }
+ close(FILE);
+ if ($found_use_perl) {
+ ok(1, "$file requires Perl 5.10.1");
+ }
+ else {
+ ok(0, "$file DOES NOT require Perl 5.10.1 --WARNING");
+ }
+
+ if ($found_use_strict) {
+ ok(1, "$file uses strict");
+ }
+ else {
+ ok(0, "$file DOES NOT use strict --WARNING");
+ }
+
+ if ($found_use_warnings) {
+ ok(1, "$file uses warnings");
+ }
+ else {
+ ok(0, "$file DOES NOT use warnings --WARNING");
+ }
}
# Check to see that all error messages use tags (for l10n reasons.)
foreach my $file (@testitems) {
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next if (!$file); # skip null entries
- if (! open (FILE, $file)) {
- ok(0,"could not open $file --WARNING");
- next;
- }
- my $lineno = 0;
- my $error = 0;
-
- while (!$error && (my $file_line = <FILE>)) {
- $lineno++;
- if ($file_line =~ /Throw.*Error\("(.*?)"/) {
- if ($1 =~ /\s/) {
- ok(0,"$file has a Throw*Error call on line $lineno
- which doesn't use a tag --ERROR");
- $error = 1;
- }
- }
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next if (!$file); # skip null entries
+ if (!open(FILE, $file)) {
+ ok(0, "could not open $file --WARNING");
+ next;
+ }
+ my $lineno = 0;
+ my $error = 0;
+
+ while (!$error && (my $file_line = <FILE>)) {
+ $lineno++;
+ if ($file_line =~ /Throw.*Error\("(.*?)"/) {
+ if ($1 =~ /\s/) {
+ ok(
+ 0, "$file has a Throw*Error call on line $lineno
+ which doesn't use a tag --ERROR"
+ );
+ $error = 1;
+ }
}
+ }
- ok(1,"$file uses Throw*Error calls correctly") if !$error;
+ ok(1, "$file uses Throw*Error calls correctly") if !$error;
- close(FILE);
+ close(FILE);
}
# Forbird the { foo => $cgi->param() } syntax, for security reasons.
foreach my $file (@testitems) {
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next unless $file; # skip null entries
- if (!open(FILE, $file)) {
- ok(0, "could not open $file --WARNING");
- next;
- }
- my $lineno = 0;
- my @unsafe_args;
-
- while (my $file_line = <FILE>) {
- $lineno++;
- $file_line =~ s/^\s*(.+)\s*$/$1/; # Remove leading and trailing whitespaces.
- if ($file_line =~ /^[^#]+=> \$cgi\->param/) {
- push(@unsafe_args, "$file_line on line $lineno");
- }
- }
-
- if (@unsafe_args) {
- ok(0, "$file incorrectly passes a CGI argument to a hash --ERROR\n" .
- join("\n", @unsafe_args));
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next unless $file; # skip null entries
+ if (!open(FILE, $file)) {
+ ok(0, "could not open $file --WARNING");
+ next;
+ }
+ my $lineno = 0;
+ my @unsafe_args;
+
+ while (my $file_line = <FILE>) {
+ $lineno++;
+ $file_line =~ s/^\s*(.+)\s*$/$1/; # Remove leading and trailing whitespaces.
+ if ($file_line =~ /^[^#]+=> \$cgi\->param/) {
+ push(@unsafe_args, "$file_line on line $lineno");
}
- else {
- ok(1, "$file has no vulnerable hash syntax");
- }
-
- close(FILE);
+ }
+
+ if (@unsafe_args) {
+ ok(0,
+ "$file incorrectly passes a CGI argument to a hash --ERROR\n"
+ . join("\n", @unsafe_args));
+ }
+ else {
+ ok(1, "$file has no vulnerable hash syntax");
+ }
+
+ close(FILE);
}
exit 0;
diff --git a/t/004template.t b/t/004template.t
index 909f1a231..61e895bf2 100644
--- a/t/004template.t
+++ b/t/004template.t
@@ -22,20 +22,22 @@ use CGI qw(-no_debug);
use File::Spec;
use Template;
-use Test::More tests => ( scalar(@referenced_files) + 2 * $num_actual_files );
+use Test::More tests => (scalar(@referenced_files) + 2 * $num_actual_files);
# Capture the TESTOUT from Test::More or Test::Builder for printing errors.
# This will handle verbosity for us automatically.
my $fh;
{
- no warnings qw(unopened); # Don't complain about non-existent filehandles
- if (-e \*Test::More::TESTOUT) {
- $fh = \*Test::More::TESTOUT;
- } elsif (-e \*Test::Builder::TESTOUT) {
- $fh = \*Test::Builder::TESTOUT;
- } else {
- $fh = \*STDOUT;
- }
+ no warnings qw(unopened); # Don't complain about non-existent filehandles
+ if (-e \*Test::More::TESTOUT) {
+ $fh = \*Test::More::TESTOUT;
+ }
+ elsif (-e \*Test::Builder::TESTOUT) {
+ $fh = \*Test::Builder::TESTOUT;
+ }
+ else {
+ $fh = \*STDOUT;
+ }
}
# Check to make sure all templates that are referenced in Bugzilla
@@ -44,80 +46,89 @@ my $fh;
# fall back to English if necessary.
foreach my $file (@referenced_files) {
- my $found = 0;
- foreach my $path (@english_default_include_paths) {
- my $pathfile = File::Spec->catfile($path, $file);
- if (-e $pathfile) {
- $found = 1;
- last;
- }
+ my $found = 0;
+ foreach my $path (@english_default_include_paths) {
+ my $pathfile = File::Spec->catfile($path, $file);
+ if (-e $pathfile) {
+ $found = 1;
+ last;
}
+ }
- ok($found, "$file found");
+ ok($found, "$file found");
}
foreach my $include_path (@include_paths) {
- # Processes all the templates to make sure they have good syntax
- my $provider = Template::Provider->new(
- {
- INCLUDE_PATH => $include_path ,
- # Need to define filters used in the codebase, they don't
- # actually have to function in this test, just be defined.
- # See Template.pm for the actual codebase definitions.
-
- # Initialize templates (f.e. by loading plugins like Hook).
- PRE_PROCESS => "global/variables.none.tmpl",
-
- FILTERS =>
- {
- html_linebreak => sub { return $_; },
- js => sub { return $_ } ,
- base64 => sub { return $_ } ,
- url_quote => sub { return $_ } ,
- css_class_quote => sub { return $_ } ,
- xml => sub { return $_ } ,
- quoteUrls => sub { return $_ } ,
- bug_link => [ sub { return sub { return $_; } }, 1] ,
- csv => sub { return $_ } ,
- unitconvert => sub { return $_ },
- time => sub { return $_ } ,
- wrap_comment => sub { return $_ },
- none => sub { return $_ } ,
- ics => [ sub { return sub { return $_; } }, 1] ,
- markdown => sub { return $_ } ,
+
+ # Processes all the templates to make sure they have good syntax
+ my $provider = Template::Provider->new({
+ INCLUDE_PATH => $include_path,
+
+ # Need to define filters used in the codebase, they don't
+ # actually have to function in this test, just be defined.
+ # See Template.pm for the actual codebase definitions.
+
+ # Initialize templates (f.e. by loading plugins like Hook).
+ PRE_PROCESS => "global/variables.none.tmpl",
+
+ FILTERS => {
+ html_linebreak => sub { return $_; },
+ js => sub { return $_ },
+ base64 => sub { return $_ },
+ url_quote => sub { return $_ },
+ css_class_quote => sub { return $_ },
+ xml => sub { return $_ },
+ quoteUrls => sub { return $_ },
+ bug_link => [
+ sub {
+ return sub { return $_; }
+ },
+ 1
+ ],
+ csv => sub { return $_ },
+ unitconvert => sub { return $_ },
+ time => sub { return $_ },
+ wrap_comment => sub { return $_ },
+ none => sub { return $_ },
+ ics => [
+ sub {
+ return sub { return $_; }
},
+ 1
+ ],
+ markdown => sub { return $_ },
+ },
+ });
+
+ foreach my $file (@{$actual_files{$include_path}}) {
+ my $path = File::Spec->catfile($include_path, $file);
+
+ # These are actual files, so there's no need to check for existence.
+
+ my ($data, $err) = $provider->fetch($file);
+
+ if (!$err) {
+ ok(1, "$path syntax ok");
+ }
+ else {
+ ok(0, "$path has bad syntax --ERROR");
+ print $fh $data . "\n";
+ }
+
+ # Make sure no forbidden constructs are present.
+ local $/;
+ open(FILE, '<', $path) or die "Can't open $file: $!\n";
+ $data = <FILE>;
+ close(FILE);
+
+ # Forbid single quotes to delimit URLs, see bug 926085.
+ if ($data =~ /href=\\?'/) {
+ ok(0, "$path contains blacklisted constructs: href='...'");
}
- );
-
- foreach my $file (@{$actual_files{$include_path}}) {
- my $path = File::Spec->catfile($include_path, $file);
-
- # These are actual files, so there's no need to check for existence.
-
- my ($data, $err) = $provider->fetch($file);
-
- if (!$err) {
- ok(1, "$path syntax ok");
- }
- else {
- ok(0, "$path has bad syntax --ERROR");
- print $fh $data . "\n";
- }
-
- # Make sure no forbidden constructs are present.
- local $/;
- open(FILE, '<', $path) or die "Can't open $file: $!\n";
- $data = <FILE>;
- close (FILE);
-
- # Forbid single quotes to delimit URLs, see bug 926085.
- if ($data =~ /href=\\?'/) {
- ok(0, "$path contains blacklisted constructs: href='...'");
- }
- else {
- ok(1, "$path contains no blacklisted constructs");
- }
+ else {
+ ok(1, "$path contains no blacklisted constructs");
}
+ }
}
exit 0;
diff --git a/t/005whitespace.t b/t/005whitespace.t
index be13890bb..492e3bee1 100644
--- a/t/005whitespace.t
+++ b/t/005whitespace.t
@@ -19,49 +19,57 @@ use Support::Files;
use Support::Templates;
use File::Spec;
-use Test::More tests => (scalar(@Support::Files::testitems)
- + scalar(@Support::Files::test_files)
- + $Support::Templates::num_actual_files) * 3;
+use Test::More tests => (
+ scalar(@Support::Files::testitems)
+ + scalar(@Support::Files::test_files)
+ + $Support::Templates::num_actual_files)
+ * 3;
my @testitems = (@Support::Files::testitems, @Support::Files::test_files);
for my $path (@Support::Templates::include_paths) {
- push(@testitems, map(File::Spec->catfile($path, $_),
- Support::Templates::find_actual_files($path)));
+ push(
+ @testitems,
+ map(File::Spec->catfile($path, $_),
+ Support::Templates::find_actual_files($path))
+ );
}
my %results;
foreach my $file (@testitems) {
- open (FILE, "$file");
- my @contents = <FILE>;
- if (grep /\t/, @contents) {
- ok(0, "$file contains tabs --WARNING");
- } else {
- ok(1, "$file has no tabs");
- }
- close (FILE);
+ open(FILE, "$file");
+ my @contents = <FILE>;
+ if (grep /\t/, @contents) {
+ ok(0, "$file contains tabs --WARNING");
+ }
+ else {
+ ok(1, "$file has no tabs");
+ }
+ close(FILE);
}
foreach my $file (@testitems) {
- open (FILE, "$file");
- my @contents = <FILE>;
- if (grep /\r/, @contents) {
- ok(0, "$file contains non-OS-conformant line endings --WARNING");
- } else {
- ok(1, "All line endings of $file are OS conformant");
- }
- close (FILE);
+ open(FILE, "$file");
+ my @contents = <FILE>;
+ if (grep /\r/, @contents) {
+ ok(0, "$file contains non-OS-conformant line endings --WARNING");
+ }
+ else {
+ ok(1, "All line endings of $file are OS conformant");
+ }
+ close(FILE);
}
foreach my $file (@testitems) {
- open (FILE, "$file");
- my $first_line = <FILE>;
- if ($first_line =~ /\xef\xbb\xbf/) {
- ok(0, "$file contains Byte Order Mark --WARNING");
- } else {
- ok(1, "$file is free of a Byte Order Mark");
- }
- close (FILE);
+ open(FILE, "$file");
+ my $first_line = <FILE>;
+ if ($first_line =~ /\xef\xbb\xbf/) {
+ ok(0, "$file contains Byte Order Mark --WARNING");
+ }
+ else {
+ ok(1, "$file is free of a Byte Order Mark");
+ }
+ close(FILE);
}
exit 0;
diff --git a/t/006spellcheck.t b/t/006spellcheck.t
index a7e7c6d72..c76449957 100644
--- a/t/006spellcheck.t
+++ b/t/006spellcheck.t
@@ -19,73 +19,77 @@ use Support::Files;
# -1 because 006spellcheck.t must not be checked.
use Test::More tests => scalar(@Support::Files::testitems)
- + scalar(@Support::Files::test_files) - 1;
+ + scalar(@Support::Files::test_files) - 1;
# Capture the TESTOUT from Test::More or Test::Builder for printing errors.
# This will handle verbosity for us automatically.
my $fh;
{
- no warnings qw(unopened); # Don't complain about non-existent filehandles
- if (-e \*Test::More::TESTOUT) {
- $fh = \*Test::More::TESTOUT;
- } elsif (-e \*Test::Builder::TESTOUT) {
- $fh = \*Test::Builder::TESTOUT;
- } else {
- $fh = \*STDOUT;
- }
+ no warnings qw(unopened); # Don't complain about non-existent filehandles
+ if (-e \*Test::More::TESTOUT) {
+ $fh = \*Test::More::TESTOUT;
+ }
+ elsif (-e \*Test::Builder::TESTOUT) {
+ $fh = \*Test::Builder::TESTOUT;
+ }
+ else {
+ $fh = \*STDOUT;
+ }
}
my @testitems = (@Support::Files::testitems, @Support::Files::test_files);
#add the words to check here:
my @evilwords = qw(
- anyways
- appearence
- arbitary
- cancelled
- critera
- databasa
- dependan
- existance
- existant
- paramater
- refered
- repsentation
- retreive
- suported
- varsion
+ anyways
+ appearence
+ arbitary
+ cancelled
+ critera
+ databasa
+ dependan
+ existance
+ existant
+ paramater
+ refered
+ repsentation
+ retreive
+ suported
+ varsion
);
my $evilwordsregexp = join('|', @evilwords);
foreach my $file (@testitems) {
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next if (!$file); # skip null entries
- # Do not try to validate this file as it obviously contains a list
- # of wrongly spelled words.
- next if ($file eq 't/006spellcheck.t');
-
- if (open (FILE, $file)) { # open the file for reading
-
- my $found_word = '';
-
- while (my $file_line = <FILE>) { # and go through the file line by line
- if ($file_line =~ /($evilwordsregexp)/i) { # found an evil word
- $found_word = $1;
- last;
- }
- }
-
- close (FILE);
-
- if ($found_word) {
- ok(0,"$file: found SPELLING ERROR $found_word --WARNING");
- } else {
- ok(1,"$file does not contain registered spelling errors");
- }
- } else {
- ok(0,"could not open $file for spellcheck --WARNING");
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next if (!$file); # skip null entries
+ # Do not try to validate this file as it obviously contains a list
+ # of wrongly spelled words.
+ next if ($file eq 't/006spellcheck.t');
+
+ if (open(FILE, $file)) { # open the file for reading
+
+ my $found_word = '';
+
+ while (my $file_line = <FILE>) { # and go through the file line by line
+ if ($file_line =~ /($evilwordsregexp)/i) { # found an evil word
+ $found_word = $1;
+ last;
+ }
+ }
+
+ close(FILE);
+
+ if ($found_word) {
+ ok(0, "$file: found SPELLING ERROR $found_word --WARNING");
+ }
+ else {
+ ok(1, "$file does not contain registered spelling errors");
}
+ }
+ else {
+ ok(0, "could not open $file for spellcheck --WARNING");
+ }
}
exit 0;
diff --git a/t/007util.t b/t/007util.t
index b6d23bc32..e25c66fe9 100644
--- a/t/007util.t
+++ b/t/007util.t
@@ -19,8 +19,8 @@ use Test::More tests => 17;
use DateTime;
BEGIN {
- use_ok('Bugzilla');
- use_ok('Bugzilla::Util');
+ use_ok('Bugzilla');
+ use_ok('Bugzilla::Util');
}
# We need to override user preferences so we can get an expected value when
@@ -29,38 +29,57 @@ Bugzilla->user->{'settings'}->{'timezone'}->{'value'} = "local";
# We need to know the local timezone for the date chosen in our tests.
# Below, tests are run against Nov. 24, 2002.
-my $tz = Bugzilla->local_timezone->short_name_for_datetime(DateTime->new(year => 2002, month => 11, day => 24));
+my $tz = Bugzilla->local_timezone->short_name_for_datetime(
+ DateTime->new(year => 2002, month => 11, day => 24));
# we don't test the taint functions since that's going to take some more work.
# XXX: test taint functions
#html_quote():
-is(html_quote("<lala&@>"),"&lt;lala&amp;&#64;&gt;",'html_quote');
+is(html_quote("<lala&@>"), "&lt;lala&amp;&#64;&gt;", 'html_quote');
#url_quote():
-is(url_quote("<lala&>gaa\"'[]{\\"),"%3Clala%26%3Egaa%22%27%5B%5D%7B%5C",'url_quote');
+is(url_quote("<lala&>gaa\"'[]{\\"),
+ "%3Clala%26%3Egaa%22%27%5B%5D%7B%5C", 'url_quote');
#trim():
-is(trim(" fg<*\$%>+=~~ "),'fg<*$%>+=~~','trim()');
+is(trim(" fg<*\$%>+=~~ "), 'fg<*$%>+=~~', 'trim()');
#format_time();
-is(format_time("2002.11.24 00:05"), "2002-11-24 00:05 $tz",'format_time("2002.11.24 00:05") is ' . format_time("2002.11.24 00:05"));
-is(format_time("2002.11.24 00:05:56"), "2002-11-24 00:05:56 $tz",'format_time("2002.11.24 00:05:56")');
-is(format_time("2002.11.24 00:05:56", "%Y-%m-%d %R"), '2002-11-24 00:05', 'format_time("2002.11.24 00:05:56", "%Y-%m-%d %R") (with no timezone)');
-is(format_time("2002.11.24 00:05:56", "%Y-%m-%d %R %Z"), "2002-11-24 00:05 $tz", 'format_time("2002.11.24 00:05:56", "%Y-%m-%d %R %Z") (with timezone)');
+is(
+ format_time("2002.11.24 00:05"),
+ "2002-11-24 00:05 $tz",
+ 'format_time("2002.11.24 00:05") is ' . format_time("2002.11.24 00:05")
+);
+is(
+ format_time("2002.11.24 00:05:56"),
+ "2002-11-24 00:05:56 $tz",
+ 'format_time("2002.11.24 00:05:56")'
+);
+is(
+ format_time("2002.11.24 00:05:56", "%Y-%m-%d %R"),
+ '2002-11-24 00:05',
+ 'format_time("2002.11.24 00:05:56", "%Y-%m-%d %R") (with no timezone)'
+);
+is(
+ format_time("2002.11.24 00:05:56", "%Y-%m-%d %R %Z"),
+ "2002-11-24 00:05 $tz",
+ 'format_time("2002.11.24 00:05:56", "%Y-%m-%d %R %Z") (with timezone)'
+);
# email_filter
my %email_strings = (
- 'somebody@somewhere.com' => 'somebody',
- 'Somebody <somebody@somewhere.com>' => 'Somebody <somebody>',
- 'One Person <one@person.com>, Two Person <two@person.com>'
- => 'One Person <one>, Two Person <two>',
- 'This string contains somebody@somewhere.com and also this@that.com'
- => 'This string contains somebody and also this',
+ 'somebody@somewhere.com' => 'somebody',
+ 'Somebody <somebody@somewhere.com>' => 'Somebody <somebody>',
+ 'One Person <one@person.com>, Two Person <two@person.com>' =>
+ 'One Person <one>, Two Person <two>',
+ 'This string contains somebody@somewhere.com and also this@that.com' =>
+ 'This string contains somebody and also this',
);
+
foreach my $input (keys %email_strings) {
- is(Bugzilla::Util::email_filter($input), $email_strings{$input},
- "email_filter('$input')");
+ is(Bugzilla::Util::email_filter($input),
+ $email_strings{$input}, "email_filter('$input')");
}
# validate_email_syntax. We need to override some parameters.
@@ -68,14 +87,18 @@ my $params = Bugzilla->params;
$params->{emailregexp} = '.*';
$params->{emailsuffix} = '';
my $ascii_email = 'admin@company.com';
+
# U+0430 returns the Cyrillic "а", which looks similar to the ASCII "a".
my $utf8_email = "\N{U+0430}dmin\@company.com";
-ok(validate_email_syntax($ascii_email), 'correctly formatted ASCII-only email address is valid');
-ok(!validate_email_syntax($utf8_email), 'correctly formatted email address with non-ASCII characters is rejected');
+ok(validate_email_syntax($ascii_email),
+ 'correctly formatted ASCII-only email address is valid');
+ok(!validate_email_syntax($utf8_email),
+ 'correctly formatted email address with non-ASCII characters is rejected');
# diff_arrays():
my @old_array = qw(alpha beta alpha gamma gamma beta alpha delta epsilon gamma);
my @new_array = qw(alpha alpha beta gamma epsilon delta beta delta);
+
# The order is not relevant when comparing both arrays for matching items,
# i.e. (foo bar) and (bar foo) are the same arrays (same items).
# But when returning data, we try to respect the initial order.
@@ -83,5 +106,6 @@ my @new_array = qw(alpha alpha beta gamma epsilon delta beta delta);
# Removed (in this order): gamma alpha gamma.
# Added (in this order): delta
my ($removed, $added) = diff_arrays(\@old_array, \@new_array);
-is_deeply($removed, [qw(gamma alpha gamma)], 'diff_array(\@old, \@new) (check removal)');
+is_deeply($removed, [qw(gamma alpha gamma)],
+ 'diff_array(\@old, \@new) (check removal)');
is_deeply($added, [qw(delta)], 'diff_array(\@old, \@new) (check addition)');
diff --git a/t/008filter.t b/t/008filter.t
index d86e6c7a6..6c9924020 100644
--- a/t/008filter.t
+++ b/t/008filter.t
@@ -29,196 +29,200 @@ use Cwd;
# Undefine the record separator so we can read in whole files at once
my $oldrecsep = $/;
-my $topdir = cwd;
+my $topdir = cwd;
$/ = undef;
our %safe;
foreach my $path (@Support::Templates::include_paths) {
- $path =~ s|\\|/|g if ON_WINDOWS; # convert \ to / in path if on windows
- $path =~ m|template/([^/]+)/([^/]+)|;
- my $lang = $1;
- my $flavor = $2;
-
- chdir $topdir; # absolute path
- my @testitems = Support::Templates::find_actual_files($path);
- chdir $topdir; # absolute path
-
- next unless @testitems;
-
- # Some people require this, others don't. No-one knows why.
- chdir $path; # relative path
-
- # We load a %safe list of acceptable exceptions.
- if (-r "filterexceptions.pl") {
- do "filterexceptions.pl";
- if (ON_WINDOWS) {
- # filterexceptions.pl uses / separated paths, while
- # find_actual_files returns \ separated ones on Windows.
- # Here, we convert the filter exception hash to use \.
- foreach my $file (keys %safe) {
- my $orig_file = $file;
- $file =~ s|/|\\|g;
- if ($file ne $orig_file) {
- $safe{$file} = $safe{$orig_file};
- delete $safe{$orig_file};
- }
- }
+ $path =~ s|\\|/|g if ON_WINDOWS; # convert \ to / in path if on windows
+ $path =~ m|template/([^/]+)/([^/]+)|;
+ my $lang = $1;
+ my $flavor = $2;
+
+ chdir $topdir; # absolute path
+ my @testitems = Support::Templates::find_actual_files($path);
+ chdir $topdir; # absolute path
+
+ next unless @testitems;
+
+ # Some people require this, others don't. No-one knows why.
+ chdir $path; # relative path
+
+ # We load a %safe list of acceptable exceptions.
+ if (-r "filterexceptions.pl") {
+ do "filterexceptions.pl";
+ if (ON_WINDOWS) {
+
+ # filterexceptions.pl uses / separated paths, while
+ # find_actual_files returns \ separated ones on Windows.
+ # Here, we convert the filter exception hash to use \.
+ foreach my $file (keys %safe) {
+ my $orig_file = $file;
+ $file =~ s|/|\\|g;
+ if ($file ne $orig_file) {
+ $safe{$file} = $safe{$orig_file};
+ delete $safe{$orig_file};
}
+ }
}
-
- # We preprocess the %safe hash of lists into a hash of hashes. This allows
- # us to flag which members were not found, and report that as a warning,
- # thereby keeping the lists clean.
- foreach my $file (keys %safe) {
- if (ref $safe{$file} eq 'ARRAY') {
- my $list = $safe{$file};
- $safe{$file} = {};
- foreach my $directive (@$list) {
- $safe{$file}{$directive} = 0;
- }
- }
+ }
+
+ # We preprocess the %safe hash of lists into a hash of hashes. This allows
+ # us to flag which members were not found, and report that as a warning,
+ # thereby keeping the lists clean.
+ foreach my $file (keys %safe) {
+ if (ref $safe{$file} eq 'ARRAY') {
+ my $list = $safe{$file};
+ $safe{$file} = {};
+ foreach my $directive (@$list) {
+ $safe{$file}{$directive} = 0;
+ }
}
+ }
- foreach my $file (@testitems) {
- # There are some files we don't check, because there is no need to
- # filter their contents due to their content-type.
- if ($file =~ /\.(pm|txt|rst|png)\.tmpl$/) {
- ok(1, "($lang/$flavor) $file is filter-safe");
- next;
- }
+ foreach my $file (@testitems) {
- # Read the entire file into a string
- open (FILE, "<$file") || die "Can't open $file: $!\n";
- my $slurp = <FILE>;
- close (FILE);
+ # There are some files we don't check, because there is no need to
+ # filter their contents due to their content-type.
+ if ($file =~ /\.(pm|txt|rst|png)\.tmpl$/) {
+ ok(1, "($lang/$flavor) $file is filter-safe");
+ next;
+ }
- my @unfiltered;
+ # Read the entire file into a string
+ open(FILE, "<$file") || die "Can't open $file: $!\n";
+ my $slurp = <FILE>;
+ close(FILE);
- # /g means we execute this loop for every match
- # /s means we ignore linefeeds in the regexp matches
- while ($slurp =~ /\[%(?:-|\+|~|=)?(.*?)(?:-|\+|~|=)?%\]/gs) {
- my $directive = $1;
+ my @unfiltered;
- my @lineno = ($` =~ m/\n/gs);
- my $lineno = scalar(@lineno) + 1;
+ # /g means we execute this loop for every match
+ # /s means we ignore linefeeds in the regexp matches
+ while ($slurp =~ /\[%(?:-|\+|~|=)?(.*?)(?:-|\+|~|=)?%\]/gs) {
+ my $directive = $1;
- if (!directive_ok($file, $directive)) {
+ my @lineno = ($` =~ m/\n/gs);
+ my $lineno = scalar(@lineno) + 1;
- # This intentionally makes no effort to eliminate duplicates; to do
- # so would merely make it more likely that the user would not
- # escape all instances when attempting to correct an error.
- push(@unfiltered, "$lineno:$directive");
- }
- }
+ if (!directive_ok($file, $directive)) {
- my $fullpath = File::Spec->catfile($path, $file);
+ # This intentionally makes no effort to eliminate duplicates; to do
+ # so would merely make it more likely that the user would not
+ # escape all instances when attempting to correct an error.
+ push(@unfiltered, "$lineno:$directive");
+ }
+ }
- if (@unfiltered) {
- my $uflist = join("\n ", @unfiltered);
- ok(0, "($lang/$flavor) $fullpath has unfiltered directives:\n $uflist\n--ERROR");
- }
- else {
- # Find any members of the exclusion list which were not found
- my @notfound;
- foreach my $directive (keys %{$safe{$file}}) {
- push(@notfound, $directive) if ($safe{$file}{$directive} == 0);
- }
-
- if (@notfound) {
- my $nflist = join("\n ", @notfound);
- ok(0, "($lang/$flavor) $fullpath - filterexceptions.pl has extra members:\n $nflist\n" .
- "--WARNING");
- }
- else {
- # Don't use the full path here - it's too long and unwieldy.
- ok(1, "($lang/$flavor) $file is filter-safe");
- }
- }
+ my $fullpath = File::Spec->catfile($path, $file);
+
+ if (@unfiltered) {
+ my $uflist = join("\n ", @unfiltered);
+ ok(0,
+ "($lang/$flavor) $fullpath has unfiltered directives:\n $uflist\n--ERROR");
}
+ else {
+ # Find any members of the exclusion list which were not found
+ my @notfound;
+ foreach my $directive (keys %{$safe{$file}}) {
+ push(@notfound, $directive) if ($safe{$file}{$directive} == 0);
+ }
+
+ if (@notfound) {
+ my $nflist = join("\n ", @notfound);
+ ok(0,
+ "($lang/$flavor) $fullpath - filterexceptions.pl has extra members:\n $nflist\n"
+ . "--WARNING");
+ }
+ else {
+ # Don't use the full path here - it's too long and unwieldy.
+ ok(1, "($lang/$flavor) $file is filter-safe");
+ }
+ }
+ }
}
sub directive_ok {
- my ($file, $directive) = @_;
+ my ($file, $directive) = @_;
- # Comments
- return 1 if $directive =~ /^#/;
+ # Comments
+ return 1 if $directive =~ /^#/;
- # Remove any leading/trailing whitespace.
- $directive =~ s/^\s*//;
- $directive =~ s/\s*$//;
+ # Remove any leading/trailing whitespace.
+ $directive =~ s/^\s*//;
+ $directive =~ s/\s*$//;
- # Ignore blocks explicitly marked as ok
- return 1 if $directive =~ /\b## no-008filter\b/;
+ # Ignore blocks explicitly marked as ok
+ return 1 if $directive =~ /\b## no-008filter\b/;
- # Empty directives are ok; they are usually line break helpers
- return 1 if $directive eq '';
+ # Empty directives are ok; they are usually line break helpers
+ return 1 if $directive eq '';
- # Make sure we're not looking for ./ in the $safe hash
- $file =~ s#^\./##;
+ # Make sure we're not looking for ./ in the $safe hash
+ $file =~ s#^\./##;
- # Exclude those on the nofilter list
- if (defined($safe{$file}{$directive})) {
- $safe{$file}{$directive}++;
- return 1;
- };
+ # Exclude those on the nofilter list
+ if (defined($safe{$file}{$directive})) {
+ $safe{$file}{$directive}++;
+ return 1;
+ }
- # Directives
- return 1 if $directive =~ /^(IF|END|UNLESS|FOREACH|PROCESS|INCLUDE|
+ # Directives
+ return 1 if $directive =~ /^(IF|END|UNLESS|FOREACH|PROCESS|INCLUDE|
BLOCK|USE|ELSE|NEXT|LAST|DEFAULT|FLUSH|
ELSIF|SET|SWITCH|CASE|WHILE|RETURN|STOP|
TRY|CATCH|FINAL|THROW|CLEAR|MACRO|FILTER|
RAWPERL|PERL|CALL|WRAPPER)/x;
- # ? :
- if ($directive =~ /.+\?(.+):(.+)/) {
- return 1 if directive_ok($file, $1) && directive_ok($file, $2);
- }
+ # ? :
+ if ($directive =~ /.+\?(.+):(.+)/) {
+ return 1 if directive_ok($file, $1) && directive_ok($file, $2);
+ }
- # + - * /
- return 1 if $directive =~ /[+\-*\/]/;
+ # + - * /
+ return 1 if $directive =~ /[+\-*\/]/;
- # Numbers
- return 1 if $directive =~ /^[0-9]+$/;
+ # Numbers
+ return 1 if $directive =~ /^[0-9]+$/;
- # Simple assignments
- return 1 if $directive =~ /^[\w\.\$\{\}]+\s+=\s+/;
+ # Simple assignments
+ return 1 if $directive =~ /^[\w\.\$\{\}]+\s+=\s+/;
- # Conditional literals with either sort of quotes
- # There must be no $ in the string for it to be a literal
- return 1 if $directive =~ /^(["'])[^\$]*[^\\]\1/;
- return 1 if $directive =~ /^(["'])\1/;
+ # Conditional literals with either sort of quotes
+ # There must be no $ in the string for it to be a literal
+ return 1 if $directive =~ /^(["'])[^\$]*[^\\]\1/;
+ return 1 if $directive =~ /^(["'])\1/;
- # Special values always used for numbers
- return 1 if $directive =~ /^[ijkn]$/;
- return 1 if $directive =~ /^count$/;
+ # Special values always used for numbers
+ return 1 if $directive =~ /^[ijkn]$/;
+ return 1 if $directive =~ /^count$/;
- # Params
- return 1 if $directive =~ /^Param\(/;
+ # Params
+ return 1 if $directive =~ /^Param\(/;
- # Hooks
- return 1 if $directive =~ /^Hook.process\(/;
+ # Hooks
+ return 1 if $directive =~ /^Hook.process\(/;
- # Other functions guaranteed to return OK output
- return 1 if $directive =~ /^(time2str|url)\(/;
+ # Other functions guaranteed to return OK output
+ return 1 if $directive =~ /^(time2str|url)\(/;
- # Safe Template Toolkit virtual methods
- return 1 if $directive =~ /\.(length$|size$|push\(|unshift\(|delete\()/;
+ # Safe Template Toolkit virtual methods
+ return 1 if $directive =~ /\.(length$|size$|push\(|unshift\(|delete\()/;
- # Special Template Toolkit loop variable
- return 1 if $directive =~ /^loop\.(index|count)$/;
+ # Special Template Toolkit loop variable
+ return 1 if $directive =~ /^loop\.(index|count)$/;
- # Branding terms
- return 1 if $directive =~ /^terms\./;
+ # Branding terms
+ return 1 if $directive =~ /^terms\./;
- # Things which are already filtered
- # Note: If a single directive prints two things, and only one is
- # filtered, we may not catch that case.
- return 1 if $directive =~ /FILTER\ (html|csv|js|base64|css_class_quote|ics|
+ # Things which are already filtered
+ # Note: If a single directive prints two things, and only one is
+ # filtered, we may not catch that case.
+ return 1 if $directive =~ /FILTER\ (html|csv|js|base64|css_class_quote|ics|
quoteUrls|time|uri|xml|lower|html_light|
obsolete|inactive|closed|unitconvert|
txt|html_linebreak|none|json|null|id|
markdown)\b/x;
- return 0;
+ return 0;
}
$/ = $oldrecsep;
diff --git a/t/009bugwords.t b/t/009bugwords.t
index ebfd99507..48a601513 100644
--- a/t/009bugwords.t
+++ b/t/009bugwords.t
@@ -32,48 +32,52 @@ use Test::More tests => ($Support::Templates::num_actual_files);
# Find all the templates
my @testitems;
for my $path (@Support::Templates::include_paths) {
- push(@testitems, map(File::Spec->catfile($path, $_),
- Support::Templates::find_actual_files($path)));
+ push(
+ @testitems,
+ map(File::Spec->catfile($path, $_),
+ Support::Templates::find_actual_files($path))
+ );
}
foreach my $file (@testitems) {
- my @errors;
-
- # Read the entire file into a string
- local $/;
- open (FILE, "<$file") || die "Can't open $file: $!\n";
- my $slurp = <FILE>;
- close (FILE);
-
- # /g means we execute this loop for every match
- # /s means we ignore linefeeds in the regexp matches
- # This extracts everything which is _not_ a directive.
- while ($slurp =~ /%\](.*?)(\[%|$)/gs) {
- my $text = $1;
-
- my @lineno = ($` =~ m/\n/gs);
- my $lineno = scalar(@lineno) + 1;
-
- # "a bug", "bug", "bugs"
- if (grep /(a?[\s>]bugs?[\s.:;,<])/i, $text) {
- # Exclude variable assignment.
- unless (grep /bugs =/, $text) {
- push(@errors, [$lineno, $text]);
- next;
- }
- }
+ my @errors;
+
+ # Read the entire file into a string
+ local $/;
+ open(FILE, "<$file") || die "Can't open $file: $!\n";
+ my $slurp = <FILE>;
+ close(FILE);
+
+ # /g means we execute this loop for every match
+ # /s means we ignore linefeeds in the regexp matches
+ # This extracts everything which is _not_ a directive.
+ while ($slurp =~ /%\](.*?)(\[%|$)/gs) {
+ my $text = $1;
+
+ my @lineno = ($` =~ m/\n/gs);
+ my $lineno = scalar(@lineno) + 1;
+
+ # "a bug", "bug", "bugs"
+ if (grep /(a?[\s>]bugs?[\s.:;,<])/i, $text) {
+
+ # Exclude variable assignment.
+ unless (grep /bugs =/, $text) {
+ push(@errors, [$lineno, $text]);
+ next;
+ }
}
+ }
- if (scalar(@errors)) {
- ok(0, "$file contains invalid bare words (e.g. 'bug') --WARNING");
+ if (scalar(@errors)) {
+ ok(0, "$file contains invalid bare words (e.g. 'bug') --WARNING");
- foreach my $error (@errors) {
- print "$error->[0]: $error->[1]\n";
- }
- }
- else {
- ok(1, "$file has no invalid barewords");
+ foreach my $error (@errors) {
+ print "$error->[0]: $error->[1]\n";
}
+ }
+ else {
+ ok(1, "$file has no invalid barewords");
+ }
}
exit 0;
diff --git a/t/010dependencies.t b/t/010dependencies.t
index 777d42ed1..ed6475689 100644
--- a/t/010dependencies.t
+++ b/t/010dependencies.t
@@ -30,7 +30,8 @@ use constant MODULE_REGEX => qr/
['"]?
([\w:\.\\]+)
/x;
-use constant BASE_REGEX => qr/^use (?:base|parent) (?:-norequire, )?qw\(([^\)]+)/;
+use constant BASE_REGEX =>
+ qr/^use (?:base|parent) (?:-norequire, )?qw\(([^\)]+)/;
# Extract all Perl modules.
foreach my $file (@Support::Files::testitems) {
@@ -42,46 +43,47 @@ foreach my $file (@Support::Files::testitems) {
}
foreach my $module (keys %mods) {
- my $reading = 1;
- my @use;
-
- open(SOURCE, $mods{$module});
- while (my $line = <SOURCE>) {
- last if ($line =~ /^__END__/);
- if ($line =~ /^=cut/) {
- $reading = 1;
- next;
- }
- next unless $reading;
- if ($line =~ /^=(head|over|item|back|pod|begin|end|for)/) {
- $reading = 0;
- next;
- }
- if ($line =~ /^package\s+([^;]);/) {
- $module = $1;
- }
- elsif ($line =~ BASE_REGEX or $line =~ MODULE_REGEX) {
- my $used_string = $1;
- # "use base"/"use parent" can have multiple modules
- my @used_array = split(/\s+/, $used_string);
- foreach my $used (@used_array) {
- next if $used !~ /^Bugzilla/;
- $used =~ s#/#::#g;
- $used =~ s#\.pm$##;
- $used =~ s#\$module#[^:]+#;
- $used =~ s#\${[^}]+}#[^:]+#;
- $used =~ s#[" ]##g;
- push(@use, grep(/^\Q$used\E$/, keys %mods));
- }
- }
+ my $reading = 1;
+ my @use;
+
+ open(SOURCE, $mods{$module});
+ while (my $line = <SOURCE>) {
+ last if ($line =~ /^__END__/);
+ if ($line =~ /^=cut/) {
+ $reading = 1;
+ next;
+ }
+ next unless $reading;
+ if ($line =~ /^=(head|over|item|back|pod|begin|end|for)/) {
+ $reading = 0;
+ next;
}
- close (SOURCE);
+ if ($line =~ /^package\s+([^;]);/) {
+ $module = $1;
+ }
+ elsif ($line =~ BASE_REGEX or $line =~ MODULE_REGEX) {
+ my $used_string = $1;
- foreach my $u (@use) {
- if (!grep {$_ eq $u} @{$deps{$module}}) {
- push(@{$deps{$module}}, $u);
+ # "use base"/"use parent" can have multiple modules
+ my @used_array = split(/\s+/, $used_string);
+ foreach my $used (@used_array) {
+ next if $used !~ /^Bugzilla/;
+ $used =~ s#/#::#g;
+ $used =~ s#\.pm$##;
+ $used =~ s#\$module#[^:]+#;
+ $used =~ s#\${[^}]+}#[^:]+#;
+ $used =~ s#[" ]##g;
+ push(@use, grep(/^\Q$used\E$/, keys %mods));
}
}
+ }
+ close(SOURCE);
+
+ foreach my $u (@use) {
+ if (!grep { $_ eq $u } @{$deps{$module}}) {
+ push(@{$deps{$module}}, $u);
+ }
+ }
}
sub creates_loop {
diff --git a/t/011pod.t b/t/011pod.t
index 4f5fa87f7..3c6eb200f 100644
--- a/t/011pod.t
+++ b/t/011pod.t
@@ -24,29 +24,33 @@ use Test::More tests => scalar(@Support::Files::testitems);
# This will handle verbosity for us automatically.
my $fh;
{
- no warnings 'unopened';
- if (-e \*Test::More::TESTOUT) {
- $fh = \*Test::More::TESTOUT;
- } elsif (-e \*Test::Builder::TESTOUT) {
- $fh = \*Test::Builder::TESTOUT;
- } else {
- $fh = \*STDOUT;
- }
+ no warnings 'unopened';
+ if (-e \*Test::More::TESTOUT) {
+ $fh = \*Test::More::TESTOUT;
+ }
+ elsif (-e \*Test::Builder::TESTOUT) {
+ $fh = \*Test::Builder::TESTOUT;
+ }
+ else {
+ $fh = \*STDOUT;
+ }
}
my @testitems = @Support::Files::testitems;
foreach my $file (@testitems) {
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next if (!$file); # skip null entries
- my $error_count = podchecker($file, $fh);
- if ($error_count < 0) {
- ok(1,"$file does not contain any POD");
- } elsif ($error_count == 0) {
- ok(1,"$file has correct POD syntax");
- } else {
- ok(0,"$file has incorrect POD syntax --ERROR");
- }
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next if (!$file); # skip null entries
+ my $error_count = podchecker($file, $fh);
+ if ($error_count < 0) {
+ ok(1, "$file does not contain any POD");
+ }
+ elsif ($error_count == 0) {
+ ok(1, "$file has correct POD syntax");
+ }
+ else {
+ ok(0, "$file has incorrect POD syntax --ERROR");
+ }
}
exit 0;
diff --git a/t/012throwables.t b/t/012throwables.t
index af7a27eb2..4a5d9e0a5 100644
--- a/t/012throwables.t
+++ b/t/012throwables.t
@@ -6,7 +6,6 @@
# defined by the Mozilla Public License, v. 2.0.
-
##################
#Bugzilla Test 12#
######Errors######
@@ -32,11 +31,11 @@ push @{$Errors{code}{template_error}{used_in}{'Bugzilla/Error.pm'}}, 0;
# Define files to test. Each file would have a list of error messages, if any.
my %test_templates = ();
-my %test_modules = ();
+my %test_modules = ();
# Find all modules
foreach my $module (@Support::Files::testitems) {
- $test_modules{$module} = ();
+ $test_modules{$module} = ();
}
# Find all error templates
@@ -44,20 +43,20 @@ foreach my $module (@Support::Files::testitems) {
# hairy. But let us do it only once.
foreach my $include_path (@include_paths) {
- foreach my $path (@{$actual_files{$include_path}}) {
- my $file = File::Spec->catfile($include_path, $path);
- $file =~ s/\s.*$//; # nuke everything after the first space
- $file =~ s|\\|/|g if ON_WINDOWS; # convert \ to / in path if on windows
- $test_templates{$file} = ()
- if $file =~ m#global/(code|user)-error(?:-errors)?\.html\.tmpl#;
-
- # Make sure the extension is not disabled
- if ($file =~ m#^(extensions/[^/]+/)#) {
- $test_templates{$file} = ()
- if ! -e "${1}disabled"
- && $file =~ m#global/(code|user)-error-errors\.html\.tmpl#;
- }
+ foreach my $path (@{$actual_files{$include_path}}) {
+ my $file = File::Spec->catfile($include_path, $path);
+ $file =~ s/\s.*$//; # nuke everything after the first space
+ $file =~ s|\\|/|g if ON_WINDOWS; # convert \ to / in path if on windows
+ $test_templates{$file} = ()
+ if $file =~ m#global/(code|user)-error(?:-errors)?\.html\.tmpl#;
+
+ # Make sure the extension is not disabled
+ if ($file =~ m#^(extensions/[^/]+/)#) {
+ $test_templates{$file} = ()
+ if !-e "${1}disabled"
+ && $file =~ m#global/(code|user)-error-errors\.html\.tmpl#;
}
+ }
}
# Count the tests. The +1 is for checking the WS_ERROR_CODE errors.
@@ -69,112 +68,115 @@ plan tests => $tests;
# Collect all errors defined in templates
foreach my $file (keys %test_templates) {
- $file =~ m|template/([^/]+).*/global/([^/]+)-error(?:-errors)?\.html\.tmpl|;
- my $lang = $1;
- my $errtype = $2;
-
- if (! open (TMPL, $file)) {
- Register(\%test_templates, $file, "could not open file --WARNING");
- next;
- }
-
- my $lineno=0;
- while (my $line = <TMPL>) {
- $lineno++;
- if ($line =~ /\[%\s[A-Z]+\s*error\s*==\s*"(.+)"\s*%\]/) {
- my $errtag = $1;
- if ($errtag =~ /\s/) {
- Register(\%test_templates, $file,
- "has an error definition \"$errtag\" at line $lineno with "
- . "space(s) embedded --ERROR");
- }
- else {
- push @{$Errors{$errtype}{$errtag}{defined_in}{$lang}{$file}}, $lineno;
- }
- }
+ $file =~ m|template/([^/]+).*/global/([^/]+)-error(?:-errors)?\.html\.tmpl|;
+ my $lang = $1;
+ my $errtype = $2;
+
+ if (!open(TMPL, $file)) {
+ Register(\%test_templates, $file, "could not open file --WARNING");
+ next;
+ }
+
+ my $lineno = 0;
+ while (my $line = <TMPL>) {
+ $lineno++;
+ if ($line =~ /\[%\s[A-Z]+\s*error\s*==\s*"(.+)"\s*%\]/) {
+ my $errtag = $1;
+ if ($errtag =~ /\s/) {
+ Register(\%test_templates, $file,
+ "has an error definition \"$errtag\" at line $lineno with "
+ . "space(s) embedded --ERROR");
+ }
+ else {
+ push @{$Errors{$errtype}{$errtag}{defined_in}{$lang}{$file}}, $lineno;
+ }
}
- close(TMPL);
+ }
+ close(TMPL);
}
# Collect all used errors from cgi/pm files
foreach my $file (keys %test_modules) {
- $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
- next if (!$file); # skip null entries
- if (! open (TMPL, $file)) {
- Register(\%test_modules, $file, "could not open file --WARNING");
- next;
- }
-
- my $lineno = 0;
- while (my $line = <TMPL>) {
- last if $line =~ /^__END__/; # skip the POD (at least in
- # Bugzilla/Error.pm)
- $lineno++;
- if ($line =~
-/^[^#]*\b(Throw(Code|User)Error|(user_)?error\s+=>)\s*\(?\s*["'](.*?)['"]/) {
- my $errtype;
- # If it's a normal ThrowCode/UserError
- if ($2) {
- $errtype = lc($2);
- }
- # If it's an AUTH_ERROR tag
- else {
- $errtype = $3 ? 'user' : 'code';
- }
- my $errtag = $4;
- push @{$Errors{$errtype}{$errtag}{used_in}{$file}}, $lineno;
- }
+ $file =~ s/\s.*$//; # nuke everything after the first space (#comment)
+ next if (!$file); # skip null entries
+ if (!open(TMPL, $file)) {
+ Register(\%test_modules, $file, "could not open file --WARNING");
+ next;
+ }
+
+ my $lineno = 0;
+ while (my $line = <TMPL>) {
+ last if $line =~ /^__END__/; # skip the POD (at least in
+ # Bugzilla/Error.pm)
+ $lineno++;
+ if ($line
+ =~ /^[^#]*\b(Throw(Code|User)Error|(user_)?error\s+=>)\s*\(?\s*["'](.*?)['"]/)
+ {
+ my $errtype;
+
+ # If it's a normal ThrowCode/UserError
+ if ($2) {
+ $errtype = lc($2);
+ }
+
+ # If it's an AUTH_ERROR tag
+ else {
+ $errtype = $3 ? 'user' : 'code';
+ }
+ my $errtag = $4;
+ push @{$Errors{$errtype}{$errtag}{used_in}{$file}}, $lineno;
}
+ }
- close(TMPL);
+ close(TMPL);
}
# Now let us start the checks
foreach my $errtype (keys %Errors) {
- foreach my $errtag (keys %{$Errors{$errtype}}) {
- # Check for undefined tags
- if (!defined $Errors{$errtype}{$errtag}{defined_in}) {
- UsedIn($errtype, $errtag, "any");
+ foreach my $errtag (keys %{$Errors{$errtype}}) {
+
+ # Check for undefined tags
+ if (!defined $Errors{$errtype}{$errtag}{defined_in}) {
+ UsedIn($errtype, $errtag, "any");
+ }
+ else {
+ # Check for all languages!!!
+ my @langs = ();
+ foreach my $lang (@languages) {
+ if (!defined $Errors{$errtype}{$errtag}{defined_in}{$lang}) {
+ push @langs, $lang;
}
- else {
- # Check for all languages!!!
- my @langs = ();
- foreach my $lang (@languages) {
- if (!defined $Errors{$errtype}{$errtag}{defined_in}{$lang}) {
- push @langs, $lang;
- }
- }
- if (scalar @langs) {
- UsedIn($errtype, $errtag, join(', ',@langs));
- }
-
- # Now check for tag usage in all DEFINED languages
- foreach my $lang (keys %{$Errors{$errtype}{$errtag}{defined_in}}) {
- if (!defined $Errors{$errtype}{$errtag}{used_in}) {
- DefinedIn($errtype, $errtag, $lang);
- }
- }
+ }
+ if (scalar @langs) {
+ UsedIn($errtype, $errtag, join(', ', @langs));
+ }
+
+ # Now check for tag usage in all DEFINED languages
+ foreach my $lang (keys %{$Errors{$errtype}{$errtag}{defined_in}}) {
+ if (!defined $Errors{$errtype}{$errtag}{used_in}) {
+ DefinedIn($errtype, $errtag, $lang);
}
+ }
}
+ }
}
# And make sure that everything defined in WS_ERROR_CODE
# is actually a valid error.
foreach my $err_name (keys %{WS_ERROR_CODE()}) {
- if (!defined $Errors{'code'}{$err_name}
- && !defined $Errors{'user'}{$err_name})
- {
- Register(\%test_modules, 'WS_ERROR_CODE',
- "Error tag '$err_name' is used in WS_ERROR_CODE in"
- . " Bugzilla/WebService/Constants.pm"
- . " but not defined in any template, and not used in any code.");
- }
+ if (!defined $Errors{'code'}{$err_name} && !defined $Errors{'user'}{$err_name})
+ {
+ Register(\%test_modules, 'WS_ERROR_CODE',
+ "Error tag '$err_name' is used in WS_ERROR_CODE in"
+ . " Bugzilla/WebService/Constants.pm"
+ . " but not defined in any template, and not used in any code.");
+ }
}
# Now report modules results
foreach my $file (sort keys %test_modules) {
- Report($file, @{$test_modules{$file}});
+ Report($file, @{$test_modules{$file}});
}
# And report WS_ERROR_CODE results
@@ -182,56 +184,67 @@ Report('WS_ERROR_CODE', @{$test_modules{'WS_ERROR_CODE'}});
# Now report templates results
foreach my $file (sort keys %test_templates) {
- Report($file, @{$test_templates{$file}});
+ Report($file, @{$test_templates{$file}});
}
sub Register {
- my ($hash, $file, $message, $warning) = @_;
- # If set to 1, $warning will avoid the test to fail.
- $warning ||= 0;
- push(@{$hash->{$file}}, {'message' => $message, 'warning' => $warning});
+ my ($hash, $file, $message, $warning) = @_;
+
+ # If set to 1, $warning will avoid the test to fail.
+ $warning ||= 0;
+ push(@{$hash->{$file}}, {'message' => $message, 'warning' => $warning});
}
sub Report {
- my ($file, @errors) = @_;
- if (scalar @errors) {
- # Do we only have warnings to report or also real errors?
- my @real_errors = grep {$_->{'warning'} == 0} @errors;
- # Extract error messages.
- @errors = map {$_->{'message'}} @errors;
- if (scalar(@real_errors)) {
- ok(0, "$file has ". scalar(@errors) ." error(s):\n" . join("\n", @errors));
- }
- else {
- ok(1, "--WARNING $file has " . scalar(@errors) .
- " unused error tag(s):\n" . join("\n", @errors));
- }
+ my ($file, @errors) = @_;
+ if (scalar @errors) {
+
+ # Do we only have warnings to report or also real errors?
+ my @real_errors = grep { $_->{'warning'} == 0 } @errors;
+
+ # Extract error messages.
+ @errors = map { $_->{'message'} } @errors;
+ if (scalar(@real_errors)) {
+ ok(0, "$file has " . scalar(@errors) . " error(s):\n" . join("\n", @errors));
}
else {
- # This is used for both code and template files, so let's use
- # file-independent phrase
- ok(1, "$file uses error tags correctly");
+ ok(1,
+ "--WARNING $file has "
+ . scalar(@errors)
+ . " unused error tag(s):\n"
+ . join("\n", @errors));
}
+ }
+ else {
+ # This is used for both code and template files, so let's use
+ # file-independent phrase
+ ok(1, "$file uses error tags correctly");
+ }
}
sub UsedIn {
- my ($errtype, $errtag, $lang) = @_;
- $lang = $lang || "any";
- foreach my $file (keys %{$Errors{$errtype}{$errtag}{used_in}}) {
- Register(\%test_modules, $file,
- "$errtype error tag '$errtag' is used at line(s) ("
- . join (',', @{$Errors{$errtype}{$errtag}{used_in}{$file}})
- . ") but not defined for language(s): $lang");
- }
+ my ($errtype, $errtag, $lang) = @_;
+ $lang = $lang || "any";
+ foreach my $file (keys %{$Errors{$errtype}{$errtag}{used_in}}) {
+ Register(\%test_modules, $file,
+ "$errtype error tag '$errtag' is used at line(s) ("
+ . join(',', @{$Errors{$errtype}{$errtag}{used_in}{$file}})
+ . ") but not defined for language(s): $lang");
+ }
}
+
sub DefinedIn {
- my ($errtype, $errtag, $lang) = @_;
- foreach my $file (keys %{$Errors{$errtype}{$errtag}{defined_in}{$lang}}) {
- Register(\%test_templates, $file,
- "$errtype error tag '$errtag' is defined at line(s) ("
- . join (',', @{$Errors{$errtype}{$errtag}{defined_in}{$lang}{$file}})
- . ") but is not used anywhere", 1);
- }
+ my ($errtype, $errtag, $lang) = @_;
+ foreach my $file (keys %{$Errors{$errtype}{$errtag}{defined_in}{$lang}}) {
+ Register(
+ \%test_templates,
+ $file,
+ "$errtype error tag '$errtag' is defined at line(s) ("
+ . join(',', @{$Errors{$errtype}{$errtag}{defined_in}{$lang}{$file}})
+ . ") but is not used anywhere",
+ 1
+ );
+ }
}
exit 0;
diff --git a/t/901-secure-mail-loop.t b/t/901-secure-mail-loop.t
index 5f6230a7d..2959626fa 100644
--- a/t/901-secure-mail-loop.t
+++ b/t/901-secure-mail-loop.t
@@ -15,20 +15,20 @@ use Crypt::OpenPGP;
my $pubring = new Crypt::OpenPGP::KeyRing(Data => PUBLIC_KEY());
my $pgp = new Crypt::OpenPGP(PubRing => $pubring);
{
- local $SIG{ALRM} = sub { fail("stuck in a loop"); exit; };
- alarm(120);
- my $encrypted = $pgp->encrypt(
- Data => "hello, world",
- Recipients => "@",
- Cipher => 'CAST5',
- Armour => 0
- );
- alarm(0);
+ local $SIG{ALRM} = sub { fail("stuck in a loop"); exit; };
+ alarm(120);
+ my $encrypted = $pgp->encrypt(
+ Data => "hello, world",
+ Recipients => "@",
+ Cipher => 'CAST5',
+ Armour => 0
+ );
+ alarm(0);
}
pass("didn't get stuck in a loop");
sub PUBLIC_KEY {
- return <<'KEY';
+ return <<'KEY';
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.9 (GNU/Linux)
diff --git a/t/902-crypt-openpgp-random.t b/t/902-crypt-openpgp-random.t
index a692ea589..12b662e5e 100644
--- a/t/902-crypt-openpgp-random.t
+++ b/t/902-crypt-openpgp-random.t
@@ -13,13 +13,13 @@ use Test::More tests => 2;
use Crypt::OpenPGP::Util;
{
- local $SIG{ALRM} = sub {
- fail("getting random bytes froze program");
- exit;
- };
- alarm(60);
- my $bytes = Crypt::OpenPGP::Util::get_random_bytes(32);
- alarm(0);
- pass("getting random bytes didn't freeze program");
- is(length $bytes, 32, "got 32 bytes");
+ local $SIG{ALRM} = sub {
+ fail("getting random bytes froze program");
+ exit;
+ };
+ alarm(60);
+ my $bytes = Crypt::OpenPGP::Util::get_random_bytes(32);
+ alarm(0);
+ pass("getting random bytes didn't freeze program");
+ is(length $bytes, 32, "got 32 bytes");
}
diff --git a/t/903-passwdqc-conf.t b/t/903-passwdqc-conf.t
index fe7ce9b53..718947377 100644
--- a/t/903-passwdqc-conf.t
+++ b/t/903-passwdqc-conf.t
@@ -12,12 +12,28 @@ use autodie;
use Test::More 1.302;
use ok 'Bugzilla::Config::Auth';
-ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("undef, 24, 11, 8, 7")) == 0, "default value is valid");
-ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("underf, 24, 11, 8, 7")) != 0, "underf is not valid");
-is(Bugzilla::Config::Auth::_check_passwdqc_min("undef, 24, 25, 8, 7"), "Int2 is larger than Int1 (24)", "25 can't come after 24");
-ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("")) != 0, "empty string is invalid");
-ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("24")) != 0, "24 is invalid");
-ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("-24")) != 0, "-24 is invalid");
-ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("10, 10, 10, 10, 0")) != 0, "10, 10, 10, 10, 0 is invalid");
+ok(
+ length(Bugzilla::Config::Auth::_check_passwdqc_min("undef, 24, 11, 8, 7")) == 0,
+ "default value is valid"
+);
+ok(
+ length(Bugzilla::Config::Auth::_check_passwdqc_min("underf, 24, 11, 8, 7"))
+ != 0,
+ "underf is not valid"
+);
+is(
+ Bugzilla::Config::Auth::_check_passwdqc_min("undef, 24, 25, 8, 7"),
+ "Int2 is larger than Int1 (24)",
+ "25 can't come after 24"
+);
+ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("")) != 0,
+ "empty string is invalid");
+ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("24")) != 0,
+ "24 is invalid");
+ok(length(Bugzilla::Config::Auth::_check_passwdqc_min("-24")) != 0,
+ "-24 is invalid");
+ok(
+ length(Bugzilla::Config::Auth::_check_passwdqc_min("10, 10, 10, 10, 0")) != 0,
+ "10, 10, 10, 10, 0 is invalid");
done_testing;
diff --git a/t/Support/Files.pm b/t/Support/Files.pm
index 603d95cf9..7142b11b9 100644
--- a/t/Support/Files.pm
+++ b/t/Support/Files.pm
@@ -17,56 +17,58 @@ use File::Find;
our @additional_files = ();
use constant IGNORE => qw(
- Bugzilla/DuoAPI.pm
- Bugzilla/DuoWeb.pm
+ Bugzilla/DuoAPI.pm
+ Bugzilla/DuoWeb.pm
);
our @files = glob('*');
-find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/;}, qw(Bugzilla docs));
+find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/; },
+ qw(Bugzilla docs));
push(@files, 'extensions/create.pl', 'docs/makedocs.pl', 'cpanfile');
-our @extensions =
- grep { $_ ne 'extensions/create.pl' && ! -e "$_/disabled" }
- glob('extensions/*');
+our @extensions = grep { $_ ne 'extensions/create.pl' && !-e "$_/disabled" }
+ glob('extensions/*');
foreach my $extension (@extensions) {
- find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$|\.pl$/;}, $extension);
+ find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$|\.pl$/; },
+ $extension);
}
our @test_files = glob('t/*.t xt/*/*.t');
foreach my $extension (@extensions) {
- # Skip disabled extensions
- next if -e "$extension/disabled";
- find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/;}, $extension);
+ # Skip disabled extensions
+ next if -e "$extension/disabled";
+
+ find(sub { push(@files, $File::Find::name) if $_ =~ /\.pm$/; }, $extension);
}
sub isTestingFile {
- my ($file) = @_;
- my $exclude;
-
- foreach my $ignore (IGNORE) {
- return undef if $ignore eq $file;
- }
-
- if ($file =~ /\.psgi$|\.cgi$|\.pl$|\.pm$/) {
- return 1;
- }
- my $additional;
- foreach $additional (@additional_files) {
- if ($file eq $additional) { return 1; }
- }
- return undef;
+ my ($file) = @_;
+ my $exclude;
+
+ foreach my $ignore (IGNORE) {
+ return undef if $ignore eq $file;
+ }
+
+ if ($file =~ /\.psgi$|\.cgi$|\.pl$|\.pm$/) {
+ return 1;
+ }
+ my $additional;
+ foreach $additional (@additional_files) {
+ if ($file eq $additional) { return 1; }
+ }
+ return undef;
}
our (@testitems, @module_files);
foreach my $currentfile (@files) {
- if (isTestingFile($currentfile)) {
- push(@testitems, $currentfile);
- }
- push(@module_files, $currentfile) if $currentfile =~ /\.pm$/;
+ if (isTestingFile($currentfile)) {
+ push(@testitems, $currentfile);
+ }
+ push(@module_files, $currentfile) if $currentfile =~ /\.pm$/;
}
1;
diff --git a/t/Support/Templates.pm b/t/Support/Templates.pm
index 5071d67ae..f5a3c8b2f 100644
--- a/t/Support/Templates.pm
+++ b/t/Support/Templates.pm
@@ -13,9 +13,9 @@ use warnings;
use lib 't';
use base qw(Exporter);
-@Support::Templates::EXPORT =
- qw(@languages @include_paths @english_default_include_paths
- %include_path @referenced_files %actual_files $num_actual_files);
+@Support::Templates::EXPORT
+ = qw(@languages @include_paths @english_default_include_paths
+ %include_path @referenced_files %actual_files $num_actual_files);
use Bugzilla;
use Bugzilla::Constants;
@@ -26,15 +26,15 @@ use File::Find;
use File::Spec;
# English default include paths
-our @english_default_include_paths =
- (File::Spec->catdir(bz_locations()->{'templatedir'}, 'en', 'default'));
+our @english_default_include_paths
+ = (File::Spec->catdir(bz_locations()->{'templatedir'}, 'en', 'default'));
# And the extensions too
foreach my $extension (@Support::Files::extensions) {
- my $dir = File::Spec->catdir($extension, 'template', 'en', 'default');
- if (-e $dir) {
- push @english_default_include_paths, $dir;
- }
+ my $dir = File::Spec->catdir($extension, 'template', 'en', 'default');
+ if (-e $dir) {
+ push @english_default_include_paths, $dir;
+ }
}
# Files which are referenced in the cgi files
@@ -47,37 +47,39 @@ our %actual_files = ();
our $num_actual_files = 0;
# Set the template available languages and include paths
-our @languages = @{ Bugzilla->languages };
-our @include_paths = @{ template_include_path({ language => Bugzilla->languages }) };
+our @languages = @{Bugzilla->languages};
+our @include_paths
+ = @{template_include_path({language => Bugzilla->languages})};
our @files;
# Local subroutine used with File::Find
sub find_templates {
- # Prune CVS directories
- if (-d $_ && $_ eq 'CVS') {
- $File::Find::prune = 1;
- return;
- }
- # Only include files ending in '.tmpl'
- if (-f $_ && $_ =~ m/\.tmpl$/i) {
- my $filename;
- my $local_dir = File::Spec->abs2rel($File::Find::dir,
- $File::Find::topdir);
+ # Prune CVS directories
+ if (-d $_ && $_ eq 'CVS') {
+ $File::Find::prune = 1;
+ return;
+ }
- # File::Spec 3.13 and newer return "." instead of "" if both
- # arguments of abs2rel() are identical.
- $local_dir = "" if ($local_dir eq ".");
+ # Only include files ending in '.tmpl'
+ if (-f $_ && $_ =~ m/\.tmpl$/i) {
+ my $filename;
+ my $local_dir = File::Spec->abs2rel($File::Find::dir, $File::Find::topdir);
- if ($local_dir) {
- $filename = File::Spec->catfile($local_dir, $_);
- } else {
- $filename = $_;
- }
+ # File::Spec 3.13 and newer return "." instead of "" if both
+ # arguments of abs2rel() are identical.
+ $local_dir = "" if ($local_dir eq ".");
- push(@files, $filename);
+ if ($local_dir) {
+ $filename = File::Spec->catfile($local_dir, $_);
}
+ else {
+ $filename = $_;
+ }
+
+ push(@files, $filename);
+ }
}
# Scan the given template include path for templates
@@ -90,7 +92,7 @@ sub find_actual_files {
foreach my $include_path (@include_paths) {
- $actual_files{$include_path} = [ find_actual_files($include_path) ];
+ $actual_files{$include_path} = [find_actual_files($include_path)];
$num_actual_files += scalar(@{$actual_files{$include_path}});
}
@@ -99,20 +101,21 @@ foreach my $include_path (@include_paths) {
my %seen;
foreach my $file (@Support::Files::testitems) {
- open (FILE, $file);
- my @lines = <FILE>;
- close (FILE);
- foreach my $line (@lines) {
- if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
- my $template = $1;
- # Ignore templates with $ in the name, since they're
- # probably vars, not real files
- next if $template =~ m/\$/;
- next if $seen{$template};
- push (@referenced_files, $template);
- $seen{$template} = 1;
- }
+ open(FILE, $file);
+ my @lines = <FILE>;
+ close(FILE);
+ foreach my $line (@lines) {
+ if ($line =~ m/template->process\(\"(.+?)\", .+?\)/) {
+ my $template = $1;
+
+ # Ignore templates with $ in the name, since they're
+ # probably vars, not real files
+ next if $template =~ m/\$/;
+ next if $seen{$template};
+ push(@referenced_files, $template);
+ $seen{$template} = 1;
}
+ }
}
1;
diff --git a/t/bmo/comments.t b/t/bmo/comments.t
index 00002040c..323d1730f 100644
--- a/t/bmo/comments.t
+++ b/t/bmo/comments.t
@@ -22,51 +22,50 @@ Bugzilla->error_mode(ERROR_MODE_DIE);
my $user = Bugzilla::User->check({id => 1});
Bugzilla->set_user($user);
-my $bug_1 = Bugzilla::Bug->create(
- {
- short_desc => 'A test bug',
- product => 'Firefox',
- component => 'General',,
- bug_severity => 'normal',
- groups => [],
- op_sys => 'Unspecified',
- rep_platform => 'Unspecified',
- version => 'Trunk',
- keywords => [],
- cc => [],
- comment => 'This is a brand new bug',
- assigned_to => Bugzilla->params->{'nobody_user'},
- }
-);
+my $bug_1 = Bugzilla::Bug->create({
+ short_desc => 'A test bug',
+ product => 'Firefox',
+ component => 'General',
+ ,
+ bug_severity => 'normal',
+ groups => [],
+ op_sys => 'Unspecified',
+ rep_platform => 'Unspecified',
+ version => 'Trunk',
+ keywords => [],
+ cc => [],
+ comment => 'This is a brand new bug',
+ assigned_to => Bugzilla->params->{'nobody_user'},
+});
ok($bug_1->id, "got a new bug");
-my $urlbase = Bugzilla->localconfig->{urlbase};
+my $urlbase = Bugzilla->localconfig->{urlbase};
my $bug_1_id = $bug_1->id;
-my $bug_2 = Bugzilla::Bug->create(
- {
- short_desc => 'A bug that references another bug',
- product => 'Firefox',
- component => 'General',,
- bug_severity => 'normal',
- groups => [],
- op_sys => 'Unspecified',
- rep_platform => 'Unspecified',
- version => 'Trunk',
- keywords => [],
- cc => [],
- comment => "This is related to ${urlbase}show_bug.cgi?id=$bug_1_id",
- assigned_to => Bugzilla->params->{'nobody_user'},
- }
-);
+my $bug_2 = Bugzilla::Bug->create({
+ short_desc => 'A bug that references another bug',
+ product => 'Firefox',
+ component => 'General',
+ ,
+ bug_severity => 'normal',
+ groups => [],
+ op_sys => 'Unspecified',
+ rep_platform => 'Unspecified',
+ version => 'Trunk',
+ keywords => [],
+ cc => [],
+ comment => "This is related to ${urlbase}show_bug.cgi?id=$bug_1_id",
+ assigned_to => Bugzilla->params->{'nobody_user'},
+});
my $bug_2_id = $bug_2->id;
Bugzilla::Template::quoteUrls(
- $bug_2->comments->[0]->body, undef, undef, undef,
- sub {
- my $bug_id = $_[0];
- is($bug_id, $bug_1_id, "found Bug $bug_1_id on Bug $bug_2_id");
- }
+ $bug_2->comments->[0]->body,
+ undef, undef, undef,
+ sub {
+ my $bug_id = $_[0];
+ is($bug_id, $bug_1_id, "found Bug $bug_1_id on Bug $bug_2_id");
+ }
);
done_testing;
diff --git a/t/bmo/passwords.t b/t/bmo/passwords.t
index 83bea60be..f3dd449bb 100644
--- a/t/bmo/passwords.t
+++ b/t/bmo/passwords.t
@@ -6,8 +6,12 @@ use autodie;
use constant DRIVER => 'Test::Selenium::Remote::Driver';
use Test::More 1.302;
+
#use constant DRIVER => 'Test::Selenium::Chrome';
-BEGIN { plan skip_all => "these tests only run in CI" unless $ENV{CI} && $ENV{CIRCLE_JOB} eq 'test_bmo' };
+BEGIN {
+ plan skip_all => "these tests only run in CI"
+ unless $ENV{CI} && $ENV{CIRCLE_JOB} eq 'test_bmo';
+}
use ok DRIVER;
@@ -16,245 +20,248 @@ my $ADMIN_PW_OLD = $ENV{BZ_TEST_ADMIN_PASS} // 'Te6Oovohch';
my $ADMIN_PW_NEW = $ENV{BZ_TEST_ADMIN_NEWPASS} // 'she7Ka8t';
my @require_env = qw(
- BZ_BASE_URL
- BZ_TEST_NEWBIE
- BZ_TEST_NEWBIE_PASS
+ BZ_BASE_URL
+ BZ_TEST_NEWBIE
+ BZ_TEST_NEWBIE_PASS
);
if (DRIVER =~ /Remote/) {
- push @require_env, qw( TWD_HOST TWD_PORT );
+ push @require_env, qw( TWD_HOST TWD_PORT );
}
-my @missing_env = grep { ! exists $ENV{$_} } @require_env;
+my @missing_env = grep { !exists $ENV{$_} } @require_env;
BAIL_OUT("Missing env: @missing_env") if @missing_env;
eval {
- my $sel = DRIVER->new(base_url => $ENV{BZ_BASE_URL});
- $sel->set_implicit_wait_timeout(600);
-
- login_ok($sel, $ADMIN_LOGIN, $ADMIN_PW_OLD);
-
- change_password($sel, $ADMIN_PW_OLD, 'Ju9shiePhie6', 'zeeKuj0leib7');
- $sel->title_is("Passwords Don't Match");
- $sel->body_text_contains('The two passwords you entered did not match.');
-
- change_password($sel, $ADMIN_PW_OLD . "x", "newpassword2", "newpassword2");
- $sel->title_is("Incorrect Old Password");
-
- change_password($sel, $ADMIN_PW_OLD, "password", "password");
- $sel->title_is("Password Fails Requirements");
-
- change_password($sel, $ADMIN_PW_OLD, $ADMIN_PW_NEW, $ADMIN_PW_NEW);
- $sel->title_is("User Preferences");
- logout_ok($sel);
-
- login_ok($sel, $ADMIN_LOGIN, $ADMIN_PW_NEW);
-
- # we don't protect against password re-use
- change_password($sel, $ADMIN_PW_NEW, $ADMIN_PW_OLD, $ADMIN_PW_OLD);
- $sel->title_is("User Preferences");
- logout_ok($sel);
-
- login_ok($sel, $ENV{BZ_TEST_NEWBIE}, $ENV{BZ_TEST_NEWBIE_PASS});
-
- $sel->get_ok("/editusers.cgi");
- $sel->title_is("Authorization Required");
- logout_ok($sel);
-
- login_ok($sel, $ADMIN_LOGIN, $ADMIN_PW_OLD);
-
- toggle_require_password_change($sel, $ENV{BZ_TEST_NEWBIE});
- logout_ok($sel);
-
- login($sel, $ENV{BZ_TEST_NEWBIE}, $ENV{BZ_TEST_NEWBIE_PASS});
- $sel->title_is('Password change required');
- click_and_type($sel, "old_password", $ENV{BZ_TEST_NEWBIE_PASS});
- click_and_type($sel, "new_password1", "password");
- click_and_type($sel, "new_password2", "password");
- submit($sel, '//input[@id="submit"]');
- $sel->title_is('Password Fails Requirements');
-
- $sel->go_back_ok();
- $sel->title_is('Password change required');
- click_and_type($sel, "old_password", $ENV{BZ_TEST_NEWBIE_PASS});
- click_and_type($sel, "new_password1", "!!" . $ENV{BZ_TEST_NEWBIE_PASS});
- click_and_type($sel, "new_password2", "!!" . $ENV{BZ_TEST_NEWBIE_PASS});
- submit($sel, '//input[@id="submit"]');
- $sel->title_is('Password Changed');
- change_password(
- $sel,
- "!!" . $ENV{BZ_TEST_NEWBIE_PASS},
- $ENV{BZ_TEST_NEWBIE_PASS},
- $ENV{BZ_TEST_NEWBIE_PASS}
- );
- $sel->title_is("User Preferences");
-
- $sel->get_ok("/userprefs.cgi?tab=account");
- $sel->title_is("User Preferences");
- click_link($sel, "I forgot my password");
- $sel->body_text_contains(
- ["A token for changing your password has been emailed to you.",
- "Follow the instructions in that email to change your password."],
- );
- my $token = get_token();
- ok($token, "got a token from resetting password");
- $sel->get_ok("/token.cgi?t=$token&a=cfmpw");
- $sel->title_is('Change Password');
- click_and_type($sel, "password", "nopandas");
- click_and_type($sel, "matchpassword", "nopandas");
- submit($sel, '//input[@id="update"]');
- $sel->title_is('Password Fails Requirements');
- $sel->go_back_ok();
- $sel->title_is('Change Password');
- click_and_type($sel, "password", '??' . $ENV{BZ_TEST_NEWBIE_PASS});
- click_and_type($sel, "matchpassword", '??' . $ENV{BZ_TEST_NEWBIE_PASS});
- submit($sel, '//input[@id="update"]');
- $sel->title_is('Password Changed');
- $sel->get_ok("/token.cgi?t=$token&a=cfmpw");
- $sel->title_is('Token Does Not Exist');
- $sel->get_ok("/login");
- $sel->title_is('Log in to Bugzilla');
- login_ok($sel, $ENV{BZ_TEST_NEWBIE}, "??" . $ENV{BZ_TEST_NEWBIE_PASS});
- change_password(
- $sel,
- "??" . $ENV{BZ_TEST_NEWBIE_PASS},
- $ENV{BZ_TEST_NEWBIE_PASS},
- $ENV{BZ_TEST_NEWBIE_PASS}
- );
- $sel->title_is("User Preferences");
-
- logout_ok($sel);
- open my $fh, '>', '/app/data/mailer.testfile';
- close $fh;
-
- $sel->get('/createaccount.cgi');
- $sel->title_is('Create a new Bugzilla account');
- click_and_type($sel, 'login', $ENV{BZ_TEST_NEWBIE2});
- $sel->find_element('//input[@id="etiquette"]', 'xpath')->click();
- submit($sel, '//input[@value="Create Account"]');
- $sel->title_is("Request for new user account '$ENV{BZ_TEST_NEWBIE2}' submitted");
- my ($create_token) = search_mailer_testfile(
- qr{/token\.cgi\?t=([^&]+)&a=request_new_account}xs
- );
- $sel->get("/token.cgi?t=$create_token&a=request_new_account");
- click_and_type($sel, 'passwd1', $ENV{BZ_TEST_NEWBIE2_PASS});
- click_and_type($sel, 'passwd2', $ENV{BZ_TEST_NEWBIE2_PASS});
- submit($sel, '//input[@value="Create"]');
-
- $sel->title_is('Bugzilla Main Page');
- $sel->body_text_contains(
- ["The user account $ENV{BZ_TEST_NEWBIE2} has been created",
- "successfully"]
- );
+ my $sel = DRIVER->new(base_url => $ENV{BZ_BASE_URL});
+ $sel->set_implicit_wait_timeout(600);
+
+ login_ok($sel, $ADMIN_LOGIN, $ADMIN_PW_OLD);
+
+ change_password($sel, $ADMIN_PW_OLD, 'Ju9shiePhie6', 'zeeKuj0leib7');
+ $sel->title_is("Passwords Don't Match");
+ $sel->body_text_contains('The two passwords you entered did not match.');
+
+ change_password($sel, $ADMIN_PW_OLD . "x", "newpassword2", "newpassword2");
+ $sel->title_is("Incorrect Old Password");
+
+ change_password($sel, $ADMIN_PW_OLD, "password", "password");
+ $sel->title_is("Password Fails Requirements");
+
+ change_password($sel, $ADMIN_PW_OLD, $ADMIN_PW_NEW, $ADMIN_PW_NEW);
+ $sel->title_is("User Preferences");
+ logout_ok($sel);
+
+ login_ok($sel, $ADMIN_LOGIN, $ADMIN_PW_NEW);
+
+ # we don't protect against password re-use
+ change_password($sel, $ADMIN_PW_NEW, $ADMIN_PW_OLD, $ADMIN_PW_OLD);
+ $sel->title_is("User Preferences");
+ logout_ok($sel);
+
+ login_ok($sel, $ENV{BZ_TEST_NEWBIE}, $ENV{BZ_TEST_NEWBIE_PASS});
+
+ $sel->get_ok("/editusers.cgi");
+ $sel->title_is("Authorization Required");
+ logout_ok($sel);
+
+ login_ok($sel, $ADMIN_LOGIN, $ADMIN_PW_OLD);
+
+ toggle_require_password_change($sel, $ENV{BZ_TEST_NEWBIE});
+ logout_ok($sel);
+
+ login($sel, $ENV{BZ_TEST_NEWBIE}, $ENV{BZ_TEST_NEWBIE_PASS});
+ $sel->title_is('Password change required');
+ click_and_type($sel, "old_password", $ENV{BZ_TEST_NEWBIE_PASS});
+ click_and_type($sel, "new_password1", "password");
+ click_and_type($sel, "new_password2", "password");
+ submit($sel, '//input[@id="submit"]');
+ $sel->title_is('Password Fails Requirements');
+
+ $sel->go_back_ok();
+ $sel->title_is('Password change required');
+ click_and_type($sel, "old_password", $ENV{BZ_TEST_NEWBIE_PASS});
+ click_and_type($sel, "new_password1", "!!" . $ENV{BZ_TEST_NEWBIE_PASS});
+ click_and_type($sel, "new_password2", "!!" . $ENV{BZ_TEST_NEWBIE_PASS});
+ submit($sel, '//input[@id="submit"]');
+ $sel->title_is('Password Changed');
+ change_password(
+ $sel,
+ "!!" . $ENV{BZ_TEST_NEWBIE_PASS},
+ $ENV{BZ_TEST_NEWBIE_PASS},
+ $ENV{BZ_TEST_NEWBIE_PASS}
+ );
+ $sel->title_is("User Preferences");
+
+ $sel->get_ok("/userprefs.cgi?tab=account");
+ $sel->title_is("User Preferences");
+ click_link($sel, "I forgot my password");
+ $sel->body_text_contains(
+ [
+ "A token for changing your password has been emailed to you.",
+ "Follow the instructions in that email to change your password."
+ ],
+ );
+ my $token = get_token();
+ ok($token, "got a token from resetting password");
+ $sel->get_ok("/token.cgi?t=$token&a=cfmpw");
+ $sel->title_is('Change Password');
+ click_and_type($sel, "password", "nopandas");
+ click_and_type($sel, "matchpassword", "nopandas");
+ submit($sel, '//input[@id="update"]');
+ $sel->title_is('Password Fails Requirements');
+ $sel->go_back_ok();
+ $sel->title_is('Change Password');
+ click_and_type($sel, "password", '??' . $ENV{BZ_TEST_NEWBIE_PASS});
+ click_and_type($sel, "matchpassword", '??' . $ENV{BZ_TEST_NEWBIE_PASS});
+ submit($sel, '//input[@id="update"]');
+ $sel->title_is('Password Changed');
+ $sel->get_ok("/token.cgi?t=$token&a=cfmpw");
+ $sel->title_is('Token Does Not Exist');
+ $sel->get_ok("/login");
+ $sel->title_is('Log in to Bugzilla');
+ login_ok($sel, $ENV{BZ_TEST_NEWBIE}, "??" . $ENV{BZ_TEST_NEWBIE_PASS});
+ change_password(
+ $sel,
+ "??" . $ENV{BZ_TEST_NEWBIE_PASS},
+ $ENV{BZ_TEST_NEWBIE_PASS},
+ $ENV{BZ_TEST_NEWBIE_PASS}
+ );
+ $sel->title_is("User Preferences");
+
+ logout_ok($sel);
+ open my $fh, '>', '/app/data/mailer.testfile';
+ close $fh;
+
+ $sel->get('/createaccount.cgi');
+ $sel->title_is('Create a new Bugzilla account');
+ click_and_type($sel, 'login', $ENV{BZ_TEST_NEWBIE2});
+ $sel->find_element('//input[@id="etiquette"]', 'xpath')->click();
+ submit($sel, '//input[@value="Create Account"]');
+ $sel->title_is(
+ "Request for new user account '$ENV{BZ_TEST_NEWBIE2}' submitted");
+ my ($create_token)
+ = search_mailer_testfile(qr{/token\.cgi\?t=([^&]+)&a=request_new_account}xs);
+ $sel->get("/token.cgi?t=$create_token&a=request_new_account");
+ click_and_type($sel, 'passwd1', $ENV{BZ_TEST_NEWBIE2_PASS});
+ click_and_type($sel, 'passwd2', $ENV{BZ_TEST_NEWBIE2_PASS});
+ submit($sel, '//input[@value="Create"]');
+
+ $sel->title_is('Bugzilla Main Page');
+ $sel->body_text_contains([
+ "The user account $ENV{BZ_TEST_NEWBIE2} has been created", "successfully"
+ ]);
};
if ($@) {
- fail("got exception $@");
+ fail("got exception $@");
}
done_testing();
sub submit {
- my ($sel, $xpath) = @_;
- $sel->find_element($xpath, 'xpath')->submit();
+ my ($sel, $xpath) = @_;
+ $sel->find_element($xpath, 'xpath')->submit();
}
sub get_token {
- my $token;
- my $count = 0;
- do {
- sleep 1 if $count++;
- open my $fh, '<', '/app/data/mailer.testfile';
- my $content = do {
- local $/ = undef;
- <$fh>;
- };
- ($token) = $content =~ m!/token\.cgi\?t=3D([^&]+)&a=3Dcfmpw!s;
- close $fh;
- } until $token || $count > 60;
- return $token;
+ my $token;
+ my $count = 0;
+ do {
+ sleep 1 if $count++;
+ open my $fh, '<', '/app/data/mailer.testfile';
+ my $content = do {
+ local $/ = undef;
+ <$fh>;
+ };
+ ($token) = $content =~ m!/token\.cgi\?t=3D([^&]+)&a=3Dcfmpw!s;
+ close $fh;
+ } until $token || $count > 60;
+ return $token;
}
sub search_mailer_testfile {
- my ($regexp) = @_;
- my $content = "";
- my @result;
- my $count = 0;
- do {
- sleep 1 if $count++;
- open my $fh, '<', '/app/data/mailer.testfile';
- $content .= do {
- local $/ = undef;
- <$fh>;
- };
- close $fh;
- my $decoded = $content;
- $decoded =~ s/\r\n/\n/gs;
- $decoded =~ s/=\n//gs;
- $decoded =~ s/=([[:xdigit:]]{2})/chr(hex($1))/ges;
- @result = $decoded =~ $regexp;
- } until @result || $count > 60;
- return @result;
+ my ($regexp) = @_;
+ my $content = "";
+ my @result;
+ my $count = 0;
+ do {
+ sleep 1 if $count++;
+ open my $fh, '<', '/app/data/mailer.testfile';
+ $content .= do {
+ local $/ = undef;
+ <$fh>;
+ };
+ close $fh;
+ my $decoded = $content;
+ $decoded =~ s/\r\n/\n/gs;
+ $decoded =~ s/=\n//gs;
+ $decoded =~ s/=([[:xdigit:]]{2})/chr(hex($1))/ges;
+ @result = $decoded =~ $regexp;
+ } until @result || $count > 60;
+ return @result;
}
sub click_and_type {
- my ($sel, $name, $text) = @_;
+ my ($sel, $name, $text) = @_;
- eval {
- my $el = $sel->find_element(qq{//*[\@id="bugzilla-body"]//input[\@name="$name"]}, 'xpath');
- $el->click();
- $sel->send_keys_to_active_element($text);
- pass("found $name and typed $text");
- };
- if ($@) {
- fail("failed to find $name");
- }
+ eval {
+ my $el
+ = $sel->find_element(qq{//*[\@id="bugzilla-body"]//input[\@name="$name"]},
+ 'xpath');
+ $el->click();
+ $sel->send_keys_to_active_element($text);
+ pass("found $name and typed $text");
+ };
+ if ($@) {
+ fail("failed to find $name");
+ }
}
sub click_link {
- my ($sel, $text) = @_;
- my $el = $sel->find_element($text, 'link_text');
- $el->click();
+ my ($sel, $text) = @_;
+ my $el = $sel->find_element($text, 'link_text');
+ $el->click();
}
sub change_password {
- my ($sel, $old, $new1, $new2) = @_;
- $sel->get_ok("/userprefs.cgi?tab=account");
- $sel->title_is("User Preferences");
- click_and_type($sel, "old_password", $old);
- click_and_type($sel, "new_password1", $new1);
- click_and_type($sel, "new_password2", $new2);
- submit($sel, '//input[@value="Submit Changes"]');
+ my ($sel, $old, $new1, $new2) = @_;
+ $sel->get_ok("/userprefs.cgi?tab=account");
+ $sel->title_is("User Preferences");
+ click_and_type($sel, "old_password", $old);
+ click_and_type($sel, "new_password1", $new1);
+ click_and_type($sel, "new_password2", $new2);
+ submit($sel, '//input[@value="Submit Changes"]');
}
sub toggle_require_password_change {
- my ($sel, $login) = @_;
- $sel->get_ok("/editusers.cgi");
- $sel->title_is("Search users");
- click_and_type($sel, 'matchstr', $login);
- submit($sel, '//input[@id="search"]');
- $sel->title_is("Select user");
- click_link($sel, $login);
- $sel->find_element('//input[@id="password_change_required"]')->click;
- submit($sel, '//input[@id="update"]');
- $sel->title_is("User $login updated");
+ my ($sel, $login) = @_;
+ $sel->get_ok("/editusers.cgi");
+ $sel->title_is("Search users");
+ click_and_type($sel, 'matchstr', $login);
+ submit($sel, '//input[@id="search"]');
+ $sel->title_is("Select user");
+ click_link($sel, $login);
+ $sel->find_element('//input[@id="password_change_required"]')->click;
+ submit($sel, '//input[@id="update"]');
+ $sel->title_is("User $login updated");
}
sub login {
- my ($sel, $login, $password) = @_;
+ my ($sel, $login, $password) = @_;
- $sel->get_ok("/login");
- $sel->title_is("Log in to Bugzilla");
- click_and_type($sel, 'Bugzilla_login', $login);
- click_and_type($sel, 'Bugzilla_password', $password);
- submit($sel, '//*[@id="bugzilla-body"]//input[@name="GoAheadAndLogIn"]');
+ $sel->get_ok("/login");
+ $sel->title_is("Log in to Bugzilla");
+ click_and_type($sel, 'Bugzilla_login', $login);
+ click_and_type($sel, 'Bugzilla_password', $password);
+ submit($sel, '//*[@id="bugzilla-body"]//input[@name="GoAheadAndLogIn"]');
}
sub login_ok {
- my ($sel) = @_;
- login(@_);
- $sel->title_is('Bugzilla Main Page');
+ my ($sel) = @_;
+ login(@_);
+ $sel->title_is('Bugzilla Main Page');
}
sub logout_ok {
- my ($sel) = @_;
- $sel->get_ok('/index.cgi?logout=1');
- $sel->title_is("Logged Out");
+ my ($sel) = @_;
+ $sel->get_ok('/index.cgi?logout=1');
+ $sel->title_is("Logged Out");
}
diff --git a/t/critic.t b/t/critic.t
index 6e37cc0df..182f8c8e6 100644
--- a/t/critic.t
+++ b/t/critic.t
@@ -14,4 +14,4 @@ use Test::More;
my $ok = eval { require Test::Perl::Critic::Progressive };
plan skip_all => 'T::P::C::Progressive required for this test' unless $ok;
-Test::Perl::Critic::Progressive::progressive_critic_ok(); \ No newline at end of file
+Test::Perl::Critic::Progressive::progressive_critic_ok();
diff --git a/t/css.t b/t/css.t
index a64cadea6..520fd45af 100644
--- a/t/css.t
+++ b/t/css.t
@@ -17,21 +17,22 @@ use Test::More;
my $root = cwd();
find(
- {
- wanted => sub {
- if (/\.css$/) {
- my $css_file = $File::Find::name;
- my $content = read_file($_);
- while ($content =~ m{url\(["']?([^\?\)"']+)(?:\?.+)?['"]?\)}g) {
- my $file = $1;
- my $file_rel_root = File::Spec->abs2rel(realpath(File::Spec->rel2abs($file)), $root);
+ {
+ wanted => sub {
+ if (/\.css$/) {
+ my $css_file = $File::Find::name;
+ my $content = read_file($_);
+ while ($content =~ m{url\(["']?([^\?\)"']+)(?:\?.+)?['"]?\)}g) {
+ my $file = $1;
+ my $file_rel_root
+ = File::Spec->abs2rel(realpath(File::Spec->rel2abs($file)), $root);
- ok(-f $file, "$css_file references $file ($file_rel_root)");
- }
- }
- },
+ ok(-f $file, "$css_file references $file ($file_rel_root)");
+ }
+ }
},
- 'skins'
+ },
+ 'skins'
);
done_testing;
diff --git a/t/daemon-control-catch-signal.t b/t/daemon-control-catch-signal.t
index c42e26fc1..9db43d330 100644
--- a/t/daemon-control-catch-signal.t
+++ b/t/daemon-control-catch-signal.t
@@ -15,61 +15,61 @@ use Test::More;
use ok 'Bugzilla::DaemonControl', qw(catch_signal);
-my $loop = IO::Async::Loop->new;
+my $loop = IO::Async::Loop->new;
my $signal_test_out = '';
-my $signal_test = IO::Async::Process->new(
- code => sub {
- my $f = catch_signal("TERM", 42);
- say $f->isa('Future') ? "I have a Future" : '';
- my $val = $f->get;
- say "Got $val from TERM";
- sleep 30;
- say "I Failed My Mission";
- },
- stdout => { into => \$signal_test_out },
- on_finish => sub {
- $loop->stop;
- },
- on_exception => sub {
- diag "@_";
- fail("got exception");
- $loop->stop;
- }
+my $signal_test = IO::Async::Process->new(
+ code => sub {
+ my $f = catch_signal("TERM", 42);
+ say $f->isa('Future') ? "I have a Future" : '';
+ my $val = $f->get;
+ say "Got $val from TERM";
+ sleep 30;
+ say "I Failed My Mission";
+ },
+ stdout => {into => \$signal_test_out},
+ on_finish => sub {
+ $loop->stop;
+ },
+ on_exception => sub {
+ diag "@_";
+ fail("got exception");
+ $loop->stop;
+ }
);
diag "starting signal test";
$loop->add($signal_test);
-ok( $signal_test->is_running, "signal test is running");
+ok($signal_test->is_running, "signal test is running");
my $send_first_term = IO::Async::Timer::Countdown->new(
- delay => 5,
- on_expire => sub {
- diag "sending first TERM";
- ok($signal_test->is_running, "signal test is still running");
- $signal_test->kill('TERM');
- }
+ delay => 5,
+ on_expire => sub {
+ diag "sending first TERM";
+ ok($signal_test->is_running, "signal test is still running");
+ $signal_test->kill('TERM');
+ }
);
$send_first_term->start;
$loop->add($send_first_term);
my $send_second_term = IO::Async::Timer::Countdown->new(
- delay => 10,
- on_expire => sub {
- diag "sending second TERM";
- ok($signal_test->is_running, "signal test is still running");
- $signal_test->kill('TERM');
- }
+ delay => 10,
+ on_expire => sub {
+ diag "sending second TERM";
+ ok($signal_test->is_running, "signal test is still running");
+ $signal_test->kill('TERM');
+ }
);
$send_second_term->start;
$loop->add($send_second_term);
my $timeout = IO::Async::Timer::Countdown->new(
- delay => 60,
- on_expire => sub {
- fail("test ran for too long");
- $loop->stop;
- },
+ delay => 60,
+ on_expire => sub {
+ fail("test ran for too long");
+ $loop->stop;
+ },
);
$timeout->start;
@@ -79,7 +79,15 @@ $loop->run;
diag $signal_test_out;
like($signal_test_out, qr/I have a Future/, "catch_signal() returned a future");
-like($signal_test_out, qr/Got 42 from TERM/, "catch_signal() returned the right value when done");
-unlike($signal_test_out, qr/I Failed My Mission/, "catch_signal() only happened once");
+like(
+ $signal_test_out,
+ qr/Got 42 from TERM/,
+ "catch_signal() returned the right value when done"
+);
+unlike(
+ $signal_test_out,
+ qr/I Failed My Mission/,
+ "catch_signal() only happened once"
+);
-done_testing(); \ No newline at end of file
+done_testing();
diff --git a/t/docker.t b/t/docker.t
index c1f85088c..dad75243c 100644
--- a/t/docker.t
+++ b/t/docker.t
@@ -14,16 +14,16 @@ use IO::Handle;
use Test::More;
my $dockerfile = 'Dockerfile';
-my $ci_config = '.circleci/config.yml';
+my $ci_config = '.circleci/config.yml';
my $base;
open my $dockerfile_fh, '<', $dockerfile;
while (my $line = readline $dockerfile_fh) {
- chomp $line;
- if ($line =~ /^FROM\s+(\S+)/ms) {
- $base = $1;
- last;
- }
+ chomp $line;
+ if ($line =~ /^FROM\s+(\S+)/ms) {
+ $base = $1;
+ last;
+ }
}
close $dockerfile_fh;
@@ -40,12 +40,12 @@ my $regex = qr{
open my $ci_config_fh, '<', $ci_config;
while (my $line = readline $ci_config_fh) {
- chomp $line;
- if ($line =~ /($regex)/ms) {
- my $ln = $ci_config_fh->input_line_number;
- fail("found docker image $1, expected $base in $ci_config line $ln");
- }
- pass("Forbidden version not found");
+ chomp $line;
+ if ($line =~ /($regex)/ms) {
+ my $ln = $ci_config_fh->input_line_number;
+ fail("found docker image $1, expected $base in $ci_config line $ln");
+ }
+ pass("Forbidden version not found");
}
close $ci_config_fh;
diff --git a/t/extract-nicks.t b/t/extract-nicks.t
index 7063cf366..2b1b4a777 100644
--- a/t/extract-nicks.t
+++ b/t/extract-nicks.t
@@ -14,32 +14,17 @@ use Test::More;
binmode STDOUT, ':encoding(utf-8)';
my @expect = (
- ['dhanesh95'],
- ['kentuckyfriedtakahe', 'k17e'],
- ['emceeaich'],
- ['seban'],
- ['emceeaich'],
- ['glob'],
- ['briansmith', 'bsmith'],
- ['bz'],
- ['dkl-test'],
- ['dylan'],
- ['7'],
- ['bwinton'],
- ['canuckistani'],
- ['GaryChen', 'PYChen', 'gchen', '陳柏宇'],
- ['gfx'],
- ['ted.mielczarek'],
- [],
- ['tb-l10n'],
- ['Gavin'],
- ['прозвище'],
+ ['dhanesh95'], ['kentuckyfriedtakahe', 'k17e'], ['emceeaich'], ['seban'],
+ ['emceeaich'], ['glob'], ['briansmith', 'bsmith'], ['bz'], ['dkl-test'],
+ ['dylan'], ['7'], ['bwinton'], ['canuckistani'],
+ ['GaryChen', 'PYChen', 'gchen', '陳柏宇'], ['gfx'], ['ted.mielczarek'], [],
+ ['tb-l10n'], ['Gavin'], ['прозвище'],
);
while (<DATA>) {
- my @nicks = extract_nicks($_);
- is_deeply(\@nicks, shift @expect);
+ my @nicks = extract_nicks($_);
+ is_deeply(\@nicks, shift @expect);
}
done_testing;
diff --git a/t/hash-sig.t b/t/hash-sig.t
index 30d3098d4..9579b0c39 100644
--- a/t/hash-sig.t
+++ b/t/hash-sig.t
@@ -12,13 +12,14 @@ use Bugzilla::Util qw(generate_random_password);
use Bugzilla::Token qw(issue_hash_sig check_hash_sig);
use Test::More;
-my $localconfig = { site_wide_secret => generate_random_password(256) };
+my $localconfig = {site_wide_secret => generate_random_password(256)};
{
- package Bugzilla;
- sub localconfig { $localconfig }
+
+ package Bugzilla;
+ sub localconfig {$localconfig}
}
my $sig = issue_hash_sig("hero", "batman");
ok(check_hash_sig("hero", $sig, "batman"), "sig for batman checks out");
-done_testing(); \ No newline at end of file
+done_testing();
diff --git a/t/json-boxes.t b/t/json-boxes.t
index 4d9816e83..0fca3d997 100644
--- a/t/json-boxes.t
+++ b/t/json-boxes.t
@@ -30,7 +30,7 @@ is "$box", $box->label;
$box->encode;
-is encode_json([ $box ]), encode_json([ encode_json($box->value) ]);
+is encode_json([$box]), encode_json([encode_json($box->value)]);
is "$box", q[{"foo":1}];
done_testing;
diff --git a/t/markdown.t b/t/markdown.t
index 83e0dc051..ca31fcdc0 100644
--- a/t/markdown.t
+++ b/t/markdown.t
@@ -13,34 +13,30 @@ use Test2::V0;
my $parser = Bugzilla->markdown_parser;
-is(
- $parser->render_html('# header'),
- "<h1>header</h1>\n",
- 'Simple header'
-);
+is($parser->render_html('# header'), "<h1>header</h1>\n", 'Simple header');
is(
- $parser->render_html('`code snippet`'),
- "<p><code>code snippet</code></p>\n",
- 'Simple code snippet'
+ $parser->render_html('`code snippet`'),
+ "<p><code>code snippet</code></p>\n",
+ 'Simple code snippet'
);
is(
- $parser->render_html('http://bmo-web.vm'),
- "<p><a href=\"http://bmo-web.vm\">http://bmo-web.vm</a></p>\n",
- 'Autolink extension'
+ $parser->render_html('http://bmo-web.vm'),
+ "<p><a href=\"http://bmo-web.vm\">http://bmo-web.vm</a></p>\n",
+ 'Autolink extension'
);
is(
- $parser->render_html('<script>hijack()</script>'),
- "&lt;script>hijack()&lt;/script>\n",
- 'Tagfilter extension'
+ $parser->render_html('<script>hijack()</script>'),
+ "&lt;script>hijack()&lt;/script>\n",
+ 'Tagfilter extension'
);
is(
- $parser->render_html('~~strikethrough~~'),
- "<p><del>strikethrough</del></p>\n",
- 'Strikethrough extension'
+ $parser->render_html('~~strikethrough~~'),
+ "<p><del>strikethrough</del></p>\n",
+ 'Strikethrough extension'
);
my $table_markdown = <<'MARKDOWN';
@@ -66,10 +62,6 @@ my $table_html = <<'HTML';
</table>
HTML
-is(
- $parser->render_html($table_markdown),
- $table_html,
- 'Table extension'
-);
+is($parser->render_html($table_markdown), $table_html, 'Table extension');
done_testing;
diff --git a/t/mock-db.t b/t/mock-db.t
index 54ceef100..e031a749b 100644
--- a/t/mock-db.t
+++ b/t/mock-db.t
@@ -16,30 +16,30 @@ use ok 'Bugzilla::Test::MockDB';
use ok 'Bugzilla::Test::Util', qw(create_user);
try {
- Bugzilla::Test::MockDB->import();
- pass('made fake in-memory db');
+ Bugzilla::Test::MockDB->import();
+ pass('made fake in-memory db');
}
catch {
- diag $_;
- fail('made fake in-memory db');
+ diag $_;
+ fail('made fake in-memory db');
};
try {
- create_user('bob@pants.gov', '*');
- ok( Bugzilla::User->new({name => 'bob@pants.gov'})->id, 'create a user' );
+ create_user('bob@pants.gov', '*');
+ ok(Bugzilla::User->new({name => 'bob@pants.gov'})->id, 'create a user');
}
catch {
- fail('create a user');
+ fail('create a user');
};
try {
- my $rob = create_user('rob@pants.gov', '*');
- Bugzilla::User->check({id => $rob->id});
- pass('rob@pants.gov checks out');
+ my $rob = create_user('rob@pants.gov', '*');
+ Bugzilla::User->check({id => $rob->id});
+ pass('rob@pants.gov checks out');
}
catch {
- diag $_;
- fail('rob@pants.gov fails');
+ diag $_;
+ fail('rob@pants.gov fails');
};
done_testing;
diff --git a/t/mock-params.t b/t/mock-params.t
index 7c2318130..4b8097c6a 100644
--- a/t/mock-params.t
+++ b/t/mock-params.t
@@ -12,10 +12,10 @@ use lib qw( . lib local/lib/perl5 );
use Test::More;
use Test2::Tools::Mock qw(mock);
use Bugzilla::Test::MockParams (
- phabricator_auth_callback_url => 'http://pants.gov/',
-);
+ phabricator_auth_callback_url => 'http://pants.gov/',);
-is(Bugzilla->params->{phabricator_auth_callback_url}, 'http://pants.gov/', 'import default params');
+is(Bugzilla->params->{phabricator_auth_callback_url},
+ 'http://pants.gov/', 'import default params');
Bugzilla::Test::MockParams->import(phabricator_api_key => 'FAKE-KEY');
diff --git a/t/mojo-example.t b/t/mojo-example.t
index 8ed4835da..62dd83340 100644
--- a/t/mojo-example.t
+++ b/t/mojo-example.t
@@ -11,23 +11,24 @@ use 5.10.1;
use lib qw( . lib local/lib/perl5 );
BEGIN {
- $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf';
- # There's a plugin called Hostage that makes the application require specific Host: headers.
- # we disable that for these tests.
- $ENV{BUGZILLA_DISABLE_HOSTAGE} = 1;
+ $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf';
+
+# There's a plugin called Hostage that makes the application require specific Host: headers.
+# we disable that for these tests.
+ $ENV{BUGZILLA_DISABLE_HOSTAGE} = 1;
}
# this provides a default urlbase.
# Most localconfig options the other Bugzilla::Test::Mock* modules take care for us.
-use Bugzilla::Test::MockLocalconfig ( urlbase => 'http://bmo-web.vm' );
+use Bugzilla::Test::MockLocalconfig (urlbase => 'http://bmo-web.vm');
# This configures an in-memory sqlite database.
use Bugzilla::Test::MockDB;
# This redirects reads and writes from the config file (data/params)
use Bugzilla::Test::MockParams (
- phabricator_enabled => 1,
- announcehtml => '<div id="announcement">Mojo::Test is awesome</div>',
+ phabricator_enabled => 1,
+ announcehtml => '<div id="announcement">Mojo::Test is awesome</div>',
);
# Util provides a few functions more making mock data in the DB.
@@ -38,7 +39,7 @@ use Test2::Tools::Mock;
use Test::Mojo;
my $api_user = create_user('api@mozilla.org', '*');
-my $api_key = issue_api_key('api@mozilla.org')->api_key;
+my $api_key = issue_api_key('api@mozilla.org')->api_key;
# Mojo::Test loads the application and provides methods for
# testing requests without having to run a server.
@@ -55,22 +56,24 @@ $t->get_ok('/__lbheartbeat__')->status_is(200)->content_is('httpd OK');
# we can use json_is or json_like to check APIs.
# The first pair to json_like is a JSON pointer (RFC 6901)
-$t->get_ok('/bzapi/configuration')->status_is(200)->json_like( '/announcement' => qr/Mojo::Test is awesome/ );
+$t->get_ok('/bzapi/configuration')->status_is(200)
+ ->json_like('/announcement' => qr/Mojo::Test is awesome/);
# for web requests, you use text_like (or text_is) with CSS selectors.
-$t->get_ok('/')->status_is(200)->text_like( '#announcement' => qr/Mojo::Test is awesome/ );
+$t->get_ok('/')->status_is(200)
+ ->text_like('#announcement' => qr/Mojo::Test is awesome/);
# Chaining is not magical, you can break up longer lines
# by calling methods on $t, as below.
-$t->get_ok('/rest/whoami' => { 'X-Bugzilla-API-Key' => $api_key });
+$t->get_ok('/rest/whoami' => {'X-Bugzilla-API-Key' => $api_key});
$t->status_is(200);
$t->json_is('/name' => $api_user->login);
-$t->json_is('/id' => $api_user->id);
+$t->json_is('/id' => $api_user->id);
# Each time you call $t->get_ok, post_ok, etc the previous request is cleared.
$t->get_ok('/rest/whoami');
$t->status_is(200);
$t->json_is('/name' => '');
-$t->json_is('/id' => 0);
+$t->json_is('/id' => 0);
done_testing;
diff --git a/t/security-risk.t b/t/security-risk.t
index 520953bc0..cd6ce1ff3 100644
--- a/t/security-risk.t
+++ b/t/security-risk.t
@@ -11,7 +11,7 @@ use 5.10.1;
use lib qw( . lib local/lib/perl5 );
use Bugzilla;
-BEGIN { Bugzilla->extensions };
+BEGIN { Bugzilla->extensions }
use Test::More;
use Test2::Tools::Mock;
@@ -21,136 +21,125 @@ use ok 'Bugzilla::Report::SecurityRisk';
can_ok('Bugzilla::Report::SecurityRisk', qw(new results));
sub check_open_state_mock {
- my ($state) = @_;
- return grep { /^$state$/ } qw(UNCOMFIRMED NEW ASSIGNED REOPENED);
+ my ($state) = @_;
+ return grep {/^$state$/} qw(UNCOMFIRMED NEW ASSIGNED REOPENED);
}
try {
- use Bugzilla::Report::SecurityRisk;
- my $report = Bugzilla::Report::SecurityRisk->new(
- start_date => DateTime->new( year => 2000, month => 1, day => 9 ),
- end_date => DateTime->new( year => 2000, month => 1, day => 16 ),
- products => [ 'Firefox', 'Core' ],
- sec_keywords => [ 'sec-critical', 'sec-high' ],
- check_open_state => \&check_open_state_mock,
- initial_bug_ids => [ 1, 2, 3, 4 ],
- initial_bugs => {
- 1 => {
- id => 1,
- product => 'Firefox',
- sec_level => 'sec-high',
- is_open => 0,
- created_at => DateTime->new( year => 2000, month => 1, day => 1 ),
- },
- 2 => {
- id => 2,
- product => 'Core',
- sec_level => 'sec-critical',
- is_open => 0,
- created_at => DateTime->new( year => 2000, month => 1, day => 1 ),
- },
- 3 => {
- id => 3,
- product => 'Core',
- sec_level => 'sec-high',
- is_open => 1,
- created_at => DateTime->new( year => 2000, month => 1, day => 5 ),
- },
- 4 => {
- id => 4,
- product => 'Firefox',
- sec_level => 'sec-critical',
- is_open => 1,
- created_at => DateTime->new( year => 2000, month => 1, day => 10 ),
- },
- },
- events => [
- # Canned event's should be in reverse chronological order.
- {
- bug_id => 2,
- bug_when => DateTime->new( year => 2000, month => 1, day => 14 ),
- field_name => 'keywords',
- removed => '',
- added => 'sec-critical',
+ use Bugzilla::Report::SecurityRisk;
+ my $report = Bugzilla::Report::SecurityRisk->new(
+ start_date => DateTime->new(year => 2000, month => 1, day => 9),
+ end_date => DateTime->new(year => 2000, month => 1, day => 16),
+ products => ['Firefox', 'Core'],
+ sec_keywords => ['sec-critical', 'sec-high'],
+ check_open_state => \&check_open_state_mock,
+ initial_bug_ids => [1, 2, 3, 4],
+ initial_bugs => {
+ 1 => {
+ id => 1,
+ product => 'Firefox',
+ sec_level => 'sec-high',
+ is_open => 0,
+ created_at => DateTime->new(year => 2000, month => 1, day => 1),
+ },
+ 2 => {
+ id => 2,
+ product => 'Core',
+ sec_level => 'sec-critical',
+ is_open => 0,
+ created_at => DateTime->new(year => 2000, month => 1, day => 1),
+ },
+ 3 => {
+ id => 3,
+ product => 'Core',
+ sec_level => 'sec-high',
+ is_open => 1,
+ created_at => DateTime->new(year => 2000, month => 1, day => 5),
+ },
+ 4 => {
+ id => 4,
+ product => 'Firefox',
+ sec_level => 'sec-critical',
+ is_open => 1,
+ created_at => DateTime->new(year => 2000, month => 1, day => 10),
+ },
+ },
+ events => [
+
+ # Canned event's should be in reverse chronological order.
+ {
+ bug_id => 2,
+ bug_when => DateTime->new(year => 2000, month => 1, day => 14),
+ field_name => 'keywords',
+ removed => '',
+ added => 'sec-critical',
+
+ },
+ {
+ bug_id => 1,
+ bug_when => DateTime->new(year => 2000, month => 1, day => 12),
+ field_name => 'bug_status',
+ removed => 'ASSIGNED',
+ added => 'RESOLVED',
+ },
+ ],
+ );
+ my $actual_results = $report->results;
+ my $expected_results = [
+ {
+ date => DateTime->new(year => 2000, month => 1, day => 9),
+ bugs_by_product => {
+ 'Firefox' => {
- },
- {
- bug_id => 1,
- bug_when => DateTime->new( year => 2000, month => 1, day => 12 ),
- field_name => 'bug_status',
- removed => 'ASSIGNED',
- added => 'RESOLVED',
- },
- ],
- );
- my $actual_results = $report->results;
- my $expected_results = [
- {
- date => DateTime->new( year => 2000, month => 1, day => 9 ),
- bugs_by_product => {
- 'Firefox' => {
- # Rewind the event that caused 1 to close.
- open => [1],
- closed => [],
- median_age_open => 8
- },
- 'Core' => {
- # 2 wasn't a sec-critical bug on the report date.
- open => [3],
- closed => [],
- median_age_open => 4
- }
- },
- bugs_by_sec_keyword => {
- 'sec-critical' => {
- # 2 wasn't a sec-crtical bug and 4 wasn't created yet on the report date.
- open => [],
- closed => [],
- median_age_open => 0
- },
- 'sec-high' => {
- # Rewind the event that caused 1 to close.
- open => [ 1, 3 ],
- closed => [],
- median_age_open => 6
- }
- },
+ # Rewind the event that caused 1 to close.
+ open => [1],
+ closed => [],
+ median_age_open => 8
},
- { # The report on 2000-01-16 matches the state of initial_bugs.
- date => DateTime->new( year => 2000, month => 1, day => 16 ),
- bugs_by_product => {
- 'Firefox' => {
- open => [4],
- closed => [1],
- median_age_open => 6
- },
- 'Core' => {
- open => [3],
- closed => [2],
- median_age_open => 11
- }
- },
- bugs_by_sec_keyword => {
- 'sec-critical' => {
- open => [4],
- closed => [2],
- median_age_open => 6
- },
- 'sec-high' => {
- open => [3],
- closed => [1],
- median_age_open => 11
- }
- },
+ 'Core' => {
+
+ # 2 wasn't a sec-critical bug on the report date.
+ open => [3],
+ closed => [],
+ median_age_open => 4
+ }
+ },
+ bugs_by_sec_keyword => {
+ 'sec-critical' => {
+
+ # 2 wasn't a sec-crtical bug and 4 wasn't created yet on the report date.
+ open => [],
+ closed => [],
+ median_age_open => 0
},
- ];
+ 'sec-high' => {
+
+ # Rewind the event that caused 1 to close.
+ open => [1, 3],
+ closed => [],
+ median_age_open => 6
+ }
+ },
+ },
+ { # The report on 2000-01-16 matches the state of initial_bugs.
+ date => DateTime->new(year => 2000, month => 1, day => 16),
+ bugs_by_product => {
+ 'Firefox' => {open => [4], closed => [1], median_age_open => 6},
+ 'Core' => {open => [3], closed => [2], median_age_open => 11}
+ },
+ bugs_by_sec_keyword => {
+ 'sec-critical' => {open => [4], closed => [2], median_age_open => 6},
+ 'sec-high' => {open => [3], closed => [1], median_age_open => 11}
+ },
+ },
+ ];
- is_deeply($actual_results, $expected_results, 'Report results are accurate');
+ is_deeply($actual_results, $expected_results, 'Report results are accurate');
}
catch {
- fail('got an exception during main part of test');
- diag($_);
+ fail('got an exception during main part of test');
+ diag($_);
};
done_testing;
diff --git a/t/sqlite-memory.t b/t/sqlite-memory.t
index 66f8e5d29..6b5d8bfd6 100644
--- a/t/sqlite-memory.t
+++ b/t/sqlite-memory.t
@@ -15,12 +15,12 @@ use Capture::Tiny qw(capture_merged);
use Bugzilla::Test::MockParams;
BEGIN {
- $ENV{LOCALCONFIG_ENV} = 'BMO';
- $ENV{BMO_db_driver} = 'sqlite';
- $ENV{BMO_db_name} = ':memory:';
-};
+ $ENV{LOCALCONFIG_ENV} = 'BMO';
+ $ENV{BMO_db_driver} = 'sqlite';
+ $ENV{BMO_db_name} = ':memory:';
+}
use Bugzilla;
-BEGIN { Bugzilla->extensions };
+BEGIN { Bugzilla->extensions }
isa_ok(Bugzilla->dbh, 'Bugzilla::DB::Sqlite');
@@ -29,61 +29,82 @@ use ok 'Bugzilla::Install';
use ok 'Bugzilla::Install::DB';
my $lives_ok = sub {
- my ($desc, $code) = @_;
- my $output;
- try {
- $output = capture_merged { $code->() };
- pass($desc);
- } catch {
- diag $_;
- fail($desc);
- } finally {
- diag "OUTPUT: $output" if $output;
- };
+ my ($desc, $code) = @_;
+ my $output;
+ try {
+ $output = capture_merged { $code->() };
+ pass($desc);
+ }
+ catch {
+ diag $_;
+ fail($desc);
+ }
+ finally {
+ diag "OUTPUT: $output" if $output;
+ };
};
my $output = '';
-$lives_ok->('bz_setup_database' => sub {
- Bugzilla->dbh->bz_setup_database
-});
+$lives_ok->(
+ 'bz_setup_database' => sub {
+ Bugzilla->dbh->bz_setup_database;
+ }
+);
+
+$lives_ok->(
+ 'bz_populate_enum_tables' => sub {
-$lives_ok->('bz_populate_enum_tables' => sub {
# Populate the tables that hold the values for the <select> fields.
Bugzilla->dbh->bz_populate_enum_tables();
-});
+ }
+);
-$lives_ok->('update_fielddefs_definition' => sub {
+$lives_ok->(
+ 'update_fielddefs_definition' => sub {
Bugzilla::Install::DB::update_fielddefs_definition();
-});
+ }
+);
-$lives_ok->('populate_field_definitions' => sub {
+$lives_ok->(
+ 'populate_field_definitions' => sub {
Bugzilla::Field::populate_field_definitions();
-});
+ }
+);
-$lives_ok->('init_workflow' => sub {
+$lives_ok->(
+ 'init_workflow' => sub {
Bugzilla::Install::init_workflow();
-});
+ }
+);
-$lives_ok->('update_table_definitions' => sub {
+$lives_ok->(
+ 'update_table_definitions' => sub {
Bugzilla::Install::DB->update_table_definitions({});
-});
+ }
+);
-$lives_ok->('update_system_groups' => sub {
+$lives_ok->(
+ 'update_system_groups' => sub {
Bugzilla::Install::update_system_groups();
-});
+ }
+);
# "Log In" as the fake superuser who can do everything.
Bugzilla->set_user(Bugzilla::User->super_user);
-$lives_ok->('update_settings' => sub {
+$lives_ok->(
+ 'update_settings' => sub {
Bugzilla::Install::update_settings();
-});
+ }
+);
SKIP: {
- skip 'default product cannot be created without default assignee', 1;
- $lives_ok->('create_default_product' => sub {
- Bugzilla::Install::create_default_product();
- });
+ skip 'default product cannot be created without default assignee', 1;
+ $lives_ok->(
+ 'create_default_product' => sub {
+ Bugzilla::Install::create_default_product();
+ }
+ );
}
done_testing;