Skip to content

Commit 8e02a94

Browse files
committed
Merge branch 'main' of https://github.com/finos/git-proxy into 1150-vitest-migration-from-service
2 parents f936e9e + 9f24d3f commit 8e02a94

File tree

3 files changed

+73
-10
lines changed

3 files changed

+73
-10
lines changed

package-lock.json

Lines changed: 44 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/proxy/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class Proxy {
5252
const allowedList: Repo[] = await getRepos();
5353

5454
defaultAuthorisedRepoList.forEach(async (x) => {
55-
const found = allowedList.find((y) => y.project === x.project && x.name === y.name);
55+
const found = allowedList.find((y) => y.url === x.url);
5656
if (!found) {
5757
const repo = await createRepo(x);
5858
await addUserCanPush(repo._id!, 'admin');

test/testProxyRoute.test.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ import service from '../src/service';
2020
const TEST_DEFAULT_REPO = {
2121
url: 'https://github.com/finos/git-proxy.git',
2222
name: 'git-proxy',
23-
project: 'finos/git-proxy',
23+
project: 'finos',
2424
host: 'github.com',
2525
proxyUrlPrefix: '/github.com/finos/git-proxy.git',
2626
};
2727

2828
const TEST_GITLAB_REPO = {
2929
url: 'https://gitlab.com/gitlab-community/meta.git',
3030
name: 'gitlab',
31-
project: 'gitlab-community/meta',
31+
project: 'gitlab-community',
3232
host: 'gitlab.com',
3333
proxyUrlPrefix: '/gitlab.com/gitlab-community/meta.git',
3434
};
3535

3636
const TEST_UNKNOWN_REPO = {
3737
url: 'https://github.com/finos/fdc3.git',
3838
name: 'fdc3',
39-
project: 'finos/fdc3',
39+
project: 'finos',
4040
host: 'github.com',
4141
proxyUrlPrefix: '/github.com/finos/fdc3.git',
4242
fallbackUrlPrefix: '/finos/fdc3.git',
@@ -214,6 +214,31 @@ describe.skip('proxy express application', () => {
214214
expect(res2.status).toBe(200);
215215
expect(res2.text).toContain('Rejecting repo');
216216
}, 5000);
217+
218+
it('should create the default repo if it does not exist', async function () {
219+
// Remove the default repo from the db and check it no longer exists
220+
await cleanupRepo(TEST_DEFAULT_REPO.url);
221+
222+
const repo = await db.getRepoByUrl(TEST_DEFAULT_REPO.url);
223+
expect(repo).toBeNull();
224+
225+
// Restart the proxy
226+
await proxy.stop();
227+
await proxy.start();
228+
229+
// Check that the default repo was created in the db
230+
const repo2 = await db.getRepoByUrl(TEST_DEFAULT_REPO.url);
231+
expect(repo2).not.toBeNull();
232+
233+
// Check that the default repo isn't duplicated on subsequent restarts
234+
await proxy.stop();
235+
await proxy.start();
236+
237+
const allRepos = await db.getRepos();
238+
const matchingRepos = allRepos.filter((r) => r.url === TEST_DEFAULT_REPO.url);
239+
240+
expect(matchingRepos).toHaveLength(1);
241+
});
217242
});
218243

219244
describe('handleRefsErrorMessage', () => {

0 commit comments

Comments
 (0)