Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,32 @@
2009-09-07 Atsushi Enomoto <atsushi@ximian.com>
* X509CertificateClaimSetTest.cs : mark as Ignore (not working on
.NET either).
2007-11-27 Atsushi Enomoto <atsushi@ximian.com>
* X509CertificateClaimSetTest.cs : fixed DefaultValue() test to
reflect .net results.
2007-02-05 Atsushi Enomoto <atsushi@ximian.com>
* X509CertificateClaimSetTest.cs : issuer claim should not be
equivalent to that of the cert itself.
2006-10-07 Atsushi Enomoto <atsushi@ximian.com>
* ClaimSetTest.cs, X509CertificateClaimSetTest.cs : new tests.
* ClaimTest.cs : added test for System and ToString().
2006-09-07 Atsushi Enomoto <atsushi@ximian.com>
* ClaimTest.cs : new test.
2006-09-04 Atsushi Enomoto <atsushi@ximian.com>
* ClaimTypesTest.cs : updated namespace URI.
2006-08-28 Atsushi Enomoto <atsushi@ximian.com>
* ClaimTypesTest.cs : new test.

View File

@@ -0,0 +1,54 @@
//
// ClaimSetTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IdentityModel.Claims;
using System.Net.Mail;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Claims
{
[TestFixture]
public class ClaimSetTest
{
[Test]
public void SystemClaimSet ()
{
Assert.AreEqual (2, ClaimSet.System.Count, "#1");
Assert.AreEqual (ClaimSet.System, ClaimSet.System.Issuer, "#2");
Assert.IsTrue (ClaimSet.System.ContainsClaim (Claim.System), "#3");
foreach (Claim c in ClaimSet.System) {
Assert.AreEqual (ClaimTypes.System, c.ClaimType, "#4");
if (c.Right != Rights.Identity)
Assert.AreEqual (Rights.PossessProperty, c.Right, "#5");
}
}
}
}

View File

@@ -0,0 +1,118 @@
//
// ClaimTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IdentityModel.Claims;
using System.Net.Mail;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Claims
{
[TestFixture]
public class ClaimTest
{
[Test]
public void CreateClaims ()
{
Claim c;
// premises
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/right/identity", Rights.Identity, "#1");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/right/possessproperty", Rights.PossessProperty, "#2");
c = Claim.CreateDnsClaim ("123.45.6.7");
AssertClaim ("Dns", c, ClaimTypes.Dns, "123.45.6.7", Rights.PossessProperty);
Uri uri = new Uri ("http://www.mono-project.com");
c = Claim.CreateUriClaim (uri);
AssertClaim ("Uri", c, ClaimTypes.Uri, uri, Rights.PossessProperty);
MailAddress mail = new MailAddress ("rupert@ximian.com");
c = Claim.CreateMailAddressClaim (mail);
AssertClaim ("Mail", c, ClaimTypes.Email, mail, Rights.PossessProperty);
c = Claim.CreateNameClaim ("Rupert");
AssertClaim ("Name", c, ClaimTypes.Name, "Rupert", Rights.PossessProperty);
c = Claim.CreateSpnClaim ("foo");
AssertClaim ("Spn", c, ClaimTypes.Spn, "foo", Rights.PossessProperty);
c = Claim.CreateUpnClaim ("foo");
AssertClaim ("Upn", c, ClaimTypes.Upn, "foo", Rights.PossessProperty);
//SecurityIdentifier sid = new SecurityIdentifier (blah);
//c = Claim.CreateWindowsSidClaim (sid);
//AssertClaim ("Sid", c, ClaimTypes.Sid, blah, Rights.PossessProperty);
byte [] hash = new byte [] {1, 2, 3, 4, 5, 6, 7, 8, 9};
c = Claim.CreateHashClaim (hash);
AssertClaim ("Hash", c, ClaimTypes.Hash, hash, Rights.PossessProperty);
RSA rsa = RSA.Create ();
c = Claim.CreateRsaClaim (rsa);
AssertClaim ("Rsa", c, ClaimTypes.Rsa, rsa, Rights.PossessProperty);
X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.pfx", "mono");
byte [] chash = cert.GetCertHash ();
c = Claim.CreateThumbprintClaim (chash);
AssertClaim ("Thumbprint", c, ClaimTypes.Thumbprint, chash, Rights.PossessProperty);
c = Claim.CreateX500DistinguishedNameClaim (cert.SubjectName);
AssertClaim ("X500Name", c, ClaimTypes.X500DistinguishedName, cert.SubjectName, Rights.PossessProperty);
}
[Test]
public void TestToString ()
{
Assert.AreEqual (
String.Concat (Rights.PossessProperty, ": ", ClaimTypes.Name),
Claim.CreateNameClaim ("mono").ToString (),
"#1");
}
[Test]
public void SystemClaim ()
{
Assert.AreEqual (
String.Concat (Rights.Identity, ": ", ClaimTypes.System),
Claim.System.ToString (),
"#1");
Assert.AreEqual ("System", Claim.System.Resource, "#2");
}
public static void AssertClaim (string label, Claim c, string type, object resource, string right)
{
Assert.AreEqual (type, c.ClaimType, label + ".ClaimType");
if (resource != null)
Assert.AreEqual (resource, c.Resource, label + ".Resource");
Assert.AreEqual (right, c.Right, label + ".Right");
}
}
}

View File

@@ -0,0 +1,104 @@
//
// ClaimTypesTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IdentityModel.Claims;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Claims
{
[TestFixture]
public class ClaimTypesTest
{
[Test]
public void Constants ()
{
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/anonymous",
ClaimTypes.Anonymous, "#1");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authentication",
ClaimTypes.Authentication, "#2");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/authorizationdecision",
ClaimTypes.AuthorizationDecision, "#3");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/country",
ClaimTypes.Country, "#4");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth",
ClaimTypes.DateOfBirth, "#5");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/denyonlysid",
ClaimTypes.DenyOnlySid, "#6");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dns",
ClaimTypes.Dns, "#7");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress",
ClaimTypes.Email, "#8");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/gender",
ClaimTypes.Gender, "#9");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname",
ClaimTypes.GivenName, "#10");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/hash",
ClaimTypes.Hash, "#11");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/homephone",
ClaimTypes.HomePhone, "#12");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/locality",
ClaimTypes.Locality, "#13");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/mobilephone",
ClaimTypes.MobilePhone, "#14");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name",
ClaimTypes.Name, "#15");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier",
ClaimTypes.NameIdentifier, "#16");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/otherphone",
ClaimTypes.OtherPhone, "#17");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/postalcode",
ClaimTypes.PostalCode, "#18");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/privatepersonalidentifier",
ClaimTypes.PPID, "#19");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/rsa",
ClaimTypes.Rsa, "#20");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/sid",
ClaimTypes.Sid, "#21");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/spn",
ClaimTypes.Spn, "#22");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/stateorprovince",
ClaimTypes.StateOrProvince, "#23");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/streetaddress",
ClaimTypes.StreetAddress, "#24");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname",
ClaimTypes.Surname, "#25");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/system",
ClaimTypes.System, "#26");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/thumbprint",
ClaimTypes.Thumbprint, "#27");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn",
ClaimTypes.Upn, "#28");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/uri",
ClaimTypes.Uri, "#29");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/webpage",
ClaimTypes.Webpage, "#30");
Assert.AreEqual ("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/x500distinguishedname",
ClaimTypes.X500DistinguishedName, "#31");
}
}
}

View File

@@ -0,0 +1,72 @@
//
// X509CertificateClaimSetTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IdentityModel.Claims;
using System.Net.Mail;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Claims
{
[TestFixture]
public class X509CertificateClaimSetTest
{
static X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.pfx", "mono");
[Test]
[Ignore ("not up to date")] // X509Chain
public void DefaultValues ()
{
X509Chain chain = new X509Chain ();
chain.Build (cert);
Assert.IsTrue (chain.ChainElements.Count > 1, "#0");
ClaimSet cs = new X509CertificateClaimSet (cert);
ClaimSet ident = cs.Issuer;
X509CertificateClaimSet x509is = ident as X509CertificateClaimSet;
Assert.IsNotNull (x509is, "#0-2");
Assert.AreEqual (chain.ChainElements [1].Certificate, x509is.X509Certificate, "#0-3");
Assert.AreEqual (6, cs.Count, "#1");
Assert.AreEqual (6, ident.Issuer.Count, "#2");
Assert.IsFalse (cs.ContainsClaim (Claim.System), "#3");
List<string> d = new List<string> ();
foreach (Claim c in cs) {
if (c.ClaimType != ClaimTypes.Thumbprint)
Assert.AreEqual (Rights.PossessProperty, c.Right, "#4");
d.Add (c.ClaimType);
}
Assert.IsTrue (d.Contains (ClaimTypes.X500DistinguishedName), "#5");
Assert.IsTrue (d.Contains (ClaimTypes.Thumbprint), "#6");
Assert.IsTrue (d.Contains (ClaimTypes.Dns), "#7");
Assert.IsTrue (d.Contains (ClaimTypes.Rsa), "#8");
Assert.IsTrue (d.Contains (ClaimTypes.Name), "#9");
}
}
}

View File

@@ -0,0 +1,4 @@
2006-09-14 Atsushi Enomoto <atsushi@ximian.com>
* MySecurityTokenSerializer.cs : new support file.

View File

@@ -0,0 +1,99 @@
//
// MySecurityTokenSerializer.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Globalization;
using System.IO;
using System.IdentityModel.Claims;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Common
{
public class MySecurityTokenSerializer : SecurityTokenSerializer
{
protected override bool CanReadKeyIdentifierClauseCore (XmlReader reader)
{
return false;
}
protected override bool CanReadKeyIdentifierCore (XmlReader reader)
{
return false;
}
protected override bool CanReadTokenCore (XmlReader reader)
{
return false;
}
protected override SecurityKeyIdentifierClause ReadKeyIdentifierClauseCore (XmlReader reader)
{
throw new NotSupportedException ();
}
protected override SecurityKeyIdentifier ReadKeyIdentifierCore (XmlReader reader)
{
throw new NotSupportedException ();
}
protected override SecurityToken ReadTokenCore (XmlReader reader, SecurityTokenResolver resolver)
{
throw new NotSupportedException ();
}
protected override bool CanWriteKeyIdentifierClauseCore (SecurityKeyIdentifierClause clause)
{
return false;
}
protected override bool CanWriteKeyIdentifierCore (SecurityKeyIdentifier ident)
{
return false;
}
protected override bool CanWriteTokenCore (SecurityToken token)
{
return false;
}
protected override void WriteKeyIdentifierClauseCore (XmlWriter writer, SecurityKeyIdentifierClause clause)
{
throw new NotSupportedException ();
}
protected override void WriteKeyIdentifierCore (XmlWriter writer, SecurityKeyIdentifier ident)
{
throw new NotSupportedException ();
}
protected override void WriteTokenCore (XmlWriter writer, SecurityToken token)
{
throw new NotSupportedException ();
}
}
}

View File

@@ -0,0 +1,74 @@
//
// AuthorizationContextTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Claims
{
[TestFixture]
public class AuthorizationContextTest
{
class MyAuthorizationPolicy : IAuthorizationPolicy
{
string id = "uuid:" + Guid.NewGuid ();
public string Id {
get { return id; }
}
public ClaimSet Issuer {
get { return ClaimSet.System; }
}
public bool Evaluate (EvaluationContext ctx, ref object state)
{
return true;
}
}
[Test]
public void CreateDefaultAuthorizationContext ()
{
AuthorizationContext a =
AuthorizationContext.CreateDefaultAuthorizationContext (new IAuthorizationPolicy [0]);
Assert.AreEqual (DateTime.MaxValue.AddDays (-1), a.ExpirationTime, "#1-1");
Assert.AreEqual (0, a.Properties.Count, "#1-2");
Assert.AreEqual (0, a.ClaimSets.Count, "#1-3");
a = AuthorizationContext.CreateDefaultAuthorizationContext (new IAuthorizationPolicy [] { new MyAuthorizationPolicy ()});
Assert.AreEqual (DateTime.MaxValue.AddDays (-1), a.ExpirationTime, "#2-1");
Assert.AreEqual (0, a.Properties.Count, "#2-2");
Assert.AreEqual (0, a.ClaimSets.Count, "#2-3");
}
}
}

View File

@@ -0,0 +1,3 @@
2006-10-11 Atsushi Enomoto <atsushi@ximian.com>
* AuthorizationContextTest.cs : new test.

View File

@@ -0,0 +1,32 @@
2007-03-05 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenRequirementTest.cs : added TryGetProperty() tests.
2007-02-21 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenResolverTest.cs : test for ResolveToken() which cannot
resolve the token.
2006-09-27 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenResolverTest.cs : new test.
2006-09-14 Atsushi Enomoto <atsushi@ximian.com>
* TestEvaluationContext.cs,
CustomUserNameSecurityTokenAuthenticatorTest.cs,
SamlSecurityTokenAuthenticatorTest.cs,
RsaSecurityTokenAuthenticatorTest.cs,
X509SecurityTokenAuthenticatorTest.cs : new tests.
2006-08-28 Atsushi Enomoto <atsushi@ximian.com>
* X509SecurityTokenProviderTest.cs : new test.
2006-07-04 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenRequirementTest.cs : updated to match June CTP.
2006-03-23 Atsushi Enomoto <atsushi@ximian.com>
* SecurityTokenRequirementTest.cs : new file.

View File

@@ -0,0 +1,82 @@
//
// CustomUserNameSecurityTokenAuthenticatorTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Principal;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
using Authenticator = System.IdentityModel.Selectors.CustomUserNameSecurityTokenAuthenticator;
using PolicyCollection = System.Collections.ObjectModel.ReadOnlyCollection<System.IdentityModel.Policy.IAuthorizationPolicy>;
namespace MonoTests.System.IdentityModel.Selectors
{
[TestFixture]
public class CustomUserNameSecurityTokenAuthenticatorTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorCertNull ()
{
new Authenticator (null);
}
[Test]
public void Validation ()
{
Authenticator a = new Authenticator (
UserNamePasswordValidator.None);
PolicyCollection pl = a.ValidateToken (new UserNameSecurityToken ("mono", "mono"));
Assert.AreEqual (1, pl.Count, "#1");
IAuthorizationPolicy p = pl [0];
Assert.AreEqual (ClaimSet.System, p.Issuer, "#2");
TestEvaluationContext ec = new TestEvaluationContext ();
object o = null;
Assert.IsTrue (p.Evaluate (ec, ref o), "#3");
Assert.AreEqual (DateTime.MaxValue.AddDays (-1), ec.ExpirationTime, "#4");
IList<IIdentity> identities = ec.Properties ["Identities"] as IList<IIdentity>;
Assert.IsNotNull (identities, "#5");
Assert.AreEqual (1, identities.Count, "#6");
IIdentity ident = identities [0];
Assert.AreEqual (true, ident.IsAuthenticated, "#6-2");
// it's implementation details.
//Assert.AreEqual ("NoneUserNamePasswordValidator", ident.AuthenticationType, "#6-3");
Assert.AreEqual ("mono", ident.Name, "#6-4");
Assert.AreEqual (1, ec.ClaimSets.Count, "#7");
Assert.IsTrue (p.Evaluate (ec, ref o), "#8");
identities = ec.Properties ["Identities"] as IList<IIdentity>;
Assert.AreEqual (2, identities.Count, "#9");
Assert.AreEqual (2, ec.ClaimSets.Count, "#10");
}
}
}

View File

@@ -0,0 +1,68 @@
//
// RsaSecurityTokenAuthenticatorTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
using Authenticator = System.IdentityModel.Selectors.RsaSecurityTokenAuthenticator;
using PolicyCollection = System.Collections.ObjectModel.ReadOnlyCollection<System.IdentityModel.Policy.IAuthorizationPolicy>;
namespace MonoTests.System.IdentityModel.Selectors
{
[TestFixture]
public class RsaSecurityTokenAuthenticatorTest
{
[Test]
public void Validation ()
{
RSA rsa = (RSA) new X509Certificate2 ("Test/Resources/test.cer").PublicKey.Key;
Authenticator a = new Authenticator ();
PolicyCollection pl = a.ValidateToken (new RsaSecurityToken (rsa));
Assert.AreEqual (1, pl.Count, "#1");
IAuthorizationPolicy p = pl [0];
Assert.AreEqual (ClaimSet.System, p.Issuer, "#2");
TestEvaluationContext ec = new TestEvaluationContext ();
object o = null;
Assert.IsTrue (p.Evaluate (ec, ref o), "#3");
// mhm, should this really be converted to UTC?
Assert.AreEqual (DateTime.MaxValue.AddDays (-1), ec.ExpirationTime, "#4");
Assert.AreEqual (0, ec.Properties.Count, "#5");
Assert.AreEqual (1, ec.ClaimSets.Count, "#6");
Assert.IsTrue (p.Evaluate (ec, ref o), "#7");
Assert.AreEqual (2, ec.ClaimSets.Count, "#8");
}
}
}

View File

@@ -0,0 +1,120 @@
//
// SamlSecurityTokenAuthenticatorTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Principal;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using NUnit.Framework;
using MonoTests.System.IdentityModel.Common;
using Authenticator = System.IdentityModel.Selectors.SamlSecurityTokenAuthenticator;
using PolicyCollection = System.Collections.ObjectModel.ReadOnlyCollection<System.IdentityModel.Policy.IAuthorizationPolicy>;
namespace MonoTests.System.IdentityModel.Selectors
{
[TestFixture]
public class SamlSecurityTokenAuthenticatorTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorCertNull ()
{
new Authenticator (null);
}
[Test]
[Ignore ("not done yet")]
public void Validation ()
{
Authenticator a = new Authenticator (
new SecurityTokenAuthenticator [] {
new CustomUserNameSecurityTokenAuthenticator (UserNamePasswordValidator.None),
new X509SecurityTokenAuthenticator (X509CertificateValidator.None),
});
PolicyCollection pl = a.ValidateToken (GetSamlToken ());
Assert.AreEqual (1, pl.Count, "#1");
IAuthorizationPolicy p = pl [0];
Assert.AreEqual (ClaimSet.System, p.Issuer, "#2");
TestEvaluationContext ec = new TestEvaluationContext ();
object o = null;
Assert.IsTrue (p.Evaluate (ec, ref o), "#3");
Assert.AreEqual (DateTime.MaxValue.AddDays (-1), ec.ExpirationTime, "#4");
IList<IIdentity> identities = ec.Properties ["Identities"] as IList<IIdentity>;
Assert.IsNotNull (identities, "#5");
Assert.AreEqual (1, identities.Count, "#6");
IIdentity ident = identities [0];
Assert.AreEqual (true, ident.IsAuthenticated, "#6-2");
// it's implementation details.
//Assert.AreEqual ("NoneUserNamePasswordValidator", ident.AuthenticationType, "#6-3");
Assert.AreEqual ("mono", ident.Name, "#6-4");
Assert.AreEqual (1, ec.ClaimSets.Count, "#7");
Assert.IsTrue (p.Evaluate (ec, ref o), "#8");
identities = ec.Properties ["Identities"] as IList<IIdentity>;
Assert.AreEqual (2, identities.Count, "#9");
Assert.AreEqual (2, ec.ClaimSets.Count, "#10");
}
SamlSecurityToken GetSamlToken ()
{
SamlAssertion a = new SamlAssertion ();
SamlSubject subject = new SamlSubject (
SamlConstants.UserNameNamespace,
"urn:myqualifier",
"myname");
SamlAttribute attr = new SamlAttribute (Claim.CreateNameClaim ("myname"));
SamlAttributeStatement statement =
new SamlAttributeStatement (subject, new SamlAttribute [] {attr});
a.Statements.Add (statement);
a.Issuer = "my_hero";
X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.pfx", "mono");
X509AsymmetricSecurityKey key =
new X509AsymmetricSecurityKey (cert);
a.SigningCredentials =
new SigningCredentials (key,
SecurityAlgorithms.HmacSha1Signature,
SecurityAlgorithms.Sha256Digest);
XmlDocument doc = new XmlDocument ();
XmlWriter w = doc.CreateNavigator ().AppendChild ();
using (XmlDictionaryWriter dw = XmlDictionaryWriter.CreateDictionaryWriter (w)) {
a.WriteXml (dw, new SamlSerializer (), new MySecurityTokenSerializer ());
}
Console.Error.WriteLine (doc.OuterXml);
return new SamlSecurityToken (a);
}
}
}

View File

@@ -0,0 +1,97 @@
//
// SecurityTokenRequirementTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Selectors
{
[TestFixture]
public class SecurityTokenRequirementTest
{
[Test]
public void Constants ()
{
Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/identitymodel/securitytokenrequirement/KeySize",
SecurityTokenRequirement.KeySizeProperty, "#1");
Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/identitymodel/securitytokenrequirement/KeyType",
SecurityTokenRequirement.KeyTypeProperty, "#2");
Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/identitymodel/securitytokenrequirement/KeyUsage",
SecurityTokenRequirement.KeyUsageProperty, "#3");
Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/identitymodel/securitytokenrequirement/RequireCryptographicToken",
SecurityTokenRequirement.RequireCryptographicTokenProperty, "#4");
Assert.AreEqual ("http://schemas.microsoft.com/ws/2006/05/identitymodel/securitytokenrequirement/TokenType",
SecurityTokenRequirement.TokenTypeProperty, "#5");
}
[Test]
public void DefaultValues ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
Assert.AreEqual (0, r.KeySize, "#1");
Assert.AreEqual (SecurityKeyType.SymmetricKey, r.KeyType, "#2");
Assert.AreEqual (SecurityKeyUsage.Signature, r.KeyUsage, "#3");
Assert.IsNull (r.TokenType, "#4");
Assert.AreEqual (false, r.RequireCryptographicToken, "#5");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TryGetPropertyTypeMismatch ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
r.Properties ["urn:foo"] = 1;
string s;
r.TryGetProperty<string> ("urn:foo", out s);
}
[Test]
public void TryGetPropertyTypeBaseMatch ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
r.Properties ["urn:foo"] = 1;
object o;
r.TryGetProperty<object> ("urn:foo", out o);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void TryGetPropertyTypeConvertible ()
{
SecurityTokenRequirement r =
new SecurityTokenRequirement ();
r.Properties ["urn:foo"] = 1;
double d;
r.TryGetProperty<double> ("urn:foo", out d);
}
}
}

View File

@@ -0,0 +1,81 @@
//
// SecurityTokenResolverTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.ObjectModel;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using NUnit.Framework;
namespace MonoTests.System.IdentityModel.Selectors
{
[TestFixture]
public class SecurityTokenResolverTest
{
SecurityTokenResolver GetResolver (bool canMatchLocalId, params SecurityToken [] tokens)
{
return SecurityTokenResolver.CreateDefaultSecurityTokenResolver (new ReadOnlyCollection<SecurityToken> (tokens), canMatchLocalId);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TryResolveTokenNullClause ()
{
SecurityTokenResolver r = GetResolver (true, new SecurityToken [0]);
SecurityToken token;
r.TryResolveToken ((SecurityKeyIdentifierClause) null, out token);
}
[Test]
public void TryResolveToken ()
{
SecurityTokenResolver r = GetResolver (true, new SecurityToken [0]);
SecurityToken token;
Assert.IsFalse (r.TryResolveToken (new LocalIdKeyIdentifierClause ("foo"), out token));
UserNameSecurityToken userName =
new UserNameSecurityToken ("mono", "", "urn:foo");
LocalIdKeyIdentifierClause kic =
new LocalIdKeyIdentifierClause ("urn:foo");
r = GetResolver (true, new SecurityToken [] {userName});
Assert.IsTrue (r.TryResolveToken (kic, out token));
r = GetResolver (false, new SecurityToken [] {userName});
Assert.IsFalse (r.TryResolveToken (kic, out token));
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ResolveTokenNonExistent ()
{
SecurityTokenResolver r = GetResolver (true, new SecurityToken [0]);
SecurityToken token;
Assert.IsNull (r.ResolveToken (new LocalIdKeyIdentifierClause ("urn:foo")));
}
}
}

View File

@@ -0,0 +1,84 @@
//
// TestEvaluationContext.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 Novell, Inc. http://www.novell.com
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IdentityModel.Claims;
using System.IdentityModel.Policy;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Cryptography.X509Certificates;
using NUnit.Framework;
using Authenticator = System.IdentityModel.Selectors.CustomUserNameSecurityTokenAuthenticator;
using PolicyCollection = System.Collections.ObjectModel.ReadOnlyCollection<System.IdentityModel.Policy.IAuthorizationPolicy>;
namespace MonoTests.System.IdentityModel.Selectors
{
class TestEvaluationContext : EvaluationContext
{
Collection<ClaimSet> claim_sets =
new Collection<ClaimSet> ();
ReadOnlyCollection<ClaimSet> readonly_claim_sets;
Dictionary<string,object> properties =
new Dictionary<string,object> ();
int generation;
DateTime expiration;
public override ReadOnlyCollection<ClaimSet> ClaimSets {
get {
if (readonly_claim_sets == null)
readonly_claim_sets = new ReadOnlyCollection<ClaimSet> (claim_sets);
return readonly_claim_sets;
}
}
public DateTime ExpirationTime {
get { return expiration; }
}
public override int Generation {
get { return generation; }
}
public override IDictionary<string,object> Properties {
get { return properties; }
}
public override void AddClaimSet (IAuthorizationPolicy policy, ClaimSet claimSet)
{
claim_sets.Add (claimSet);
}
public override void RecordExpirationTime (DateTime expirationTime)
{
expiration = expirationTime;
}
}
}

Some files were not shown because too many files have changed in this diff Show More