Skip to content

Commit

Permalink
Fix authentication when @scope:registry does not specify trailing sla…
Browse files Browse the repository at this point in the history
…sh (#2168)
  • Loading branch information
KidkArolis authored and bestander committed Dec 7, 2016
1 parent eb66b9c commit 776359e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
14 changes: 14 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,20 @@ test('install a scoped module from authed private registry', (): Promise<void> =
});
});

test('install a scoped module from authed private registry with a missing trailing slash', (): Promise<void> => {
return runInstall({noLockfile: true}, 'install-from-authed-private-registry-no-slash', async (config) => {
const authedRequests = request.__getAuthedRequests();
assert.equal(authedRequests[0].url, 'https://registry.yarnpkg.com/@types%2flodash');
assert.equal(authedRequests[0].headers.authorization, 'Bearer abc123');
assert.equal(authedRequests[1].url, 'https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.37.tgz');
assert.equal(authedRequests[1].headers.authorization, 'Bearer abc123');
assert.equal(
(await fs.readFile(path.join(config.cwd, 'node_modules', '@types', 'lodash', 'index.d.ts'))).split('\n')[0],
'// Type definitions for Lo-Dash 4.14',
);
});
});

test.concurrent('install a module with incompatible optional dependency should skip dependency',
(): Promise<void> => {
return runInstall({}, 'install-should-skip-incompatible-optional-dep', async (config) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//registry.yarnpkg.com/:_authToken=abc123
@types:registry=https://registry.yarnpkg.com
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"@types/lodash": "4.14.37"
}
}
2 changes: 1 addition & 1 deletion src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default class NpmRegistry extends Registry {
registry = registry.replace(/^https?:/, '');

// Check for bearer token.
let auth = this.getScopedOption(registry, '_authToken');
let auth = this.getScopedOption(registry.replace(/\/?$/, '/'), '_authToken');
if (auth) {
return `Bearer ${String(auth)}`;
}
Expand Down

0 comments on commit 776359e

Please sign in to comment.