using System.Net; using System.Text; using Flypaper.Core.Models; using Flypaper.Core.Runtime; using Flypaper.Core.Strategies; using Flypaper.Tests.Fakes; using Shouldly; namespace Flypaper.Tests.Core; public sealed class FileContentTests { [Theory] [InlineData("/.env", "env-drip")] [InlineData("/app/.ENV.production", "env-drip")] [InlineData("/config.json", "json-drip")] [InlineData("/sitemap.xml", "xml-drip")] [InlineData("/docker-compose.yml", "yaml-drip")] [InlineData("/backup/db.sql", "sql-drip")] [InlineData("/.git/config", "git-drip")] [InlineData("/robots.txt", "robots-drip")] public void Matches_known_paths(string path, string expected) => FileContent.Match(path).ShouldNotBeNull().Name.ShouldBe(expected); [Theory] [InlineData("/")] [InlineData("/index.php")] [InlineData("/wp-login.php")] [InlineData("/environment")] [InlineData("")] [InlineData(null)] public void Ignores_other_paths(string? path) => FileContent.Match(path).ShouldBeNull(); [Theory] [InlineData("/.env", "APP_NAME=")] [InlineData("/config.json", "{")] [InlineData("/sitemap.xml", "(() => strategy.RunAsync(channel, cts.Token)); Encoding.UTF8.GetString(channel.Writes.First()).ShouldStartWith("APP_NAME="); channel.Writes.First().Length.ShouldBeGreaterThanOrEqualTo(300); strategy.Describe().ShouldBe("env-drip 30000-30000ms 1-64B head 300B"); strategy.MediaType.ShouldStartWith("text/plain"); } private static ConfiguredStrategySelector Selector(bool matchPath) { var options = TestOptions.Monitor(new DripOptions { MatchPath = matchPath }); var random = new SeededRandomSource(11); return new ConfiguredStrategySelector( [ new HtmlDripStrategy(options, random, TimeProvider.System), new TextDripStrategy(options, random, TimeProvider.System), .. FileContent.Profiles.Select(profile => new FileDripStrategy(profile, options, random, TimeProvider.System)) ], options, random); } }