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

Add support for strict-ssl config #1025

Merged
merged 6 commits into from
Oct 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default class Config {
userAgent: String(this.getOption('user-agent')),
httpProxy: String(this.getOption('proxy') || ''),
httpsProxy: String(this.getOption('https-proxy') || ''),
strictSSL: Boolean(this.getOption('strict-ssl')),
});
}

Expand Down
19 changes: 14 additions & 5 deletions src/registries/yarn-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const DEFAULTS = {
'ignore-scripts': false,
'ignore-optional': false,
registry: YARN_REGISTRY,
'strict-ssl': true,
'user-agent': [
`yarn/${pkg.version}`,
'npm/?',
Expand Down Expand Up @@ -56,14 +57,22 @@ export default class YarnRegistry extends NpmRegistry {
homeConfig: Object;

getOption(key: string): mixed {
let val = this.config[key] || this.registries.npm.getOption(npmMap[key]);
let val = this.config[key];

// if we have no yarn option for this or have used a default then use the npm
// value if it exists
if (!val || val === DEFAULTS[key]) {
val = this.registries.npm.getOption(key) || val;
// if this isn't set in a yarn config, then use npm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this commit from the PR, happy to accept the other option but I have problems with this code that I'll address in your other PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, this seems fine. Thanks!

if (typeof val === 'undefined') {
val = this.registries.npm.getOption(npmMap[key]);
}

if (typeof val === 'undefined') {
val = this.registries.npm.getOption(key);
}

// if this isn't set in a yarn config or npm config, then use the default (or undefined)
if (typeof val === 'undefined') {
val = DEFAULTS[key];
}

return val;
}

Expand Down
11 changes: 10 additions & 1 deletion src/util/request-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type RequestParams<T> = {
proxy?: string,
encoding?: ?string,
forever?: boolean,
strictSSL?: boolean,
headers?: {
[name: string]: string
},
Expand Down Expand Up @@ -67,6 +68,7 @@ export default class RequestManager {
this.captureHar = false;
this.httpsProxy = null;
this.httpProxy = null;
this.strictSSL = true;
this.userAgent = '';
this.reporter = reporter;
this.running = 0;
Expand All @@ -82,6 +84,7 @@ export default class RequestManager {
running: number;
httpsProxy: ?string;
httpProxy: ?string;
strictSSL: boolean;
offlineQueue: Array<RequestOptions>;
queue: Array<Object>;
max: number;
Expand All @@ -98,6 +101,7 @@ export default class RequestManager {
captureHar?: boolean,
httpProxy?: string,
httpsProxy?: string,
strictSSL?: boolean,
}) {
if (opts.userAgent != null) {
this.userAgent = opts.userAgent;
Expand All @@ -118,6 +122,10 @@ export default class RequestManager {
if (opts.httpsProxy != null) {
this.httpsProxy = opts.httpsProxy;
}

if (opts.strictSSL !== null && typeof opts.strictSSL !== 'undefined') {
this.strictSSL = opts.strictSSL;
}
}

/**
Expand Down Expand Up @@ -155,7 +163,8 @@ export default class RequestManager {
params.method = params.method || 'GET';
params.forever = true;
params.retryAttempts = 0;

params.strictSSL = this.strictSSL;

params.headers = Object.assign({
'User-Agent': this.userAgent,
}, params.headers);
Expand Down