Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 7766 [details]
Unit tests and NUnit output
While trying to use the ClaimsIdentity and ClaimsPrincipal in my project using Mono 3.6.0 I encountered a lot of problems in the constructor behaviour for both ClaimsIdentity and ClaimsPrincipal. This prevents me from using the authn and authz parts of the Microsoft.Owin/ASP.NET WebAPI stack.
These errors can be categorized as:
- constructor missing, but is available on .Net 4.5 (thus throw a missing method exception, found this one while creating unit tests on windows, are running the resulting assembly on mono):
- internal errors (like NullRef exception, ArgumentNullException)
- functional erros
- specified AuthenticationType override is not used (i.e. taken from base identity instead of using the specified override)
- ClaimsPrincipal ctor(IIdentity) does not use the identity
- values not set as specified in the documentation and/or as .Net 4.5 does
As work has been done in mono-master in this area I've also tested against mono-master (93e590439ca940b89b9871a8392a5248838c806c), which at least fixes the missing method exceptions, but still isn't right.
I've attached my unit tests for ClaimsPrincipal and ClaimsIdentity, see ClaimsIdentityTest.cs and ClaimsPrincipalTest.cs (which all succeed on .Net 4.5).
The mono output of the unittests is attached as corlib_claims_mono-3.6.0.txt and corlib_claims_mono-master_20140822.txt
How to reproduce:
- build the unittests on Microsoft.Net (building on mono would fail due to missing methods and/or due to the fact that GenericIdentity/GenericPrincipal do not derive from ClaimsIdentity/ClaimsPrincipal on Mono)
csc /r:nunit.framework.dll /define:NET_4_5 /debug /o- /out:corlib-tests-claims-constructor.dll /target:library ClaimsIdentityTest.cs ClaimsPrincipalTest.cs
- run the unittests using Mono.
mono nunit-console.exe -nologo -framework=4.5 corlib-tests.dll -labels
- The constructors for mono 3.6.x and newer do not throw exceptions
- The constructors for mono 3.6.x and newer behave like .Net 4.5
- GenericIdentity and GenericPrincipal derive from ClaimsIdentity/Principal (on the net_4_5 profile)
Fixed in master.
Thanks for the contribution.
Thanks, that was amazingly quick.
Two minor things looking at the commit (don't know if this is the right place to mention it):
1. GenericPrincipal does not inherit from ClaimsPrincipal, but it does in .net 4.5 (not a big deal for me, but I thought I'd mention it for completeness)
2. ClaimsIdentity.HasClaim(type,value) now does a OrdinalCaseInsensitive match on both type and value. Reading MSDN (and creating a small test) I'd have thought it should be OrdinalCaseInsensitive on Type and Ordinal on Value.
public void HasClaim_typeValue_Works()
var id = new ClaimsIdentity(
new Claim ("claim_type", "claim_value"),
new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"),
new Claim ("claim_role_type", "claim_role_value"),
Assert.IsTrue(id.HasClaim("claim_type", "claim_value"), "#1");
Assert.IsTrue(id.HasClaim("cLaIm_TyPe", "claim_value"), "#2");
Assert.IsFalse(id.HasClaim("claim_type", "cLaIm_VaLuE"), "#3");
Assert.IsFalse(id.HasClaim("Xclaim_type", "claim_value"), "#4");
Assert.IsFalse(id.HasClaim("claim_type", "Xclaim_value"), "#5");
Fixed in master as well.