Skip to content

Commit

Permalink
Fix #33 with test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzzzerd committed Sep 10, 2018
1 parent 59f4041 commit 4270a14
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/FMData.Rest/FileMakerRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,16 @@ public override async Task ProcessContainer<T>(T instance)
{
var containerField = prop.GetCustomAttribute<ContainerDataForAttribute>().ContainerField;
var containerEndPoint = ti.GetDeclaredProperty(containerField).GetValue(instance) as string;

if (string.IsNullOrEmpty(containerEndPoint))
{
continue;
}
else if (!Uri.IsWellFormedUriString(containerEndPoint, UriKind.Absolute))
{
continue;
}

var data = await _client.GetAsync(containerEndPoint);
var dataBytes = await data.Content.ReadAsByteArrayAsync();
prop.SetValue(instance, dataBytes);
Expand Down
10 changes: 10 additions & 0 deletions src/FMData.Xml/FileMakerXmlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,16 @@ public override async Task ProcessContainer<T>(T instance)
{
var containerField = prop.GetCustomAttribute<ContainerDataForAttribute>().ContainerField;
var containerEndPoint = ti.GetDeclaredProperty(containerField).GetValue(instance) as string;

if (string.IsNullOrEmpty(containerEndPoint))
{
continue;
}
else if (!Uri.IsWellFormedUriString(containerEndPoint, UriKind.Absolute))
{
continue;
}

var data = await _client.GetAsync(containerEndPoint);
var dataBytes = await data.Content.ReadAsByteArrayAsync();
prop.SetValue(instance, dataBytes);
Expand Down
33 changes: 33 additions & 0 deletions tests/FMData.Rest.Tests/FindRequestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,39 @@ public async Task GetByRecordId_ShouldHaveContainerWithContainerDataFor()
Assert.Equal(bytes, response.SomeContainerFieldData);
}

[Theory]
[InlineData((string)null)]
[InlineData("//somefile")]
[InlineData("http:/localhost/somefile")]
[InlineData("s:localhost/")]
[InlineData("somefolder/somefile.ext")]
public async Task ProcessContainerData_Should_Skip_InvalidUris(string uri)
{
// arrange
var mockHttp = new MockHttpMessageHandler();

var server = "http://localhost";
var file = "test-file";
var user = "unit";
var pass = "test";

mockHttp.When(HttpMethod.Post, $"{server}/fmi/data/v1/databases/{file}/sessions")
.Respond("application/json", DataApiResponses.SuccessfulAuthentication());

var fdc = new FileMakerRestClient(mockHttp.ToHttpClient(), server, file, user, pass);

var model = new ContainerFieldTestModel
{
SomeContainerField = uri
};

// act
await fdc.ProcessContainer(model);

// assert
Assert.Null(model.SomeContainerFieldData);
}


[Fact]
public async Task SendAsync_Dictionary_WithPortals_ShouldHaveData()
Expand Down

0 comments on commit 4270a14

Please sign in to comment.