Skip to content

Commit

Permalink
Use originUri.LocalPath instead of Uri.UnescapeDataString when parsin…
Browse files Browse the repository at this point in the history
…g origin

Test ReturnsExpectedResponseWithSpace_OnSuccess against an URI including an escaped character

Update SftpReader to log hostname and path on exception
  • Loading branch information
griffri committed Jul 31, 2024
1 parent 6059e82 commit d2e3b0b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ public async Task LoadAssetFromOrigin_ReturnsExpectedResponseWithNonStandardPort
result.ContentLength.Should().Be(stream.Length);
}

[Fact]
public async Task LoadAssetFromOrigin_ReturnsExpectedResponseWithSpace_OnSuccess()
[Theory]
[InlineData("sftp://www.someuri.com/public_ftp/some folder/someId")]
[InlineData("sftp://www.someuri.com/public_ftp/some%20folder/someId")]
public async Task LoadAssetFromOrigin_ReturnsExpectedResponseWithSpace_OnSuccess(string originUri)
{
// Arrange
var content = "this is a test";

var stream = content.ToMemoryStream();

const string originUri = "sftp://www.someuri.com/public_ftp/some folder/someId";

var basicCredentials = new BasicCredentials()
{
Expand Down
2 changes: 1 addition & 1 deletion src/protagonist/DLCS.Repository/SFTP/SftpReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<Stream> RetrieveFile(ConnectionInfo connectionInfo,
outputStream.Close();
}

logger.LogError(ex, "Error downloading SFTP file");
logger.LogError(ex, "Error downloading SFTP file from Host: {Hostname}, Path: {Path}", connectionInfo.Host, path);
throw;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public async Task<OriginResponse> LoadAssetFromOrigin(AssetId assetId, string or

try
{
var originPath = Uri.UnescapeDataString(originUri.AbsolutePath);
var outputStream = await sftpReader.RetrieveFile(connectionInfo, originPath, cancellationToken);
var outputStream = await sftpReader.RetrieveFile(connectionInfo, originUri.LocalPath, cancellationToken);
return new OriginResponse(outputStream).WithContentLength(outputStream.Length);
}
catch (Exception ex)
Expand Down

0 comments on commit d2e3b0b

Please sign in to comment.