Skip to content

Commit

Permalink
fix(amazon/firewall): Ensure we use a valid default vpc instead of no…
Browse files Browse the repository at this point in the history
…ne (#8524)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
vigneshm and mergify[bot] committed Aug 28, 2020
1 parent 1a20a4a commit 0de610e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Expand Up @@ -113,8 +113,8 @@ describe('Controller: CreateSecurityGroup', function() {
this.$scope.securityGroup.regions = ['us-east-1'];
this.ctrl.accountUpdated();
this.$scope.$digest();
expect(this.$scope.availableSecurityGroups.length).toBe(2);
expect(this.$scope.existingSecurityGroupNames).toEqual(['group1', 'group2']);
expect(this.$scope.availableSecurityGroups.length).toBe(1);
expect(this.$scope.existingSecurityGroupNames).toEqual(['group3']);
});

it('filters existing names based on join of groups from all regions', function() {
Expand All @@ -136,7 +136,7 @@ describe('Controller: CreateSecurityGroup', function() {
this.$scope.securityGroup.vpcId = 'vpc1-tw';
this.ctrl.accountUpdated();
this.$scope.$digest();
expect(this.$scope.availableSecurityGroups.length).toBe(1);
expect(this.$scope.availableSecurityGroups.length).toBe(0);
});

it('filters VPCs based on account + region', function() {
Expand Down Expand Up @@ -178,10 +178,13 @@ describe('Controller: CreateSecurityGroup', function() {

it('removes rules that are not available when account changes', function() {
let securityGroup = this.$scope.securityGroup;
securityGroup.credentials = 'test';
this.ctrl.accountUpdated();
this.$scope.$digest();
this.$scope.availableSecurityGroups.forEach(group => securityGroup.securityGroupIngress.push({ name: group }));
expect(securityGroup.securityGroupIngress.length).toBe(2);

securityGroup.credentials = 'test';
securityGroup.credentials = 'prod';
this.ctrl.accountUpdated();
this.$scope.$digest();
expect(this.$scope.state.removedRules.length).toBe(1);
Expand All @@ -190,13 +193,16 @@ describe('Controller: CreateSecurityGroup', function() {

it('does not repeatedly add removed rule warnings when multiple rules for the same group are removed', function() {
let securityGroup = this.$scope.securityGroup;
securityGroup.credentials = 'test';
this.ctrl.accountUpdated();
this.$scope.$digest();
this.$scope.availableSecurityGroups.forEach(group => {
securityGroup.securityGroupIngress.push({ name: group, startPort: 7001, endPort: 7001, protocol: 'HTTPS' });
securityGroup.securityGroupIngress.push({ name: group, startPort: 7000, endPort: 7000, protocol: 'HTTP' });
});
expect(securityGroup.securityGroupIngress.length).toBe(4);

securityGroup.credentials = 'test';
securityGroup.credentials = 'prod';
this.ctrl.accountUpdated();
this.$scope.$digest();
expect(this.$scope.state.removedRules).toEqual(['group2']);
Expand Down
Expand Up @@ -187,7 +187,8 @@ module(AMAZON_SECURITYGROUP_CONFIGURE_CONFIGSECURITYGROUP_MIXIN_CONTROLLER, [
// We matched the vpc ids from one account to another but they are never the same. In order to ensure that users still retain their VPC choice, irrespective of the account, we switched to using vpc names instead of vpc ids
const selectedVpc = $scope.allVpcs.find(vpc => vpc.id === $scope.securityGroup.vpcId);
const match = (available || []).find(vpc => selectedVpc && selectedVpc.label === vpc.label);
const defaultVpc = (available || []).find(vpc => AWSProviderSettings.defaults.vpc === vpc.label);
const defaultVpc =
(available || []).find(vpc => AWSProviderSettings.defaults.vpc === vpc.label) || ($scope.activeVpcs || [])[0];
$scope.securityGroup.vpcId = (match && match.ids[0]) || (defaultVpc && defaultVpc.ids[0]);
this.vpcUpdated();
};
Expand Down

0 comments on commit 0de610e

Please sign in to comment.