-
-
Notifications
You must be signed in to change notification settings - Fork 158
Fix: incorrect resource type comparison #821
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
27f31be
chore: review
maurei 5bf5f4b
Merge branch 'master' into fix/resourcetype-comparison-bug
maurei 6464d1e
fix: merge
maurei 4bbd1b6
fix: remove filter
maurei f27e020
fix: formatting
maurei 11a49a9
chore: review
maurei 46e4f4c
fix: icollection
maurei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
src/JsonApiDotNetCore/Middleware/AsyncResourceTypeMatchFilter.cs
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
src/JsonApiDotNetCore/Middleware/IAsyncResourceTypeMatchFilter.cs
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
test/JsonApiDotNetCoreExampleTests/Acceptance/Spec/ResourceTypeMismatchTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using JsonApiDotNetCore.Serialization.Objects; | ||
using Newtonsoft.Json; | ||
using Xunit; | ||
|
||
namespace JsonApiDotNetCoreExampleTests.Acceptance.Spec | ||
{ | ||
public sealed class ResourceTypeMismatchTests : FunctionalTestCollection<StandardApplicationFactory> | ||
{ | ||
public ResourceTypeMismatchTests(StandardApplicationFactory factory) : base(factory) { } | ||
|
||
[Fact] | ||
public async Task Posting_Resource_With_Mismatching_Resource_Type_Returns_Conflict() | ||
{ | ||
// Arrange | ||
string content = JsonConvert.SerializeObject(new | ||
{ | ||
data = new | ||
{ | ||
type = "people" | ||
} | ||
}); | ||
|
||
// Act | ||
var (body, _) = await Post("/api/v1/todoItems", content); | ||
|
||
// Assert | ||
var errorDocument = JsonConvert.DeserializeObject<ErrorDocument>(body); | ||
Assert.Single(errorDocument.Errors); | ||
Assert.Equal(HttpStatusCode.Conflict, errorDocument.Errors[0].StatusCode); | ||
Assert.Equal("Resource type mismatch between request body and endpoint URL.", errorDocument.Errors[0].Title); | ||
Assert.Equal("Expected resource of type 'todoItems' in POST request body at endpoint '/api/v1/todoItems', instead of 'people'.", errorDocument.Errors[0].Detail); | ||
} | ||
|
||
[Fact] | ||
public async Task Patching_Resource_With_Mismatching_Resource_Type_Returns_Conflict() | ||
{ | ||
// Arrange | ||
string content = JsonConvert.SerializeObject(new | ||
{ | ||
data = new | ||
{ | ||
type = "people", | ||
id = 1 | ||
} | ||
}); | ||
|
||
// Act | ||
var (body, _) = await Patch("/api/v1/todoItems/1", content); | ||
|
||
// Assert | ||
var errorDocument = JsonConvert.DeserializeObject<ErrorDocument>(body); | ||
Assert.Single(errorDocument.Errors); | ||
Assert.Equal(HttpStatusCode.Conflict, errorDocument.Errors[0].StatusCode); | ||
Assert.Equal("Resource type mismatch between request body and endpoint URL.", errorDocument.Errors[0].Title); | ||
Assert.Equal("Expected resource of type 'todoItems' in PATCH request body at endpoint '/api/v1/todoItems/1', instead of 'people'.", errorDocument.Errors[0].Detail); | ||
} | ||
|
||
[Fact] | ||
public async Task Patching_Through_Relationship_Link_With_Mismatching_Resource_Type_Returns_Conflict() | ||
{ | ||
// Arrange | ||
string content = JsonConvert.SerializeObject(new | ||
{ | ||
data = new | ||
{ | ||
type = "todoItems", | ||
id = 1 | ||
} | ||
}); | ||
|
||
// Act | ||
var (body, _) = await Patch("/api/v1/todoItems/1/relationships/owner", content); | ||
|
||
// Assert | ||
var errorDocument = JsonConvert.DeserializeObject<ErrorDocument>(body); | ||
Assert.Single(errorDocument.Errors); | ||
Assert.Equal(HttpStatusCode.Conflict, errorDocument.Errors[0].StatusCode); | ||
Assert.Equal("Resource type mismatch between request body and endpoint URL.", errorDocument.Errors[0].Title); | ||
Assert.Equal("Expected resource of type 'people' in PATCH request body at endpoint '/api/v1/todoItems/1/relationships/owner', instead of 'todoItems'.", errorDocument.Errors[0].Detail); | ||
} | ||
|
||
[Fact] | ||
public async Task Patching_Through_Relationship_Link_With_Multiple_Resources_Types_Returns_Conflict() | ||
{ | ||
// Arrange | ||
string content = JsonConvert.SerializeObject(new | ||
{ | ||
data = new object[] | ||
{ | ||
new { type = "todoItems", id = 1 }, | ||
new { type = "articles", id = 2 }, | ||
} | ||
}); | ||
|
||
// Act | ||
var (body, _) = await Patch("/api/v1/todoItems/1/relationships/childrenTodos", content); | ||
|
||
// Assert | ||
var errorDocument = JsonConvert.DeserializeObject<ErrorDocument>(body); | ||
Assert.Single(errorDocument.Errors); | ||
Assert.Equal(HttpStatusCode.Conflict, errorDocument.Errors[0].StatusCode); | ||
Assert.Equal("Resource type mismatch between request body and endpoint URL.", errorDocument.Errors[0].Title); | ||
Assert.Equal("Expected resource of type 'todoItems' in PATCH request body at endpoint '/api/v1/todoItems/1/relationships/childrenTodos', instead of 'articles'.", errorDocument.Errors[0].Detail); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.