Added check to UriUtility to check for default.aspx since this path will show up for pre-IIS7 websites, added

unit tests for UriUtility, updated UmbracoModule to use the UmbracoUrl to pass to the document request.
Added more unit tests for LookupByNiceUrl.
This commit is contained in:
shannon@ShandemVaio
2012-08-09 11:08:24 +06:00
parent e75aebc4fd
commit 67e921f862
5 changed files with 43 additions and 26 deletions

View File

@@ -1,4 +1,3 @@
using System;
using System.Configuration;
using System.Linq;
using System.Web;
@@ -16,7 +15,6 @@ using umbraco.cms.businesslogic.template;
namespace Umbraco.Tests.DocumentLookups
{
[TestFixture, RequiresSTA]
public abstract class BaseTest
{
@@ -114,26 +112,11 @@ namespace Umbraco.Tests.DocumentLookups
public class LookupByNiceUrlTests : BaseTest
{
//[TestCase("/default.aspx")]
//public void Match_Document_By_Non_Directory_Url(string urlAsString)
//{
// var template = Template.MakeNew("test", new User(0));
// var routingContext = GetRoutingContext(urlAsString, template);
// var cleanUrl = routingContext.UmbracoContext.HttpContext.Request.Url;
// var path = routingContext.UmbracoContext.RequestUrl.AbsolutePath.ToLower();
// UmbracoModule.LegacyCleanUmbPageFromQueryString(ref cleanUrl, ref path);
// var docRequest = new DocumentRequest(cleanUrl, routingContext);
// var lookup = new LookupByNiceUrl();
// var result = lookup.TrySetDocument(docRequest);
// Assert.IsTrue(result);
//}
[TestCase("/")]
[TestCase("/default.aspx")] //this one is actually rather important since this is the path that comes through when we are running in pre-IIS 7 for the root document '/' !
[TestCase("/Sub1")]
[TestCase("/sub1")]
[TestCase("/sub1.aspx")]
public void Match_Document_By_Directory_Url_Hide_Top_Level(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
@@ -150,13 +133,15 @@ namespace Umbraco.Tests.DocumentLookups
}
[TestCase("/")]
[TestCase("/default.aspx")] //this one is actually rather important since this is the path that comes through when we are running in pre-IIS 7 for the root document '/' !
[TestCase("/home/Sub1")]
[TestCase("/Home/Sub1")] //different cases
[TestCase("/home/Sub1.aspx")]
public void Match_Document_By_Directory_Url(string urlAsString)
{
var template = Template.MakeNew("test", new User(0));
var routingContext = GetRoutingContext(urlAsString, template);
var url = routingContext.UmbracoContext.HttpContext.Request.Url;
var url = routingContext.UmbracoContext.UmbracoUrl;
var docRequest = new DocumentRequest(url, routingContext);
var lookup = new LookupByNiceUrl();

View File

@@ -61,6 +61,7 @@
<Compile Include="ContentStoreTests.cs" />
<Compile Include="DataTypeFactoryTests.cs" />
<Compile Include="DocumentLookups\LookupByNiceUrlTests.cs" />
<Compile Include="UriUtilityTests.cs" />
<Compile Include="MacroFieldEditorsResolverTests.cs" />
<Compile Include="MacroEngineFactoryTests.cs" />
<Compile Include="ManyObjectResolverTests.cs" />

View File

@@ -0,0 +1,26 @@
using System;
using NUnit.Framework;
using Umbraco.Web;
namespace Umbraco.Tests
{
[TestFixture]
public class UriUtilityTests
{
[TestCase("http://Localhost/", "http://localhost/")]
[TestCase("http://localhost/default.aspx", "http://localhost/")]
[TestCase("http://localhost/default.aspx?test=blah", "http://localhost/?test=blah")]
[TestCase("http://localhost/home/Sub1", "http://localhost/home/sub1")]
[TestCase("http://localhost/home/Sub1.aspx", "http://localhost/home/sub1")]
[TestCase("http://localhost/home/Sub1.aspx?test=blah", "http://localhost/home/sub1?test=blah")]
public void Uri_To_Umbraco(string url, string expected)
{
var uri = new Uri(url);
var expectedUri = new Uri(expected);
var result = UriUtility.UriToUmbraco(uri);
Assert.AreEqual(expectedUri.ToString(), result.ToString());
}
}
}

View File

@@ -72,8 +72,8 @@ namespace Umbraco.Web
//assign the routing context back to the umbraco context
umbracoContext.RoutingContext = routingContext;
var uri = httpContext.Request.Url;
var lpath = uri.AbsolutePath.ToLower();
var uri = umbracoContext.UmbracoUrl;
var lpath = umbracoContext.UmbracoUrl.AbsolutePath.ToLowerInvariant();
// legacy - no idea what this is
LegacyCleanUmbPageFromQueryString(ref uri, ref lpath);
@@ -348,6 +348,7 @@ namespace Umbraco.Web
// "Clean umbPage from querystring, caused by .NET 2.0 default Auth Controls"
// but really, at the moment I have no idea what this does, and why...
// SD: I also have no idea what this does, I've googled umbPage and really nothing shows up
internal static void LegacyCleanUmbPageFromQueryString(ref Uri uri, ref string lpath)
{
string receivedQuery = uri.Query;

View File

@@ -71,15 +71,19 @@ namespace Umbraco.Web
{
var path = uri.GetSafeAbsolutePath();
path = path.ToLower();
//we need to check if the path is /default.aspx because this will occur when using a
//web server pre IIS 7 when requesting the root document
//if this is the case we need to change it to '/'
path = path.ToLower();
if (path.EndsWith("default.aspx", StringComparison.InvariantCultureIgnoreCase))
{
path = path.Substring(0, path.Length - "default.aspx".Length);
}
if (path != "/")
path = path.TrimEnd('/');
if (path.EndsWith(".aspx"))
path = path.Substring(0, path.Length - ".aspx".Length);
if (path.EndsWith(".aspx"))
path = path.Substring(0, path.Length - ".aspx".Length);
return uri.Rewrite(path);
}