Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
22ec504b0f | |||
3d39f65ed0 | |||
7c450876f2 | |||
d7c3752dfa | |||
f53e5bcc83 | |||
d8301314a7 | |||
155b0b9f91 | |||
61c493ce72 |
24
changelog.md
24
changelog.md
@ -1,5 +1,29 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-09-18 - 5.1.3 - fix(ts_node/classes.tapnodetools.ts)
|
||||||
|
Refactored methods and improved type annotations in TapNodeTools class.
|
||||||
|
|
||||||
|
- Refactored `runCommand` method to include proper type annotations.
|
||||||
|
- Enhanced `createHttpsCert` method with proper type annotations and key generation logic.
|
||||||
|
- Introduced `generateSelfSignedCert` method for better code organization and readability.
|
||||||
|
|
||||||
|
## 2024-09-18 - 5.1.2 - fix(TapNodeTools)
|
||||||
|
Default parameter added to createHttpsCert method
|
||||||
|
|
||||||
|
- Updated createHttpsCert method to provide a default value for the parameter commonName.
|
||||||
|
|
||||||
|
## 2024-09-18 - 5.1.1 - fix(ts_node)
|
||||||
|
Fixed createHttpsCert interface
|
||||||
|
|
||||||
|
- Removed unnecessary keyFile and certFile parameters from createHttpsCert method.
|
||||||
|
|
||||||
|
## 2024-09-18 - 5.1.0 - feat(ts_node)
|
||||||
|
Add support for HTTPS certificate creation
|
||||||
|
|
||||||
|
- Added TapNodeTools class with methods to run commands and create HTTPS certificates
|
||||||
|
- Exported necessary plugins including crypto and fs for node
|
||||||
|
- Updated test cases to include tests for HTTPS certificate creation
|
||||||
|
|
||||||
## 2024-09-17 - 5.0.25 - fix(core)
|
## 2024-09-17 - 5.0.25 - fix(core)
|
||||||
Fix typos in package.json, update dependencies and update workflow.
|
Fix typos in package.json, update dependencies and update workflow.
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/tapbundle",
|
"name": "@push.rocks/tapbundle",
|
||||||
"private": false,
|
"private": false,
|
||||||
"version": "5.0.25",
|
"version": "5.1.3",
|
||||||
"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",
|
||||||
|
@ -7,4 +7,12 @@ tap.test('should execure a command', async () => {
|
|||||||
expect(result.exitCode).toEqual(0);
|
expect(result.exitCode).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should create a https cert', async () => {
|
||||||
|
const { key, cert } = await tapNodeTools.createHttpsCert('localhost');
|
||||||
|
console.log(key);
|
||||||
|
console.log(cert);
|
||||||
|
expect(key).toInclude('-----BEGIN PRIVATE KEY-----');
|
||||||
|
expect(cert).toInclude('-----BEGIN CERTIFICATE-----');
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/tapbundle',
|
name: '@push.rocks/tapbundle',
|
||||||
version: '5.0.25',
|
version: '5.1.3',
|
||||||
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.'
|
||||||
}
|
}
|
||||||
|
65
ts_node/classes.tapnodetools.ts
Normal file
65
ts_node/classes.tapnodetools.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import * as plugins from './plugins.js';
|
||||||
|
import { createSign } from 'crypto';
|
||||||
|
|
||||||
|
class TapNodeTools {
|
||||||
|
private smartshellInstance: plugins.smartshell.Smartshell;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
public async runCommand(commandArg: string): Promise<any> {
|
||||||
|
if (!this.smartshellInstance) {
|
||||||
|
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
||||||
|
executor: 'bash',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const result = await this.smartshellInstance.exec(commandArg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async createHttpsCert(
|
||||||
|
commonName: string = 'localhost'
|
||||||
|
): Promise<{ key: string; cert: string }> {
|
||||||
|
// Generate RSA key pair
|
||||||
|
const { publicKey, privateKey } = plugins.crypto.generateKeyPairSync('rsa', {
|
||||||
|
modulusLength: 2048,
|
||||||
|
publicExponent: 65537,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a self-signed certificate
|
||||||
|
const cert = this.generateSelfSignedCert(publicKey, privateKey, commonName);
|
||||||
|
|
||||||
|
// Export the private key and return the cert and key
|
||||||
|
const keyContent = privateKey.export({
|
||||||
|
type: 'pkcs8',
|
||||||
|
format: 'pem',
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
key: keyContent as string,
|
||||||
|
cert: cert,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private generateSelfSignedCert(publicKey, privateKey, commonName: string): string {
|
||||||
|
const sign = createSign('SHA256');
|
||||||
|
const certData = {
|
||||||
|
subject: `/CN=${commonName}`,
|
||||||
|
publicKey: publicKey.export({ type: 'spki', format: 'pem' }),
|
||||||
|
};
|
||||||
|
|
||||||
|
sign.update(JSON.stringify(certData));
|
||||||
|
sign.end();
|
||||||
|
|
||||||
|
const signature = sign.sign(privateKey, 'base64');
|
||||||
|
|
||||||
|
return (
|
||||||
|
'-----BEGIN CERTIFICATE-----\n' +
|
||||||
|
Buffer.from(certData.publicKey).toString('base64') +
|
||||||
|
'\n' +
|
||||||
|
signature +
|
||||||
|
'\n-----END CERTIFICATE-----\n'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const tapNodeTools = new TapNodeTools();
|
@ -1,21 +1 @@
|
|||||||
import * as plugins from './plugins.js';
|
export * from './classes.tapnodetools.js';
|
||||||
|
|
||||||
class TapNodeTools {
|
|
||||||
|
|
||||||
private smartshellInstance: plugins.smartshell.Smartshell;
|
|
||||||
constructor() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public async runCommand(commandArg) {
|
|
||||||
if (!this.smartshellInstance) {
|
|
||||||
this.smartshellInstance = new plugins.smartshell.Smartshell({
|
|
||||||
executor: 'bash',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const result = await this.smartshellInstance.exec(commandArg);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const tapNodeTools = new TapNodeTools();
|
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
// node native
|
||||||
|
import * as crypto from 'crypto';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
export { crypto,fs };
|
||||||
|
|
||||||
|
// @push.rocks scope
|
||||||
import * as smartshell from '@push.rocks/smartshell';
|
import * as smartshell from '@push.rocks/smartshell';
|
||||||
|
|
||||||
export { smartshell };
|
export { smartshell };
|
||||||
|
Reference in New Issue
Block a user