Imported Upstream version 5.18.0.142

Former-commit-id: 7467d4b717762eeaf652d77f1486dd11ffb1ff1f
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-10-09 08:20:59 +00:00
parent e52655b4dc
commit 0abdbe5a7d
1547 changed files with 93792 additions and 47893 deletions

View File

@@ -1,280 +0,0 @@
//
// SslSecurityTokenParametersTest.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.
//
#if !MOBILE && !XAMMAC_4_5
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Security;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using System.Xml;
using NUnit.Framework;
using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
namespace MonoTests.System.ServiceModel.Security.Tokens
{
[TestFixture]
public class SslSecurityTokenParametersTest
{
class MyParameters : SslSecurityTokenParameters
{
public bool HasAsymmetricKeyEx {
get { return HasAsymmetricKey; }
}
public bool SupportsClientAuthenticationEx {
get { return SupportsClientAuthentication; }
}
public bool SupportsClientWindowsIdentityEx {
get { return SupportsClientWindowsIdentity; }
}
public bool SupportsServerAuthenticationEx {
get { return SupportsServerAuthentication; }
}
public SecurityKeyIdentifierClause CallCreateKeyIdentifierClause (
SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
{
return CreateKeyIdentifierClause (token, referenceStyle);
}
public void InitRequirement (SecurityTokenRequirement requirement)
{
InitializeSecurityTokenRequirement (requirement);
}
}
[Test]
public void DefaultValues ()
{
MyParameters tp = new MyParameters ();
Assert.AreEqual (SecurityTokenInclusionMode.AlwaysToRecipient, tp.InclusionMode, "#1");
Assert.AreEqual (SecurityTokenReferenceStyle.Internal, tp.ReferenceStyle, "#2");
Assert.AreEqual (true, tp.RequireDerivedKeys, "#3");
Assert.AreEqual (false, tp.HasAsymmetricKeyEx, "#4");
Assert.AreEqual (false, tp.SupportsClientAuthenticationEx, "#5");
Assert.AreEqual (false, tp.SupportsClientWindowsIdentityEx, "#6");
Assert.AreEqual (true, tp.SupportsServerAuthenticationEx, "#7");
Assert.AreEqual (false, tp.RequireCancellation, "#2-1");
Assert.AreEqual (false, tp.RequireClientCertificate, "#2-2");
}
[Test]
public void InitializeSecurityTokenParameters ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
Assert.AreEqual (ServiceModelSecurityTokenTypes.AnonymousSslnego, r.TokenType, "#1");
Assert.AreEqual (false, r.Properties [ReqType.SupportSecurityContextCancellationProperty], "#2");
SslSecurityTokenParameters dummy;
Assert.IsTrue (r.TryGetProperty<SslSecurityTokenParameters> (ReqType.IssuedSecurityTokenParametersProperty, out dummy), "#3");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoTargetAddress ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoSecurityBindingElement ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoIssuerBindingContext ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoMessageSecurityVersion ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (),
new BindingParameterCollection ());
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
public void CreateProvider ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (),
new BindingParameterCollection ());
r.MessageSecurityVersion = MessageSecurityVersion.Default.SecurityTokenVersion;
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
[Ignore ("This ends up to fail to connect. Anyways it's too implementation dependent.")]
public void CreateProviderGetToken ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (new HttpTransportBindingElement ()),
new BindingParameterCollection ());
r.MessageSecurityVersion = MessageSecurityVersion.Default.SecurityTokenVersion;
// This is required at GetToken().
r.SecurityAlgorithmSuite = SecurityAlgorithmSuite.Default;
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
// TLS negotiation token provider is created.
SecurityTokenProvider p =
manager.CreateSecurityTokenProvider (r);
((ICommunicationObject) p).Open ();
p.GetToken (TimeSpan.FromSeconds (5));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void CreateRecipientProviderAnonymous ()
{
CreateRecipientProviderCore (false);
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void CreateRecipientProviderMutual ()
{
CreateRecipientProviderCore (true);
}
void CreateRecipientProviderCore (bool mutual)
{
MyParameters tp = new MyParameters ();
tp.RequireClientCertificate = true;
RecipientServiceModelSecurityTokenRequirement r =
new RecipientServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.ListenUri = new Uri ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (),
new BindingParameterCollection ());
r.MessageSecurityVersion = MessageSecurityVersion.Default.SecurityTokenVersion;
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
public void CreateKeyIdentifierClauseSCT ()
{
MyParameters tp = new MyParameters ();
SecurityContextSecurityToken sct =
new SecurityContextSecurityToken (new UniqueId (), new byte [32], DateTime.MinValue, DateTime.MaxValue);
SecurityKeyIdentifierClause kic =
tp.CallCreateKeyIdentifierClause (sct, SecurityTokenReferenceStyle.Internal);
Assert.IsTrue (kic is LocalIdKeyIdentifierClause, "#1");
SecurityContextKeyIdentifierClause scic = tp.CallCreateKeyIdentifierClause (sct, SecurityTokenReferenceStyle.External)
as SecurityContextKeyIdentifierClause;
Assert.IsNotNull (scic, "#2");
Assert.IsNull (scic.Generation, "#3");
}
}
}
#endif

View File

@@ -1,259 +0,0 @@
//
// SspiSecurityTokenParametersTest.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.
//
#if !MOBILE && !XAMMAC_4_5
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.Net.Security;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using NUnit.Framework;
using ReqType = System.ServiceModel.Security.Tokens.ServiceModelSecurityTokenRequirement;
namespace MonoTests.System.ServiceModel.Security.Tokens
{
[TestFixture]
public class SspiSecurityTokenParametersTest
{
class MyParameters : SspiSecurityTokenParameters
{
public bool HasAsymmetricKeyEx {
get { return HasAsymmetricKey; }
}
public bool SupportsClientAuthenticationEx {
get { return SupportsClientAuthentication; }
}
public bool SupportsClientWindowsIdentityEx {
get { return SupportsClientWindowsIdentity; }
}
public bool SupportsServerAuthenticationEx {
get { return SupportsServerAuthentication; }
}
public SecurityKeyIdentifierClause CallCreateKeyIdentifierClause (
SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
{
return CreateKeyIdentifierClause (token, referenceStyle);
}
public void InitRequirement (SecurityTokenRequirement requirement)
{
InitializeSecurityTokenRequirement (requirement);
}
}
[Test]
public void DefaultValues ()
{
MyParameters tp = new MyParameters ();
Assert.AreEqual (SecurityTokenInclusionMode.AlwaysToRecipient, tp.InclusionMode, "#1");
Assert.AreEqual (SecurityTokenReferenceStyle.Internal, tp.ReferenceStyle, "#2");
Assert.AreEqual (true, tp.RequireDerivedKeys, "#3");
Assert.AreEqual (false, tp.HasAsymmetricKeyEx, "#4");
Assert.AreEqual (true, tp.SupportsClientAuthenticationEx, "#5");
Assert.AreEqual (true, tp.SupportsClientWindowsIdentityEx, "#6");
Assert.AreEqual (true, tp.SupportsServerAuthenticationEx, "#7");
Assert.AreEqual (false, tp.RequireCancellation, "#2-1");
}
[Test]
public void InitializeSecurityTokenParameters ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
Assert.AreEqual (ServiceModelSecurityTokenTypes.Spnego, r.TokenType, "#1");
Assert.AreEqual (false, r.Properties [ReqType.SupportSecurityContextCancellationProperty], "#2");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoTargetAddress ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoSecurityBindingElement ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
manager.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoIssuerBindingContext ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
//SecurityTokenProvider p =
manager.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderNoMessageSecurityVersion ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (),
new BindingParameterCollection ());
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
//SecurityTokenProvider p =
manager.CreateSecurityTokenProvider (r);
}
[Test]
public void CreateProvider ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (),
new BindingParameterCollection ());
r.MessageSecurityVersion = MessageSecurityVersion.Default.SecurityTokenVersion;
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
//SecurityTokenProvider p =
manager.CreateSecurityTokenProvider (r);
}
void CreateProviderOpenGetToken (bool getToken)
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (new HttpTransportBindingElement ()),
new BindingParameterCollection ());
r.MessageSecurityVersion = MessageSecurityVersion.Default.SecurityTokenVersion;
// This is required at GetToken().
r.SecurityAlgorithmSuite = SecurityAlgorithmSuite.Default;
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
// TLS negotiation token provider is created.
SecurityTokenProvider p =
manager.CreateSecurityTokenProvider (r);
((ICommunicationObject) p).Open ();
if (!getToken)
return;
p.GetToken (TimeSpan.FromSeconds (5));
}
[Test]
public void CreateProviderOpen ()
{
CreateProviderOpenGetToken (false);
}
[Test]
[Ignore ("This ends up to fail to connect. Anyways it's too implementation dependent.")]
public void CreateProviderGetToken ()
{
CreateProviderOpenGetToken (true);
}
[Test]
public void CreateAuthenticator ()
{
MyParameters tp = new MyParameters ();
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
tp.InitRequirement (r);
ClientCredentials cred = new ClientCredentials ();
ClientCredentialsSecurityTokenManager manager =
new ClientCredentialsSecurityTokenManager (cred);
SecurityTokenResolver resolver;
// SecurityTokenAuthenticator authenticator =
manager.CreateSecurityTokenAuthenticator (r, out resolver);
}
}
}
#endif

View File

@@ -290,87 +290,6 @@ namespace MonoTests.System.ServiceModel.Security
Assert.IsNotNull (p, "#1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void CreateProviderAnonSslError ()
{
RecipientServiceModelSecurityTokenRequirement r =
new RecipientServiceModelSecurityTokenRequirement ();
r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
r.ListenUri = new Uri ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (), new BindingParameterCollection ());
r.MessageSecurityVersion =
MessageSecurityVersion.Default.SecurityTokenVersion;
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
}
[Test]
[Ignore ("incomplete")]
[Category ("NotWorking")]
public void CreateProviderAnonSsl ()
{
RecipientServiceModelSecurityTokenRequirement r =
new RecipientServiceModelSecurityTokenRequirement ();
new MySslSecurityTokenParameters ().InitRequirement (r);
Assert.IsFalse (r.Properties.ContainsKey (ReqType.ChannelParametersCollectionProperty), "#1");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.EndpointFilterTableProperty), "#2");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.HttpAuthenticationSchemeProperty), "#3");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.IsOutOfBandTokenProperty), "#4");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.IssuerAddressProperty), "#5");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.MessageDirectionProperty), "#6");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.MessageSecurityVersionProperty), "#7");
//Assert.IsTrue (r.Properties.ContainsKey (SecurityTokenRequirement.PeerAuthenticationMode), "#8");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.SecurityAlgorithmSuiteProperty), "#9");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.SecurityBindingElementProperty), "#10");
Assert.IsFalse (r.Properties.ContainsKey (ReqType.SupportingTokenAttachmentModeProperty), "#11");
Assert.AreEqual (null, r.TransportScheme, "#12");
r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
r.ListenUri = new Uri ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (), new BindingParameterCollection ());
r.MessageSecurityVersion =
MessageSecurityVersion.Default.SecurityTokenVersion;
r.Properties [ReqType.SecurityAlgorithmSuiteProperty] =
SecurityAlgorithmSuite.Default;
r.TransportScheme = "https";
r.Properties [ReqType.ChannelParametersCollectionProperty] = new ChannelParameterCollection ();
r.Properties [ReqType.EndpointFilterTableProperty] = null;
r.Properties [ReqType.HttpAuthenticationSchemeProperty] = AuthenticationSchemes.Anonymous;
r.Properties [ReqType.IsOutOfBandTokenProperty] = true;
r.Properties [ReqType.IssuerAddressProperty] = new EndpointAddress ("http://localhost:9090");
// r.Properties [ReqType.MessageDirectionProperty] = MessageDirection.Input;
r.Properties [ReqType.SecurityBindingElementProperty] = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.SupportingTokenAttachmentModeProperty] = SecurityTokenAttachmentMode.Signed;
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
}
RecipientServiceModelSecurityTokenRequirement CreateAnonSslRequirement ()
{
RecipientServiceModelSecurityTokenRequirement r =
new RecipientServiceModelSecurityTokenRequirement ();
MySslSecurityTokenParameters p = new MySslSecurityTokenParameters ();
p.InitRequirement (r);
r.SecurityBindingElement = new SymmetricSecurityBindingElement (new X509SecurityTokenParameters ());
r.Properties [ReqType.IssuedSecurityTokenParametersProperty] = p.Clone ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (new HttpTransportBindingElement ()), new BindingParameterCollection ());
r.Properties [ReqType.MessageSecurityVersionProperty] =
MessageSecurityVersion.Default.SecurityTokenVersion;
return r;
}
RecipientServiceModelSecurityTokenRequirement CreateSecureConvRequirement ()
{
RecipientServiceModelSecurityTokenRequirement r =
@@ -396,107 +315,6 @@ namespace MonoTests.System.ServiceModel.Security
return r;
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateAuthenticatorAnonSslNoSecurityBindingElement ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
r.SecurityBindingElement = null;
SecurityTokenResolver resolver;
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateAuthenticatorAnonSslNoIssuedSecurityTokenParameters ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
r.Properties.Remove (ReqType.IssuedSecurityTokenParametersProperty);
SecurityTokenResolver resolver;
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateAuthenticatorAnonSslNoIssuerBindingContext ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
r.Properties.Remove (ReqType.IssuerBindingContextProperty);
SecurityTokenResolver resolver;
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
// The type of exception should not matter though.
[ExpectedException (typeof (NotSupportedException))]
[Category ("NotWorking")]
public void CreateAuthenticatorAnonSslNullMessageSecurityVersion ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
r.MessageSecurityVersion = null;
SecurityTokenResolver resolver;
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateAuthenticatorAnonSslNoMessageSecurityVersion ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
r.Properties.Remove (ReqType.MessageSecurityVersionProperty);
SecurityTokenResolver resolver;
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")]
public void CreateAuthenticatorAnonSslNoServiceCertificate ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
SecurityTokenResolver resolver;
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateAuthenticatorAnonSslCertPublicOnly ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
SecurityTokenResolver resolver;
def_c.ServiceCredentials.ServiceCertificate.Certificate =
new X509Certificate2 ("Test/Resources/test.cer");
def_c.CreateSecurityTokenAuthenticator (r, out resolver);
}
[Test]
[Category ("NotWorking")]
public void CreateAuthenticatorAnonSsl ()
{
RecipientServiceModelSecurityTokenRequirement r =
CreateAnonSslRequirement ();
SecurityTokenResolver resolver;
X509Certificate2 cert = new X509Certificate2 ("Test/Resources/test.pfx", "mono");
def_c.ServiceCredentials.ServiceCertificate.Certificate = cert;
SecurityTokenAuthenticator a = def_c.CreateSecurityTokenAuthenticator (r, out resolver);
// non-standard authenticator type.
Assert.IsNotNull (resolver, "#1");
Assert.IsTrue (a is IIssuanceSecurityTokenAuthenticator, "#2");
try {
a.ValidateToken (new X509SecurityToken (cert));
Assert.Fail ("It cannot validate raw X509SecurityToken");
} catch (SecurityTokenValidationException) {
}
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void CreateProviderSecureConv ()

View File

@@ -229,204 +229,12 @@ namespace MonoTests.System.ServiceModel
Assert.IsNotNull (p, "#1");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderAnonSslNoTargetAddress ()
{
SecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
// r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
new MySslSecurityTokenParameters ().InitRequirement (r);
def_c.CreateSecurityTokenProvider (r);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderAnonSslNoBindingElement ()
{
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderAnonSslNoIssuerBindingContext ()
{
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
// r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
new MySslSecurityTokenParameters ().InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderAnonSslNoMessageSecurityVersion ()
{
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
// r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
new MySslSecurityTokenParameters ().InitRequirement (r);
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
r.SecurityBindingElement = new SymmetricSecurityBindingElement ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (new CustomBinding (), new BindingParameterCollection ());
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
}
EndpointAddress CreateEndpointAddress (string s, bool publicOnly)
{
return new EndpointAddress (new Uri (s),
new X509CertificateEndpointIdentity (publicOnly ? certpub : cert));
}
InitiatorServiceModelSecurityTokenRequirement GetAnonSslProviderRequirement (bool useTransport)
{
return GetSslProviderRequirement (useTransport, false);
}
InitiatorServiceModelSecurityTokenRequirement GetMutualSslProviderRequirement (bool useTransport)
{
return GetSslProviderRequirement (useTransport, true);
}
InitiatorServiceModelSecurityTokenRequirement GetSslProviderRequirement (bool useTransport, bool mutual)
{
InitiatorServiceModelSecurityTokenRequirement r =
new InitiatorServiceModelSecurityTokenRequirement ();
new MySslSecurityTokenParameters (mutual).InitRequirement (r);
// r.TokenType = ServiceModelSecurityTokenTypes.AnonymousSslnego;
r.TargetAddress = new EndpointAddress ("http://localhost:8080");
// r.TargetAddress = CreateEndpointAddress ("http://localhost:8080", true);
r.SecurityBindingElement = SecurityBindingElement.CreateUserNameForSslBindingElement ();
CustomBinding binding =
useTransport ?
new CustomBinding (new HandlerTransportBindingElement (null)) :
new CustomBinding ();
r.Properties [ReqType.IssuerBindingContextProperty] =
new BindingContext (binding, new BindingParameterCollection ());
r.MessageSecurityVersion =
MessageSecurityVersion.Default.SecurityTokenVersion;
r.SecurityAlgorithmSuite =
SecurityAlgorithmSuite.Default;
Assert.IsFalse (new MyManager (new MyClientCredentials ()).IsIssued (r), "premise");
return r;
}
[Test]
public void CreateProviderAnonSsl ()
{
CreateProviderAnonSsl (false);
CreateProviderAnonSsl (true);
}
public void CreateProviderAnonSsl (bool useTransport)
{
InitiatorServiceModelSecurityTokenRequirement r =
GetAnonSslProviderRequirement (useTransport);
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
ICommunicationObject comm = p as ICommunicationObject;
Assert.IsNotNull (comm, "#2");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
[Category ("NotWorking")]
public void GetAnonSslProviderSecurityTokenNoTransport ()
{
InitiatorServiceModelSecurityTokenRequirement r =
GetAnonSslProviderRequirement (false);
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
ICommunicationObject comm = p as ICommunicationObject;
Assert.IsNotNull (comm, "#2");
comm.Open ();
try {
p.GetToken (TimeSpan.FromSeconds (5));
} finally {
comm.Close ();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void GetAnonSslProviderSecurityTokenNoAlgorithmSuite ()
{
InitiatorServiceModelSecurityTokenRequirement r =
GetAnonSslProviderRequirement (true);
r.Properties.Remove (ReqType.SecurityAlgorithmSuiteProperty);
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
ICommunicationObject comm = p as ICommunicationObject;
Assert.IsNotNull (comm, "#2");
comm.Open ();
try {
p.GetToken (TimeSpan.FromSeconds (5));
} finally {
comm.Close ();
}
}
[Test]
[Ignore ("it somehow causes NRE - smells .NET bug.")]
public void GetAnonSslProviderSecurityToken ()
{
InitiatorServiceModelSecurityTokenRequirement r =
GetAnonSslProviderRequirement (true);
// What causes NRE!?
def_c.ClientCredentials.ClientCertificate.Certificate = certpub;
r.Properties [ReqType.IssuedSecurityTokenParametersProperty] =
new X509SecurityTokenParameters ();
r.TargetAddress = CreateEndpointAddress ("http://localhost:8080", true);
r.IssuerAddress = CreateEndpointAddress ("http://localhost:8080", true);
r.IssuerBinding = new CustomBinding (new HandlerTransportBindingElement (null));
def_c.ClientCredentials.ServiceCertificate.DefaultCertificate = certpub;
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
ICommunicationObject comm = p as ICommunicationObject;
Assert.IsNotNull (comm, "#2");
comm.Open ();
try {
p.GetToken (TimeSpan.FromSeconds (5));
} finally {
comm.Close ();
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void CreateProviderMutualSslWithoutClientCert ()
{
InitiatorServiceModelSecurityTokenRequirement r =
GetMutualSslProviderRequirement (true);
SecurityTokenProvider p =
def_c.CreateSecurityTokenProvider (r);
Assert.IsNotNull (p, "#1");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CreateProviderSecureConvNoTargetAddress ()