mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
Rewrite Icon fetching (#3023)
* Rewrite Icon fetching * Move validation to IconUri, Uri, or UriBuilder * `dotnet format` 🤖 * PR suggestions * Add not null compiler hint * Add twitter to test case * Move Uri manipulation to UriService * Implement MockedHttpClient Presents better, fluent handling of message matching and response building. * Add redirect handling tests * Add testing to models * More aggressively dispose content in icon link * Format 🤖 * Update icon lockfile * Convert to cloned stream for HttpResponseBuilder Content was being disposed when HttResponseMessage was being disposed. This avoids losing our reference to our content and allows multiple usages of the same `MockedHttpMessageResponse` * Move services to extension Extension is shared by testing and allows access to services from our service tests * Remove unused `using` * Prefer awaiting asyncs for better exception handling * `dotnet format` 🤖 * Await async * Update tests to use test TLD and ip ranges * Remove unused interfaces * Make assignments static when possible * Prefer invariant comparer to downcasing * Prefer injecting interface services to implementations * Prefer comparer set in HashSet initialization * Allow SVG icons * Filter out icons with unknown formats * Seek to beginning of MemoryStream after writing it * More appropriate to not return icon if it's invalid * Add svg icon test
This commit is contained in:
22
test/Icons.Test/Models/IconUriTests.cs
Normal file
22
test/Icons.Test/Models/IconUriTests.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System.Net;
|
||||
using Bit.Icons.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Icons.Test.Models;
|
||||
|
||||
public class IconUriTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("https://icon.test", "1.1.1.1", true)]
|
||||
[InlineData("https://icon.test:4443", "1.1.1.1", false)] // Non standard port
|
||||
[InlineData("http://test", "1.1.1.1", false)] // top level domain
|
||||
[InlineData("https://icon.test", "127.0.0.1", false)] // IP is internal
|
||||
[InlineData("https://icon.test", "::1", false)] // IP is internal
|
||||
[InlineData("https://1.1.1.1", "::1", false)] // host is IP
|
||||
public void IsValid(string uri, string ip, bool expectedResult)
|
||||
{
|
||||
var result = new IconUri(new Uri(uri), IPAddress.Parse(ip)).IsValid;
|
||||
|
||||
Assert.Equal(expectedResult, result);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user