Skip to content

Commit

Permalink
improve Git coverage (yarnpkg#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tudor Gergely authored and samccone committed Oct 22, 2016
1 parent 0c5bd61 commit f71a70d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
30 changes: 30 additions & 0 deletions __tests__/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,33 @@ test('cleanUrl', () => {
expect(Git.cleanUrl('git://github.com/npm-opam/ocamlfind.git'))
.toEqual('git://github.com/npm-opam/ocamlfind.git');
});

test('isCommitHash', () => {
expect(Git.isCommitHash('ca82a6dff817ec66f44312307202690a93763949'))
.toBeTruthy();
expect(Git.isCommitHash('abc12'))
.toBeTruthy();
expect(Git.isCommitHash(''))
.toBeFalsy();
expect(Git.isCommitHash('abc12_'))
.toBeFalsy();
expect(Git.isCommitHash('gccda'))
.toBeFalsy();
expect(Git.isCommitHash('abC12'))
.toBeFalsy();
});

test('assertUrl', () => {
expect(() => Git.assertUrl('http://random.repo', ''))
.toThrow();
expect(() => Git.assertUrl('http://random.repo', 'ab_12'))
.toThrow();
expect(() => Git.assertUrl('git://random.repo', ''))
.toThrow();
expect(() => Git.assertUrl('https://random.repo', ''))
.not.toThrow();
expect(() => Git.assertUrl('http://random.repo', 'abc12'))
.not.toThrow();
expect(() => Git.assertUrl('git://random.repo', 'abc12'))
.not.toThrow();
});
4 changes: 2 additions & 2 deletions src/util/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Git {
}

/**
* Check if the input `target` is a 40 character hex commit hash.
* Check if the input `target` is a 5-40 character hex commit hash.
*/

static isCommitHash(target: string): boolean {
Expand All @@ -95,7 +95,7 @@ export default class Git {

const parts = url.parse(ref);

if (parts.protocol === 'git') {
if (parts.protocol === 'git:') {
throw new SecurityError(
`Refusing to download the git repo ${ref} over plain git without a commit hash`,
);
Expand Down

0 comments on commit f71a70d

Please sign in to comment.