-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
spec/cfn_nag_integration/cfn_nag_serverless_transform_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
require 'cfn-nag/cfn_nag_config' | ||
require 'cfn-nag/cfn_nag' | ||
|
||
describe CfnNag do | ||
before(:all) do | ||
CfnNagLogging.configure_logging(debug: false) | ||
@cfn_nag = CfnNag.new(config: CfnNagConfig.new) | ||
end | ||
|
||
# the heavy lifting for dealing with metadata is down in cfn-model. just make sure we've got a good version | ||
# of the parser that doesn't blow up | ||
context 'serverless function with metadata', :lambda do | ||
it 'parses properly' do | ||
template_name = 'yaml/sam/metadata.yml' | ||
actual_aggregate_results = @cfn_nag.audit_aggregate_across_files input_path: test_template_path(template_name) | ||
|
||
expected_aggregate_results = [ | ||
{ | ||
filename: test_template_path(template_name), | ||
file_results: { | ||
failure_count: 0, | ||
violations: [ | ||
Violation.new( | ||
id: 'W58', type: Violation::WARNING, | ||
message: LambdaFunctionCloudWatchLogsRule.new.rule_text, | ||
logical_resource_ids: %w[SomeFunction2], | ||
line_numbers: [-1] | ||
) | ||
] | ||
} | ||
} | ||
] | ||
|
||
expect(actual_aggregate_results).to eq expected_aggregate_results | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
Transform: 'AWS::Serverless-2016-10-31' | ||
Parameters: | ||
Site: | ||
Type: String | ||
FunctionRoleArn: | ||
Type: String | ||
Globals: | ||
Api: | ||
EndpointConfiguration: REGIONAL | ||
Function: | ||
Runtime: java8 | ||
MemorySize: 1408 | ||
Timeout: 30 | ||
CodeUri: | ||
Bucket: !Sub "bucket.lambda.${Site}" | ||
Key: !Sub "lambda/code/${Site}/jar-with-dependencies.jar" | ||
Resources: | ||
SomeFunction: | ||
Type: 'AWS::Serverless::Function' | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W58 | ||
reason: I know what I am doing | ||
Properties: | ||
FunctionName: !Sub "${Site}-Function" | ||
Handler: "com.test.Function::handleRequest" | ||
Tracing: Active | ||
Role: !Ref FunctionRoleArn | ||
Tags: | ||
warmup: 'True' | ||
SomeFunction2: | ||
Type: 'AWS::Serverless::Function' | ||
Properties: | ||
FunctionName: !Sub "${Site}-Function" | ||
Handler: "com.test.Function::handleRequest" | ||
Tracing: Active | ||
Role: !Ref FunctionRoleArn | ||
Tags: | ||
warmup: 'True' |