Skip to content

Commit b034cda

Browse files
Added invalid cookie tests (#2297)
* Added invalid cookie tests
1 parent 2ae0b6a commit b034cda

File tree

12 files changed

+339
-76
lines changed

12 files changed

+339
-76
lines changed

.github/workflows/build-dev.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ jobs:
3535
-
3636
name: Unshallow
3737
run: git fetch --prune --unshallow
38-
3938
-
4039
name: NuGet login
4140
uses: NuGet/login@v1
4241
id: nuget-login
4342
with:
4443
user: ${{ secrets.NUGET_USER }}
45-
4644
-
4745
name: Create and push NuGet package
4846
run: |

.github/workflows/pull-request.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: windows-latest
2424
strategy:
2525
matrix:
26-
dotnet: ['net48', 'net8.0', 'net9.0']
26+
dotnet: ['net48', 'net8.0', 'net9.0', 'net10.0']
2727

2828
steps:
2929
-
@@ -61,7 +61,7 @@ jobs:
6161
runs-on: ubuntu-latest
6262
strategy:
6363
matrix:
64-
dotnet: ['net8.0', 'net9.0']
64+
dotnet: ['net8.0', 'net9.0', 'net10.0']
6565

6666
steps:
6767
-

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ RestSharp.IntegrationTests/config.json
5555
/out/
5656
/docs/.vuepress/dist/
5757
.vscode/
58-
.temp/
58+
.temp/
59+
*.trx

Directory.Packages.props

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
</PropertyGroup>
5-
<PropertyGroup Label="Package versions for .NET 10" Condition="'$(TargetFramework)' == 'net10.0'">
6-
<MicrosoftTestHostVer>10.0.0-rc.2.25502.107</MicrosoftTestHostVer>
7-
<SystemTextJsonVer>10.0.0-rc.2.25502.107</SystemTextJsonVer>
8-
</PropertyGroup>
9-
<PropertyGroup Label="Package versions for .NET 9" Condition="'$(TargetFramework)' == 'net9.0'">
10-
<MicrosoftTestHostVer>9.0.10</MicrosoftTestHostVer>
11-
</PropertyGroup>
12-
<PropertyGroup Label="Package versions for .NET 8" Condition="'$(TargetFramework)' == 'net8.0'">
13-
<MicrosoftTestHostVer>8.0.21</MicrosoftTestHostVer>
14-
</PropertyGroup>
15-
<PropertyGroup Label="Package versions for pre-.NET 10" Condition="'$(TargetFramework)' != 'net10.0'">
16-
<SystemTextJsonVer>9.0.10</SystemTextJsonVer>
17-
</PropertyGroup>
18-
<ItemGroup Label="Runtime dependencies">
19-
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3"/>
20-
<PackageVersion Include="CsvHelper" Version="33.0.1"/>
21-
<PackageVersion Include="System.Text.Json" Version="$(SystemTextJsonVer)"/>
22-
</ItemGroup>
23-
<ItemGroup Label="Compile dependencies">
24-
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0"/>
25-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0"/>
26-
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0"/>
27-
<PackageVersion Include="MinVer" Version="6.0.0"/>
28-
<PackageVersion Include="Nullable" Version="1.3.1"/>
29-
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.3"/>
30-
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0"/>
31-
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0"/>
32-
</ItemGroup>
33-
<ItemGroup Label="Testing dependencies">
34-
<PackageVersion Include="HttpMultipartParser" Version="8.4.0"/>
35-
<PackageVersion Include="PolySharp" Version="1.15.0"/>
36-
<PackageVersion Include="AutoFixture" Version="4.18.1"/>
37-
<PackageVersion Include="coverlet.collector" Version="6.0.2"/>
38-
<PackageVersion Include="FluentAssertions" Version="7.0.0"/>
39-
<PackageVersion Include="HttpTracer" Version="2.1.1"/>
40-
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftTestHostVer)"/>
41-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
42-
<PackageVersion Include="Moq" Version="4.20.72"/>
43-
<PackageVersion Include="Polly" Version="8.5.0"/>
44-
<PackageVersion Include="rest-mock-core" Version="0.7.12"/>
45-
<PackageVersion Include="RichardSzalay.MockHttp" Version="7.0.0"/>
46-
<PackageVersion Include="System.Net.Http.Json" Version="9.0.0"/>
47-
<PackageVersion Include="Xunit.Extensions.Logging" Version="1.1.0"/>
48-
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="All"/>
49-
<PackageVersion Include="xunit" Version="2.9.2"/>
50-
<PackageVersion Include="WireMock.Net" Version="1.6.10"/>
51-
<PackageVersion Include="WireMock.Net.FluentAssertions" Version="1.5.51"/>
52-
</ItemGroup>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<PropertyGroup Label="Package versions for .NET 10" Condition="'$(TargetFramework)' == 'net10.0'">
6+
<MicrosoftTestHostVer>10.0.0-rc.2.25502.107</MicrosoftTestHostVer>
7+
<SystemTextJsonVer>10.0.0-rc.2.25502.107</SystemTextJsonVer>
8+
</PropertyGroup>
9+
<PropertyGroup Label="Package versions for .NET 9" Condition="'$(TargetFramework)' == 'net9.0'">
10+
<MicrosoftTestHostVer>9.0.10</MicrosoftTestHostVer>
11+
</PropertyGroup>
12+
<PropertyGroup Label="Package versions for .NET 8" Condition="'$(TargetFramework)' == 'net8.0'">
13+
<MicrosoftTestHostVer>8.0.21</MicrosoftTestHostVer>
14+
</PropertyGroup>
15+
<PropertyGroup Label="Package versions for pre-.NET 10" Condition="'$(TargetFramework)' != 'net10.0'">
16+
<SystemTextJsonVer>9.0.10</SystemTextJsonVer>
17+
</PropertyGroup>
18+
<ItemGroup Label="Runtime dependencies">
19+
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
20+
<PackageVersion Include="CsvHelper" Version="33.0.1" />
21+
<PackageVersion Include="System.Text.Json" Version="$(SystemTextJsonVer)" />
22+
</ItemGroup>
23+
<ItemGroup Label="Compile dependencies">
24+
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
25+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.12.0" />
26+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
27+
<PackageVersion Include="MinVer" Version="6.0.0" />
28+
<PackageVersion Include="Nullable" Version="1.3.1" />
29+
<PackageVersion Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.3" />
30+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
31+
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0" />
32+
</ItemGroup>
33+
<ItemGroup Label="Testing dependencies">
34+
<PackageVersion Include="HttpMultipartParser" Version="8.4.0" />
35+
<PackageVersion Include="PolySharp" Version="1.15.0" />
36+
<PackageVersion Include="AutoFixture" Version="4.18.1" />
37+
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
38+
<PackageVersion Include="FluentAssertions" Version="7.0.0" />
39+
<PackageVersion Include="HttpTracer" Version="2.1.1" />
40+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="$(MicrosoftTestHostVer)" />
41+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
42+
<PackageVersion Include="Moq" Version="4.20.72" />
43+
<PackageVersion Include="Polly" Version="8.5.0" />
44+
<PackageVersion Include="rest-mock-core" Version="0.7.12" />
45+
<PackageVersion Include="RichardSzalay.MockHttp" Version="7.0.0" />
46+
<PackageVersion Include="System.Net.Http.Json" Version="9.0.0" />
47+
<PackageVersion Include="Xunit.Extensions.Logging" Version="1.1.0" />
48+
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="All" />
49+
<PackageVersion Include="xunit" Version="2.9.2" />
50+
<PackageVersion Include="WireMock.Net" Version="1.15.0" />
51+
<PackageVersion Include="WireMock.Net.FluentAssertions" Version="1.5.51" />
52+
</ItemGroup>
5353
</Project>

agents.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
### RestSharp – Developer Notes (agents.md)
2+
3+
#### Scope
4+
This document captures project-specific knowledge to speed up advanced development and maintenance of RestSharp. It focuses on build, configuration, and testing details unique to this repository, plus conventions and tips that help avoid common pitfalls.
5+
6+
---
7+
8+
### Build and configuration
9+
10+
- Solution layout
11+
- Root solution: `RestSharp.sln`.
12+
- Library sources in `src/RestSharp` targeting multiple frameworks via shared props.
13+
- Tests live under `test/` and are multi-targeted (see below).
14+
15+
- Multi-targeting
16+
- Tests target: `net48; net8.0; net9.0; net10.0` (defined in `test/Directory.Build.props`).
17+
- .NET Framework 4.8 support is provided via `Microsoft.NETFramework.ReferenceAssemblies.net472` for reference assemblies during build when `TargetFramework == net48`.
18+
- CI uses `actions/setup-dotnet@v4` with `dotnet-version: 9.0.x` for packaging; building tests locally may require multiple SDKs if you intend to run against all TFMs. Practically, you can run on a single installed TFM by overriding `-f`.
19+
- CI for pull requests runs tests against the supported .NET versions (.NET 8, .NET 9, and .NET 10) on Linux and Windows. On Windows, it also runs tests against .NET Framework 4.8.
20+
21+
- Central props
22+
- `test/Directory.Build.props` imports `props/Common.props` from the repo root. This propagates common settings into all test projects.
23+
- Notable properties:
24+
- `<IsTestProject>true</IsTestProject>` and `<IsPackable>false</IsPackable>` in tests.
25+
- `<Nullable>disable</Nullable>` in tests (be mindful when adding nullable-sensitive code in tests).
26+
- `<NoWarn>xUnit1033;CS8002</NoWarn>` to quiet specific analyzer warnings.
27+
- Test logs: `VSTestLogger` and `VSTestResultsDirectory` are preconfigured to write TRX per TFM into `test-results/<TFM>`.
28+
29+
- Packaging (FYI)
30+
- CI workflow `.github/workflows/build-dev.yml` demonstrates release packaging: `dotnet pack -c Release -o nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg` and `dotnet nuget push` to nuget.org using OIDC via `NuGet/login@v1`.
31+
32+
---
33+
34+
### Testing
35+
36+
- Test frameworks and helpers
37+
- xUnit is the test framework. `test/Directory.Build.props` adds global `using` aliases for `Xunit`, `FluentAssertions`, and `AutoFixture` so you can use `[Fact]`, `Should()`, etc., without explicit `using` statements in each test file.
38+
- Additional packages commonly used in unit tests (see `test/RestSharp.Tests/RestSharp.Tests.csproj`): `Moq`, `RichardSzalay.MockHttp`, `System.Net.Http.Json`.
39+
- Integrated tests leverage `WireMockServer` (see `RestSharp.Tests.Integrated`) and use assets under `Assets/` where needed.
40+
41+
- Running tests
42+
- Run all tests for the entire solution:
43+
```
44+
dotnet test RestSharp.sln -c Debug
45+
```
46+
- Run a specific test project (multi-targeted will run for all installed TFMs):
47+
```
48+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj
49+
```
50+
- Select a single target framework (useful if you don’t have all SDKs installed):
51+
```
52+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj -f net8.0
53+
```
54+
- Run by fully-qualified name (FQN) — recommended for pinpointing a single test:
55+
```
56+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj \
57+
--filter "FullyQualifiedName=RestSharp.Tests.UrlBuilderTests_Get.Should_build_url_with_query"
58+
```
59+
Notes:
60+
- Prefer `FullyQualifiedName` for precision. Class and method names are case-sensitive.
61+
- You can combine with `-f net8.0` to avoid cross-TFM failures when only one SDK is present.
62+
- Run by namespace or class:
63+
```
64+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj --filter "RestSharp.Tests.UrlBuilderTests"
65+
```
66+
67+
- Logs and results
68+
- TRX logs are written per TFM into `test-results/<TFM>/` with file name `<ProjectName>.trx` as configured by `VSTestLogger`/`VSTestResultsDirectory` in `Directory.Build.props`.
69+
- To additionally emit console diagnostics:
70+
```
71+
dotnet test -v n
72+
```
73+
74+
- Code coverage
75+
- The `coverlet.collector` package is referenced for data-collector based coverage.
76+
- Example coverage run (generates cobertura xml):
77+
```
78+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj \
79+
-f net8.0 \
80+
--collect:"XPlat Code Coverage" \
81+
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura
82+
```
83+
- Output will be placed under the test results directory for the given run.
84+
85+
- Adding new tests
86+
- New xUnit test files can be added anywhere under the corresponding test project directory; no extra `using` directives are required for `Xunit`/`FluentAssertions`/`AutoFixture` thanks to `Directory.Build.props` implicit usings.
87+
- Prefer co-locating tests by feature area and splitting large suites using partial classes (see `UrlBuilderTests.cs` with `UrlBuilderTests.Get.cs`/`Post.cs` linked via `DependentUpon` in the project) to keep navigation manageable.
88+
- For HTTP behavior, use `WireMockServer` in integrated tests rather than live endpoints. See `test/RestSharp.Tests.Integrated/DownloadFileTests.cs` for a pattern: spin up a server, register expectations in the constructor, and dispose in `IDisposable.Dispose`.
89+
- Follow existing assertions style with FluentAssertions.
90+
91+
- Verified example run
92+
- The test infrastructure was validated by executing a trivial `[Fact]` via fully qualified name using the built-in test runner. Use the FQN filtering example above to replicate.
93+
94+
---
95+
96+
### Additional development information
97+
98+
- Code style and analyzers
99+
- Adhere to the style used in `src/RestSharp` and existing tests. Test projects disable nullable by default; the main library might have different settings (check the respective `*.csproj` and imported props).
100+
- The repo uses central package management via `Directory.Packages.props`. Prefer bumping versions there unless a project has a specific override.
101+
102+
- HTTP/integration test guidance
103+
- Use `WireMockServer` for predictable, offline tests. Avoid time-sensitive or locale-sensitive assertions in integrated tests; when needed, pin formats (e.g., `"d"`) as seen in `ObjectParserTests`.
104+
- Be explicit about stream usage across TFMs. Some tests use `#if NET8_0_OR_GREATER` to select APIs like `Stream.ReadExactly`.
105+
106+
- Multi-TFM nuances
107+
- When debugging TFM-specific behavior, run `dotnet test -f <TFM>` to reproduce. Conditional compilation symbols (e.g., `NET8_0_OR_GREATER`) are used in tests; ensure your changes compile under all declared target frameworks or scope them with `#if`.
108+
109+
- Artifacts and outputs
110+
- NuGet packages are output to `nuget/` during local `dotnet pack` unless overridden.
111+
- Test artifacts are collected under `test-results/<TFM>/` per the configuration.
112+
113+
- Common pitfalls
114+
- Running tests targeting `net48` on non-Windows environments requires the reference assemblies (already pulled by package reference) but still may need Mono/compat setup on some systems; if unavailable, skip with `-f`.
115+
- Some integrated tests rely on asset files under `Assets/`. Ensure `AppDomain.CurrentDomain.BaseDirectory` resolves correctly when running from IDE vs CLI.
116+
117+
---
118+
119+
### Quick commands reference
120+
121+
```
122+
# Build solution
123+
dotnet build RestSharp.sln -c Release
124+
125+
# Run all tests for a single TFM
126+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj -f net8.0
127+
128+
# Run a single test by FQN
129+
dotnet test test/RestSharp.Tests/RestSharp.Tests.csproj --filter "FullyQualifiedName=RestSharp.Tests.ObjectParserTests.ShouldUseRequestProperty"
130+
131+
# Pack (local)
132+
dotnet pack src/RestSharp/RestSharp.csproj -c Release -o nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg
133+
```

src/RestSharp/RestClient.Async.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
using RestSharp.Extensions;
1616

17+
// ReSharper disable PossiblyMistakenUseOfCancellationToken
18+
1719
namespace RestSharp;
1820

1921
public partial class RestClient {

src/RestSharp/RestClient.Extensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,10 @@ [EnumeratorCancellation] CancellationToken cancellationToken
171171

172172
using var reader = new StreamReader(stream);
173173

174-
while (!reader.EndOfStream && !cancellationToken.IsCancellationRequested) {
175174
#if NET7_0_OR_GREATER
176-
var line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false);
175+
while (await reader.ReadLineAsync(cancellationToken) is { } line && !cancellationToken.IsCancellationRequested) {
177176
#else
178-
var line = await reader.ReadLineAsync().ConfigureAwait(false);
177+
while (await reader.ReadLineAsync() is { } line && !cancellationToken.IsCancellationRequested) {
179178
#endif
180179
if (string.IsNullOrWhiteSpace(line)) continue;
181180

test/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<PropertyGroup>
44
<IsTestProject>true</IsTestProject>
55
<IsPackable>false</IsPackable>
6-
<TargetFrameworks>net48;net8.0;net9.0</TargetFrameworks>
6+
<TargetFrameworks>net48;net8.0;net9.0;net10.0</TargetFrameworks>
77
<Nullable>disable</Nullable>
8-
<NoWarn>xUnit1033</NoWarn>
8+
<NoWarn>xUnit1033;CS8002</NoWarn>
99
<VSTestLogger>trx%3bLogFileName=$(MSBuildProjectName).trx</VSTestLogger>
1010
<VSTestResultsDirectory>$(RepoRoot)/test-results/$(TargetFramework)</VSTestResultsDirectory>
1111
</PropertyGroup>

0 commit comments

Comments
 (0)