Skip to content

Commit d652f9d

Browse files
committed
chore: reject none clone urls
1 parent 828e8c4 commit d652f9d

File tree

4 files changed

+12
-29
lines changed

4 files changed

+12
-29
lines changed

src/db/file/repo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const getRepo = async (name: string) => {
5252

5353
export const getRepoByUrl = async (url: string) => {
5454
return new Promise<Repo | null>((resolve, reject) => {
55-
db.findOne({ url: url.toLowerCase().replace('.git', '') }, (err: Error | null, doc: Repo) => {
55+
db.findOne({ url: url.toLowerCase() }, (err: Error | null, doc: Repo) => {
5656
// ignore for code coverage as neDB rarely returns errors even for an invalid query
5757
/* istanbul ignore if */
5858
if (err) {

src/db/mongo/repo.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ export const getRepo = async (name: string) => {
1919
};
2020

2121
export const getRepoByUrl = async (url: string) => {
22-
url = url.toLowerCase().replace('.git', '');
2322
const collection = await connect(collectionName);
24-
return collection.findOne({ url: { $eq: url } });
23+
return collection.findOne({ url: { $eq: url.toLowerCase() } });
2524
};
2625

2726
export const createRepo = async (repo: Repo) => {

test/db/file/repo.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('File DB', () => {
1818
const repoData = {
1919
name: 'sample',
2020
users: { canPush: [] },
21-
url: 'http://example.com/sample-repo',
21+
url: 'http://example.com/sample-repo.git',
2222
};
2323

2424
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData));
@@ -33,27 +33,27 @@ describe('File DB', () => {
3333
const repoData = {
3434
name: 'sample',
3535
users: { canPush: [] },
36-
url: 'https://github.com/finos/git-proxy',
36+
url: 'https://github.com/finos/git-proxy.git',
3737
};
3838

3939
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData));
4040

41-
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy');
41+
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git');
4242
expect(result).to.equal(repoData);
4343
});
4444

4545
it('should get the repo using the url, stripping off the .git', async () => {
4646
const repoData = {
4747
name: 'sample',
4848
users: { canPush: [] },
49-
url: 'https://github.com/finos/git-proxy',
49+
url: 'https://github.com/finos/git-proxy.git',
5050
};
5151

5252
sandbox.stub(repoModule.db, 'findOne').callsFake((query, cb) => cb(null, repoData));
5353

5454
const result = await repoModule.getRepoByUrl('https://github.com/finos/git-proxy.git');
5555

56-
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/git-proxy'}))).to.be.true;
56+
expect(repoModule.db.findOne.calledWith(sinon.match({ url: 'https://github.com/finos/git-proxy.git'}))).to.be.true;
5757
expect(result).to.equal(repoData);
5858
});
5959
});

test/db/mongo/repo.test.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('MongoDB', () => {
2222
const repoData = {
2323
name: 'sample',
2424
users: { canPush: [] },
25-
url: 'http://example.com/sample-repo',
25+
url: 'http://example.com/sample-repo.git',
2626
};
2727
repoCollection.findOne.resolves(repoData);
2828

@@ -38,47 +38,31 @@ describe('MongoDB', () => {
3838
const repoData = {
3939
name: 'sample',
4040
users: { canPush: [] },
41-
url: 'https://github.com/finos/git-proxy',
42-
};
43-
repoCollection.findOne.resolves(repoData);
44-
45-
const result = await getRepoByUrl('https://github.com/finos/git-proxy');
46-
expect(result).to.equal(repoData);
47-
expect(connectionStub.calledWith('repos')).to.be.true;
48-
expect(
49-
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy' } }),
50-
).to.be.true;
51-
});
52-
53-
it('should get the repo using the url, stripping off the .git', async () => {
54-
const repoData = {
55-
name: 'sample',
56-
users: { canPush: [] },
57-
url: 'https://github.com/finos/git-proxy',
41+
url: 'https://github.com/finos/git-proxy.git',
5842
};
5943
repoCollection.findOne.resolves(repoData);
6044

6145
const result = await getRepoByUrl('https://github.com/finos/git-proxy.git');
6246
expect(result).to.equal(repoData);
6347
expect(connectionStub.calledWith('repos')).to.be.true;
6448
expect(
65-
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy' } }),
49+
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy.git' } }),
6650
).to.be.true;
6751
});
6852

6953
it('should get the repo using the url, ignoring the case', async () => {
7054
const repoData = {
7155
name: 'sample',
7256
users: { canPush: [] },
73-
url: 'https://github.com/finos/git-proxy',
57+
url: 'https://github.com/finos/git-proxy.git',
7458
};
7559
repoCollection.findOne.resolves(repoData);
7660

7761
const result = await getRepoByUrl('https://github.com/Finos/Git-Proxy.git');
7862
expect(result).to.equal(repoData);
7963
expect(connectionStub.calledWith('repos')).to.be.true;
8064
expect(
81-
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy' } }),
65+
repoCollection.findOne.calledWith({ url: { $eq: 'https://github.com/finos/git-proxy.git' } }),
8266
).to.be.true;
8367
});
8468
});

0 commit comments

Comments
 (0)