コード例 #1
0
func TestComplaintMessage(t *testing.T) {
	jsonStr := `
	{
		"Type" : "Notification",
		"MessageId" : "f6cdc099-1020-554c-9f24-8d3f8067f821",
		"TopicArn" : "arn:aws:sns:eu-west-1:646538960088:gallery-upload",
		"Subject" : "Amazon S3 Notification",
		"Message" : "{\"notificationType\":\"Complaint\",\"complaint\":{\"complainedRecipients\":[{\"emailAddress\":\"email_to_check\"}],\"timestamp\":\"2015-04-20T22:04:04.000Z\",\"feedbackId\":\"0000014cd8dc1928-2916b250-e7a9-11e4-b632-1f8199fde76d-000000\"},\"mail\":{\"timestamp\":\"2015-04-20T21:48:25.000Z\",\"source\":\"[email protected]\",\"messageId\":\"0000014cd8cdc387-a26f1294-af94-4470-9449-14cf425460ec-000000\",\"destination\":[\"[email protected]\"]}}",
		"Timestamp" : "2015-04-14T03:48:23.584Z",
		"SignatureVersion" : "1",
		"Signature" : "liP1M+gnXDSo5A4mZJ/lO8Ah0rsC1ThfU0cmU5QmLezGB/VRq5G9V1QObO5phohsWLhMZiNTLVDWe9KCg9zKx+/X1S880Ytjd+Dyj4y1G29zATG3hzuRI1Ernp0dqHyIMwvbLrh6mqge65EPA/dzWVUjIehlGnLCeM9fSWrHqpPdyCT0egeC21eA98TxCvs5aWoND9pIcfUh0zSH6J7CT+QxEcjBKIb2dHhARdE75lrfDyM5QkVg6kEvQ/M9LEJExXC5KCXHVpKlsEQwL/qU4YKSTlIzkU2RpJrbMEtNjWFottBxr5WzkV98/CxkxjysEXtFW7xF7kyVsGOjmkKzHQ=="
	}
	`

	var errs *[]error

	email := "email_to_check"

	n := snsNotice{}
	utils.Decoder([]byte(jsonStr), &n)

	errs = utils.Validate(&n)

	if len(*errs) != 0 {
		t.Error("Could not parse JSON message")
		return
	}

	msg := complaintMessage{}
	utils.Decoder([]byte(n.Message), &msg)

	errs = utils.Validate(&msg)

	if len(*errs) != 0 {
		t.Error("Could not parse Records")
		return
	}

	complaint := msg.Complaint.Recipients[0]

	if complaint.Email != email {
		t.Error("Email should have been", email, "Found", complaint.Email)
	}
}
コード例 #2
0
ファイル: bounce_test.go プロジェクト: gitter-badger/khabar
func TestBounceMessage(t *testing.T) {
	jsonStr := `
	{
		"Type" : "Notification",
		"MessageId" : "f6cdc099-1020-554c-9f24-8d3f8067f821",
		"TopicArn" : "arn:aws:sns:eu-west-1:646538960088:gallery-upload",
		"Subject" : "Amazon S3 Notification",
		"Message" : "{\"notificationType\":\"Bounce\",\"bounce\":{\"bounceSubType\":\"General\",\"bounceType\":\"Transient\",\"bouncedRecipients\":[{\"emailAddress\":\"email_to_check\"}],\"timestamp\":\"2015-05-06T14:01:11.000Z\",\"feedbackId\":\"0000014d2987c258-5a97950e-f3f8-11e4-ad72-eb371f28d002-000000\"},\"mail\":{\"timestamp\":\"2015-05-06T13:53:59.000Z\",\"source\":\"[email protected]\",\"messageId\":\"0000014d2981266d-970f4d92-5c32-460d-8f7e-77bd5fd5c235-000000\",\"destination\":[\"[email protected]\"]}}",
		"Timestamp" : "2015-04-14T03:48:23.584Z",
		"SignatureVersion" : "1",
		"Signature" : "liP1M+gnXDSo5A4mZJ/lO8Ah0rsC1ThfU0cmU5QmLezGB/VRq5G9V1QObO5phohsWLhMZiNTLVDWe9KCg9zKx+/X1S880Ytjd+Dyj4y1G29zATG3hzuRI1Ernp0dqHyIMwvbLrh6mqge65EPA/dzWVUjIehlGnLCeM9fSWrHqpPdyCT0egeC21eA98TxCvs5aWoND9pIcfUh0zSH6J7CT+QxEcjBKIb2dHhARdE75lrfDyM5QkVg6kEvQ/M9LEJExXC5KCXHVpKlsEQwL/qU4YKSTlIzkU2RpJrbMEtNjWFottBxr5WzkV98/CxkxjysEXtFW7xF7kyVsGOjmkKzHQ=="
	}
	`

	var errs *[]error

	email := "email_to_check"

	n := snsNotice{}
	utils.Decoder([]byte(jsonStr), &n)

	errs = utils.Validate(&n)

	if len(*errs) != 0 {
		t.Error("Could not parse JSON message")
		return
	}

	msg := bounceMessage{}
	utils.Decoder([]byte(n.Message), &msg)

	errs = utils.Validate(&msg)

	if len(*errs) != 0 {
		t.Error("Could not parse Records")
		return
	}

	bounce := msg.Bounce.Recipients[0]

	if bounce.Email != email {
		t.Error("Email should have been", email, "Found", bounce.Email)
	}
}
コード例 #3
0
ファイル: sns_test.go プロジェクト: gitter-badger/khabar
func TestSNSNoticeFail(t *testing.T) {
	jsonStr := `{
		"Type" : "Notification",
		"MessageId" : "f6cdc099-1020-554c-9f24-8d3f8067f821",
		"TopicArn" : "arn:aws:sns:eu-west-1:646538960088:gallery-upload",
		"Subject" : "Amazon S3 Notification"
	}`

	n := snsNotice{}
	utils.Decoder([]byte(jsonStr), &n)

	errs := utils.Validate(&n)
	if len(*errs) == 0 {
		t.Error("Message should be absent.")
		return
	}
}
コード例 #4
0
ファイル: bounce.go プロジェクト: gitter-badger/khabar
func (self *SnsBounce) Post(request *gottp.Request) {

	args := new(snsNotice)

	request.ConvertArguments(&args)

	if !utils.ValidateAndRaiseError(request, args) {
		log.Println("Invalid Request", request.GetArguments())
		return
	}

	msg := bounceMessage{}
	gottpUtils.Decoder([]byte(args.Message), &msg)

	errs := gottpUtils.Validate(&msg)
	if len(*errs) > 0 {
		request.Raise(gottp.HttpError{
			http.StatusBadRequest,
			ConcatenateErrors(errs),
		})

		return
	}

	if msg.Type != BounceNotification {
		log.Println("Invalid Bounce Request", request.GetArguments())

		request.Raise(gottp.HttpError{
			http.StatusBadRequest,
			"Invalid Bounce Request",
		})

		return
	}

	for _, entry := range msg.Bounce.Recipients {
		DisableBounceEmail(entry.Email, request)
	}

	request.Write(utils.R{
		StatusCode: http.StatusOK,
		Data:       nil,
	})

}