1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-11 06:10:05 +00:00

chore: removed httpsAgent type + clean up

This commit is contained in:
Saad Jutt
2021-10-07 13:45:50 +05:00
parent 2849e6ed07
commit 6ff8eece7b
11 changed files with 46 additions and 143 deletions

View File

@@ -5,12 +5,6 @@ import { app, mockedAuthResponse } from './SAS_server_app'
import { ServerType } from '@sasjs/utils'
import SASjs from '../SASjs'
import * as axiosModules from '../utils/createAxiosInstance'
import {
clientCert,
createCertificates,
rootCaCert,
serverCert
} from './serverUtils'
const axiosActual = jest.requireActual('axios')
@@ -84,9 +78,7 @@ describe('RequestClient - Self Signed Server', () => {
adapter = new SASjs({
serverUrl: SERVER_URL,
serverType: ServerType.SasViya,
httpsAgentConfiguration: {
selfSigned: { ca: [sslConfig.certificate] }
}
httpsAgentOptions: { ca: [sslConfig.certificate] }
})
})
@@ -115,9 +107,7 @@ describe('RequestClient - Self Signed Server', () => {
const adapterAllowInsecure = new SASjs({
serverUrl: SERVER_URL,
serverType: ServerType.SasViya,
httpsAgentConfiguration: {
allowInsecure: true
}
httpsAgentOptions: { rejectUnauthorized: false }
})
const authResponse = await adapterAllowInsecure.getAccessToken(

View File

@@ -1,77 +0,0 @@
var https = require('https')
var { Cert } = require('selfsigned-ca')
// Root CA certificate used to sign other certificates.
// argument(s) point to .crt and .key file paths - ./selfsigned.root-ca.crt & ./selfsigned.root-ca.key
export const rootCaCert = new Cert('selfsigned.root-ca')
// The certificate generated for use in the HTTP server. It is signed by the CA certificate.
// That way you can create any amount of certificates and they will be all trusted as long
// as the Root CA certificate is trusted (installed to device's keychain).
// argument(s) point to .crt and .key file paths - ./selfsigned.localhost.crt & ./selfsigned.localhost.key
export const serverCert = new Cert(`selfsigned.localhost`)
export const clientCert = new Cert(`selfsigned.client`)
// .then(startHttpsServer)
// .then(() => console.log('certificates ready, server listening'))
// .catch(console.error)
export async function createCertificates() {
// await createRootCertificate()
console.log('creating server certificate')
createServerCertificate()
console.log('server certificate created & stored')
}
function startHttpsServer() {
var server = https.createServer(serverCert, (req: any, res: any) => {
res.writeHead(200)
res.end('hello world\n')
})
server.listen(443)
}
async function loadRootCertificate() {
await rootCaCert.load()
if (!(await rootCaCert.isInstalled())) {
// Make sure the CA is installed to device's keychain so that all server certificates
// signed by the CA are automatically trusted and green.
await rootCaCert.install()
}
}
async function createRootCertificate() {
console.log('createRootCertificate')
// Couldn't load existing root CA certificate. Generate new one.
rootCaCert.createRootCa({
subject: {
commonName: 'My Trusted Certificate Authority'
}
})
console.log('rootCaCert', rootCaCert)
// console.log('createRootCertificate saving')
// await rootCaCert.save()
// console.log('createRootCertificate saved')
// Install the newly created CA to device's keychain so that all server certificates
// signed by the CA are automatically trusted and green.
// await rootCaCert.install()
// console.log('createRootCertificate installed')
}
async function createServerCertificate() {
var serverCertOptions = {
subject: {
commonName: 'localhost'
},
extensions: [
{
name: 'subjectAltName',
altNames: [
{ type: 2, value: 'localhost' }, // DNS
{ type: 7, ip: '127.0.0.1' } // IP
]
}
]
}
serverCert.create(serverCertOptions, rootCaCert)
await serverCert.save()
}