From 477c612dcaefde11c92ff188a87d34655c3e80f2 Mon Sep 17 00:00:00 2001 From: Flavio Signorelli Date: Thu, 10 Nov 2016 17:59:41 +0000 Subject: [PATCH 1/4] fix private ssh urls --- .../resolvers/exotics/bitbucket-resolver.js | 52 ++++++++++++++++++- src/resolvers/exotics/git-resolver.js | 2 +- src/resolvers/exotics/hosted-git-resolver.js | 48 +++++++++++++++-- src/util/request-manager.js | 3 ++ 4 files changed, 99 insertions(+), 6 deletions(-) diff --git a/__tests__/resolvers/exotics/bitbucket-resolver.js b/__tests__/resolvers/exotics/bitbucket-resolver.js index a3a5d151a6..168be27b39 100644 --- a/__tests__/resolvers/exotics/bitbucket-resolver.js +++ b/__tests__/resolvers/exotics/bitbucket-resolver.js @@ -1,11 +1,13 @@ /* @flow */ - +import {explodeHostedGitFragment} from '../../../src/resolvers/exotics/hosted-git-resolver.js'; import BitBucketResolver from '../../../src/resolvers/exotics/bitbucket-resolver.js'; import type {ExplodedFragment} from '../../../src/resolvers/exotics/hosted-git-resolver.js'; import Git from '../../../src/util/git.js'; +import * as reporters from '../../../src/reporters/index.js'; const url = require('url'); const _bitBucketBase = 'https://bitbucket.org/'; +const reporter = new reporters.NoopReporter({}); test('hostname should be "bitbucket.org" ', () => { expect(BitBucketResolver.hostname).toBe('bitbucket.org'); @@ -15,6 +17,54 @@ test('protocol should be "bitbucket" ', () => { expect(BitBucketResolver.protocol).toBe('bitbucket'); }); +test('explodeHostedGitFragment should work for colon separator after host', () => { + const fragmentString = 'git@bitbucket.org:team2/repo.git'; + + const expectedFragment: ExplodedFragment = { + user: 'team2', + repo: 'repo', + hash: '', + }; + + expect(explodeHostedGitFragment(fragmentString, reporter)).toEqual(expectedFragment); +}); + +test('explodeHostedGitFragment should work for colon separator after host and with protocol before', () => { + const fragmentString = 'git+ssh://git@bitbucket.org:team/repo.git'; + + const expectedFragment: ExplodedFragment = { + user: 'team', + repo: 'repo', + hash: '', + }; + + expect(explodeHostedGitFragment(fragmentString, reporter)).toEqual(expectedFragment); +}); + +test('explodeHostedGitFragment should work for slash separator after host', () => { + const fragmentString = 'git@bitbucket.org/team/repo.git'; + + const expectedFragment: ExplodedFragment = { + user: 'team', + repo: 'repo', + hash: '', + }; + + expect(explodeHostedGitFragment(fragmentString, reporter)).toEqual(expectedFragment); +}); + +test('explodeHostedGitFragment should work for package name and colon separator after host', () => { + const fragmentString = 'package@git@bitbucket.org:team/repo.git'; + + const expectedFragment: ExplodedFragment = { + user: 'team', + repo: 'repo', + hash: '', + }; + + expect(explodeHostedGitFragment(fragmentString, reporter)).toEqual(expectedFragment); +}); + test('getTarballUrl should return the correct bitbucket tarball url', () => { const fragment: ExplodedFragment = { user: 'foo', diff --git a/src/resolvers/exotics/git-resolver.js b/src/resolvers/exotics/git-resolver.js index 933df367d9..bc2e32877a 100644 --- a/src/resolvers/exotics/git-resolver.js +++ b/src/resolvers/exotics/git-resolver.js @@ -15,7 +15,7 @@ const urlParse = require('url').parse; // we purposefully omit https and http as those are only valid if they end in the .git extension const GIT_PROTOCOLS = ['git:', 'git+ssh:', 'git+https:', 'ssh:']; -const GIT_HOSTS = ['github.com', 'gitlab.com', 'bitbucket.com']; +const GIT_HOSTS = ['github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']; export default class GitResolver extends ExoticResolver { constructor(request: PackageRequest, fragment: string) { diff --git a/src/resolvers/exotics/hosted-git-resolver.js b/src/resolvers/exotics/hosted-git-resolver.js index 76bf36dcda..819c020b22 100644 --- a/src/resolvers/exotics/hosted-git-resolver.js +++ b/src/resolvers/exotics/hosted-git-resolver.js @@ -15,21 +15,61 @@ export type ExplodedFragment = { hash: string, }; -export function explodeHostedGitFragment(fragment: string, reporter: Reporter): ExplodedFragment { +export function explodeHostedGitFragment(fragment: string, reporter: Reporter): ExplodedFragment { + + const preParts = fragment.split('@'); + if (preParts.length > 2) { + fragment = preParts[1] + '@' + preParts[2]; + } + // TODO: make sure this only has a length of 2 const parts = fragment.split(':'); - fragment = parts.pop(); + //fragment = parts.pop(); + + //console.log('Input Fragment: ' + fragment); + + if (parts.length == 3) { // protocol + host + folder + parts[1] = parts[1].indexOf('//') >= 0 ? parts[1].substr(2) : parts[1]; + fragment = parts[1] + '/' + parts[2]; + } else if (parts.length == 2) { + if (parts[0].indexOf('@') == -1) { // protocol + host + fragment = parts[1]; + } else { // host + folder + fragment = parts[0] + '/' + parts[1]; + } + } else if (parts.length == 1) { + fragment = parts[0]; + } else { + throw new MessageError(reporter.lang('invalidHostedGitFragment', fragment)); + } - const userParts = fragment.split('/'); + //console.log('Output Fragment: ' + fragment); + + const userParts = fragment.split('/'); + + //console.log(userParts); if (userParts.length >= 2) { + + if (userParts[0].indexOf('@') >= 0) { + userParts.shift(); + } + const user = userParts.shift(); const repoParts = userParts.join('/').split(/(?:[.]git)?#(.*)/); + + //console.log(repoParts); + + // console.log({ + // user, + // repo: repoParts[0].replace('.git', ''), + // hash: repoParts[1] || '', + // }); if (repoParts.length <= 3) { return { user, - repo: repoParts[0], + repo: repoParts[0].replace('.git', ''), hash: repoParts[1] || '', }; } diff --git a/src/util/request-manager.js b/src/util/request-manager.js index e0e134a2bf..49108965c6 100644 --- a/src/util/request-manager.js +++ b/src/util/request-manager.js @@ -370,6 +370,9 @@ export default class RequestManager { if (res.statusCode === 400 || res.statusCode === 404 || res.statusCode === 401) { body = false; } + if (res.request.followRedirect == false && (res.statusCode == 301 || res.statusCode == 302)) { + body = false; + } resolve(body); } }; From d524f6c44949275a88be3d4d9e629cd932172887 Mon Sep 17 00:00:00 2001 From: Flavio Signorelli Date: Tue, 15 Nov 2016 11:57:57 +0000 Subject: [PATCH 2/4] removing console.log --- src/resolvers/exotics/hosted-git-resolver.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/resolvers/exotics/hosted-git-resolver.js b/src/resolvers/exotics/hosted-git-resolver.js index 819c020b22..31a5a2510b 100644 --- a/src/resolvers/exotics/hosted-git-resolver.js +++ b/src/resolvers/exotics/hosted-git-resolver.js @@ -26,8 +26,6 @@ export function explodeHostedGitFragment(fragment: string, reporter: Reporter): const parts = fragment.split(':'); //fragment = parts.pop(); - //console.log('Input Fragment: ' + fragment); - if (parts.length == 3) { // protocol + host + folder parts[1] = parts[1].indexOf('//') >= 0 ? parts[1].substr(2) : parts[1]; fragment = parts[1] + '/' + parts[2]; @@ -43,12 +41,8 @@ export function explodeHostedGitFragment(fragment: string, reporter: Reporter): throw new MessageError(reporter.lang('invalidHostedGitFragment', fragment)); } - //console.log('Output Fragment: ' + fragment); - const userParts = fragment.split('/'); - //console.log(userParts); - if (userParts.length >= 2) { if (userParts[0].indexOf('@') >= 0) { @@ -57,14 +51,6 @@ export function explodeHostedGitFragment(fragment: string, reporter: Reporter): const user = userParts.shift(); const repoParts = userParts.join('/').split(/(?:[.]git)?#(.*)/); - - //console.log(repoParts); - - // console.log({ - // user, - // repo: repoParts[0].replace('.git', ''), - // hash: repoParts[1] || '', - // }); if (repoParts.length <= 3) { return { From eba69330197d185a631af5b059dc5fe3e136816d Mon Sep 17 00:00:00 2001 From: Flavio Signorelli Date: Wed, 16 Nov 2016 11:22:18 +0000 Subject: [PATCH 3/4] removed some comments --- src/resolvers/exotics/hosted-git-resolver.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/resolvers/exotics/hosted-git-resolver.js b/src/resolvers/exotics/hosted-git-resolver.js index 31a5a2510b..0be7d9c49e 100644 --- a/src/resolvers/exotics/hosted-git-resolver.js +++ b/src/resolvers/exotics/hosted-git-resolver.js @@ -22,9 +22,7 @@ export function explodeHostedGitFragment(fragment: string, reporter: Reporter): fragment = preParts[1] + '@' + preParts[2]; } - // TODO: make sure this only has a length of 2 const parts = fragment.split(':'); - //fragment = parts.pop(); if (parts.length == 3) { // protocol + host + folder parts[1] = parts[1].indexOf('//') >= 0 ? parts[1].substr(2) : parts[1]; From 5a9ec96caf6d5430fcc59afbb52991f1e4250ee9 Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Wed, 4 Jan 2017 00:05:27 -0800 Subject: [PATCH 4/4] remove lines that cause tests to fail --- src/util/request-manager.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/util/request-manager.js b/src/util/request-manager.js index 49108965c6..e0e134a2bf 100644 --- a/src/util/request-manager.js +++ b/src/util/request-manager.js @@ -370,9 +370,6 @@ export default class RequestManager { if (res.statusCode === 400 || res.statusCode === 404 || res.statusCode === 401) { body = false; } - if (res.request.followRedirect == false && (res.statusCode == 301 || res.statusCode == 302)) { - body = false; - } resolve(body); } };