Skip to content

Commit 2350b59

Browse files
committed
Merge branch 'main' into 1150-vitest-migration-from-service
2 parents ef6b730 + a0e5bcc commit 2350b59

4 files changed

Lines changed: 22 additions & 27 deletions

File tree

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"import": "./dist/src/types/models.js",
3030
"require": "./dist/src/types/models.js",
3131
"types": "./dist/src/types/models.d.ts"
32+
},
33+
"./plugin": {
34+
"import": "./dist/src/plugin.js",
35+
"require": "./dist/src/plugin.js",
36+
"types": "./dist/src/plugin.d.ts"
3237
}
3338
},
3439
"scripts": {

src/proxy/processors/pre-processor/parseAction.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ const exec = async (req: {
99
}) => {
1010
const id = Date.now();
1111
const timestamp = id;
12-
const pathBreakdown = processUrlPath(req.originalUrl);
1312
let type = 'default';
14-
if (pathBreakdown) {
15-
if (pathBreakdown.gitPath.endsWith('git-upload-pack') && req.method === 'GET') {
16-
type = 'pull';
17-
} else if (
18-
pathBreakdown.gitPath.includes('git-receive-pack') &&
19-
req.method === 'POST' &&
20-
req.headers['content-type'] === 'application/x-git-receive-pack-request'
21-
) {
22-
type = 'push';
23-
}
24-
} // else failed to parse proxy URL path - which is logged in the parsing util
13+
14+
//inspect content-type headers to classify requests as push or pull operations
15+
// see git http protocol docs for more details: https://github.com/git/git/blob/master/Documentation/gitprotocol-http.adoc
16+
if (req.headers['content-type'] === 'application/x-git-upload-pack-request') {
17+
type = 'pull';
18+
} else if (req.headers['content-type'] === 'application/x-git-receive-pack-request') {
19+
type = 'push';
20+
}
2521

2622
// Proxy URLs take the form https://<git proxy domain>:<port>/<proxied domain>/<repoPath>
2723
// e.g. https://git-proxy-instance.com:8443/github.com/finos/git-proxy.git
2824
// We'll receive /github.com/finos/git-proxy.git as the req.url / req.originalUrl
2925
// Add protocol (assume SSL) to reconstruct full URL - noting path will start with a /
26+
const pathBreakdown = processUrlPath(req.originalUrl);
3027
let url = 'https:/' + (pathBreakdown?.repoPath ?? 'NOT-FOUND');
3128

3229
console.log(`Parse action calculated repo URL: ${url} for inbound URL path: ${req.originalUrl}`);

test/plugin/plugin.test.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,25 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
22
import { spawnSync } from 'child_process';
33
import { rmSync } from 'fs';
44
import { join } from 'path';
5-
import {
6-
isCompatiblePlugin,
7-
PullActionPlugin,
8-
PushActionPlugin,
9-
PluginLoader,
10-
} from '../../src/plugin';
5+
import { isCompatiblePlugin, PushActionPlugin, PluginLoader } from '../../src/plugin';
116

127
const testPackagePath = join(__dirname, '../fixtures', 'test-package');
138

14-
// Temporarily skipping these until plugin loading is refactored to use ESM/TS
15-
describe.skip('loading plugins from packages', { timeout: 10000 }, () => {
9+
describe('loading plugins from packages', () => {
1610
beforeAll(() => {
1711
spawnSync('npm', ['install'], { cwd: testPackagePath, timeout: 5000 });
1812
});
1913

2014
it(
2115
'should load plugins that are the default export (module.exports = pluginObj)',
2216
async () => {
23-
const loader = new PluginLoader([join(testPackagePath, 'default-export.ts')]);
17+
const loader = new PluginLoader([join(testPackagePath, 'default-export.js')]);
2418
await loader.load();
2519
expect(loader.pushPlugins.length).toBe(1);
2620
expect(loader.pushPlugins.every((p) => isCompatiblePlugin(p))).toBe(true);
27-
expect(loader.pushPlugins[0]).toBeInstanceOf(PushActionPlugin);
21+
expect(
22+
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
23+
).toBe(true);
2824
},
2925
{ timeout: 10000 },
3026
);
@@ -43,8 +39,6 @@ describe.skip('loading plugins from packages', { timeout: 10000 }, () => {
4339
expect(
4440
loader.pullPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPullActionPlugin')),
4541
).toBe(true);
46-
expect(loader.pushPlugins[0]).toBeInstanceOf(PushActionPlugin);
47-
expect(loader.pullPlugins[0]).toBeInstanceOf(PullActionPlugin);
4842
},
4943
{ timeout: 10000 },
5044
);
@@ -59,7 +53,6 @@ describe.skip('loading plugins from packages', { timeout: 10000 }, () => {
5953
expect(
6054
loader.pushPlugins.every((p) => isCompatiblePlugin(p, 'isGitProxyPushActionPlugin')),
6155
).toBe(true);
62-
expect(loader.pushPlugins[0]).toBeInstanceOf(PushActionPlugin);
6356
},
6457
{ timeout: 10000 },
6558
);

test/testParseAction.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Pre-processor: parseAction', () => {
3030
const req = {
3131
originalUrl: '/github.com/finos/git-proxy.git/git-upload-pack',
3232
method: 'GET',
33-
headers: {},
33+
headers: { 'content-type': 'application/x-git-upload-pack-request' },
3434
};
3535

3636
const action = await preprocessor.exec(req);
@@ -44,7 +44,7 @@ describe('Pre-processor: parseAction', () => {
4444
const req = {
4545
originalUrl: '/finos/git-proxy.git/git-upload-pack',
4646
method: 'GET',
47-
headers: {},
47+
headers: { 'content-type': 'application/x-git-upload-pack-request' },
4848
};
4949

5050
const action = await preprocessor.exec(req);

0 commit comments

Comments
 (0)