Skip to content

Commit

Permalink
added certSuccess field
Browse files Browse the repository at this point in the history
  • Loading branch information
mamari90 committed Feb 8, 2024
1 parent 858e46c commit bf93802
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/const.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const keysForTelemetry = ['success', 'message', 'duration', 'runLocation'];
const keysForEvent = ['duration', 'targetStatus', 'targetExpirationTimestamp', 'httpStatus', 'targetTlsVersion', 'targetExpireInDays'] ;
const keysForEvent = ['duration', 'targetStatus', 'targetExpirationTimestamp', 'httpStatus', 'targetTlsVersion', 'targetExpireInDays', 'certSuccess'] ;
const keysForEventProperties = ['domain', 'checkCert'];
const TLS_VERSION_KEY = "TLS_VERSION"
const START_TIMESTAMP_KEY = "x-request-timestamp"
Expand All @@ -12,4 +12,4 @@ module.exports = {
TLS_VERSION_KEY,
START_TIMESTAMP_KEY,
RESPONSE_TIME_KEY
}
}
54 changes: 28 additions & 26 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('eventSender tests', () => {
return utils.eventSender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackEvent).toHaveBeenCalledTimes(1);
})

});

test('calls sendEvent with base event data when no metrics provided', () => {
Expand All @@ -116,16 +116,16 @@ describe('eventSender tests', () => {
measurements : {},
properties: {}
}

return utils.eventSender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackEvent).toHaveBeenCalledWith(expected);
})

});

test('calls sendEvent with enriched event data when api metrics provided', () => {
dummyMetricContex.apiMetrics = {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
Expand All @@ -139,7 +139,7 @@ describe('eventSender tests', () => {
let expected = {
...dummyMetricContex.baseEventData,
measurements: {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
Expand All @@ -151,31 +151,33 @@ describe('eventSender tests', () => {
'checkCert': true
}
}

return utils.eventSender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackEvent).toHaveBeenCalledWith(expected);
})

});

test('calls sendEvent with enriched event data when cert metrics provided', () => {
dummyMetricContex.certMetrics = {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
'targetTlsVersion': 1.3,
'targetExpireInDays': 8,
'domain': "foo",
'checkCert': true
'checkCert': true,
'certSuccess': 1
}


let expected = {
...dummyMetricContex.baseEventData,
measurements: {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'certSuccess': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
'targetTlsVersion': 1.3,
Expand All @@ -186,7 +188,7 @@ describe('eventSender tests', () => {
'checkCert': true
}
}

return utils.eventSender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackEvent).toHaveBeenCalledWith(expected);
})
Expand All @@ -197,7 +199,7 @@ describe('eventSender tests', () => {

describe('telemetrySender tests', () => {
test('not calls trackAvailability when no metric provided', () => {

return utils.telemetrySender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackAvailability).toHaveBeenCalledTimes(0);
})
Expand All @@ -206,7 +208,7 @@ describe('telemetrySender tests', () => {

test('calls trackAvailability once when only api metric provided', () => {
dummyMetricContex.apiMetrics = {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
Expand All @@ -215,7 +217,7 @@ describe('telemetrySender tests', () => {
'domain': "foo",
'checkCert': true
}

return utils.telemetrySender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackAvailability).toHaveBeenCalledTimes(1);
})
Expand All @@ -224,7 +226,7 @@ describe('telemetrySender tests', () => {
test('calls trackAvailability once when only cert metric provided', () => {

dummyMetricContex.certMetrics = {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
Expand All @@ -233,7 +235,7 @@ describe('telemetrySender tests', () => {
'domain': "foo",
'checkCert': true
}

return utils.telemetrySender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackAvailability).toHaveBeenCalledTimes(1);
})
Expand All @@ -242,7 +244,7 @@ describe('telemetrySender tests', () => {
test('trackAvailability not called when cert metric provided but checkCertificate is false', () => {

dummyMetricContex.certMetrics = {
'duration': 100,
'duration': 100,
'targetStatus': 1,
'targetExpirationTimestamp': 1000,
'httpStatus': 200,
Expand All @@ -252,12 +254,12 @@ describe('telemetrySender tests', () => {
'checkCert': true
}
dummyMetricContex.monitoringConfiguration.checkCertificate = false

return utils.telemetrySender(dummyTelemetryClient)(dummyMetricContex).then(data =>{
expect(trackAvailability).toHaveBeenCalledTimes(0);
})
});

})


Expand Down Expand Up @@ -308,17 +310,17 @@ describe('certChecker tests', () => {
dummySslClient.get.mockReturnValue(new Promise((resolve, reject) => {
resolve({valid_to: expirationDate})
}))

dummyMetricContex.monitoringConfiguration.checkCertificate = true

let expected = {
...dummyMetricContex
}

expected.certMetrics['success'] = true;
expected.certMetrics['success'] = true;
expected.certMetrics['certSuccess'] = true
expected.certMetrics['checkCert'] = true
expected.certMetrics['targetExpireInDays'] = 10
expected.certMetrics['targetExpireInDays'] = 10
expected.certMetrics['targetExpirationTimestamp'] = expirationDate.getTime();
expected.certMetrics['runLocation'] = `${dummyMetricContex.monitoringConfiguration.type}-cert`
expected.certMetrics.domain = "myhost.com"
Expand All @@ -332,7 +334,7 @@ describe('certChecker tests', () => {
dummySslClient.get.mockReturnValue(new Promise((resolve, reject) => {
reject({message: "error message"})
}))

let myMetricContext = {
...dummyMetricContex
}
Expand All @@ -342,7 +344,7 @@ describe('certChecker tests', () => {
...myMetricContext
}

expected.certMetrics['success'] = false;
expected.certMetrics['success'] = false;
expected.certMetrics['checkCert'] = true
expected.certMetrics['message'] = "error message"
expected.certMetrics['runLocation'] = `${dummyMetricContex.monitoringConfiguration.type}-cert`
Expand Down Expand Up @@ -426,5 +428,5 @@ describe('checkApi tests', () => {
})
});

})

})

0 comments on commit bf93802

Please sign in to comment.