Skip to content

Commit

Permalink
OCM-4513 | fix: Fixed kms arn regex pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
den-rgb committed Oct 26, 2023
1 parent 1e92673 commit 9f825a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/resource/validations/kms_arn_regex_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var KmsArnRE = regexp.MustCompile(
`^arn:aws[\w-]*:kms:[\w-]+:\d{12}:key\/mrk-[0-9a-f]{32}$|[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`,
`^arn:aws[\w-]*:kms:[\w-]+:\d{12}:key\/(mrk-[0-9a-f]{32}$|[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$)`,
)

func ValidateKMSKeyARN(kmsKeyARN *string) error {
Expand Down
11 changes: 11 additions & 0 deletions pkg/resource/validations/kms_arn_regex_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ var _ = Describe("Validations", func() {
})
})

Context("when kmsKeyARN is not empty but is not prefixed with 'mrk'", func() {
BeforeEach(func() {
kmsKeyARN = "arn:aws:notkms:us-west-2:301721915996:key/9fdfaf2f-efb7-4db7-a5c3-0d047c52f094"
})

It("should return an error", func() {
err := ValidateKMSKeyARN(&kmsKeyARN)
Expect(err).To(HaveOccurred())
})
})

Context("when kmsKeyARN is not empty and does not match the regex", func() {
BeforeEach(func() {
kmsKeyARN = "invalid-kms-key-arn"
Expand Down

0 comments on commit 9f825a8

Please sign in to comment.