Skip to content

Commit 437e1cc

Browse files
committed
fix: create a default action chain that will run on non-pull or push queries
1 parent 8d1183d commit 437e1cc

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/proxy/chain.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@ const pullActionChain: ((req: any, action: Action) => Promise<Action>)[] = [
2727
proc.push.checkRepoInAuthorisedList,
2828
];
2929

30+
const defaultActionChain: ((req: any, action: Action) => Promise<Action>)[] = [
31+
proc.push.checkRepoInAuthorisedList,
32+
];
33+
3034
let pluginsInserted = false;
3135

3236
export const executeChain = async (req: any, res: any): Promise<Action> => {
3337
let action: Action = {} as Action;
38+
3439
try {
3540
action = await proc.pre.parseAction(req);
3641
const actionFns = await getChain(action);
3742

3843
for (const fn of actionFns) {
3944
action = await fn(req, action);
40-
if (!action.continue()) {
41-
return action;
42-
}
43-
44-
if (action.allowPush) {
45-
return action;
45+
if (!action.continue() || action.allowPush) {
46+
break;
4647
}
4748
}
4849
} catch (e) {
@@ -93,9 +94,13 @@ export const getChain = async (
9394
// This is set to true so that we don't re-insert the plugins into the chain
9495
pluginsInserted = true;
9596
}
96-
if (action.type === 'pull') return pullActionChain;
97-
if (action.type === 'push') return pushActionChain;
98-
return [];
97+
if (action.type === 'pull') {
98+
return pullActionChain;
99+
} else if (action.type === 'push') {
100+
return pushActionChain;
101+
} else {
102+
return defaultActionChain;
103+
}
99104
};
100105

101106
export default {
@@ -114,6 +119,9 @@ export default {
114119
get pullActionChain() {
115120
return pullActionChain;
116121
},
122+
get defaultActionChain() {
123+
return defaultActionChain;
124+
},
117125
executeChain,
118126
getChain,
119127
};

test/chain.test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -277,17 +277,15 @@ describe('proxy chain', function () {
277277
expect(mockPushProcessors.audit.called).to.be.true;
278278
});
279279

280-
it('executeChain should run no actions if not a push or pull', async function () {
280+
it('executeChain should always run at least checkRepoInAuthList', async function () {
281281
const req = {};
282282
const action = { type: 'foo', continue: () => true, allowPush: true };
283283

284-
processors.pre.parseAction.resolves(action);
285-
286-
const result = await chain.executeChain(req);
284+
mockPreProcessors.parseAction.resolves(action);
285+
mockPushProcessors.checkRepoInAuthorisedList.resolves(action);
287286

288-
expect(mockPushProcessors.checkRepoInAuthorisedList.called).to.be.false;
289-
expect(mockPushProcessors.parsePush.called).to.be.false;
290-
expect(result).to.deep.equal(action);
287+
await chain.executeChain(req);
288+
expect(mockPushProcessors.checkRepoInAuthorisedList.called).to.be.true;
291289
});
292290

293291
it('should approve push automatically and record in the database', async function () {

0 commit comments

Comments
 (0)