Skip to content

Commit 872509e

Browse files
committed
test: parsePush
1 parent 583e020 commit 872509e

File tree

2 files changed

+143
-1
lines changed

2 files changed

+143
-1
lines changed

src/proxy/processors/push-action/parsePush.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import fs from 'fs';
44
import path from 'path';
55
import lod from 'lodash';
66
import { CommitContent } from '../types';
7-
import * as util from 'util';
87

98
const BitMask = require('bit-mask') as any;
109

@@ -59,6 +58,7 @@ async function exec(req: any, action: Action): Promise<Action> {
5958
} finally {
6059
action.addStep(step);
6160
}
61+
console.log('action: ', JSON.stringify(action, null, 2));
6262
return action;
6363
}
6464

test/testParsePush.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
const chai = require('chai');
2+
const actions = require('../src/proxy/actions/Action');
3+
const processor = require('../src/proxy/processors/push-action/parsePush');
4+
const expect = chai.expect;
5+
6+
const reqBody = Buffer.from([
7+
48, 48, 98, 100, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48,
8+
48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 32, 53, 56, 51,
9+
101, 48, 50, 48, 57, 54, 102, 49, 99, 54, 98, 100, 100, 52, 52, 49, 48, 54, 56, 102, 101, 54, 101,
10+
101, 102, 97, 53, 99, 54, 53, 52, 54, 99, 56, 57, 100, 57, 32, 114, 101, 102, 115, 47, 104, 101,
11+
97, 100, 115, 47, 57, 55, 49, 45, 116, 101, 115, 116, 0, 32, 114, 101, 112, 111, 114, 116, 45,
12+
115, 116, 97, 116, 117, 115, 45, 118, 50, 32, 115, 105, 100, 101, 45, 98, 97, 110, 100, 45, 54,
13+
52, 107, 32, 111, 98, 106, 101, 99, 116, 45, 102, 111, 114, 109, 97, 116, 61, 115, 104, 97, 49,
14+
32, 97, 103, 101, 110, 116, 61, 103, 105, 116, 47, 50, 46, 51, 57, 46, 53, 46, 40, 65, 112, 112,
15+
108, 101, 46, 71, 105, 116, 45, 49, 53, 52, 41, 48, 48, 48, 48, 80, 65, 67, 75, 0, 0, 0, 2, 0, 0,
16+
0, 14, 153, 17, 120, 156, 165, 77, 193, 78, 197, 48, 12, 187, 247, 43, 114, 71, 122, 106, 182,
17+
116, 235, 16, 66, 220, 249, 0, 206, 33, 205, 216, 128, 173, 83, 151, 233, 253, 62, 65, 124, 2,
18+
185, 56, 182, 101, 219, 154, 42, 116, 148, 211, 52, 163, 202, 76, 152, 120, 204, 154, 144, 48, 83,
19+
41, 25, 123, 154, 10, 137, 223, 251, 192, 49, 28, 220, 116, 55, 96, 77, 99, 212, 161, 143, 168,
20+
89, 138, 120, 14, 71, 157, 132, 138, 215, 96, 55, 105, 44, 220, 11, 117, 18, 248, 178, 165, 54,
21+
120, 109, 235, 9, 111, 122, 26, 60, 125, 249, 107, 245, 88, 180, 221, 238, 46, 188, 236, 108, 191,
22+
120, 147, 186, 61, 3, 142, 52, 36, 95, 78, 61, 60, 68, 140, 49, 184, 186, 173, 102, 250, 143, 138,
23+
96, 238, 61, 2, 151, 207, 203, 195, 133, 141, 65, 248, 176, 171, 41, 220, 87, 91, 224, 111, 2,
24+
182, 243, 3, 230, 86, 55, 231, 251, 89, 191, 53, 252, 0, 42, 141, 90, 85, 154, 15, 120, 156, 165,
25+
140, 193, 14, 194, 48, 12, 67, 239, 253, 138, 220, 145, 166, 46, 105, 86, 134, 16, 226, 206, 7,
26+
112, 78, 215, 84, 32, 4, 155, 186, 76, 252, 62, 221, 55, 112, 177, 173, 103, 217, 86, 85, 97, 192,
27+
33, 150, 88, 2, 75, 68, 164, 192, 33, 104, 161, 137, 48, 17, 138, 150, 193, 103, 196, 62, 170,
28+
207, 110, 145, 170, 31, 131, 192, 189, 98, 36, 225, 20, 104, 143, 37, 113, 200, 40, 60, 210, 49,
29+
101, 150, 182, 161, 72, 156, 147, 147, 205, 30, 115, 133, 91, 125, 174, 112, 215, 213, 224, 252,
30+
106, 209, 230, 229, 161, 181, 251, 54, 112, 253, 136, 237, 222, 77, 243, 251, 2, 125, 12, 3, 211,
31+
24, 113, 132, 131, 239, 189, 119, 141, 190, 159, 102, 250, 199, 133, 179, 214, 157, 96, 87, 200,
32+
98, 2, 147, 44, 182, 85, 117, 63, 50, 250, 77, 243, 240, 2, 224, 16, 152, 60, 5, 50, 165, 6, 153,
33+
5, 155, 56, 162, 8, 96, 31, 156, 9, 238, 140, 120, 156, 187, 200, 115, 145, 103, 195, 74, 86, 17,
34+
25, 105, 157, 254, 148, 168, 195, 170, 243, 171, 47, 212, 199, 116, 38, 95, 127, 24, 243, 226,
35+
241, 228, 189, 172, 83, 0, 225, 116, 15, 62, 254, 1, 137, 133, 157, 21, 251, 180, 160, 188, 206,
36+
135, 191, 105, 98, 239, 115, 191, 202, 198, 146, 137, 120, 156, 219, 204, 180, 153, 105, 194, 46,
37+
145, 132, 148, 30, 206, 0, 117, 161, 251, 231, 23, 48, 88, 10, 26, 120, 204, 49, 76, 112, 251, 51,
38+
241, 92, 42, 0, 175, 39, 11, 238, 254, 1, 179, 193, 177, 252, 130, 173, 32, 172, 145, 25, 128,
39+
205, 95, 40, 239, 37, 5, 13, 48, 103, 120, 156, 219, 192, 184, 129, 113, 66, 181, 72, 95, 193, 78,
40+
15, 155, 135, 7, 210, 124, 95, 180, 243, 55, 89, 173, 139, 153, 94, 42, 165, 55, 177, 95, 17, 0,
41+
203, 243, 12, 234, 166, 9, 120, 156, 51, 52, 48, 48, 51, 49, 81, 200, 204, 75, 73, 173, 208, 43,
42+
41, 102, 136, 168, 106, 126, 242, 175, 223, 38, 98, 70, 233, 150, 78, 150, 124, 14, 231, 143, 7,
43+
62, 94, 51, 49, 0, 2, 133, 130, 162, 84, 221, 130, 162, 252, 228, 212, 226, 226, 252, 34, 134,
44+
208, 157, 186, 31, 47, 168, 153, 190, 187, 95, 115, 108, 227, 228, 83, 235, 117, 121, 131, 174,
45+
139, 64, 213, 149, 22, 103, 232, 38, 38, 151, 100, 230, 231, 49, 120, 186, 158, 186, 240, 178,
46+
233, 194, 73, 102, 190, 226, 174, 151, 186, 110, 98, 38, 139, 254, 174, 54, 132, 216, 88, 82, 89,
47+
144, 90, 12, 178, 113, 183, 90, 205, 75, 54, 177, 89, 121, 201, 63, 152, 99, 2, 84, 150, 73, 249,
48+
91, 22, 138, 0, 0, 241, 97, 60, 0, 240, 2, 29, 168, 35, 56, 248, 127, 160, 194, 136, 30, 255, 23,
49+
237, 239, 105, 74, 117, 135, 167, 30, 120, 156, 1, 32, 0, 223, 255, 144, 5, 144, 5, 176, 219, 1,
50+
20, 127, 49, 60, 26, 210, 115, 209, 143, 23, 37, 16, 222, 210, 126, 210, 106, 226, 169, 206, 174,
51+
147, 239, 1, 161, 221, 228, 15, 87, 247, 35, 150, 215, 66, 131, 112, 24, 188, 81, 66, 54, 3, 47,
52+
142, 65, 47, 209, 115, 29, 175, 162, 120, 156, 133, 144, 205, 74, 195, 64, 20, 133, 9, 168, 72,
53+
213, 98, 65, 112, 39, 71, 16, 82, 181, 166, 110, 20, 108, 113, 233, 70, 240, 7, 170, 187, 108,
54+
166, 201, 109, 50, 154, 204, 196, 228, 6, 44, 84, 250, 4, 130, 208, 7, 240, 25, 164, 27, 93, 186,
55+
113, 231, 75, 248, 16, 174, 77, 127, 108, 107, 41, 56, 171, 59, 223, 185, 231, 91, 220, 175, 195,
56+
239, 163, 167, 183, 13, 25, 70, 58, 102, 236, 64, 36, 72, 89, 6, 104, 196, 58, 132, 217, 27, 205,
57+
106, 238, 229, 181, 96, 180, 129, 114, 25, 142, 47, 148, 71, 144, 138, 99, 237, 166, 14, 185, 104,
58+
232, 24, 142, 136, 56, 141, 165, 242, 192, 148, 48, 92, 193, 2, 66, 185, 96, 141, 186, 72, 8, 236,
59+
211, 32, 209, 42, 7, 56, 90, 37, 58, 32, 43, 208, 94, 49, 251, 2, 102, 141, 123, 101, 217, 144,
60+
153, 47, 74, 19, 191, 111, 168, 192, 86, 49, 221, 89, 117, 237, 54, 43, 182, 106, 239, 77, 63, 91,
61+
153, 216, 237, 11, 128, 211, 218, 197, 185, 149, 12, 53, 205, 226, 111, 111, 123, 180, 96, 218,
62+
106, 134, 64, 56, 44, 181, 170, 204, 204, 166, 228, 7, 99, 251, 160, 245, 159, 219, 44, 101, 113,
63+
247, 195, 120, 156, 235, 94, 45, 4, 243, 157, 247, 165, 173, 194, 176, 0, 88, 55, 90, 170, 162,
64+
137, 206, 243, 98, 177, 187, 190, 252, 105, 92, 143, 162, 77, 142, 137, 208, 106, 141, 65, 36, 98,
65+
82, 252, 7, 137, 148, 253, 236, 240, 147, 200, 209, 97, 40, 153, 105, 146, 118, 86, 243, 107, 251,
66+
227, 149, 144, 146, 68, 120, 52, 195, 116, 18, 10, 25, 12, 97, 247, 56, 111, 172, 108, 128, 238,
67+
201, 41, 193, 35, 190, 20, 206, 237, 25, 177, 40, 33, 85, 81, 54, 227, 161, 154, 251, 1, 177, 118,
68+
158, 164, 240, 2, 224, 16, 152, 60, 5, 50, 165, 6, 153, 5, 155, 56, 162, 8, 96, 31, 156, 9, 238,
69+
140, 120, 156, 1, 32, 0, 223, 255, 209, 12, 209, 12, 176, 169, 5, 20, 74, 65, 131, 50, 107, 113,
70+
230, 114, 231, 216, 102, 25, 202, 231, 246, 248, 64, 46, 179, 105, 147, 189, 5, 148, 248, 3, 15,
71+
241, 254, 1, 137, 133, 157, 21, 251, 180, 160, 188, 206, 135, 191, 105, 98, 239, 115, 191, 202,
72+
198, 146, 137, 120, 156, 1, 30, 0, 225, 255, 179, 2, 179, 2, 144, 186, 20, 89, 17, 51, 252, 210,
73+
252, 47, 239, 152, 111, 118, 189, 211, 171, 86, 247, 39, 115, 216, 188, 145, 206, 101, 231, 103,
74+
16, 69, 254, 1, 179, 193, 177, 252, 130, 173, 32, 172, 145, 25, 128, 205, 95, 40, 239, 37, 5, 13,
75+
48, 103, 120, 156, 219, 192, 184, 129, 113, 66, 181, 200, 76, 253, 153, 162, 149, 114, 17, 45, 5,
76+
123, 236, 213, 75, 27, 95, 69, 95, 87, 191, 160, 57, 177, 95, 17, 0, 183, 85, 12, 112, 166, 9,
77+
120, 156, 51, 52, 48, 48, 51, 49, 81, 200, 204, 75, 73, 173, 208, 43, 41, 102, 136, 168, 106, 126,
78+
242, 175, 223, 38, 98, 70, 233, 150, 78, 150, 124, 14, 231, 143, 7, 62, 94, 51, 49, 0, 2, 133,
79+
130, 162, 84, 221, 130, 162, 252, 228, 212, 226, 226, 252, 34, 134, 208, 157, 186, 31, 47, 168,
80+
153, 190, 187, 95, 115, 108, 227, 228, 83, 235, 117, 121, 131, 174, 139, 64, 213, 149, 22, 103,
81+
232, 38, 38, 151, 100, 230, 231, 49, 164, 103, 172, 223, 223, 241, 226, 254, 99, 158, 21, 50, 31,
82+
222, 124, 93, 101, 95, 244, 124, 249, 113, 67, 136, 141, 37, 149, 5, 169, 197, 32, 27, 119, 171,
83+
213, 188, 100, 19, 155, 149, 151, 252, 131, 57, 38, 64, 101, 153, 148, 191, 101, 161, 8, 0, 99,
84+
166, 62, 150, 240, 2, 29, 168, 35, 56, 248, 127, 160, 194, 136, 30, 255, 23, 237, 239, 105, 74,
85+
117, 135, 167, 30, 120, 156, 1, 32, 0, 223, 255, 144, 5, 144, 5, 176, 219, 1, 20, 71, 34, 183, 94,
86+
158, 203, 170, 37, 254, 94, 138, 249, 65, 34, 11, 142, 121, 227, 207, 19, 147, 239, 1, 161, 227,
87+
254, 14, 190, 239, 3, 132, 123, 120, 156, 251, 102, 249, 208, 98, 194, 206, 141, 55, 218, 25, 181,
88+
173, 98, 242, 212, 21, 180, 21, 188, 130, 253, 253, 244, 138, 75, 138, 50, 243, 210, 51, 211, 42,
89+
53, 138, 82, 11, 53, 129, 162, 234, 49, 121, 137, 201, 37, 153, 249, 121, 86, 10, 64, 69, 147, 31,
90+
48, 137, 111, 22, 103, 190, 47, 9, 0, 1, 31, 22, 59, 61, 23, 179, 2, 16, 216, 91, 106, 130, 85,
91+
17, 219, 41, 45, 234, 231, 203, 152, 97, 30,
92+
]);
93+
94+
const actionData = {
95+
id: '1746542004301',
96+
type: 'push',
97+
method: 'POST',
98+
timestamp: 1746542004301,
99+
repo: 'kriswest/git-proxy.git',
100+
};
101+
102+
describe('Check that pushes can be parsed', async () => {
103+
it('No error should be reported for a valid push with a single commit and commitData should be parsed out', async () => {
104+
const action = new actions.Action(
105+
actionData.id,
106+
actionData.type,
107+
actionData.method,
108+
actionData.timestamp,
109+
actionData.repo,
110+
);
111+
const req = { body: reqBody };
112+
const result = await processor.exec(req, action);
113+
console.log('result: ', JSON.stringify(result, null, 2));
114+
expect(result.error).to.be.false;
115+
expect(result.blocked).to.be.false;
116+
expect(result.steps[0].stepName).to.equal('parsePackFile');
117+
expect(result.project).to.equal('kriswest');
118+
expect(result.url).to.equal('https://github.com/kriswest/git-proxy.git');
119+
expect(result.branch).to.equal('refs/heads/971-test');
120+
expect(result.user).to.equal('Kris West');
121+
expect(result.commitTo).to.equal('583e02096f1c6bdd441068fe6eefa5c6546c89d9');
122+
expect(result.commitFrom).to.equal('ae570e6301e8cdcecf17e9c4d859129e0da3c42c');
123+
expect(result.commitData[0].parent).to.equal('ae570e6301e8cdcecf17e9c4d859129e0da3c42c');
124+
expect(result.commitData[0].tree).to.equal('24859f1ecf415a78e514184dd81349d4ccccb6a0');
125+
expect(result.commitData[0].author).to.equal('Kris West');
126+
expect(result.commitData[0].committer).to.equal('Kris West');
127+
expect(result.commitData[0].authorEmail).to.equal('kristopher.west@natwest.com');
128+
expect(result.commitData[0].message).to.equal(
129+
'test: adjust data capture with commit msg from console',
130+
);
131+
expect(result.commitData[0].commitTimestamp).to.equal('1746541853');
132+
expect(result.commitData[0].message).to.equal(
133+
'test: adjust data capture with commit msg from console',
134+
);
135+
});
136+
137+
// it('Should set ok=false if not in authorised', async () => {
138+
// const action = new actions.Action('123', 'type', 'get', 1234, 'thisproject/repo-is-not-ok');
139+
// const result = await processor.exec(null, action, authList);
140+
// expect(result.error).to.be.true;
141+
// });
142+
});

0 commit comments

Comments
 (0)