-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(dependencies): add test for threshold checking
- Loading branch information
1 parent
ce7edce
commit 081f273
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Test::Exception; | ||
use Test::MockObject; | ||
use Test::Output; | ||
|
||
{ | ||
package Mojo::UserAgent; | ||
use Test::MockObject; | ||
|
||
my $mock_response; | ||
|
||
sub new { | ||
my $class = shift; | ||
return Test::MockObject -> new -> mock('get', sub { | ||
my ($self, $url, $headers) = @_; | ||
return Test::MockObject -> new -> mock('result', sub { | ||
return $mock_response; | ||
}); | ||
}); | ||
} | ||
|
||
sub set_mock_response { | ||
my ($class, $response) = @_; | ||
$mock_response = $response; | ||
return; | ||
} | ||
} | ||
|
||
use lib '../lib'; | ||
use SecurityGate::Engine::Dependencies; | ||
|
||
subtest 'Threshold checking' => sub { | ||
plan tests => 2; | ||
|
||
my $mock_response = Test::MockObject -> new; | ||
Mojo::UserAgent -> set_mock_response($mock_response); | ||
$mock_response -> set_always('code', 200); | ||
$mock_response -> set_always('json', [ | ||
{ state => 'open', security_vulnerability => { severity => 'critical' } }, | ||
{ state => 'open', security_vulnerability => { severity => 'critical' } }, | ||
]); | ||
|
||
my %severity_limits_exceeded = ( | ||
critical => 1, | ||
high => 0, | ||
medium => 0, | ||
low => 0 | ||
); | ||
|
||
my %severity_limits_not_exceeded = ( | ||
critical => 2, | ||
high => 0, | ||
medium => 0, | ||
low => 0 | ||
); | ||
|
||
is( | ||
SecurityGate::Engine::Dependencies -> new('test_token', 'test_repo', \%severity_limits_exceeded), | ||
1, | ||
'Returns 1 when threshold is exceeded' | ||
); | ||
|
||
is( | ||
SecurityGate::Engine::Dependencies -> new('test_token', 'test_repo', \%severity_limits_not_exceeded), | ||
0, | ||
'Returns 0 when threshold is not exceeded' | ||
); | ||
}; | ||
|
||
done_testing(); |