Skip to content

Commit

Permalink
fix(subscriber): correct ARN validation for IAM role (#105)
Browse files Browse the repository at this point in the history
Our logic was busted. It was passing tests because the test fixture had
a lambda ARN instead. Provide fix and add a new test for the happy path
of a firehose ARN alongside the role ARN.
  • Loading branch information
jta committed Nov 29, 2023
1 parent f0751e6 commit c149da0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion handler/subscriber/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (c *Config) Validate() error {
}

roleARN, err := arn.Parse(c.RoleARN)
if err != nil || roleARN.Service != "iam" || strings.HasPrefix(roleARN.Resource, "role/") {
if err != nil || roleARN.Service != "iam" || !strings.HasPrefix(roleARN.Resource, "role/") {
errs = append(errs, fmt.Errorf("failed to parse role: %w", ErrInvalidARN))
}
}
Expand Down
11 changes: 10 additions & 1 deletion handler/subscriber/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,19 @@ func TestConfig(t *testing.T) {
Config: subscriber.Config{
CloudWatchLogsClient: &handlertest.CloudWatchLogsClient{},
FilterName: "observe-logs-subscription",
RoleARN: "arn:aws:lambda:us-east-2:123456789012:function:my-function",
RoleARN: "arn:aws:iam::123456789012:role/test",
},
ExpectError: subscriber.ErrMissingDestinationARN,
},

{
Config: subscriber.Config{
CloudWatchLogsClient: &handlertest.CloudWatchLogsClient{},
FilterName: "observe-logs-subscription",
DestinationARN: "arn:aws:firehose:us-west-2:123456789012:deliverystream/test",
RoleARN: "arn:aws:iam::123456789012:role/test",
},
},
{
Config: subscriber.Config{
CloudWatchLogsClient: &handlertest.CloudWatchLogsClient{},
Expand Down

0 comments on commit c149da0

Please sign in to comment.