Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: regenerate recently-expired test TLS certs #4777

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
skip cert expiry test on node v14, because crypto.X509Certificate cam…
…e in node v15
trentm committed Jun 8, 2024
commit a901be83f8f458d0567e0ef49d30f7d377620c0e
Original file line number Diff line number Diff line change
@@ -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';
@@ -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,
Original file line number Diff line number Diff line change
@@ -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';
@@ -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,
Original file line number Diff line number Diff line change
@@ -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';
@@ -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,
Original file line number Diff line number Diff line change
@@ -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';
@@ -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(