mirror of https://github.com/minio/minio.git
notification: Handle ARN with empty account and name types. (#2482)
Fixes #2481
This commit is contained in:
parent
810dcbf34b
commit
95c16f51cb
|
@ -100,26 +100,36 @@ func checkFilterRules(filterRules []filterRule) APIErrorCode {
|
||||||
return ErrNone
|
return ErrNone
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkQueueARN - check if the queue arn is valid.
|
// Checks validity of input ARN for a given arnType.
|
||||||
func checkQueueARN(queueARN string) APIErrorCode {
|
func checkARN(arn, arnType string) APIErrorCode {
|
||||||
if !strings.HasPrefix(queueARN, minioSqs) {
|
if !strings.HasPrefix(arn, arnType) {
|
||||||
return ErrARNNotification
|
return ErrARNNotification
|
||||||
}
|
}
|
||||||
if !strings.HasPrefix(queueARN, minioSqs+serverConfig.GetRegion()+":") {
|
if !strings.HasPrefix(arn, arnType+serverConfig.GetRegion()+":") {
|
||||||
return ErrRegionNotification
|
return ErrRegionNotification
|
||||||
}
|
}
|
||||||
|
account := strings.SplitN(strings.TrimPrefix(arn, arnType+serverConfig.GetRegion()+":"), ":", 2)
|
||||||
|
switch len(account) {
|
||||||
|
case 1:
|
||||||
|
// This means ARN is malformed, account should have min of 2elements.
|
||||||
|
return ErrARNNotification
|
||||||
|
case 2:
|
||||||
|
// Account topic id or topic name cannot be empty.
|
||||||
|
if account[0] == "" || account[1] == "" {
|
||||||
|
return ErrARNNotification
|
||||||
|
}
|
||||||
|
}
|
||||||
return ErrNone
|
return ErrNone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkQueueARN - check if the queue arn is valid.
|
||||||
|
func checkQueueARN(queueARN string) APIErrorCode {
|
||||||
|
return checkARN(queueARN, minioSqs)
|
||||||
|
}
|
||||||
|
|
||||||
// checkTopicARN - check if the topic arn is valid.
|
// checkTopicARN - check if the topic arn is valid.
|
||||||
func checkTopicARN(topicARN string) APIErrorCode {
|
func checkTopicARN(topicARN string) APIErrorCode {
|
||||||
if !strings.HasPrefix(topicARN, minioTopic) {
|
return checkARN(topicARN, minioTopic)
|
||||||
return ErrARNNotification
|
|
||||||
}
|
|
||||||
if !strings.HasPrefix(topicARN, minioTopic+serverConfig.GetRegion()+":") {
|
|
||||||
return ErrRegionNotification
|
|
||||||
}
|
|
||||||
return ErrNone
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns true if the topicARN is for an Minio sns listen type.
|
// Returns true if the topicARN is for an Minio sns listen type.
|
||||||
|
|
|
@ -119,18 +119,49 @@ func TestTopicARN(t *testing.T) {
|
||||||
topicARN: "arn:minio:sns:us-east-1:10:minio",
|
topicARN: "arn:minio:sns:us-east-1:10:minio",
|
||||||
errCode: ErrNone,
|
errCode: ErrNone,
|
||||||
},
|
},
|
||||||
// Invalid empty queue arn.
|
// Invalid empty topic arn.
|
||||||
{
|
{
|
||||||
topicARN: "",
|
topicARN: "",
|
||||||
errCode: ErrARNNotification,
|
errCode: ErrARNNotification,
|
||||||
},
|
},
|
||||||
|
// Invalid notification service type.
|
||||||
|
{
|
||||||
|
topicARN: "arn:minio:sqs:us-east-1:1:listen",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
// Invalid region 'us-west-1' in queue arn.
|
// Invalid region 'us-west-1' in queue arn.
|
||||||
{
|
{
|
||||||
topicARN: "arn:minio:sns:us-west-1:1:redis",
|
topicARN: "arn:minio:sns:us-west-1:1:listen",
|
||||||
errCode: ErrRegionNotification,
|
errCode: ErrRegionNotification,
|
||||||
},
|
},
|
||||||
|
// Empty topic account id is invalid.
|
||||||
|
{
|
||||||
|
topicARN: "arn:minio:sns:us-east-1::listen",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Empty topic account name is invalid.
|
||||||
|
{
|
||||||
|
topicARN: "arn:minio:sns:us-east-1:10:",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Empty topic account id and account name is invalid.
|
||||||
|
{
|
||||||
|
topicARN: "arn:minio:sns:us-east-1::",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Missing topic id and separator missing at the end in topic arn.
|
||||||
|
{
|
||||||
|
topicARN: "arn:minio:sns:us-east-1:listen",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Missing topic id and empty string at the end in topic arn.
|
||||||
|
{
|
||||||
|
topicARN: "arn:minio:sns:us-east-1:",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate all topics.
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
errCode := checkTopicARN(testCase.topicARN)
|
errCode := checkTopicARN(testCase.topicARN)
|
||||||
if testCase.errCode != errCode {
|
if testCase.errCode != errCode {
|
||||||
|
@ -171,13 +202,44 @@ func TestQueueARN(t *testing.T) {
|
||||||
queueARN: "",
|
queueARN: "",
|
||||||
errCode: ErrARNNotification,
|
errCode: ErrARNNotification,
|
||||||
},
|
},
|
||||||
|
// Invalid notification service type.
|
||||||
|
{
|
||||||
|
queueARN: "arn:minio:sns:us-east-1:1:listen",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
// Invalid region 'us-west-1' in queue arn.
|
// Invalid region 'us-west-1' in queue arn.
|
||||||
{
|
{
|
||||||
queueARN: "arn:minio:sqs:us-west-1:1:redis",
|
queueARN: "arn:minio:sqs:us-west-1:1:redis",
|
||||||
errCode: ErrRegionNotification,
|
errCode: ErrRegionNotification,
|
||||||
},
|
},
|
||||||
|
// Invalid queue name empty in queue arn.
|
||||||
|
{
|
||||||
|
queueARN: "arn:minio:sqs:us-east-1:1:",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Invalid queue id empty in queue arn.
|
||||||
|
{
|
||||||
|
queueARN: "arn:minio:sqs:us-east-1::redis",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Invalid queue id and queue name empty in queue arn.
|
||||||
|
{
|
||||||
|
queueARN: "arn:minio:sqs:us-east-1::",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Missing queue id and separator missing at the end in queue arn.
|
||||||
|
{
|
||||||
|
queueARN: "arn:minio:sqs:us-east-1:amqp",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
|
// Missing queue id and empty string at the end in queue arn.
|
||||||
|
{
|
||||||
|
queueARN: "arn:minio:sqs:us-east-1:",
|
||||||
|
errCode: ErrARNNotification,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate all tests for queue arn.
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
errCode := checkQueueARN(testCase.queueARN)
|
errCode := checkQueueARN(testCase.queueARN)
|
||||||
if testCase.errCode != errCode {
|
if testCase.errCode != errCode {
|
||||||
|
|
Loading…
Reference in New Issue