-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write some unit tests for createDigestForAccount
- Loading branch information
1 parent
d8a21f0
commit 2f62f3f
Showing
1 changed file
with
49 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,49 @@ | ||
import type { cloudbuster_fsbp_vulnerabilities } from '@prisma/client'; | ||
import { createDigestForAccount } from './digests'; | ||
|
||
describe('createDigestForAccount', () => { | ||
it('should return nothing if no vulnerabilities are passed to it', () => { | ||
const actual = createDigestForAccount([]); | ||
expect(actual).toBeUndefined(); | ||
}); | ||
|
||
const testVuln: cloudbuster_fsbp_vulnerabilities = { | ||
aws_account_id: '123456789012', | ||
aws_account_name: 'test-account', | ||
aws_region: 'eu-west-1', | ||
arn: 'arn:aws:service:eu-west-1:123456789012', | ||
control_id: 'S.1', | ||
first_observed_at: new Date(), | ||
remediation: 'https://example.com', | ||
severity: 'CRITICAL', | ||
repo: null, | ||
stack: null, | ||
stage: null, | ||
app: null, | ||
title: 'test-title', | ||
within_sla: false, | ||
}; | ||
it('should return a digest with the correct fields', () => { | ||
const actual = createDigestForAccount([testVuln]); | ||
expect(actual).toEqual({ | ||
accountId: '123456789012', | ||
accountName: 'test-account', | ||
actions: [ | ||
{ | ||
cta: 'View all findings on Grafana', | ||
url: 'https://metrics.gutools.co.uk/d/ddi3x35x70jy8d?var-account_name=test-account', | ||
}, | ||
], | ||
subject: 'Security Hub findings for AWS account test-account', | ||
message: `The following vulnerabilities have been found in your account in the last 60 days: | ||
**[CRITICAL] test-title** | ||
Affected resource: arn:aws:service:eu-west-1:123456789012 | ||
Remediation: [Documentation](https://example.com)`, | ||
}); | ||
}); | ||
it('should return nothing if the first observed date is older than the cut-off', () => { | ||
const vuln = { ...testVuln, first_observed_at: new Date(0) }; | ||
const actual = createDigestForAccount([vuln]); | ||
expect(actual).toBeUndefined(); | ||
}); | ||
}); |