Skip to content

Commit

Permalink
Bugfix | Uncheckable domain (#25)
Browse files Browse the repository at this point in the history
* fix issue with invalid domain

* fix test

* fix fmt

* add build

* fix format

* fix format

* fixes etc

* Try the #24 error

* fix ci

* revert 1 off test

* update package & rebuild
  • Loading branch information
Zac Rosenbauer committed May 6, 2021
1 parent 83f9043 commit 8aefd27
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 276 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ jobs:
run: yarn lint
- name: Test
run: yarn test

## You can add the action in if you need / want to test it

# - id: runAction
# name: Run Action Code
# uses: ./
- id: runActionValid
name: Try Valid URL
uses: ./
with:
domain: https://bluenova.io
expiration_days: 7
- id: runActionInvalid
name: Try Invalid URL
uses: ./
with:
domain: https://not-a-real-domain-at-all-1382712984.com
expiration_days: 7
- id: invalidActionStatus
name: Invalid URL Status
if: steps.runActionInvalid.outputs.error_message == ''
run: exit 1
79 changes: 50 additions & 29 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,38 @@ async function run() {
const alertMethod = core.getInput('alert_method');
const alertToken = core.getInput('alert_token');
const isAlertEnabled = !!alertMethod;
const result = await tls.getTLSInfo(domain);
let errorMessage = '';
let result;
try {
result = await tls.getTLSInfo(domain);
}
catch (err) {
errorMessage = err.message || `Unable to get TLS Info for domain ${domain}`;
}
if (isAlertEnabled) {
const validationResults = validate_1.validate({
expirationDays: Number(expirationDays),
approvedProtocols: getApprovedProtocols(approvedProtocols),
tlsInfo: result
});
if (validationResults.errorMessage) {
errorMessage = validationResults.errorMessage;
if (result) {
const validationResults = validate_1.validate({
expirationDays: Number(expirationDays),
approvedProtocols: getApprovedProtocols(approvedProtocols),
tlsInfo: result
});
if (validationResults.errorMessage) {
errorMessage = validationResults.errorMessage;
}
}
if (errorMessage) {
await alerts.send(alertMethod, alertToken, {
domain,
validTo: result.validTo.toISOString(),
validFrom: result.validFrom.toISOString(),
protocol: result.protocol,
validTo: (result === null || result === void 0 ? void 0 : result.validTo.toISOString()) || 'unknown',
validFrom: (result === null || result === void 0 ? void 0 : result.validFrom.toISOString()) || 'unknown',
protocol: ((result === null || result === void 0 ? void 0 : result.protocol) || 'unknown'),
errorMessage
});
}
}
core.setOutput('protocol', result.protocol);
core.setOutput('valid_to', result.validTo);
core.setOutput('valid_from', result.validFrom);
core.setOutput('protocol', (result === null || result === void 0 ? void 0 : result.protocol) || 'unknown');
core.setOutput('valid_to', (result === null || result === void 0 ? void 0 : result.validTo) || 'unknown');
core.setOutput('valid_from', (result === null || result === void 0 ? void 0 : result.validFrom) || 'unknown');
core.setOutput('error_message', errorMessage);
}
run();
Expand Down Expand Up @@ -517,6 +527,7 @@ exports.getInput = getInput;
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) {
process.stdout.write(os.EOL);
command_1.issueCommand('set-output', { name }, value);
}
exports.setOutput = setOutput;
Expand Down Expand Up @@ -3843,8 +3854,9 @@ var assert = __nccwpck_require__(2357);
var debug = __nccwpck_require__(1133);

// Create handlers that pass events from native requests
var events = ["abort", "aborted", "connect", "error", "socket", "timeout"];
var eventHandlers = Object.create(null);
["abort", "aborted", "connect", "error", "socket", "timeout"].forEach(function (event) {
events.forEach(function (event) {
eventHandlers[event] = function (arg1, arg2, arg3) {
this._redirectable.emit(event, arg1, arg2, arg3);
};
Expand Down Expand Up @@ -3899,9 +3911,7 @@ RedirectableRequest.prototype = Object.create(Writable.prototype);

RedirectableRequest.prototype.abort = function () {
// Abort the internal request
this._currentRequest.removeAllListeners();
this._currentRequest.on("error", noop);
this._currentRequest.abort();
abortRequest(this._currentRequest);

// Abort this request
this.emit("abort");
Expand Down Expand Up @@ -3992,15 +4002,22 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {
this.on("timeout", callback);
}

function destroyOnTimeout(socket) {
socket.setTimeout(msecs);
socket.removeListener("timeout", socket.destroy);
socket.addListener("timeout", socket.destroy);
}

// Sets up a timer to trigger a timeout event
function startTimer() {
function startTimer(socket) {
if (self._timeout) {
clearTimeout(self._timeout);
}
self._timeout = setTimeout(function () {
self.emit("timeout");
clearTimer();
}, msecs);
destroyOnTimeout(socket);
}

// Prevent a timeout from triggering
Expand All @@ -4016,12 +4033,13 @@ RedirectableRequest.prototype.setTimeout = function (msecs, callback) {

// Start the timer when the socket is opened
if (this.socket) {
startTimer();
startTimer(this.socket);
}
else {
this._currentRequest.once("socket", startTimer);
}

this.on("socket", destroyOnTimeout);
this.once("response", clearTimer);
this.once("error", clearTimer);

Expand Down Expand Up @@ -4100,11 +4118,8 @@ RedirectableRequest.prototype._performRequest = function () {

// Set up event handlers
request._redirectable = this;
for (var event in eventHandlers) {
/* istanbul ignore else */
if (event) {
request.on(event, eventHandlers[event]);
}
for (var e = 0; e < events.length; e++) {
request.on(events[e], eventHandlers[events[e]]);
}

// End a redirected request
Expand Down Expand Up @@ -4162,9 +4177,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
if (location && this._options.followRedirects !== false &&
statusCode >= 300 && statusCode < 400) {
// Abort the current request
this._currentRequest.removeAllListeners();
this._currentRequest.on("error", noop);
this._currentRequest.abort();
abortRequest(this._currentRequest);
// Discard the remainder of the response to avoid waiting for data
response.destroy();

Expand Down Expand Up @@ -4356,6 +4369,14 @@ function createErrorType(code, defaultMessage) {
return CustomError;
}

function abortRequest(request) {
for (var e = 0; e < events.length; e++) {
request.removeListener(events[e], eventHandlers[events[e]]);
}
request.on("error", noop);
request.abort();
}

// Exports
module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap;
Expand Down Expand Up @@ -21912,7 +21933,7 @@ module.exports = {
/***/ ((module) => {

"use strict";
module.exports = JSON.parse('{"name":"action-tls-monitor","version":"1.0.0","description":"Monitor SSL/TLS certificates for your domains.","main":"dist/main.js","repository":"git@github.com:bluenovaio/action-tls-monitor.git","author":"@bluenovaio","license":"MIT","private":false,"scripts":{"build":"tsc","format":"prettier --write **/*.ts","format-check":"prettier --check **/*.ts","lint":"eslint src/**/*.ts","package":"ncc build --source-map --license licenses.txt","test":"jest"},"dependencies":{"@actions/core":"^1.2.7","@slack/webhook":"^6.0.0","gaxios":"^4.2.0","lodash":"^4.17.21"},"devDependencies":{"@jest/types":"^26.6.2","@types/jest":"^26.0.20","@types/lodash":"^4.14.168","@types/node":"^15.0.1","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","@vercel/ncc":"0.28.4","eslint":"^7.25.0","eslint-config-semistandard":"^15.0.1","eslint-config-standard":"^16.0.2","eslint-plugin-import":"^2.22.1","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"5.1.0","eslint-plugin-standard":"^5.0.0","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.5.5","ts-node":"^9.1.1","typescript":"^4.2.3","webpack":"^5.36.2"}}');
module.exports = JSON.parse('{"name":"action-tls-monitor","version":"1.0.0","description":"Monitor SSL/TLS certificates for your domains.","main":"dist/main.js","repository":"git@github.com:bluenovaio/action-tls-monitor.git","author":"@bluenovaio","license":"MIT","private":false,"scripts":{"build":"tsc","format":"prettier --write **/*.ts","format-check":"prettier --check **/*.ts","lint":"eslint src/**/*.ts","package":"ncc build --source-map --license licenses.txt","test":"jest"},"dependencies":{"@actions/core":"^1.2.7","@slack/webhook":"^6.0.0","gaxios":"^4.2.0","lodash":"^4.17.21"},"devDependencies":{"@jest/types":"^26.6.2","@types/jest":"^26.0.20","@types/lodash":"^4.14.168","@types/node":"^15.0.1","@typescript-eslint/eslint-plugin":"^4.22.0","@typescript-eslint/parser":"^4.22.0","@vercel/ncc":"0.28.5","eslint":"^7.25.0","eslint-config-semistandard":"^15.0.1","eslint-config-standard":"^16.0.2","eslint-plugin-import":"^2.22.1","eslint-plugin-node":"^11.1.0","eslint-plugin-promise":"5.1.0","eslint-plugin-standard":"^5.0.0","jest":"^26.6.3","prettier":"^2.2.1","ts-jest":"^26.5.5","ts-node":"^9.1.1","typescript":"^4.2.3","webpack":"^5.36.2"}}');

/***/ }),

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/lib/alerts/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Protocol } from '../tls';
export interface AlertInput {
domain: string;
validTo: string;
validFrom: string;
protocol: string;
protocol: Protocol;
errorMessage: string;
}
34 changes: 10 additions & 24 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
@slack/webhook
MIT

@vercel/ncc
MIT
Copyright 2018 ZEIT, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

axios
MIT
Copyright (c) 2014-present Matt Zabriskie
Expand Down Expand Up @@ -181,27 +191,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


webpack
MIT
Copyright JS Foundation and other contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 changes: 24 additions & 14 deletions dist/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/main.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/node": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"@vercel/ncc": "0.28.4",
"@vercel/ncc": "0.28.5",
"eslint": "^7.25.0",
"eslint-config-semistandard": "^15.0.1",
"eslint-config-standard": "^16.0.2",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/alerts/__tests__/slack.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as slack from '../slack';
import { Protocol } from '../../tls';

const validTo = (new Date()).toISOString();
const validFrom = (new Date()).toISOString();
Expand All @@ -10,7 +11,7 @@ describe('buildMessage', () => {
errorMessage: 'An error of some kind',
validTo,
validFrom,
protocol: 'TLSv1.3'
protocol: 'TLSv1.3' as Protocol
})).toEqual({
icon_emoji: ':warning:',
username: 'SSL/TLS Monitor',
Expand Down
4 changes: 3 additions & 1 deletion src/lib/alerts/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Protocol } from '../tls';

export interface AlertInput {
domain: string;
validTo: string;
validFrom: string;
protocol: string;
protocol: Protocol;
errorMessage: string;
}
Loading

0 comments on commit 8aefd27

Please sign in to comment.