Skip to content

Commit

Permalink
skip cert expiry test on node v14, because crypto.X509Certificate cam…
Browse files Browse the repository at this point in the history
…e in node v15
  • Loading branch information
trentm committed Jun 8, 2024
1 parent 9ede0a9 commit a901be8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as protoLoader from '@grpc/proto-loader';
import { diag } from '@opentelemetry/api';

import * as assert from 'assert';
import { X509Certificate } from 'crypto';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as grpc from '@grpc/grpc-js';
import * as path from 'path';
Expand Down Expand Up @@ -143,15 +143,15 @@ const testCollectorExporter = (params: TestParams) => {
sinon.restore();
});

if (useTLS) {
if (useTLS && crypto.X509Certificate) {
it('test certs are valid', () => {
const certPaths = [
'./test/certs/ca.crt',
'./test/certs/client.crt',
'./test/certs/server.crt',
];
certPaths.forEach(certPath => {
const cert = new X509Certificate(fs.readFileSync(certPath));
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
const now = new Date();
assert.ok(
new Date(cert.validTo) > now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '@opentelemetry/sdk-trace-base';

import * as assert from 'assert';
import { X509Certificate } from 'crypto';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as grpc from '@grpc/grpc-js';
import * as path from 'path';
Expand Down Expand Up @@ -150,15 +150,15 @@ const testCollectorExporter = (params: TestParams) => {
sinon.restore();
});

if (useTLS) {
if (useTLS && crypto.X509Certificate) {
it('test certs are valid', () => {
const certPaths = [
'./test/certs/ca.crt',
'./test/certs/client.crt',
'./test/certs/server.crt',
];
certPaths.forEach(certPath => {
const cert = new X509Certificate(fs.readFileSync(certPath));
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
const now = new Date();
assert.ok(
new Date(cert.validTo) > now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as protoLoader from '@grpc/proto-loader';
import { diag, DiagLogger } from '@opentelemetry/api';
import * as assert from 'assert';
import { X509Certificate } from 'crypto';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as grpc from '@grpc/grpc-js';
import * as path from 'path';
Expand Down Expand Up @@ -169,15 +169,15 @@ const testOTLPMetricExporter = (params: TestParams) => {
sinon.restore();
});

if (useTLS) {
if (useTLS && crypto.X509Certificate) {
it('test certs are valid', () => {
const certPaths = [
'./test/certs/ca.crt',
'./test/certs/client.crt',
'./test/certs/server.crt',
];
certPaths.forEach(certPath => {
const cert = new X509Certificate(fs.readFileSync(certPath));
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
const now = new Date();
assert.ok(
new Date(cert.validTo) > now,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
GrpcExporterTransportParameters,
} from '../src/grpc-exporter-transport';
import * as assert from 'assert';
import { X509Certificate } from 'crypto';
import * as crypto from 'crypto';
import * as fs from 'fs';
import sinon = require('sinon');
import { Metadata, Server, ServerCredentials } from '@grpc/grpc-js';
Expand Down Expand Up @@ -126,17 +126,19 @@ describe('GrpcExporterTransport', function () {
});

describe('createSslCredentials', function () {
it('test certs are valid', () => {
const certPaths = ['./test/certs/ca.crt', './test/certs/server.crt'];
certPaths.forEach(certPath => {
const cert = new X509Certificate(fs.readFileSync(certPath));
const now = new Date();
assert.ok(
new Date(cert.validTo) > now,
`TLS cert "${certPath}" is still valid: cert.validTo="${cert.validTo}" (if this fails use 'npm run maint:regenerate-test-certs')`
);
if (crypto.X509Certificate) {
it('test certs are valid', () => {
const certPaths = ['./test/certs/ca.crt', './test/certs/server.crt'];
certPaths.forEach(certPath => {
const cert = new crypto.X509Certificate(fs.readFileSync(certPath));
const now = new Date();
assert.ok(
new Date(cert.validTo) > now,
`TLS cert "${certPath}" is still valid: cert.validTo="${cert.validTo}" (if this fails use 'npm run maint:regenerate-test-certs')`
);
});
});
});
}

it('creates SSL grpc credentials', function () {
const credentials = createSslCredentials(
Expand Down

0 comments on commit a901be8

Please sign in to comment.