Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Remove vulnerable RestSharp dependency in test suite #67

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -34,7 +33,7 @@
}

[TestMethod]
public async Task TestClientClone()

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / Coverage_Requirements

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (net462)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (netstandard2.0)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (netcoreapp3.1)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (net5.0)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (net6.0)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (net7.0)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 36 in EasyVCR.Tests/ClientTest.cs

View workflow job for this annotation

GitHub Actions / NET_Tests (net8.0)

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var client = HttpClients.NewHttpClient("cassettes", "test_client_clone", Mode.Record);
var clonedClient = client.Clone();
Expand All @@ -46,40 +45,6 @@
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
Loading