Skip to content

Commit

Permalink
fix(aws): prepend default security groups when creating ELBs (#3641)
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry authored and Justin Reynolds committed May 5, 2017
1 parent 09c62c1 commit 8503d1b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ module.exports = angular.module('spinnaker.loadBalancer.aws.create.controller',
}

function availableGroupsSorter(a, b) {
if (defaultSecurityGroups) {
if (defaultSecurityGroups.includes(a.name)) {
return -1;
}
if (defaultSecurityGroups.includes(b.name)) {
return 1;
}
}
return $scope.loadBalancer.securityGroups.includes(a.id) ? -1 :
$scope.loadBalancer.securityGroups.includes(b.id) ? 1 :
0;
Expand Down Expand Up @@ -365,8 +373,8 @@ module.exports = angular.module('spinnaker.loadBalancer.aws.create.controller',

this.subnetUpdated = function() {
var subnetPurpose = $scope.loadBalancer.subnetType || null,
subnet = $scope.subnets.filter(function(test) { return test.purpose === subnetPurpose; }),
availableVpcIds = subnet.length ? subnet[0].vpcIds : [];
subnet = $scope.subnets.find(function(test) { return test.purpose === subnetPurpose; }),
availableVpcIds = subnet ? subnet.vpcIds : [];
updateAvailableSecurityGroups(availableVpcIds);
if (subnetPurpose) {
$scope.loadBalancer.vpcId = availableVpcIds.length ? availableVpcIds[0] : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ describe('Controller: awsCreateLoadBalancerCtrl', function () {
expect(this.$scope.loadBalancer.isInternal).toBe(false);
expect(this.$scope.state.hideInternalFlag).toBeUndefined();
});
});

describe('available security groups', function () {
it('should put existing security groups in the front of the available list', function () {
const availableSecurityGroups = {
test: {
Expand All @@ -216,11 +218,38 @@ describe('Controller: awsCreateLoadBalancerCtrl', function () {
};
spyOn(this.securityGroupReader, 'getAllSecurityGroups').and.returnValue(this.$q.when(availableSecurityGroups));
spyOn(this.accountService, 'getAccountDetails').and.returnValue(this.$q.when([{name: 'test'}]));
spyOn(this.subnetReader, 'listSubnets').and.returnValue(this.$q.when([{account: 'test', region: 'us-east-1', vpcIds: ['vpc-1']}]));
spyOn(this.subnetReader, 'listSubnets').and.returnValue(this.$q.when([{account: 'test', region: 'us-east-1', vpcId: 'vpc-1'}]));
this.initialize(existingLoadBalancer);
this.$scope.$digest();
expect(this.$scope.availableSecurityGroups.map(g => g.name)).toEqual(['d', 'a', 'b', 'c']);
});

it('should put default security groups in the front of the available list', function () {
AWSProviderSettings.defaultSecurityGroups = ['sg-a'];
AWSProviderSettings.defaults.subnetType = 'external';
const availableSecurityGroups = {
test: {
aws: {
'us-east-1': [
{name: 'a', id: '1', vpcId: 'vpc-1'},
{name: 'b', id: '2', vpcId: 'vpc-1'},
{name: 'c', id: '3', vpcId: 'vpc-1'},
{name: 'd', id: '4', vpcId: 'vpc-1'},
{name: 'sg-a', id: '5', vpcId: 'vpc-1'}]
}
}
};

spyOn(this.securityGroupReader, 'getAllSecurityGroups').and.returnValue(this.$q.when(availableSecurityGroups));
spyOn(this.accountService, 'listAccounts').and.returnValue(this.$q.when([{name: 'test'}]));
spyOn(this.accountService, 'getAccountDetails').and.returnValue(this.$q.when([{name: 'test'}]));
spyOn(this.subnetReader, 'listSubnets').and.returnValue(this.$q.when([
{account: 'test', region: 'us-east-1', vpcId: 'vpc-1', purpose: 'external'}
]));
this.initialize();
this.$scope.$digest();
expect(this.$scope.availableSecurityGroups.map(g => g.name)).toEqual(['sg-a', 'a', 'b', 'c', 'd']);
});
});

});

0 comments on commit 8503d1b

Please sign in to comment.