Skip to content

Commit

Permalink
GetSharedAccessPath would not return due to UTC / DateTimeOffset issu…
Browse files Browse the repository at this point in the history
…e. (had no test coverage)
  • Loading branch information
Ron DeFreitas committed Sep 11, 2015
1 parent 2ef1e38 commit 3c1e1b2
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
39 changes: 39 additions & 0 deletions AzureBlobFileSystem.Test/StorageUniversalTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using NUnit.Framework;
Expand Down Expand Up @@ -206,5 +207,43 @@ public void renameFolder_should_mode_inner_files()

Assert.AreEqual("f1", SUT.ListFiles(folder + "2").Single().GetName());
}

[Test]
public void sharedPath_should_return_when_given_offset()
{
var folder = SUT.Combine(TEST_FOLDER, "folder");
SUT.CreateFolder(folder);

SUT.CreateFile(SUT.Combine(folder, "f1"));

var offset = DateTimeOffset.MaxValue;

Assert.DoesNotThrow(() =>
{
var file = SUT.ListFiles(folder).First();
var path = file.GetPath();
var sharedPath = file.GetSharedAccessPath(offset);
Trace.WriteLine(path);
Trace.WriteLine(sharedPath);
});
}

[Test]
public void sharedPath_should_return_when_not_given_offset()
{
var folder = SUT.Combine(TEST_FOLDER, "folder");
SUT.CreateFolder(folder);

SUT.CreateFile(SUT.Combine(folder, "f1"));

Assert.DoesNotThrow(() =>
{
var file = SUT.ListFiles(folder).First();
var path = file.GetPath();
var sharedPath = file.GetSharedAccessPath();
Trace.WriteLine(path);
Trace.WriteLine(sharedPath);
});
}
}
}
8 changes: 5 additions & 3 deletions AzureBlobFileSystem/AzureBlobStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public bool FileExists(string path)
return container.BlobExists(path);
}

public DateTimeOffset? DefaultSharedAccessExpiration { get; set; }

public IEnumerable<IStorageFile> ListFiles(string path)
{
path = path ?? String.Empty;
Expand Down Expand Up @@ -417,12 +419,12 @@ public string GetFileType()
{
return Path.GetExtension(GetPath());
}

public string GetSharedAccessPath()
public string GetSharedAccessPath(DateTimeOffset? expiration = null)
{
return _blob.Uri.AbsoluteUri + _blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
SharedAccessExpiryTime = DateTime.MaxValue
SharedAccessExpiryTime = expiration ?? _azureFileSystem.DefaultSharedAccessExpiration
}, "default");
}

Expand Down
4 changes: 3 additions & 1 deletion AzureBlobFileSystem/FileSystemStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ public bool FileExists(string path)
return new FileInfo(MapStorage(path)).Exists;
}

public DateTimeOffset? DefaultSharedAccessExpiration { get; set; }

public IStorageFile CreateOrReplaceFile(string path)
{
if (FileExists(path))
Expand Down Expand Up @@ -359,7 +361,7 @@ public string GetFileType()
return _fileInfo.Extension;
}

public string GetSharedAccessPath()
public string GetSharedAccessPath(DateTimeOffset? expiration = null)
{
return _path;
}
Expand Down
2 changes: 1 addition & 1 deletion AzureBlobFileSystem/IStorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IStorageFile
long GetSize();
DateTime GetLastUpdated();
string GetFileType();
string GetSharedAccessPath();
string GetSharedAccessPath(DateTimeOffset? expiration = null);

/// <summary>
/// Creates a stream for reading from the file.
Expand Down
9 changes: 9 additions & 0 deletions AzureBlobFileSystem/IStorageProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,14 @@ public interface IStorageProvider
string Combine(string path1, string path2);

bool FileExists(string path);


/// <summary>
/// Gets or sets the default shared access expiration date.
/// </summary>
/// <value>
/// The default shared access expiration date.
/// </value>
DateTimeOffset? DefaultSharedAccessExpiration { get; set; }
}
}

0 comments on commit 3c1e1b2

Please sign in to comment.