Update FileResult tests to detect a bug for the status 416 RangeNotSatisfiable

Update FileResult tests to detect a bug for the status 416 RangeNotSatisfiable :
https://github.com/aspnet/AspNetCore/issues/4943
When the body is empty, the Content-Length header should be 0 to match the body length.
This commit is contained in:
Matthias Laroche 2018-12-15 18:27:07 +01:00 committed by Artak
parent a9c358bbbd
commit 134f28f71d
5 changed files with 18 additions and 9 deletions

View File

@ -361,6 +361,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Equal(StatusCodes.Status416RangeNotSatisfiable, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(contentRange.ToString(), httpResponse.Headers[HeaderNames.ContentRange]);
Assert.Equal(0, httpResponse.ContentLength);
Assert.Empty(body);
}

View File

@ -348,7 +348,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Equal(StatusCodes.Status416RangeNotSatisfiable, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(contentRange.ToString(), httpResponse.Headers[HeaderNames.ContentRange]);
Assert.Equal(11, httpResponse.ContentLength);
Assert.Equal(0, httpResponse.ContentLength);
Assert.Empty(body);
Assert.False(readStream.CanSeek);
}
@ -486,6 +486,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Equal(StatusCodes.Status416RangeNotSatisfiable, httpResponse.StatusCode);
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(contentRange.ToString(), httpResponse.Headers[HeaderNames.ContentRange]);
Assert.Equal(0, httpResponse.ContentLength);
Assert.Empty(body);
Assert.False(readStream.CanSeek);
}

View File

@ -244,6 +244,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(contentRange.ToString(), httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Equal(0, httpResponse.ContentLength);
Assert.Empty(body);
}

View File

@ -317,6 +317,7 @@ namespace Microsoft.AspNetCore.Mvc
Assert.Equal("bytes", httpResponse.Headers[HeaderNames.AcceptRanges]);
Assert.Equal(contentRange.ToString(), httpResponse.Headers[HeaderNames.ContentRange]);
Assert.NotEmpty(httpResponse.Headers[HeaderNames.LastModified]);
Assert.Equal(0, httpResponse.ContentLength);
Assert.Empty(body);
}

View File

@ -97,6 +97,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal("text/plain", response.Content.Headers.ContentType.ToString());
Assert.Equal(0, response.Content.Headers.ContentLength);
var body = await response.Content.ReadAsStringAsync();
Assert.Empty(body);
}
@ -160,6 +161,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal("text/plain", response.Content.Headers.ContentType.ToString());
Assert.Equal(0, response.Content.Headers.ContentLength);
var body = await response.Content.ReadAsStringAsync();
Assert.Empty(body);
}
@ -255,8 +257,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
[InlineData("0-6", (int)HttpStatusCode.OK, 26)]
[InlineData("bytes = ", (int)HttpStatusCode.OK, 26)]
[InlineData("bytes = 1-4, 5-11", (int)HttpStatusCode.OK, 26)]
[InlineData("bytes = 35-36", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 26)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 26)]
[InlineData("bytes = 35-36", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
public async Task FileFromDisk_ReturnsFileWithFileName_DoesNotServeBody_ForHeadRequest_WithLastModifiedAndEtag(
string rangeString,
int httpStatusCode,
@ -365,6 +367,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal("text/plain", response.Content.Headers.ContentType.ToString());
Assert.Equal(0, response.Content.Headers.ContentLength);
Assert.Empty(body);
}
@ -455,8 +458,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
[InlineData("0-6", (int)HttpStatusCode.OK, 33)]
[InlineData("bytes = ", (int)HttpStatusCode.OK, 33)]
[InlineData("bytes = 1-4, 5-11", (int)HttpStatusCode.OK, 33)]
[InlineData("bytes = 35-36", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 33)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 33)]
[InlineData("bytes = 35-36", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
public async Task FileFromStream_ReturnsFileWithFileName_DoesNotServeBody_ForHeadRequest(
string rangeString,
int httpStatusCode,
@ -568,6 +571,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal("text/plain", response.Content.Headers.ContentType.ToString());
Assert.Equal(0, response.Content.Headers.ContentLength);
Assert.Empty(body);
}
@ -660,8 +664,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
[InlineData("0-6", (int)HttpStatusCode.OK, 41)]
[InlineData("bytes = ", (int)HttpStatusCode.OK, 41)]
[InlineData("bytes = 1-4, 5-11", (int)HttpStatusCode.OK, 41)]
[InlineData("bytes = 45-46", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 41)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 41)]
[InlineData("bytes = 45-46", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
public async Task FileFromBinaryData_ReturnsFileWithFileName_DoesNotServeBody_ForHeadRequest(
string rangeString,
int httpStatusCode,
@ -847,6 +851,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
Assert.Equal(HttpStatusCode.RequestedRangeNotSatisfiable, response.StatusCode);
Assert.NotNull(response.Content.Headers.ContentType);
Assert.Equal("text/plain", response.Content.Headers.ContentType.ToString());
Assert.Equal(0, response.Content.Headers.ContentLength);
var body = await response.Content.ReadAsStringAsync();
Assert.Empty(body);
var contentDisposition = response.Content.Headers.ContentDisposition.ToString();
@ -863,8 +868,8 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
[InlineData("0-6", (int)HttpStatusCode.OK, 38)]
[InlineData("bytes = ", (int)HttpStatusCode.OK, 38)]
[InlineData("bytes = 1-4, 5-11", (int)HttpStatusCode.OK, 38)]
[InlineData("bytes = 45-46", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 38)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 38)]
[InlineData("bytes = 45-46", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
[InlineData("bytes = -0", (int)HttpStatusCode.RequestedRangeNotSatisfiable, 0)]
public async Task FileFromEmbeddedResources_ReturnsFileWithFileName_DoesNotServeBody_ForHeadRequest(
string rangeString,
int httpStatusCode,