Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Commit

Permalink
Fixed GetAtt not throwing errors on invalid resource (#155)
Browse files Browse the repository at this point in the history
* "Fn:GetAtt" - Fixed validation for cases where a missing resource is referenced.

* Adjusted "Fn::Sub" test case.

* Update CHANGELOG.md
  • Loading branch information
RazzM13 authored and martysweet committed May 4, 2018
1 parent 3ef5cb5 commit 257eeb2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,9 +6,13 @@ and this project adheres to [Semantic
Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Merge PR #155, fixing GetAtt not throwing errors on invalid resource

### Changed
- Merge PR #157, adding licence attribute to package.json


## [1.6.2] - 2018-04-26
### Fixed
- Merge PR #150, allow AWS::CloudFormation::Stack to return custom attributes when used in Fn::GetAtt
Expand Down
14 changes: 12 additions & 2 deletions src/test/validatorTest.ts
Expand Up @@ -407,11 +407,11 @@ describe('validator', () => {
expect(result['errors']['warn']).to.have.lengthOf(0);
});

it('a sub getatt an invalid resource should result in validTemplate = false, 1 crit errors, no warnings', () => {
it('a sub getatt an invalid resource should result in validTemplate = false, 2 crit errors, no warnings', () => {
const input = 'testData/invalid/yaml/invalid_sub_getatt.yaml';
let result = validator.validateFile(input);
expect(result).to.have.deep.property('templateValid', false);
expect(result['errors']['crit']).to.have.lengthOf(1);
expect(result['errors']['crit']).to.have.lengthOf(2);
expect(result['errors']['warn']).to.have.lengthOf(0);
});

Expand Down Expand Up @@ -488,6 +488,16 @@ describe('validator', () => {
expect(result['errors']['crit']).to.have.lengthOf(0);
expect(result['errors']['warn']).to.have.lengthOf(0);
});

it("should not pass validation with !GetAtt where the resource does not exist", () => {
const input = 'testData/invalid/yaml/issue_51_missing_resource.yaml';
let result = validator.validateFile(input);
expect(result).to.have.deep.property('templateValid', false);
expect(result['errors']['crit']).to.have.lengthOf(1);
expect(result['errors']['crit'][0]).to.have.property('message', 'No resource with logical name of Database!');
expect(result['errors']['crit'][0]).to.have.property('resource', 'Outputs > DBDNS > Value');
expect(result['errors']['warn']).to.have.lengthOf(0);
});
})

describe('conditions', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/validator.ts
Expand Up @@ -1112,7 +1112,13 @@ export function fnGetAtt(reference: string, attributeName: string){
}
}
}
} else {
addError('crit',
`No resource with logical name of ${reference}!`,
placeInTemplate,
reference);
}

// Return null if not found
return null;
}
Expand Down
8 changes: 8 additions & 0 deletions testData/invalid/yaml/issue_51_missing_resource.yaml
@@ -0,0 +1,8 @@
Resources:
Bucket:
Type: AWS::S3::Bucket

Outputs:
DBDNS:
Description: DNS Name of the DB Instance
Value: !GetAtt Database.Endpoint.Address

0 comments on commit 257eeb2

Please sign in to comment.