Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
01823fb683 | |||
649e69e1f2 | |||
05a361046e | |||
a551989f8b | |||
7f765c08e4 | |||
4e7b5a693d | |||
20e36fbdf2 | |||
a61d87a9a0 | |||
953957cae3 | |||
c712a9a09c | |||
5a94f116e1 | |||
0e80700481 |
38
changelog.md
38
changelog.md
@ -1,5 +1,43 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-11-06 - 5.4.0 - feat(node)
|
||||||
|
Add smartmongo and smarts3 integration in node tools
|
||||||
|
|
||||||
|
- Added createSmartmongo method to TapNodeTools for creating SmartMongo instances.
|
||||||
|
- Added createSmarts3 method to TapNodeTools for creating Smarts3 instances.
|
||||||
|
- Updated dependencies with smartmongo and smarts3 in package.json.
|
||||||
|
|
||||||
|
## 2024-09-19 - 5.3.0 - feat(TapNodeTools)
|
||||||
|
Add getEnvVarOnDemand method to TapNodeTools
|
||||||
|
|
||||||
|
- Introduced a new method getEnvVarOnDemand to the TapNodeTools class to fetch environment variables on demand.
|
||||||
|
- Enhanced getQenv function in TapNodeTools class to cache the Qenv instance for better performance.
|
||||||
|
|
||||||
|
## 2024-09-19 - 5.2.2 - fix(core)
|
||||||
|
Ensure reliability in test setup and execution
|
||||||
|
|
||||||
|
- Added new pre-task functionality to log starting of tasks.
|
||||||
|
- Enhanced `runCommand` method to better handle shell command execution.
|
||||||
|
- Fixed issue in `createHttpsCert` to correctly generate self-signed certificates.
|
||||||
|
|
||||||
|
## 2024-09-19 - 5.2.1 - fix(tapbundle)
|
||||||
|
Add qenv package to dependencies for environment management
|
||||||
|
|
||||||
|
- Added @push.rocks/qenv to dependencies in package.json.
|
||||||
|
- Updated TapNodeTools class in ts_node/classes.tapnodetools.ts to include getQenv method.
|
||||||
|
- Imported qenv in ts_node/plugins.ts.
|
||||||
|
|
||||||
|
## 2024-09-18 - 5.2.0 - feat(TapNodeTools)
|
||||||
|
Add ability to create HTTPS certificates with self-signed option
|
||||||
|
|
||||||
|
- Introduced a new parameter `allowSelfSigned` to the `createHttpsCert` function.
|
||||||
|
|
||||||
|
## 2024-09-18 - 5.1.4 - fix(ts_node)
|
||||||
|
Fixed issues in HTTPS certificate generation for TapNodeTools
|
||||||
|
|
||||||
|
- Updated 'createHttpsCert' method in 'TapNodeTools' to use 'smartcrypto' for generating RSA key pair and self-signed certificate.
|
||||||
|
- Corrected certificate and private key PEM encoding.
|
||||||
|
|
||||||
## 2024-09-18 - 5.1.3 - fix(ts_node/classes.tapnodetools.ts)
|
## 2024-09-18 - 5.1.3 - fix(ts_node/classes.tapnodetools.ts)
|
||||||
Refactored methods and improved type annotations in TapNodeTools class.
|
Refactored methods and improved type annotations in TapNodeTools class.
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/tapbundle",
|
"name": "@push.rocks/tapbundle",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "5.1.3",
|
"version": "5.4.0",
|
||||||
"description": "A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.",
|
"description": "A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./dist_ts/index.js",
|
".": "./dist_ts/index.js",
|
||||||
@ -26,11 +26,15 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@open-wc/testing": "^4.0.0",
|
"@open-wc/testing": "^4.0.0",
|
||||||
"@push.rocks/consolecolor": "^2.0.2",
|
"@push.rocks/consolecolor": "^2.0.2",
|
||||||
|
"@push.rocks/qenv": "^6.0.5",
|
||||||
|
"@push.rocks/smartcrypto": "^2.0.4",
|
||||||
"@push.rocks/smartdelay": "^3.0.5",
|
"@push.rocks/smartdelay": "^3.0.5",
|
||||||
"@push.rocks/smartenv": "^5.0.12",
|
"@push.rocks/smartenv": "^5.0.12",
|
||||||
"@push.rocks/smartexpect": "^1.2.1",
|
"@push.rocks/smartexpect": "^1.2.1",
|
||||||
"@push.rocks/smartjson": "^5.0.20",
|
"@push.rocks/smartjson": "^5.0.20",
|
||||||
|
"@push.rocks/smartmongo": "^2.0.10",
|
||||||
"@push.rocks/smartpromise": "^4.0.4",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
|
"@push.rocks/smarts3": "^2.2.1",
|
||||||
"@push.rocks/smartshell": "^3.0.6",
|
"@push.rocks/smartshell": "^3.0.6",
|
||||||
"@push.rocks/smarttime": "^4.0.8"
|
"@push.rocks/smarttime": "^4.0.8"
|
||||||
},
|
},
|
||||||
|
9311
pnpm-lock.yaml
generated
9311
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -11,8 +11,18 @@ tap.test('should create a https cert', async () => {
|
|||||||
const { key, cert } = await tapNodeTools.createHttpsCert('localhost');
|
const { key, cert } = await tapNodeTools.createHttpsCert('localhost');
|
||||||
console.log(key);
|
console.log(key);
|
||||||
console.log(cert);
|
console.log(cert);
|
||||||
expect(key).toInclude('-----BEGIN PRIVATE KEY-----');
|
expect(key).toInclude('-----BEGIN RSA PRIVATE KEY-----');
|
||||||
expect(cert).toInclude('-----BEGIN CERTIFICATE-----');
|
expect(cert).toInclude('-----BEGIN CERTIFICATE-----');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a smartmongo instance', async () => {
|
||||||
|
const smartmongo = await tapNodeTools.createSmartmongo();
|
||||||
|
await smartmongo.stop();
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should create a smarts3 instance', async () => {
|
||||||
|
const smarts3 = await tapNodeTools.createSmarts3();
|
||||||
|
await smarts3.stop();
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/tapbundle',
|
name: '@push.rocks/tapbundle',
|
||||||
version: '5.1.3',
|
version: '5.4.0',
|
||||||
description: 'A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.'
|
description: 'A test automation library bundling utilities and tools for TAP (Test Anything Protocol) based testing, specifically tailored for tapbuffer.'
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,20 @@
|
|||||||
import * as plugins from './plugins.js';
|
import * as plugins from './plugins.js';
|
||||||
import { createSign } from 'crypto';
|
|
||||||
|
|
||||||
class TapNodeTools {
|
class TapNodeTools {
|
||||||
private smartshellInstance: plugins.smartshell.Smartshell;
|
private smartshellInstance: plugins.smartshell.Smartshell;
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
|
private qenv: plugins.qenv.Qenv;
|
||||||
|
public async getQenv(): Promise<plugins.qenv.Qenv> {
|
||||||
|
this.qenv = this.qenv || new plugins.qenv.Qenv('./', '.nogit/');
|
||||||
|
return this.qenv;
|
||||||
|
}
|
||||||
|
public async getEnvVarOnDemand(envVarNameArg: string): Promise<string> {
|
||||||
|
const qenv = await this.getQenv();
|
||||||
|
return qenv.getEnvVarOnDemand(envVarNameArg);
|
||||||
|
}
|
||||||
|
|
||||||
public async runCommand(commandArg: string): Promise<any> {
|
public async runCommand(commandArg: string): Promise<any> {
|
||||||
if (!this.smartshellInstance) {
|
if (!this.smartshellInstance) {
|
||||||
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
||||||
@ -17,48 +26,69 @@ class TapNodeTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createHttpsCert(
|
public async createHttpsCert(
|
||||||
commonName: string = 'localhost'
|
commonName: string = 'localhost',
|
||||||
|
allowSelfSigned: boolean = true
|
||||||
): Promise<{ key: string; cert: string }> {
|
): Promise<{ key: string; cert: string }> {
|
||||||
// Generate RSA key pair
|
if (allowSelfSigned) {
|
||||||
const { publicKey, privateKey } = plugins.crypto.generateKeyPairSync('rsa', {
|
// set node to allow self-signed certificates
|
||||||
modulusLength: 2048,
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
||||||
publicExponent: 65537,
|
}
|
||||||
});
|
|
||||||
|
// Generate a key pair
|
||||||
|
const keys = plugins.smartcrypto.nodeForge.pki.rsa.generateKeyPair(2048);
|
||||||
|
|
||||||
// Create a self-signed certificate
|
// Create a self-signed certificate
|
||||||
const cert = this.generateSelfSignedCert(publicKey, privateKey, commonName);
|
const cert = plugins.smartcrypto.nodeForge.pki.createCertificate();
|
||||||
|
cert.publicKey = keys.publicKey;
|
||||||
|
cert.serialNumber = '01';
|
||||||
|
cert.validity.notBefore = new Date();
|
||||||
|
cert.validity.notAfter = new Date();
|
||||||
|
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
||||||
|
|
||||||
// Export the private key and return the cert and key
|
const attrs = [
|
||||||
const keyContent = privateKey.export({
|
{ name: 'commonName', value: commonName },
|
||||||
type: 'pkcs8',
|
{ name: 'countryName', value: 'US' },
|
||||||
format: 'pem',
|
{ shortName: 'ST', value: 'California' },
|
||||||
});
|
{ name: 'localityName', value: 'San Francisco' },
|
||||||
|
{ name: 'organizationName', value: 'My Company' },
|
||||||
|
{ shortName: 'OU', value: 'Dev' },
|
||||||
|
];
|
||||||
|
cert.setSubject(attrs);
|
||||||
|
cert.setIssuer(attrs);
|
||||||
|
|
||||||
|
// Sign the certificate with its own private key (self-signed)
|
||||||
|
cert.sign(keys.privateKey, plugins.smartcrypto.nodeForge.md.sha256.create());
|
||||||
|
|
||||||
|
// PEM encode the private key and certificate
|
||||||
|
const pemKey = plugins.smartcrypto.nodeForge.pki.privateKeyToPem(keys.privateKey);
|
||||||
|
const pemCert = plugins.smartcrypto.nodeForge.pki.certificateToPem(cert);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: keyContent as string,
|
key: pemKey,
|
||||||
cert: cert,
|
cert: pemCert,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateSelfSignedCert(publicKey, privateKey, commonName: string): string {
|
/**
|
||||||
const sign = createSign('SHA256');
|
* create and return a smartmongo instance
|
||||||
const certData = {
|
*/
|
||||||
subject: `/CN=${commonName}`,
|
public async createSmartmongo() {
|
||||||
publicKey: publicKey.export({ type: 'spki', format: 'pem' }),
|
const smartmongoMod = await import('@push.rocks/smartmongo');
|
||||||
};
|
const smartmongoInstance = new smartmongoMod.SmartMongo();
|
||||||
|
await smartmongoInstance.start();
|
||||||
|
return smartmongoInstance;
|
||||||
|
}
|
||||||
|
|
||||||
sign.update(JSON.stringify(certData));
|
/**
|
||||||
sign.end();
|
* create and return a smarts3 instance
|
||||||
|
*/
|
||||||
const signature = sign.sign(privateKey, 'base64');
|
public async createSmarts3() {
|
||||||
|
const smarts3Mod = await import('@push.rocks/smarts3');
|
||||||
return (
|
const smarts3Instance = new smarts3Mod.Smarts3({
|
||||||
'-----BEGIN CERTIFICATE-----\n' +
|
cleanSlate: true,
|
||||||
Buffer.from(certData.publicKey).toString('base64') +
|
});
|
||||||
'\n' +
|
await smarts3Instance.start();
|
||||||
signature +
|
return smarts3Instance;
|
||||||
'\n-----END CERTIFICATE-----\n'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import * as fs from 'fs';
|
|||||||
export { crypto,fs };
|
export { crypto,fs };
|
||||||
|
|
||||||
// @push.rocks scope
|
// @push.rocks scope
|
||||||
|
import * as qenv from '@push.rocks/qenv';
|
||||||
|
import * as smartcrypto from '@push.rocks/smartcrypto';
|
||||||
import * as smartshell from '@push.rocks/smartshell';
|
import * as smartshell from '@push.rocks/smartshell';
|
||||||
|
|
||||||
export { smartshell };
|
export { qenv, smartcrypto, smartshell };
|
||||||
|
Reference in New Issue
Block a user