Skip to content

Commit

Permalink
[chore] Remove vulnerable RestSharp dependency in test suite (#67)
Browse files Browse the repository at this point in the history
- Remove no-longer-valid RestSharp test
  • Loading branch information
nwithan8 authored Oct 1, 2024
1 parent 3b75433 commit 85b5759
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 36 deletions.
35 changes: 0 additions & 35 deletions EasyVCR.Tests/ClientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using EasyVCR.Handlers;
using EasyVCR.RequestElements;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RestSharp;
// ReSharper disable InconsistentNaming

namespace EasyVCR.Tests
Expand Down Expand Up @@ -46,40 +45,6 @@ public async Task TestClientClone()
var handler = client.VcrHandler;
var clonedHandler = clonedClient.VcrHandler;
Assert.AreEqual(handler, clonedHandler);

// lock the original client into a request (internally, RestClient will pass/lock the options to the HttpClient, which is what causes this issue)
var options = new RestClientOptions
{
MaxTimeout = 60000,
UserAgent = "EasyVCR Test Client",
BaseUrl = new Uri("https://httpbin.org"),
};

var restClient = new RestClient(client, options);
var request = new RestRequest("https://www.google.com");
var _ = await restClient.ExecuteAsync(request);

// now, if we try to reuse the client in another RestClient, it will throw an exception that the HttpClient is already in use
Assert.ThrowsException<InvalidOperationException>(() => new RestClient(client, options));

// even if we try with a different set of options
var options2 = new RestClientOptions
{
MaxTimeout = 30000,
UserAgent = "EasyVCR Test Client 2",
BaseUrl = new Uri("https://example.com"),
};
Assert.ThrowsException<InvalidOperationException>(() => new RestClient(client, options2));

// if we use the cloned client, it will work
var restClient3 = new RestClient(clonedClient, options);
var request3 = new RestRequest("https://www.google.com");
_ = await restClient3.ExecuteAsync(request3);

// side-note, you CAN re-use the original client if you don't have any options (it's the RestClientOptions that's causing this issue)
var restClient4 = new RestClient(client);
var request4 = new RestRequest("https://www.google.com");
_ = await restClient4.ExecuteAsync(request4);
}

[TestMethod]
Expand Down
1 change: 0 additions & 1 deletion EasyVCR.Tests/EasyVCR.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RestSharp" Version="108.0.2" />
<PackageReference Include="coverlet.collector" Version="[3.1.2, 4.0.0)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit 85b5759

Please sign in to comment.