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

Issue #51 #155

Merged
merged 4 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Resources:
Bucket:
Type: AWS::S3::Bucket

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