Skip to content

Commit

Permalink
fix: set strictSSL on custom downloads from NPM config. Fixes #211
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Mar 6, 2020
1 parent efa9d9c commit d264f0b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 7 deletions.
61 changes: 57 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"chalk": "2.3.1",
"check-types": "7.3.0",
"cross-spawn": "^7.0.1",
"libnpmconfig": "^1.2.1",
"mkdirp": "0.5.1",
"q": "1.5.1",
"request": "2.87.0",
Expand Down
23 changes: 22 additions & 1 deletion standalone/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as fs from 'fs';
import * as path from 'path';
import * as chai from 'chai';
import { BinaryEntry, Config } from './install';
import { BinaryEntry, Config, useStrictSSL } from './install';

const expect = chai.expect;

Expand All @@ -19,6 +19,27 @@ describe('Install', () => {
}
});

describe('#useStrictSSL', () => {
afterEach(() => {
delete process.env['npm_config_strict-ssl']
})
describe('when "strict-ssl" is specified in an NPM configuration', () => {
it('returns a true', () => {
process.env['npm_config_strict-ssl'] = "true"
expect(useStrictSSL()).to.be.true
})
it('returns a false', () => {
process.env['npm_config_strict-ssl'] = "false"
expect(useStrictSSL()).to.be.false
})
})
describe('when "strict-ssl" is not specified in any NPM configuration', () => {
it('returns true', () => {
expect(useStrictSSL()).to.be.true
})
})
})

function createConfig(): Config {
return require('./install').createConfig();
}
Expand Down
12 changes: 10 additions & 2 deletions standalone/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import * as Request from 'request';
import unzipper = require('unzipper');
import tar = require('tar');
import pactEnvironment from '../src/pact-environment';
// we have to u se ES6 imports as it's providing correct types for chalk.
// we have to use ES6 imports as it's providing correct types for chalk.
import chalk from 'chalk';

import path = require('path');
import fs = require('fs');
import urljoin = require('url-join');

// eslint-disable-next-line @typescript-eslint/no-var-requires
const config = require('libnpmconfig')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sumchecker = require('sumchecker');

Expand Down Expand Up @@ -142,6 +144,11 @@ const CIs = [
'WERCKER_ROOT',
];

export function useStrictSSL(): boolean {
const prop = config.read()['strict-ssl']
return prop === "true" || prop === undefined || prop === ""
}

function downloadFileRetry(
url: string,
filepath: string,
Expand All @@ -157,6 +164,7 @@ function downloadFileRetry(
headers: {
'User-Agent': 'https://github.com/pact-foundation/pact-node',
},
strictSSL: useStrictSSL()
})
.on('error', (e: string) => reject(e))
.on(
Expand Down

0 comments on commit d264f0b

Please sign in to comment.