Add test verifying JS files that we ship

This commit is contained in:
nicolas.dorier
2021-11-08 19:09:00 +09:00
parent 61d89d1777
commit 3c13d6c195

View File

@@ -659,6 +659,26 @@ namespace BTCPayServer.Tests
}
}
[Fact]
[Trait("Fast", "Fast")]
public async Task CheckJsContent()
{
// This test verify that no malicious js is added in the minified files.
// We should extend the tests to other js files, but we can do as we go...
using HttpClient client = new HttpClient();
var actual = GetFileContent("BTCPayServer", "wwwroot", "vendor", "bootstrap", "bootstrap.bundle.min.js");
var version = Regex.Match(actual, "Bootstrap v([0-9]+.[0-9]+.[0-9]+)").Groups[1].Value;
var expected = await (await client.GetAsync($"https://cdn.jsdelivr.net/npm/bootstrap@{version}/dist/js/bootstrap.bundle.min.js")).Content.ReadAsStringAsync();
Assert.Equal(expected, actual.Replace("\r\n", "\n", StringComparison.OrdinalIgnoreCase));
}
string GetFileContent(params string[] path)
{
var l = path.ToList();
l.Insert(0, TestUtils.TryGetSolutionDirectoryInfo().FullName);
return File.ReadAllText(Path.Combine(l.ToArray()));
}
[Fact]
[Trait("Fast", "Fast")]
public void CanParseLegacyLabels()