示例#1
0
func TestSNSMessageNotFound(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	snsString := fmt.Sprintf(`{
		"Type" : "Notification",
		"MessageId" : "12",
		"TopicArn" : "arn",
		"Subject" : "Amazon S3 Notification",
		"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"sc-gallery\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
		"Timestamp" : "2015-04-14T03:48:23.584Z",
		"SignatureVersion" : "1",
		"Signature" : "liP1M"
	}`, "original_file/134444")

	req := tests.MockRequest{}
	req.Url = "/notify/sns/"
	req.Method = "post"
	req.Data = map[string]interface{}{}
	utils.Decoder([]byte(snsString), &req.Data)

	server.Test(&req, func(msg *tests.MockResponse) {
		exception := "This message should be ignored."
		if msg.Status != 200 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}

		if msg.Message != "" {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}
	})
}
示例#2
0
func TestSNSMessageIgnoredPath(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	snsString := fmt.Sprintf(`{
		"Type" : "Notification",
		"MessageId" : "12",
		"TopicArn" : "arn",
		"Subject" : "Amazon S3 Notification",
		"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"sc-gallery\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
		"Timestamp" : "2015-04-14T03:48:23.584Z",
		"SignatureVersion" : "1",
		"Signature" : "liP1M"
	}`, "/hello/world/")

	req := tests.MockRequest{}
	req.Url = "/notify/sns/"
	req.Method = "post"
	req.Data = map[string]interface{}{}
	utils.Decoder([]byte(snsString), &req.Data)

	server.Test(&req, func(msg *tests.MockResponse) {
		exception := "This path should have been ignroed."

		if msg.Status != 400 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}

		if !strings.Contains(msg.Message, "not meant to be monitored") {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}
	})
}
示例#3
0
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)
	}
}
示例#4
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)
	}
}
示例#5
0
文件: sns_test.go 项目: josjevv/moire
func TestSNSNoticeFail(t *testing.T) {
	n := snsNotice{}
	utils.Decoder([]byte(failedStr), &n)

	_, errs := parseMessage(n)

	if len(*errs) == 0 {
		t.Error("Message should be absent.")
		return
	}
}
示例#6
0
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
	}
}
示例#7
0
文件: bounce.go 项目: josjevv/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,
	})

}
示例#8
0
func TestSNSMessage(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	parsed_url, err := url.Parse(assetRet["upload_url"])
	if err != nil {
		t.Error(err.Error())
		return
	}

	upload_path := parsed_url.Path

	fmt.Println("Submitting messages for", upload_path)

	snsString := fmt.Sprintf(`{
		"Type" : "Notification",
		"MessageId" : "12",
		"TopicArn" : "arn",
		"Subject" : "Amazon S3 Notification",
		"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"%v\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
		"Timestamp" : "2015-04-14T03:48:23.584Z",
		"SignatureVersion" : "1",
		"Signature" : "liP1M"
	}`, config.Settings.S3.Bucket, strings.TrimPrefix(upload_path, "/"))

	req := tests.MockRequest{}
	req.Url = "/notify/sns/"
	req.Method = "post"
	req.Data = map[string]interface{}{}
	utils.Decoder([]byte(snsString), &req.Data)

	server.Test(&req, func(msg *tests.MockResponse) {
		exception := "This asset should be marked as ready."
		if msg.Status != 200 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}

		if msg.Message != "" {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}
	})
}
示例#9
0
文件: sns_test.go 项目: josjevv/moire
func TestSNSNotice(t *testing.T) {
	var errs *[]error

	ExpectedSize := 71501

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

	msg, errs := parseMessage(n)
	if len(*errs) > 0 {
		t.Error(ConcatenateErrors(errs))
	}

	record := msg.Records[0]

	if record.S3.Object.Size != ExpectedSize {
		t.Error("Object Size should have been", ExpectedSize, "Found", record.S3.Object.Size)
	}
}