-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add tests * update docs * update docs * update docs * update docs
- Loading branch information
Zac Rosenbauer
authored
Apr 11, 2021
1 parent
22f0dae
commit e9b6efb
Showing
7 changed files
with
171 additions
and
10 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,89 @@ | ||
import { validate } from '../validate'; | ||
import { Protocol, TLSInfo } from '../tls'; | ||
|
||
const ONE_DAY_MS = 1000 * 60 * 60 * 24; | ||
|
||
const exampleInput = { | ||
expirationDays: 7, | ||
approvedProtocols: [Protocol.TLSv1dot2, Protocol.TLSv1dot3], | ||
tlsInfo: { | ||
validFrom: new Date(Date.now() - (ONE_DAY_MS * 300)), | ||
validTo: new Date(Date.now() + (ONE_DAY_MS * 30)), | ||
protocol: Protocol.TLSv1dot3 | ||
} as TLSInfo | ||
}; | ||
|
||
describe('validate', () => { | ||
it('returns errorMessage for non-approved Protocol', () => { | ||
expect(validate({ | ||
...exampleInput, | ||
tlsInfo: { | ||
...exampleInput.tlsInfo, | ||
protocol: Protocol.TLSv1dot1 | ||
} | ||
})).toEqual({ | ||
expired: false, | ||
expiresSoon: false, | ||
protocolNotApproved: true, | ||
errorMessage: 'Issues found with certificate - Invalid protocol: TLSv1.1' | ||
}); | ||
}); | ||
|
||
it('returns errorMessage for missing Protocol', () => { | ||
expect(validate({ | ||
...exampleInput, | ||
tlsInfo: { | ||
...exampleInput.tlsInfo, | ||
protocol: null | ||
} | ||
})).toEqual({ | ||
expired: false, | ||
expiresSoon: false, | ||
protocolNotApproved: true, | ||
errorMessage: 'Issues found with certificate - Invalid protocol: unknown' | ||
}); | ||
}); | ||
|
||
it('returns errorMessage expired certificate', () => { | ||
expect(validate({ | ||
...exampleInput, | ||
tlsInfo: { | ||
...exampleInput.tlsInfo, | ||
validTo: new Date(Date.now() - (ONE_DAY_MS * 3)) | ||
} | ||
})).toEqual({ | ||
expired: true, | ||
expiresSoon: false, | ||
protocolNotApproved: false, | ||
errorMessage: 'Issues found with certificate - Certificate has expired' | ||
}); | ||
}); | ||
|
||
it('returns errorMessage for soon to expire certificate', () => { | ||
expect(validate({ | ||
...exampleInput, | ||
expirationDays: 40 | ||
})).toEqual({ | ||
expired: false, | ||
expiresSoon: true, | ||
protocolNotApproved: false, | ||
errorMessage: 'Issues found with certificate - Certificate will expire in less than 40 days' | ||
}); | ||
}); | ||
|
||
it('returns multiple errorMessages if applicable', () => { | ||
expect(validate({ | ||
...exampleInput, | ||
expirationDays: 40, | ||
tlsInfo: { | ||
...exampleInput.tlsInfo, | ||
protocol: null | ||
} | ||
})).toEqual({ | ||
expired: false, | ||
expiresSoon: true, | ||
protocolNotApproved: true, | ||
errorMessage: 'Issues found with certificate - Invalid protocol: unknown, Certificate will expire in less than 40 days' | ||
}); | ||
}); | ||
}); |
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,59 @@ | ||
import * as slack from '../slack'; | ||
|
||
const validTo = (new Date()).toISOString(); | ||
const validFrom = (new Date()).toISOString(); | ||
|
||
describe('buildMessage', () => { | ||
it('returns a built message', () => { | ||
expect(slack.buildMessage({ | ||
domain: 'example.com', | ||
errorMessage: 'An error of some kind', | ||
validTo, | ||
validFrom, | ||
protocol: 'TLSv1.3' | ||
})).toEqual({ | ||
icon_emoji: ':warning:', | ||
username: 'SSL/TLS Monitor', | ||
blocks: [ | ||
{ | ||
type: 'header', | ||
text: { | ||
type: 'plain_text', | ||
text: 'SSL/TLS Monitor Alert', | ||
emoji: true | ||
} | ||
}, | ||
{ | ||
type: 'section', | ||
fields: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Domain:*\n<example.com|example.com>` | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Error:*\nAn error of some kind` | ||
} | ||
] | ||
}, | ||
{ | ||
type: 'section', | ||
fields: [ | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Valid To:*\n${validTo}` | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Valid From:*\n${validFrom}` | ||
}, | ||
{ | ||
type: 'mrkdwn', | ||
text: `*Protocol:*\nTLSv1.3` | ||
} | ||
] | ||
} | ||
] | ||
}); | ||
}); | ||
}); |
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
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