-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
476 additions
and
156 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package gosns | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
"strconv" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
"github.com/google/uuid" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func GetSubscriptionAttributesV1(req *http.Request) (int, interfaces.AbstractResponseBody) { | ||
|
||
requestBody := models.NewGetSubscriptionAttributesRequest() | ||
ok := utils.REQUEST_TRANSFORMER(requestBody, req, false) | ||
|
||
if !ok { | ||
log.Error("Invalid Request - GetSubscriptionAttributesV1") | ||
return utils.CreateErrorResponseV1("InvalidParameterValue", false) | ||
} | ||
|
||
subscriptionArn := requestBody.SubscriptionArn | ||
|
||
for _, topic := range app.SyncTopics.Topics { | ||
for _, sub := range topic.Subscriptions { | ||
if sub.SubscriptionArn == subscriptionArn { | ||
|
||
entries := make([]models.SubscriptionAttributeEntry, 0, 0) | ||
entry := models.SubscriptionAttributeEntry{Key: "Owner", Value: app.CurrentEnvironment.AccountID} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "RawMessageDelivery", Value: strconv.FormatBool(sub.Raw)} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "TopicArn", Value: sub.TopicArn} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "Endpoint", Value: sub.EndPoint} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "PendingConfirmation", Value: "false"} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "ConfirmationWasAuthenticated", Value: "true"} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "SubscriptionArn", Value: sub.SubscriptionArn} | ||
entries = append(entries, entry) | ||
entry = models.SubscriptionAttributeEntry{Key: "Protocol", Value: sub.Protocol} | ||
entries = append(entries, entry) | ||
|
||
if sub.FilterPolicy != nil { | ||
filterPolicyBytes, _ := json.Marshal(sub.FilterPolicy) | ||
entry = models.SubscriptionAttributeEntry{Key: "FilterPolicy", Value: string(filterPolicyBytes)} | ||
entries = append(entries, entry) | ||
} | ||
|
||
result := models.GetSubscriptionAttributesResult{Attributes: models.GetSubscriptionAttributes{Entries: entries}} | ||
uuid := uuid.NewString() | ||
respStruct := models.GetSubscriptionAttributesResponse{ | ||
Xmlns: models.BASE_XMLNS, | ||
Result: result, | ||
Metadata: app.ResponseMetadata{RequestId: uuid}} | ||
|
||
return http.StatusOK, respStruct | ||
|
||
} | ||
} | ||
} | ||
return utils.CreateErrorResponseV1("SubscriptionNotFound", false) | ||
} |
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,121 @@ | ||
package gosns | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/Admiral-Piett/goaws/app" | ||
"github.com/Admiral-Piett/goaws/app/conf" | ||
"github.com/Admiral-Piett/goaws/app/interfaces" | ||
"github.com/Admiral-Piett/goaws/app/models" | ||
"github.com/Admiral-Piett/goaws/app/test" | ||
"github.com/Admiral-Piett/goaws/app/utils" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetSubscriptionAttributesV1_NonExistentSubscription(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "NoQueuesOrTopics") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.GetSubscriptionAttributesRequest) | ||
*v = models.GetSubscriptionAttributesRequest{ | ||
SubscriptionArn: "hogehoge", | ||
} | ||
return true | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, response := GetSubscriptionAttributesV1(r) | ||
errorResult := response.GetResult().(models.ErrorResult) | ||
|
||
expected := models.ErrorResult{ | ||
Type: "Not Found", | ||
Code: "AWS.SimpleNotificationService.NonExistentSubscription", | ||
Message: "The specified subscription does not exist for this wsdl version.", | ||
} | ||
assert.Equal(t, http.StatusNotFound, code) | ||
assert.Equal(t, expected, errorResult) | ||
} | ||
|
||
func TestGetSubscriptionAttributesV1_TransformError(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "Local") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
return false | ||
} | ||
|
||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, _ := GetSubscriptionAttributesV1(r) | ||
|
||
assert.Equal(t, http.StatusBadRequest, code) | ||
} | ||
|
||
func TestGetSubscriptionAttributesV1_success(t *testing.T) { | ||
conf.LoadYamlConfig("../conf/mock-data/mock-config.yaml", "Local") | ||
defer func() { | ||
test.ResetApp() | ||
utils.REQUEST_TRANSFORMER = utils.TransformRequest | ||
}() | ||
|
||
localTopic1 := app.SyncTopics.Topics["local-topic1"] | ||
subscriptions := localTopic1.Subscriptions | ||
utils.REQUEST_TRANSFORMER = func(resultingStruct interfaces.AbstractRequestBody, req *http.Request, emptyRequestValid bool) (success bool) { | ||
v := resultingStruct.(*models.GetSubscriptionAttributesRequest) | ||
*v = models.GetSubscriptionAttributesRequest{ | ||
// local-queue5 | ||
SubscriptionArn: subscriptions[1].SubscriptionArn, | ||
} | ||
return true | ||
} | ||
_, r := test.GenerateRequestInfo("POST", "/", nil, true) | ||
code, response := GetSubscriptionAttributesV1(r) | ||
|
||
result := response.GetResult().(models.GetSubscriptionAttributesResult) | ||
assert.Equal(t, http.StatusOK, code) | ||
expectedAttributes := []models.SubscriptionAttributeEntry{ | ||
{ | ||
Key: "Owner", | ||
Value: app.CurrentEnvironment.AccountID, | ||
}, | ||
{ | ||
Key: "RawMessageDelivery", | ||
Value: "true", | ||
}, | ||
{ | ||
Key: "TopicArn", | ||
Value: localTopic1.Arn, | ||
}, | ||
{ | ||
Key: "Endpoint", | ||
Value: subscriptions[1].EndPoint, | ||
}, | ||
{ | ||
Key: "PendingConfirmation", | ||
Value: "false", | ||
}, | ||
{ | ||
Key: "ConfirmationWasAuthenticated", | ||
Value: "true", | ||
}, { | ||
Key: "SubscriptionArn", | ||
Value: subscriptions[1].SubscriptionArn, | ||
}, { | ||
Key: "Protocol", | ||
Value: "sqs", | ||
}, | ||
{ | ||
Key: "FilterPolicy", | ||
Value: "{\"foo\":[\"bar\"]}", | ||
}, | ||
} | ||
|
||
assert.ElementsMatch(t, expectedAttributes, result.Attributes.Entries) | ||
} |
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
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
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
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
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
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
Oops, something went wrong.