44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using System;
|
|
using Paca.Browser.Security;
|
|
using Xunit;
|
|
|
|
namespace Paca.Tests.Browser;
|
|
|
|
public class ChromeSecurityBadgeEvaluatorTests
|
|
{
|
|
[Theory]
|
|
[InlineData("https://google.com", SecurityLevel.Secure)]
|
|
[InlineData("https://github.com/settings", SecurityLevel.Secure)]
|
|
[InlineData("http://insecure-site.com", SecurityLevel.Insecure)]
|
|
[InlineData("http://example.org/page", SecurityLevel.Insecure)]
|
|
[InlineData("chrome://settings", SecurityLevel.InternalScheme)]
|
|
[InlineData("paca://downloads", SecurityLevel.InternalScheme)]
|
|
[InlineData("", SecurityLevel.Blank)]
|
|
[InlineData(null, SecurityLevel.Blank)]
|
|
public void Evaluates_Basic_Urls_Correctly(string? url, SecurityLevel expectedLevel)
|
|
{
|
|
var result = SecurityBadgeEvaluator.Evaluate(url);
|
|
Assert.Equal(expectedLevel, result.Level);
|
|
Assert.False(string.IsNullOrWhiteSpace(result.Tooltip));
|
|
Assert.False(string.IsNullOrWhiteSpace(result.IconGlyph));
|
|
Assert.False(string.IsNullOrWhiteSpace(result.ColorHex));
|
|
}
|
|
|
|
[Fact]
|
|
public void SslError_Forces_Dangerous_Level()
|
|
{
|
|
var result = SecurityBadgeEvaluator.Evaluate("https://self-signed.badssl.com", hasSslError: true);
|
|
Assert.Equal(SecurityLevel.Dangerous, result.Level);
|
|
Assert.Contains("위험", result.Tooltip);
|
|
}
|
|
|
|
[Fact]
|
|
public void Localhost_Is_Considered_Secure_Development_Origin()
|
|
{
|
|
var localhost = SecurityBadgeEvaluator.Evaluate("http://localhost:52100");
|
|
Assert.Equal(SecurityLevel.Secure, localhost.Level);
|
|
|
|
var ip127 = SecurityBadgeEvaluator.Evaluate("http://127.0.0.1:8080");
|
|
Assert.Equal(SecurityLevel.Secure, ip127.Level);
|
|
}
|
|
}
|