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

Fixed the handling of empty http attributes in Batch Requests #2705

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1d5ab5e
Fixed the http attribute handling within ODataJsonLightBatchPayloadIt…
May 10, 2023
3842542
Fixed the http attribute handling within ODataJsonLightBatchPayloadIt…
May 10, 2023
f50a630
Switched http attribute test assert true to false to highlight test f…
May 15, 2023
a9c5f07
Fixed merge conflicts
May 17, 2023
8a70688
Fixed duplicate json property handling ODataJsonLightBatchPayloadItem…
Jun 19, 2023
0707d6c
Little optimization at the json property header handling.
Jun 20, 2023
bcffbfc
Minor fix, replacing duplicate http headers correctly in the non asyn…
Jun 21, 2023
22cc32a
Changed the handling of duplicate json property headers, which will n…
Jun 23, 2023
3a63962
Renamed exception messages & added them to the resource file
Jun 26, 2023
d2aa56a
Improved ODataJsonLightBatchReaderTests for NULL value headers and ad…
Jul 3, 2023
23d04e9
Added synchronous unit tests, added AssertThrowsAsync to duplicate js…
Jul 10, 2023
6271298
reverted ODataJsonLightBatchPayloadItemPropertiesCache null value han…
Jul 17, 2023
5bcca3c
Merge pull request #1 from apiaskowski/bugfix/issue-2656/batch-reques…
apiaskowski Jul 18, 2023
9018593
Fixed the JSON property handling of empty http headers, within ODataJ…
Jul 18, 2023
1b32931
Resolved merge conflicts from remote upstream branch
Jul 18, 2023
4c5b2bc
Resolved merge conflicts
Jul 18, 2023
e435745
Fixed the http attribute handling within ODataJsonLightBatchPayloadIt…
May 10, 2023
664601d
Fixed duplicate json property handling ODataJsonLightBatchPayloadItem…
Jun 19, 2023
013504c
Little optimization at the json property header handling.
Jun 20, 2023
674dfbf
Minor fix, replacing duplicate http headers correctly in the non asyn…
Jun 21, 2023
1283f79
Changed the handling of duplicate json property headers, which will n…
Jun 23, 2023
792aa94
Renamed exception messages & added them to the resource file
Jun 26, 2023
b2fc48f
reverted ODataJsonLightBatchPayloadItemPropertiesCache null value han…
Jul 17, 2023
060b700
Fixed the JSON property handling of empty http headers, within ODataJ…
Jul 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private void ScanJsonProperties()
while (this.jsonReader.NodeType != JsonNodeType.EndObject)
{
string headerName = this.jsonReader.ReadPropertyName();
string headerValue = this.jsonReader.ReadPrimitiveValue().ToString();
string headerValue = this.jsonReader.ReadPrimitiveValue()?.ToString();

// Throw an ODataException, if a duplicate header was detected
if (headers.ContainsKeyOrdinal(headerName))
Expand Down Expand Up @@ -425,7 +425,7 @@ await this.asynchronousJsonReader.ReadStartObjectAsync()
{
string headerName = await this.asynchronousJsonReader.ReadPropertyNameAsync()
.ConfigureAwait(false);
string headerValue = (await this.asynchronousJsonReader.ReadPrimitiveValueAsync().ConfigureAwait(false)).ToString();
string headerValue = (await this.asynchronousJsonReader.ReadPrimitiveValueAsync().ConfigureAwait(false))?.ToString();

// Throw an ODataException, if a duplicate header was detected
if (headers.ContainsKeyOrdinal(headerName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,78 @@ await DoReadAsync(
isResponse: false);
}

[Fact]
public void ReadBatchRequestWithNullHeaders()
{
var payload = "{\"requests\": [{" +
"\"id\": \"1\"," +
"\"method\": \"POST\"," +
"\"url\": \"http://tempuri.org/Customers\"," +
"\"headers\": {\"odata-version\":\"4.0\",\"content-type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\",\"null-header\":null}, " +
"\"body\": {\"@odata.type\":\"#NS.Customer\",\"Id\":1,\"Name\":\"Customer 1\",\"Type\":\"Retail\"}}]}";

SetupJsonLightBatchReaderAndRunTest(
payload,
(jsonLightBatchReader) =>
{
try
{
while (jsonLightBatchReader.Read())
{
if (jsonLightBatchReader.State == ODataBatchReaderState.Operation)
{
var operationRequestMessage = jsonLightBatchReader.CreateOperationRequestMessage();
// Verify that the Property "null-header" exists and it's value is set to NULL
var nullHeaderProperty = operationRequestMessage.Headers.FirstOrDefault(p => p.Key == "null-header");
Assert.NotNull(nullHeaderProperty.Key);
Assert.Null(nullHeaderProperty.Value);
}
}
}
catch (NullReferenceException ex)
{
Assert.False(true, ex.Message);
}
},
isResponse: false);
}

[Fact]
public async Task ReadBatchRequestWithNullHeadersAsync()
{
var payload = "{\"requests\": [{" +
"\"id\": \"1\"," +
"\"method\": \"POST\"," +
"\"url\": \"http://tempuri.org/Customers\"," +
"\"headers\": {\"odata-version\":\"4.0\",\"content-type\":\"application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8\",\"null-header\":null}, " +
"\"body\": {\"@odata.type\":\"#NS.Customer\",\"Id\":1,\"Name\":\"Customer 1\",\"Type\":\"Retail\"}}]}";

await SetupJsonLightBatchReaderAndRunTestAsync(
payload,
async (jsonLightBatchReader) =>
{
try
{
while (await jsonLightBatchReader.ReadAsync())
{
if (jsonLightBatchReader.State == ODataBatchReaderState.Operation)
{
var operationRequestMessage = await jsonLightBatchReader.CreateOperationRequestMessageAsync();
// Verify that the Property "null-header" exists and it's value is set to NULL
var nullHeaderProperty = operationRequestMessage.Headers.FirstOrDefault(p => p.Key == "null-header");
Assert.NotNull(nullHeaderProperty.Key);
Assert.Null(nullHeaderProperty.Value);
}
}
}
catch (NullReferenceException ex)
{
Assert.False(true, ex.Message);
}
},
isResponse: false);
}

[Fact]
public void ReadBatchRequestWithDuplicateProperties()
{
Expand Down