示例#1
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)
		}
	})
}
示例#2
0
func TestCreatePDFCollection(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	req := tests.MockRequest{}
	req.Url = "/assets"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"mime_type":  "application/pdf",
		"name":       randSeq(10),
		"collection": randSeq(5),
	}

	server.Test(&req, func(msg *tests.MockResponse) {
		utils.Convert(&msg.Data, &assetRet)

		if msg.Status != 200 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Asset creation should return status 200.")
		}

		for _, key := range []string{"upload_url", "url", "_id"} {
			if val, ok := assetRet[key]; !ok || len(val) == 0 {
				fmt.Printf("%# v", pretty.Formatter(msg))
				t.Error(key + " should be a valid string in creation return.")
			}
		}
	})
}
示例#3
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)
		}
	})
}
示例#4
0
func TestGetPDFWithSignature(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	req := tests.MockRequest{}

	req.Url = makeSignatureURL("/assets/" + assetRet["_id"])
	req.Method = "get"

	server.Test(&req, func(msg *tests.MockResponse) {
		fmt.Printf("%# v", pretty.Formatter(msg))
		fmt.Println(msg.Error)
	})
}
示例#5
0
func TestAssetShouldRaiseException(t *testing.T) {
	server := server.MockDBServer()
	config.Settings.Moire.SignRequests = false
	defer server.Close()

	req := tests.MockRequest{}
	req.Url = "/assets/hello_world/"
	req.Method = "get"

	server.Test(&req, func(msg *tests.MockResponse) {
		config.Settings.Moire.SignRequests = true
		if msg.Status != 500 {
			t.Errorf("Message should return 500 (Exception), but returned %v", msg.Status)
		}
	})
}
示例#6
0
func TestCreateAssetFailAgain(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	req := tests.MockRequest{}
	req.Url = "/assets"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"mime_type": "image/png",
	}

	server.Test(&req, func(msg *tests.MockResponse) {
		if msg.Status != 400 {
			t.Error("Asset creation should fail without name")
		}
	})
}
示例#7
0
func TestGetImageTimeout(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	req := tests.MockRequest{}
	req.Url = makeSignatureURL("/assets/" + imageRet["_id"])
	req.Method = "get"

	time1 := time.Now()

	server.Test(&req, func(msg *tests.MockResponse) {
		elapsed := time.Since(time1)
		if elapsed < time.Duration(config.Settings.Moire.ImageTimeout)*time.Second {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Should have taken more than 5 seconds to return")
		}
	})
}
示例#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
func TestGetPDF(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	req := tests.MockRequest{}
	req.Url = makeSignatureURL("/assets/" + assetRet["_id"])
	req.Method = "get"

	server.Test(&req, func(msg *tests.MockResponse) {
		if msg.Status != 404 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Message should be in pending state.")
		}

		if !strings.Contains(msg.Message, "content is still being uploaded") {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Message should be in pending state.")
		}
	})
}
示例#10
0
func TestCreatePDFURLName(t *testing.T) {
	server := server.MockDBServer()
	defer server.Close()

	f1 := randSeq(5)
	f2 := randSeq(10)
	f3 := randSeq(3)

	name := fmt.Sprintf("%v--%v//-%v.pdf", f1, f2, f3)

	req := tests.MockRequest{}
	req.Url = "/assets"
	req.Method = "post"
	req.Data = map[string]interface{}{
		"mime_type": "application/pdf",
		"name":      name,
	}

	server.Test(&req, func(msg *tests.MockResponse) {
		utils.Convert(&msg.Data, &assetRet)

		if msg.Status != 200 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error("Asset creation should return status 200.")
			return
		}

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

		fmt.Println(assetRet["upload_url"])
		if !strings.HasSuffix(upload_url.Path, ".pdf") {
			t.Error("URL must end with pdf. Found: " + upload_url.Path)
			return
		}

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

	req := tests.MockRequest{}
	req.Url = "/assets/" + assetRet["_id"] + "/thumbnail/?no_redirect=true"
	req.Method = "get"

	server.Test(&req, func(msg *tests.MockResponse) {
		exception := "This asset needs signature."
		if msg.Status != 412 {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}

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

	req := tests.MockRequest{}
	req.Url = makeSignatureURL("/assets/" + assetRet["_id"] + "/thumbnail")
	req.Method = "get"

	server.Test(&req, func(msg *tests.MockResponse) {
		exception := "Message should be in pending state."

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

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

	req := tests.MockRequest{}
	req.Url = makeSignatureURL("/assets/"+assetRet["_id"]+"/thumbnail") + "&no_redirect=true"
	req.Method = "get"

	server.Test(&req, func(msg *tests.MockResponse) {
		exception := "Message should be in pending state."

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

		if !strings.Contains(msg.Message, "content is still being uploaded") {
			fmt.Printf("%# v", pretty.Formatter(msg))
			t.Error(exception)
		}
	})
}