Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Commit

Permalink
Fixed broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodejunkie committed May 31, 2017
1 parent acd63de commit 58ad5fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Expand Up @@ -80,18 +80,19 @@ static EmbeddedStaticContentConventionBuilder()
return () => null;
}
var transformedRequestPath =
GetSafeRequestPath(requestPath, requestedPath, contentPath);
var fullFilePath =
Path.GetFullPath(GetSafeRequestPath(requestPath, requestedPath, contentPath));
transformedRequestPath =
GetEncodedPath(transformedRequestPath);
var relativeFilePath =
ResolveRelativeFilePath(fullFilePath);
// Resolve relative paths by using c:\ as a fake root path
var fileName =
Path.GetFullPath(Path.Combine("c:\\", transformedRequestPath));
var fileName = Path.Combine(
Path.DirectorySeparatorChar.ToString(),
GetEncodedPath(relativeFilePath));
var contentRootPath =
Path.GetFullPath(Path.Combine("c:\\", GetEncodedPath(contentPath)));
var contentRootPath = Path.Combine(
Path.DirectorySeparatorChar.ToString(),
GetEncodedPath(contentPath));
if (!IsWithinContentFolder(contentRootPath, fileName))
{
Expand All @@ -100,7 +101,7 @@ static EmbeddedStaticContentConventionBuilder()
}
var resourceName =
Path.GetDirectoryName(assembly.GetName().Name + fileName.Substring(2)).Replace('\\', '.').Replace('-', '_');
Path.GetDirectoryName(assembly.GetName().Name + fileName).Replace(Path.DirectorySeparatorChar, '.').Replace('-', '_');
fileName =
Path.GetFileName(fileName);
Expand All @@ -116,6 +117,14 @@ static EmbeddedStaticContentConventionBuilder()
};
}

private static string ResolveRelativeFilePath(string fullFilePath)
{
var fileRootPath =
Directory.GetDirectoryRoot(fullFilePath);

return fullFilePath.Substring(fileRootPath.Length);
}

private static string GetEncodedPath(string path)
{
return PathReplaceRegex.Replace(path.TrimStart(new[] { '/' }), Path.DirectorySeparatorChar.ToString());
Expand Down
1 change: 0 additions & 1 deletion test/Nancy.Tests/Nancy.Tests.csproj
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp1.1;net452</TargetFrameworks>
<VersionPrefix>1.4.1.0</VersionPrefix>
</PropertyGroup>

<ItemGroup>
Expand Down
25 changes: 20 additions & 5 deletions test/Nancy.Tests/Unit/Sessions/CookieBasedSessionsFixture.cs
Expand Up @@ -345,14 +345,29 @@ public void Should_generate_hmac()
[Fact]
public void Should_load_valid_test_data()
{
var inputValue = ValidHmac + ValidData;
inputValue = HttpUtility.UrlEncode(inputValue);
var store = new CookieBasedSessions(this.aesEncryptionProvider, this.defaultHmacProvider, this.defaultObjectSerializer);
var request = new Request("GET", "/", "http");
request.Cookies.Add(store.CookieName, inputValue);
// Given
var payload = new DefaultSessionObjectFormatterFixture.Payload
{
BoolValue = true
};

var cookieData = GenerateCookieData(new Dictionary<string, object>
{
{ "key1", payload }
});

var store =
new CookieBasedSessions(this.aesEncryptionProvider, this.defaultHmacProvider, this.defaultObjectSerializer);

var request =
new Request("GET", "/", "http");

request.Cookies.Add(store.CookieName, cookieData.ToString());

// When
var result = store.Load(request);

// Then
result.Count.ShouldEqual(1);
result.First().Value.ShouldBeOfType(typeof(DefaultSessionObjectFormatterFixture.Payload));
}
Expand Down

0 comments on commit 58ad5fb

Please sign in to comment.