using System.Text; using JobTrackerApi.Controllers; using JobTrackerApi.Models; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Moq; using Xunit; namespace JobTrackerApi.Tests; public sealed class BillingControllerTests { [Fact] public async Task Webhook_rejects_an_invalid_Stripe_signature() { var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary { ["Stripe:SecretKey"] = "sk_test_fake", ["Stripe:PricePremium"] = "price_fake", ["Stripe:WebhookSecret"] = "whsec_fake", ["App:PublicBaseUrl"] = "https://example.test", }).Build(); var userStore = new Mock>(); var users = new Mock>( userStore.Object, Options.Create(new IdentityOptions()), new PasswordHasher(), Array.Empty>(), Array.Empty>(), new UpperInvariantLookupNormalizer(), new IdentityErrorDescriber(), null!, NullLogger>.Instance); var roleStore = new Mock>(); var roles = new Mock>( roleStore.Object, Array.Empty>(), new UpperInvariantLookupNormalizer(), new IdentityErrorDescriber(), NullLogger>.Instance); var controller = new BillingController(configuration, users.Object, roles.Object, NullLogger.Instance) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() }, }; controller.Request.Body = new MemoryStream(Encoding.UTF8.GetBytes("{}")); controller.Request.Headers["Stripe-Signature"] = "invalid"; var result = await controller.Webhook(CancellationToken.None); Assert.IsType(result); } }