mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-24 18:11:10 +01:00
Disable DynamicLinq to fix CVE (#1242)
* Disable DynamicLinq * Disable DynamicLinq functionality
This commit is contained in:
@@ -20,8 +20,9 @@
|
||||
Name: test,
|
||||
Matchers: [
|
||||
{
|
||||
Name: LinqMatcher,
|
||||
Pattern: it.Length < 10
|
||||
Name: ExactMatcher,
|
||||
Pattern: abc,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ builder
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo", false, WireMock.Matchers.MatchOperator.Or))
|
||||
.WithParam("test", new LinqMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, "it.Length < 10"))
|
||||
.WithParam("test", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
||||
)
|
||||
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
||||
.RespondWith(Response.Create()
|
||||
|
||||
@@ -3,7 +3,7 @@ server
|
||||
.Given(Request.Create()
|
||||
.UsingMethod("GET")
|
||||
.WithPath(new WildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, "/foo", false, WireMock.Matchers.MatchOperator.Or))
|
||||
.WithParam("test", new LinqMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, "it.Length < 10"))
|
||||
.WithParam("test", new ExactMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, false, WireMock.Matchers.MatchOperator.Or, "abc"))
|
||||
)
|
||||
.WithGuid("41372914-1838-4c67-916b-b9aacdd096ce")
|
||||
.RespondWith(Response.Create()
|
||||
|
||||
@@ -20,8 +20,9 @@
|
||||
Name: test,
|
||||
Matchers: [
|
||||
{
|
||||
Name: LinqMatcher,
|
||||
Pattern: it.Length < 10
|
||||
Name: ExactMatcher,
|
||||
Pattern: abc,
|
||||
IgnoreCase: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class MappingBuilderTests
|
||||
|
||||
_sut.Given(Request.Create()
|
||||
.WithPath("/foo")
|
||||
.WithParam("test", new LinqMatcher("it.Length < 10"))
|
||||
.WithParam("test", new ExactMatcher("abc"))
|
||||
.UsingGet()
|
||||
)
|
||||
.WithGuid(MappingGuid)
|
||||
|
||||
@@ -110,18 +110,18 @@ public class MatcherTests
|
||||
result.Should().StartWith("new JsonPartialWildcardMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch,");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LinqMatcher_GetCSharpCodeArguments_ShouldReturnCorrectArguments()
|
||||
{
|
||||
// Arrange
|
||||
var matcher = new LinqMatcher("it.Contains(\"test\"");
|
||||
//[Fact]
|
||||
//public void LinqMatcher_GetCSharpCodeArguments_ShouldReturnCorrectArguments()
|
||||
//{
|
||||
// // Arrange
|
||||
// var matcher = new LinqMatcher("it.Contains(\"test\"");
|
||||
|
||||
// Act
|
||||
var result = matcher.GetCSharpCodeArguments();
|
||||
// // Act
|
||||
// var result = matcher.GetCSharpCodeArguments();
|
||||
|
||||
// Assert
|
||||
result.Should().Be("new LinqMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, \"it.Contains(\\\"test\\\"\")");
|
||||
}
|
||||
// // Assert
|
||||
// result.Should().Be("new LinqMatcher(WireMock.Matchers.MatchBehaviour.AcceptOnMatch, WireMock.Matchers.MatchOperator.Or, \"it.Contains(\\\"test\\\"\")");
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void RegexMatcher_GetCSharpCodeArguments_ShouldReturnCorrectArguments()
|
||||
|
||||
@@ -19,8 +19,8 @@ public class RequestMatchResultTests
|
||||
result1.AddScore(typeof(WildcardMatcher), 0.9, null);
|
||||
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(LinqMatcher), 1, null);
|
||||
result2.AddScore(typeof(LinqMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
|
||||
var results = new[] { result1, result2 };
|
||||
|
||||
@@ -40,9 +40,9 @@ public class RequestMatchResultTests
|
||||
result1.AddScore(typeof(WildcardMatcher), 1, null);
|
||||
|
||||
var result2 = new RequestMatchResult();
|
||||
result2.AddScore(typeof(LinqMatcher), 1, null);
|
||||
result2.AddScore(typeof(LinqMatcher), 1, null);
|
||||
result2.AddScore(typeof(LinqMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
result2.AddScore(typeof(JsonMatcher), 1, null);
|
||||
|
||||
var results = new[] { result1, result2 };
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ public class ResponseWithHandlebarsLinqTests
|
||||
{
|
||||
private readonly WireMockServerSettings _settings = new();
|
||||
|
||||
private Mock<IMapping> mappingMock;
|
||||
private readonly Mock<IMapping> _mappingMock;
|
||||
|
||||
public ResponseWithHandlebarsLinqTests()
|
||||
{
|
||||
mappingMock = new Mock<IMapping>();
|
||||
_mappingMock = new Mock<IMapping>();
|
||||
|
||||
var filesystemHandlerMock = new Mock<IFileSystemHandler>(MockBehavior.Strict);
|
||||
filesystemHandlerMock.Setup(fs => fs.ReadResponseBodyAsString(It.IsAny<string>())).Returns("abc");
|
||||
@@ -33,7 +33,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
_settings.FileSystemHandler = filesystemHandlerMock.Object;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "DynamicLinq")]
|
||||
public async Task Response_ProvideResponse_Handlebars_Linq1_String0()
|
||||
{
|
||||
// Assign
|
||||
@@ -47,7 +47,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
var response = await responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
|
||||
@@ -55,7 +55,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
Check.That(j["x"].ToString()).Equals("/pathtest");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "DynamicLinq")]
|
||||
public async Task Response_ProvideResponse_Handlebars_Linq1_String1()
|
||||
{
|
||||
// Assign
|
||||
@@ -77,7 +77,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
var response = await responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
|
||||
@@ -85,7 +85,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
Check.That(j["x"].ToString()).Equals("Test_123");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "DynamicLinq")]
|
||||
public async Task Response_ProvideResponse_Handlebars_Linq1_String2()
|
||||
{
|
||||
// Assign
|
||||
@@ -107,7 +107,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
var response = await responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
|
||||
@@ -115,7 +115,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
Check.That(j["x"].ToString()).Equals("{ N = Test_123, I = 9 }");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "DynamicLinq")]
|
||||
public async Task Response_ProvideResponse_Handlebars_Linq2_Object()
|
||||
{
|
||||
// Assign
|
||||
@@ -137,7 +137,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
var response = await responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson);
|
||||
@@ -145,7 +145,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
Check.That(j["x"].ToString()).Equals("{ N = Test_123, I = 9 }");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Fact(Skip = "DynamicLinq")]
|
||||
public void Response_ProvideResponse_Handlebars_Linq_Throws_ArgumentException()
|
||||
{
|
||||
// Assign
|
||||
@@ -162,7 +162,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Check.ThatAsyncCode(() => responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings)).Throws<ArgumentException>();
|
||||
Check.ThatAsyncCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings)).Throws<ArgumentException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -178,7 +178,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Check.ThatAsyncCode(() => responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings)).Throws<HandlebarsException>();
|
||||
Check.ThatAsyncCode(() => responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings)).Throws<HandlebarsException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -202,7 +202,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
a.Should().ThrowAsync<HandlebarsException>();
|
||||
@@ -229,7 +229,7 @@ public class ResponseWithHandlebarsLinqTests
|
||||
.WithTransformer();
|
||||
|
||||
// Act
|
||||
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
Func<Task> a = async () => await responseBuilder.ProvideResponseAsync(_mappingMock.Object, request, _settings).ConfigureAwait(false);
|
||||
|
||||
// Assert
|
||||
a.Should().ThrowAsync<HandlebarsException>();
|
||||
|
||||
@@ -302,41 +302,41 @@ message HelloReply {
|
||||
Check.ThatCode(() => _sut.Map(model)).Throws<NotSupportedException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_LinqMatcher_Pattern()
|
||||
{
|
||||
// Assign
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = "LinqMatcher",
|
||||
Pattern = "p"
|
||||
};
|
||||
//[Fact]
|
||||
//public void MatcherMapper_Map_MatcherModel_LinqMatcher_Pattern()
|
||||
//{
|
||||
// // Assign
|
||||
// var model = new MatcherModel
|
||||
// {
|
||||
// Name = "LinqMatcher",
|
||||
// Pattern = "p"
|
||||
// };
|
||||
|
||||
// Act
|
||||
var matcher = (LinqMatcher)_sut.Map(model)!;
|
||||
// // Act
|
||||
// var matcher = (LinqMatcher)_sut.Map(model)!;
|
||||
|
||||
// Assert
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
matcher.GetPatterns().Should().Contain("p");
|
||||
}
|
||||
// // Assert
|
||||
// matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
// matcher.GetPatterns().Should().Contain("p");
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_LinqMatcher_Patterns()
|
||||
{
|
||||
// Assign
|
||||
var model = new MatcherModel
|
||||
{
|
||||
Name = "LinqMatcher",
|
||||
Patterns = ["p1", "p2"]
|
||||
};
|
||||
//[Fact]
|
||||
//public void MatcherMapper_Map_MatcherModel_LinqMatcher_Patterns()
|
||||
//{
|
||||
// // Assign
|
||||
// var model = new MatcherModel
|
||||
// {
|
||||
// Name = "LinqMatcher",
|
||||
// Patterns = ["p1", "p2"]
|
||||
// };
|
||||
|
||||
// Act
|
||||
var matcher = (LinqMatcher)_sut.Map(model)!;
|
||||
// // Act
|
||||
// var matcher = (LinqMatcher)_sut.Map(model)!;
|
||||
|
||||
// Assert
|
||||
matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
matcher.GetPatterns().Should().Contain("p1", "p2");
|
||||
}
|
||||
// // Assert
|
||||
// matcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
|
||||
// matcher.GetPatterns().Should().Contain("p1", "p2");
|
||||
//}
|
||||
|
||||
[Fact]
|
||||
public void MatcherMapper_Map_MatcherModel_JsonMatcher_Pattern_As_String()
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Matchers\LinqMatcherTests.cs" />
|
||||
<Compile Remove="Util\JsonUtilsTests.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user