Skip to content

Commit a901be8

Browse files
committed
skip cert expiry test on node v14, because crypto.X509Certificate came in node v15
1 parent 9ede0a9 commit a901be8

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

experimental/packages/exporter-logs-otlp-grpc/test/OTLPLogExporter.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import * as protoLoader from '@grpc/proto-loader';
1818
import { diag } from '@opentelemetry/api';
1919

2020
import * as assert from 'assert';
21-
import { X509Certificate } from 'crypto';
21+
import * as crypto from 'crypto';
2222
import * as fs from 'fs';
2323
import * as grpc from '@grpc/grpc-js';
2424
import * as path from 'path';
@@ -143,15 +143,15 @@ const testCollectorExporter = (params: TestParams) => {
143143
sinon.restore();
144144
});
145145

146-
if (useTLS) {
146+
if (useTLS && crypto.X509Certificate) {
147147
it('test certs are valid', () => {
148148
const certPaths = [
149149
'./test/certs/ca.crt',
150150
'./test/certs/client.crt',
151151
'./test/certs/server.crt',
152152
];
153153
certPaths.forEach(certPath => {
154-
const cert = new X509Certificate(fs.readFileSync(certPath));
154+
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
155155
const now = new Date();
156156
assert.ok(
157157
new Date(cert.validTo) > now,

experimental/packages/exporter-trace-otlp-grpc/test/OTLPTraceExporter.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '@opentelemetry/sdk-trace-base';
2323

2424
import * as assert from 'assert';
25-
import { X509Certificate } from 'crypto';
25+
import * as crypto from 'crypto';
2626
import * as fs from 'fs';
2727
import * as grpc from '@grpc/grpc-js';
2828
import * as path from 'path';
@@ -150,15 +150,15 @@ const testCollectorExporter = (params: TestParams) => {
150150
sinon.restore();
151151
});
152152

153-
if (useTLS) {
153+
if (useTLS && crypto.X509Certificate) {
154154
it('test certs are valid', () => {
155155
const certPaths = [
156156
'./test/certs/ca.crt',
157157
'./test/certs/client.crt',
158158
'./test/certs/server.crt',
159159
];
160160
certPaths.forEach(certPath => {
161-
const cert = new X509Certificate(fs.readFileSync(certPath));
161+
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
162162
const now = new Date();
163163
assert.ok(
164164
new Date(cert.validTo) > now,

experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/test/OTLPMetricExporter.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import * as protoLoader from '@grpc/proto-loader';
1818
import { diag, DiagLogger } from '@opentelemetry/api';
1919
import * as assert from 'assert';
20-
import { X509Certificate } from 'crypto';
20+
import * as crypto from 'crypto';
2121
import * as fs from 'fs';
2222
import * as grpc from '@grpc/grpc-js';
2323
import * as path from 'path';
@@ -169,15 +169,15 @@ const testOTLPMetricExporter = (params: TestParams) => {
169169
sinon.restore();
170170
});
171171

172-
if (useTLS) {
172+
if (useTLS && crypto.X509Certificate) {
173173
it('test certs are valid', () => {
174174
const certPaths = [
175175
'./test/certs/ca.crt',
176176
'./test/certs/client.crt',
177177
'./test/certs/server.crt',
178178
];
179179
certPaths.forEach(certPath => {
180-
const cert = new X509Certificate(fs.readFileSync(certPath));
180+
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
181181
const now = new Date();
182182
assert.ok(
183183
new Date(cert.validTo) > now,

experimental/packages/otlp-grpc-exporter-base/test/grpc-exporter-transport.test.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
GrpcExporterTransportParameters,
2222
} from '../src/grpc-exporter-transport';
2323
import * as assert from 'assert';
24-
import { X509Certificate } from 'crypto';
24+
import * as crypto from 'crypto';
2525
import * as fs from 'fs';
2626
import sinon = require('sinon');
2727
import { Metadata, Server, ServerCredentials } from '@grpc/grpc-js';
@@ -126,17 +126,19 @@ describe('GrpcExporterTransport', function () {
126126
});
127127

128128
describe('createSslCredentials', function () {
129-
it('test certs are valid', () => {
130-
const certPaths = ['./test/certs/ca.crt', './test/certs/server.crt'];
131-
certPaths.forEach(certPath => {
132-
const cert = new X509Certificate(fs.readFileSync(certPath));
133-
const now = new Date();
134-
assert.ok(
135-
new Date(cert.validTo) > now,
136-
`TLS cert "${certPath}" is still valid: cert.validTo="${cert.validTo}" (if this fails use 'npm run maint:regenerate-test-certs')`
137-
);
129+
if (crypto.X509Certificate) {
130+
it('test certs are valid', () => {
131+
const certPaths = ['./test/certs/ca.crt', './test/certs/server.crt'];
132+
certPaths.forEach(certPath => {
133+
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
134+
const now = new Date();
135+
assert.ok(
136+
new Date(cert.validTo) > now,
137+
`TLS cert "${certPath}" is still valid: cert.validTo="${cert.validTo}" (if this fails use 'npm run maint:regenerate-test-certs')`
138+
);
139+
});
138140
});
139-
});
141+
}
140142

141143
it('creates SSL grpc credentials', function () {
142144
const credentials = createSslCredentials(

0 commit comments

Comments
 (0)