Repository navigation
Expand file tree
/
Copy pathStorefrontFormRateLimitTests.cs
More file actions
43 lines (39 loc) · 1.95 KB
/
Copy pathStorefrontFormRateLimitTests.cs
File metadata and controls
43 lines (39 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using Grand.Web.Common.Startup;
using Grand.Web.Controllers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Reflection;
namespace Grand.Web.Tests.Controllers;
/// <summary>
/// The storefront forms that mail the store or keep what a visitor sent, uploads included
/// </summary>
[TestClass]
public class StorefrontFormRateLimitTests
{
public static IEnumerable<object[]> Forms =>
[
[typeof(ContactController), nameof(ContactController.Index)],
[typeof(ContactController), nameof(ContactController.UploadFileContactAttribute)],
[typeof(VendorController), nameof(VendorController.ContactVendor)],
[typeof(ProductController), nameof(ProductController.ProductEmailAFriend)],
[typeof(ProductController), nameof(ProductController.AskQuestionOnProduct)],
[typeof(ProductController), nameof(ProductController.ProductReviews)],
[typeof(ProductController), nameof(ProductController.UploadFileProductAttribute)],
[typeof(CatalogController), nameof(CatalogController.VendorReviews)],
[typeof(BlogController), nameof(BlogController.BlogPost)],
[typeof(NewsController), nameof(NewsController.NewsCommentAdd)],
[typeof(NewsletterController), nameof(NewsletterController.SubscribeNewsletter)],
[typeof(AccountController), nameof(AccountController.PasswordRecovery)],
[typeof(ShoppingCartController), nameof(ShoppingCartController.UploadFileCheckoutAttribute)]
];
[TestMethod]
[DynamicData(nameof(Forms))]
public void PostOfTheForm_RateLimited(Type controller, string action)
{
var post = controller.GetMethods()
.Single(m => m.Name == action && m.GetCustomAttribute<HttpPostAttribute>() != null);
Assert.AreEqual(GrandCommonStartup.StorefrontFormRateLimitPolicy,
post.GetCustomAttribute<EnableRateLimitingAttribute>()?.PolicyName);
}
}