summaryrefslogtreecommitdiffstats
path: root/t/security-risk.t
diff options
context:
space:
mode:
Diffstat (limited to 't/security-risk.t')
-rw-r--r--t/security-risk.t231
1 files changed, 110 insertions, 121 deletions
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;