[Mono-dev] [PATCH] Fix Roles.IsUserInRole and enhance WebTestFramework
Tiaan Geldenhuys
tagdev at gmail.com
Thu Feb 11 10:15:09 EST 2010
Actually, this should not be changed; that expression reads "is not null BUT
ONLY empty" as it was intended. The case for null is supposed to throw an
ArgumentNullException, which should happen when the RoleProvider is called
(if the provider is implemented according to spec) or a check for null can
also be added to Roles.IsUserInRole (that can throw the exception without
calling the provider). I thought about adding a test for the null case too,
but wanted to keep the patch to a minimum to first get the basic
enhancements for RoleTest in. I think this should not have been committed
as IsNullOrEmpty.
-----Original Message-----
From: Eyal Alaluf [mailto:eyala at mainsoft.com]
Sent: 11 February 2010 3:44 AM
To: Tiaan Geldenhuys; mono-devel-list at lists.ximian.com
Cc: mhabersack at novell.com
Subject: RE: [Mono-dev] [PATCH] Fix Roles.IsUserInRole and enhance
WebTestFramework
Hi, Tiaan.
It seems to me you'd want to use 'string.IsNullOrEmpty(username)'
instead of '(username != null && username.Length <= 0)'
Eyal.
-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Tiaan
Geldenhuys
Sent: Thursday, February 11, 2010 11:17 AM
To: mono-devel-list at lists.ximian.com
Cc: mhabersack at novell.com
Subject: [Mono-dev] [PATCH] Fix Roles.IsUserInRole and enhance
WebTestFramework
The attached patch is a fix for System.Web.Security.Roles.IsUserInRole
to prevent ASP.NET MVC errors like the one shown at the bottom, which
happens when a user hasn't logged on and requests public pages with
sections that are dynamically removed using role-based
access-restrictions. It now behaves more like .NET that does not throw
an exception.
Writing a test for this fix was a bit of a challenge -- it's no wonder
there is not any working test for the Roles class yet. :) To address
this, the MonoTests.SystemWeb.Framework.WebTest class was updated
slightly to make it possible to write self-contained tests for cases
where you might want more control over the resources that are copied to
your hosted web application, such as when creating Web.config files
dynamically. The test for the current fix also serves as an example of
how this can be done. If these changes are approved, one can expand on
this for all the other Roles methods.
Please review and commit.
Thank you,
Tiaan.
NOTE: The patch files can be used without changes on both trunk and the
2.6 branch.
---------------
[System.Web.HttpUnhandledException]: Exception of type
'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.ProcessException (System.Exception e) [0x00000]
in <filename unknown>:0
at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context)
[0x00000] in <filename unknown>:0
at System.Web.HttpApplication+<Pipeline>c__Iterator5.MoveNext ()
[0x00000] in <filename unknown>:0
at System.Web.HttpApplication.Tick () [0x00000] in <filename
unknown>:0
[System.Web.HttpUnhandledException]: Exception of type
'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.ProcessException (System.Exception e) [0x00000]
in <filename unknown>:0
at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context)
[0x00000] in <filename unknown>:0
at System.Web.Mvc.ViewPage.RenderView (System.Web.Mvc.ViewContext
viewContext) [0x00000] in <filename unknown>:0
at System.Web.Mvc.WebFormView.RenderViewPage
(System.Web.Mvc.ViewContext context, System.Web.Mvc.ViewPage page)
[0x00000] in <filename unknown>:0
at System.Web.Mvc.WebFormView.Render (System.Web.Mvc.ViewContext
viewContext, System.IO.TextWriter writer) [0x00000] in <filename
unknown>:0
at System.Web.Mvc.ViewResultBase.ExecuteResult
(System.Web.Mvc.ControllerContext context) [0x00000] in <filename
unknown>:0
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult
(System.Web.Mvc.ControllerContext controllerContext,
System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename
unknown>:0
at
System.Web.Mvc.ControllerActionInvoker+<InvokeActionResultWithFilters>c_
_Ano
nStoreyE.<>m__11 () [0x00000] in <filename unknown>:0
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter
(IResultFilter filter, System.Web.Mvc.ResultExecutingContext preContext,
System.Func`1 continuation) [0x00000] in <filename unknown>:0
[System.ArgumentException]: Username cannot be empty.
at SomeRoleProvider.IsUserInRole (System.String username,
System.String
roleName) [0x00000] in <filename unknown>:0
at System.Web.Security.Roles.IsUserInRole (System.String rolename)
[0x00000] in <filename unknown>:0
at ASP.views_shared_site_master.__RenderTree
(System.Web.UI.HtmlTextWriter __output, System.Web.UI.Control
parameterContainer) [0x00000] in <filename
unknown>:0
at System.Web.UI.Control.RenderChildren (System.Web.UI.HtmlTextWriter
writer) [0x00000] in <filename unknown>:0
at System.Web.UI.Control.Render (System.Web.UI.HtmlTextWriter writer)
[0x00000] in <filename unknown>:0
at System.Web.UI.Control.RenderControl (System.Web.UI.HtmlTextWriter
writer) [0x00000] in <filename unknown>:0
at System.Web.UI.Control.RenderChildren (System.Web.UI.HtmlTextWriter
writer) [0x00000] in <filename unknown>:0
at System.Web.UI.Control.Render (System.Web.UI.HtmlTextWriter writer)
[0x00000] in <filename unknown>:0
at System.Web.UI.Page.Render (System.Web.UI.HtmlTextWriter writer)
[0x00000] in <filename unknown>:0
at System.Web.Mvc.ViewPage.Render (System.Web.UI.HtmlTextWriter
writer) [0x00000] in <filename unknown>:0
at System.Web.UI.Control.RenderControl (System.Web.UI.HtmlTextWriter
writer) [0x00000] in <filename unknown>:0
at System.Web.UI.Page.RenderPage () [0x00000] in <filename unknown>:0
at System.Web.UI.Page.InternalProcessRequest () [0x00000] in <filename
unknown>:0
at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context)
[0x00000] in <filename unknown>:0
===============
More information about the Mono-devel-list
mailing list