Skip to content

Commit 04db0f0

Browse files
authored
fix(AWS ALB): Recognize CIDR format at ip configuration (serverless#11889)
1 parent 4582913 commit 04db0f0

File tree

2 files changed

+31
-8
lines changed
  • lib/plugins/aws/package/compile/events/alb
  • test/unit/lib/plugins/aws/package/compile/events/alb

2 files changed

+31
-8
lines changed

lib/plugins/aws/package/compile/events/alb/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const compileTargetGroups = require('./lib/target-groups');
77
const compileListenerRules = require('./lib/listener-rules');
88
const compilePermissions = require('./lib/permissions');
99

10-
function defineArray(schema) {
11-
return { type: 'array', items: schema };
10+
function defineArray(schema, options = {}) {
11+
return { type: 'array', items: schema, ...options };
1212
}
1313

1414
const ALB_HTTP_HEADER_SCHEMA = {
@@ -55,12 +55,7 @@ class AwsCompileAlbEvents {
5555
pattern: '^[A-Za-z0-9*?.-]+$',
5656
maxLength: 128,
5757
}),
58-
ip: defineArray({
59-
anyOf: [
60-
{ type: 'string', format: 'ipv4' },
61-
{ type: 'string', format: 'ipv6' },
62-
],
63-
}),
58+
ip: defineArray({ type: 'string' }, { uniqueItems: true }),
6459
method: defineArray({ type: 'string', pattern: '^[A-Z_-]+$', maxLength: 40 }),
6560
path: defineArray({
6661
type: 'string',

test/unit/lib/plugins/aws/package/compile/events/alb/index.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ describe('test/unit/lib/plugins/aws/package/compile/events/alb/index.test.js', (
123123
},
124124
],
125125
},
126+
fnIpCondition: {
127+
handler: 'index.handler',
128+
events: [
129+
{
130+
alb: {
131+
...validBaseEventConfig,
132+
priority: 10,
133+
conditions: {
134+
ip: ['fe80:0000:0000:0000:0204:61ff:fe9d:f156/6', '192.168.0.1/0'],
135+
},
136+
},
137+
},
138+
],
139+
},
126140
},
127141
},
128142
});
@@ -347,4 +361,18 @@ describe('test/unit/lib/plugins/aws/package/compile/events/alb/index.test.js', (
347361
expect(config3.Values[1]).to.equal('dummyMultiValue2');
348362
});
349363
});
364+
365+
describe('should set alb ip conditions', () => {
366+
it('should allow IP CIDR format', () => {
367+
const albListenerRuleLogicalId = naming.getAlbListenerRuleLogicalId('fnIpCondition', 10);
368+
const conditions = cfResources[albListenerRuleLogicalId].Properties.Conditions;
369+
370+
expect(conditions).to.have.length(1);
371+
const config = conditions[0].SourceIpConfig;
372+
expect(config.Values).to.deep.equal([
373+
'fe80:0000:0000:0000:0204:61ff:fe9d:f156/6',
374+
'192.168.0.1/0',
375+
]);
376+
});
377+
});
350378
});

0 commit comments

Comments
 (0)