From 0567929e7c7f4a299925f16a26d43ad5f8c60dc1 Mon Sep 17 00:00:00 2001 From: Keegan Caruso Date: Tue, 23 Jun 2020 14:33:04 -0700 Subject: [PATCH] Fix usage of IDX13300 and IDX13107 (#1458) * Fix usage of IDX13300 and IDX13107 --- .../Saml2/Saml2Action.cs | 2 +- .../Saml2/Saml2Attribute.cs | 2 +- .../Saml2/Saml2AuthenticationContext.cs | 15 ++- .../Saml2AuthorizationDecisionStatement.cs | 2 +- .../Saml2/Saml2NameIdentifier.cs | 2 +- .../Saml2/Saml2SecurityTokenHandler.cs | 2 +- .../Saml2/Saml2Serializer.cs | 7 +- .../Saml2/Saml2SubjectConfirmation.cs | 4 +- .../Saml2/Saml2SubjectConfirmationData.cs | 2 +- .../Saml2ActionTests.cs | 60 +++++++++ .../Saml2AttributeTests.cs | 62 +++++++++ .../Saml2AuthenticationContextTests.cs | 126 ++++++++++++++++++ ...aml2AuthorizationDecisionStatementTests.cs | 57 ++++++++ .../Saml2NameIdentifierTests.cs | 56 ++++++++ .../Saml2SubjectConfirmationDataTests.cs | 59 ++++++++ .../Saml2SubjectConfirmationTests.cs | 56 ++++++++ .../EnvelopedSignatureWriterTests.cs | 2 +- 17 files changed, 498 insertions(+), 18 deletions(-) create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2ActionTests.cs create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AttributeTests.cs create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthenticationContextTests.cs create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthorizationDecisionStatementTests.cs create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2NameIdentifierTests.cs create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationDataTests.cs create mode 100644 test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationTests.cs diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Action.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Action.cs index afa9e937ab..f7b0f688db 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Action.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Action.cs @@ -81,7 +81,7 @@ public Uri Namespace throw LogArgumentNullException(nameof(value)); if (!value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, value), nameof(value))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(Namespace), value), nameof(value))); _namespace = value; } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Attribute.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Attribute.cs index ff41f2d64f..5a078e88cc 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Attribute.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Attribute.cs @@ -108,7 +108,7 @@ public Uri NameFormat { get => _nameFormat; set => _nameFormat = (value != null && !value.IsAbsoluteUri) - ? throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, value), nameof(value))) + ? throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(NameFormat), value), nameof(value))) : value; } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthenticationContext.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthenticationContext.cs index 87ebb42887..b021de511c 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthenticationContext.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthenticationContext.cs @@ -53,7 +53,6 @@ public class Saml2AuthenticationContext /// Creates an instance of Saml2AuthenticationContext. /// public Saml2AuthenticationContext() - : this(null, null) { } @@ -62,8 +61,8 @@ public Saml2AuthenticationContext() /// /// The class reference of the authentication context. public Saml2AuthenticationContext(Uri classReference) - : this(classReference, null) { + ClassReference = classReference; } /// @@ -75,7 +74,6 @@ public Saml2AuthenticationContext(Uri classReference, Uri declarationReference) { ClassReference = classReference; DeclarationReference = declarationReference; - AuthenticatingAuthorities = new List(); } /// @@ -87,7 +85,7 @@ public Saml2AuthenticationContext(Uri classReference, Uri declarationReference) public ICollection AuthenticatingAuthorities { get; - } + } = new List(); /// /// Gets or sets a URI reference identifying an authentication context class that @@ -105,7 +103,7 @@ public Uri ClassReference throw LogArgumentNullException(nameof(value)); if (!value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(value), value))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(ClassReference), value))); _classReference = value; } @@ -121,8 +119,11 @@ public Uri DeclarationReference get { return _declarationReference; } set { - if (value != null && !value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(value), value))); + if (value == null) + throw LogArgumentNullException(nameof(value)); + + if (!value.IsAbsoluteUri) + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(DeclarationReference), value))); _declarationReference = value; } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthorizationDecisionStatement.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthorizationDecisionStatement.cs index 6100d0c311..748a6c60f5 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthorizationDecisionStatement.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2AuthorizationDecisionStatement.cs @@ -130,7 +130,7 @@ public Uri Resource throw LogArgumentNullException(nameof(value)); if (!value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(value), value))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(Resource), value))); _resource = value; } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2NameIdentifier.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2NameIdentifier.cs index ca07ef744f..0a96f4aef9 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2NameIdentifier.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2NameIdentifier.cs @@ -84,7 +84,7 @@ public Uri Format set { if (null != value && !value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, value), nameof(value))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(Format), value), nameof(value))); _format = value; } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SecurityTokenHandler.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SecurityTokenHandler.cs index e10adf7f3d..0c7672d65a 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SecurityTokenHandler.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SecurityTokenHandler.cs @@ -657,7 +657,7 @@ protected virtual Saml2Attribute CreateAttribute(Claim claim) if (claim.Properties.TryGetValue(ClaimProperties.SamlAttributeNameFormat, out string nameFormat)) { if (!Saml2Serializer.CanCreateValidUri(nameFormat, UriKind.Absolute)) - throw LogExceptionMessage(new Saml2SecurityTokenException(FormatInvariant(LogMessages.IDX13300, ClaimProperties.SamlAttributeNameFormat))); + throw LogExceptionMessage(new Saml2SecurityTokenException(FormatInvariant(LogMessages.IDX13300, ClaimProperties.SamlAttributeNameFormat, nameFormat))); attribute.NameFormat = new Uri(nameFormat); } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Serializer.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Serializer.cs index 2df3c48b6e..618c2c01a9 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Serializer.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2Serializer.cs @@ -659,7 +659,10 @@ protected virtual Saml2AuthenticationContext ReadAuthenticationContext(XmlDictio reader.ReadStartElement(Saml2Constants.Elements.AuthnContextDeclRef, Saml2Constants.Namespace); // Now we have enough data to create the object - var authnContext = new Saml2AuthenticationContext(classRef, declRef); + var authnContext = new Saml2AuthenticationContext(classRef); + + if (declRef != null) + authnContext.DeclarationReference = declRef; // - 0-OO while (reader.IsStartElement(Saml2Constants.Elements.AuthenticatingAuthority, Saml2Constants.Namespace)) @@ -2300,7 +2303,7 @@ internal static Uri ReadSimpleUriElement(XmlDictionaryReader reader, string elem throw LogReadException(LogMessages.IDX13136, element); if (requireUri && !CanCreateValidUri(value, kind)) - throw LogReadException(LogMessages.IDX13107, element, value); + throw LogReadException(LogMessages.IDX13107, element, element, value); return new Uri(value, kind); } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmation.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmation.cs index bf21c0db55..a24876834a 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmation.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmation.cs @@ -59,7 +59,7 @@ public Saml2SubjectConfirmation(Uri method, Saml2SubjectConfirmationData subject throw LogArgumentNullException(nameof(method)); if (!method.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, method), nameof(method))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(method), method), nameof(method))); _method = method; SubjectConfirmationData = subjectConfirmationData; @@ -81,7 +81,7 @@ public Uri Method throw LogArgumentNullException(nameof(value)); if (!value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, value), nameof(value))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(Method), value), nameof(value))); _method = value; } diff --git a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmationData.cs b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmationData.cs index bfb97d5897..c5c28006bc 100644 --- a/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmationData.cs +++ b/src/Microsoft.IdentityModel.Tokens.Saml/Saml2/Saml2SubjectConfirmationData.cs @@ -109,7 +109,7 @@ public Uri Recipient throw LogArgumentNullException(nameof(value)); if (!value.IsAbsoluteUri) - throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(value), value))); + throw LogExceptionMessage(new ArgumentException(FormatInvariant(LogMessages.IDX13300, nameof(Recipient), value))); _recipient = value; } diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2ActionTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2ActionTests.cs new file mode 100644 index 0000000000..e5efb7bcac --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2ActionTests.cs @@ -0,0 +1,60 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2ActionTests + { + [Fact] + public void Saml2Action_NullValue_ArgumentNullException() + { + Assert.Throws(() => new Saml2Action(null, new Uri("http://localhost", UriKind.Absolute))); + } + + [Fact] + public void Saml2Action_NullNamespace_ArgumentNullException() + { + Assert.Throws(() => new Saml2Action("resource", null)); + } + + [Fact] + public void Saml2Action_RelativeNamespace_ArgumentException() + { + Assert.Throws(() => new Saml2Action(null, new Uri("api", UriKind.Relative))); + } + + [Fact] + public void Saml2Action_CanCreate() + { + new Saml2Action("resource", new Uri("http://localhost", UriKind.Absolute)); + } + } +} diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AttributeTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AttributeTests.cs new file mode 100644 index 0000000000..c12bc427fa --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AttributeTests.cs @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2AttributeTests + { + [Fact] + public void Saml2Attribute_RelativeNameFormat_ArgumentException() + { + var attr = new Saml2Attribute("Country"); + + Assert.Throws(() => attr.NameFormat = new Uri("resource", UriKind.Relative)); + } + + [Fact] + public void Saml2Attribute_NullNameFormat_NoException() + { + new Saml2Attribute("Country") + { + NameFormat = null + }; + } + + [Fact] + public void Saml2Attribute_AbsoluteNameFormat_NoException() + { + new Saml2Attribute("Country") + { + NameFormat = new Uri("http://resource", UriKind.Absolute) + }; + } + } +} diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthenticationContextTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthenticationContextTests.cs new file mode 100644 index 0000000000..94b4d9524e --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthenticationContextTests.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2AuthenticationContextTests + { + [Fact] + public void Saml2AuthenticationContext_Ctor_NoException() + { + new Saml2AuthenticationContext(); + } + + [Fact] + public void Saml2AuthenticationContext_CtorNullClassRef_ArgumentNullException() + { + Assert.Throws(() => new Saml2AuthenticationContext(null)); + } + + [Fact] + public void Saml2AuthenticationContext_CtorClassRef_NoException() + { + var classRef = new Uri("http://resource", UriKind.Absolute); + new Saml2AuthenticationContext(classRef); + } + + [Fact] + public void Saml2AuthenticationContext_CtorNullClassAndDeclaration_ArgumentNullException() + { + Assert.Throws(() => new Saml2AuthenticationContext(null, null)); + } + + [Fact] + public void Saml2AuthenticationContext_CtorNullDeclaration_ArgumentNullException() + { + var classRef = new Uri("http://resource", UriKind.Absolute); + Assert.Throws(() => new Saml2AuthenticationContext(classRef, null)); + } + + [Fact] + public void Saml2AuthenticationContext_CtorClassAndDeclarationRef_NoException() + { + var classRef = new Uri("http://resource", UriKind.Absolute); + var declarationReference = new Uri("http://resource", UriKind.Absolute); + new Saml2AuthenticationContext(classRef, declarationReference); + } + + [Fact] + public void Saml2AuthenticationContext_RelativeClassReference_ArgumentException() + { + var classRef = new Uri("resource", UriKind.Relative); + var authContext = new Saml2AuthenticationContext(); + Assert.Throws(() => new Saml2AuthenticationContext(classRef)); + } + + [Fact] + public void Saml2AuthenticationContext_NullClassReference_ArgumentNullException() + { + var authContext = new Saml2AuthenticationContext(); + Assert.Throws(() => authContext.ClassReference = null); + } + + [Fact] + public void Saml2AuthenticationContext_AbsoluteClassReference_NoException() + { + var classRef = new Uri("http://resource", UriKind.Absolute); + new Saml2AuthenticationContext + { + ClassReference = classRef + }; + } + + [Fact] + public void Saml2AuthenticationContext_RelativeDeclarationReference_ArgumentException() + { + var authContext = new Saml2AuthenticationContext(); + var declarationReference = new Uri("resource", UriKind.Relative); + Assert.Throws(() => authContext.DeclarationReference = declarationReference); + } + + [Fact] + public void Saml2AuthenticationContext_AbsoluteDeclarationReference_NoException() + { + var declarationReference = new Uri("http://resource", UriKind.Absolute); + new Saml2AuthenticationContext + { + DeclarationReference = declarationReference + }; + } + + [Fact] + public void Saml2AuthenticationContext_NullDeclarationReference_ArgumentNullException() + { + var authContext = new Saml2AuthenticationContext(); + Assert.Throws(() => authContext.DeclarationReference = null); + } + } +} diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthorizationDecisionStatementTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthorizationDecisionStatementTests.cs new file mode 100644 index 0000000000..811d862b4d --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2AuthorizationDecisionStatementTests.cs @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2AuthorizationDecisionStatementTests + { + [Fact] + public void Saml2AuthorizationDecisionStatement_RelativeClassReference_ArgumentException() + { + var resouce = new Uri("resource", UriKind.Relative); + Assert.Throws(() => new Saml2AuthorizationDecisionStatement(resouce, Saml2Constants.AccessDecision.Permit)); + } + + [Fact] + public void Saml2AuthorizationDecisionStatement_NullClassReference_ArgumentException() + { + Assert.Throws(() => new Saml2AuthorizationDecisionStatement(null, Saml2Constants.AccessDecision.Permit)); + } + + [Fact] + public void Saml2AuthorizationDecisionStatement_AbsoluteClassReference_NoException() + { + var resouce = new Uri("http://resource", UriKind.Absolute); + new Saml2AuthorizationDecisionStatement(resouce, Saml2Constants.AccessDecision.Permit); + } + + } +} diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2NameIdentifierTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2NameIdentifierTests.cs new file mode 100644 index 0000000000..c716af16fd --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2NameIdentifierTests.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2NameIdentifierTests + { + [Fact] + public void Saml2NameIdentifier_RelativeFormat_ArgumentException() + { + var format = new Uri("format", UriKind.Relative); + Assert.Throws(() => new Saml2NameIdentifier("name", format)); + } + + [Fact] + public void Saml2NameIdentifier_NullFormat_Noxception() + { + new Saml2NameIdentifier("name", null); + } + + [Fact] + public void Saml2NameIdentifier_AbsoluteClassReference_NoException() + { + var format = new Uri("http://resource", UriKind.Absolute); + new Saml2NameIdentifier("name", format); + } + } +} diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationDataTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationDataTests.cs new file mode 100644 index 0000000000..1f1ae406e2 --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationDataTests.cs @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2SubjectConfirmationDataTests + { + [Fact] + public void Saml2SubjectConfirmationData_RelativeFormat_ArgumentException() + { + var recipient = new Uri("recipient", UriKind.Relative); + var subjectConfirmationData = new Saml2SubjectConfirmationData(); + Assert.Throws(() => subjectConfirmationData.Recipient = recipient); + } + + [Fact] + public void Saml2SubjectConfirmationData_NullFormat_Noxception() + { + var subjectConfirmationData = new Saml2SubjectConfirmationData(); + Assert.Throws(() => subjectConfirmationData.Recipient = null); + } + + [Fact] + public void Saml2SubjectConfirmationData_AbsoluteClassReference_NoException() + { + var recipient = new Uri("http://resource", UriKind.Absolute); + var subjectConfirmationData = new Saml2SubjectConfirmationData(); + subjectConfirmationData.Recipient = recipient; + } + } +} diff --git a/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationTests.cs b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationTests.cs new file mode 100644 index 0000000000..cd47664c63 --- /dev/null +++ b/test/Microsoft.IdentityModel.Tokens.Saml.Tests/Saml2SubjectConfirmationTests.cs @@ -0,0 +1,56 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) Microsoft Corporation. +// All rights reserved. +// +// This code is licensed under the MIT License. +// +// 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 Xunit; +using Microsoft.IdentityModel.Tokens.Saml2; + +namespace Microsoft.IdentityModel.Tokens.Saml.Tests +{ + public class Saml2SubjectConfirmationTests + { + [Fact] + public void Saml2SubjectConfirmation_RelativeFormat_ArgumentException() + { + var method = new Uri("resource", UriKind.Relative); + Assert.Throws(() => new Saml2SubjectConfirmation(method)); + } + + [Fact] + public void Saml2SubjectConfirmation_NullFormat_Noxception() + { + Assert.Throws(() => new Saml2SubjectConfirmation(null)); + } + + [Fact] + public void Saml2SubjectConfirmation_AbsoluteClassReference_NoException() + { + var method = new Uri("http://resource", UriKind.Absolute); + new Saml2SubjectConfirmation(method); + } + } +} diff --git a/test/Microsoft.IdentityModel.Xml.Tests/EnvelopedSignatureWriterTests.cs b/test/Microsoft.IdentityModel.Xml.Tests/EnvelopedSignatureWriterTests.cs index 0f23b3819d..75718162f6 100644 --- a/test/Microsoft.IdentityModel.Xml.Tests/EnvelopedSignatureWriterTests.cs +++ b/test/Microsoft.IdentityModel.Xml.Tests/EnvelopedSignatureWriterTests.cs @@ -467,7 +467,7 @@ private static Saml2Assertion CreateAssertion(SigningCredentials samlpTokenSigni saml2Conditions.NotOnOrAfter = DateTime.Parse("2019-04-08T10:45:49Z"); assertion.Conditions = saml2Conditions; - var saml2AuthenticationContext = new Saml2AuthenticationContext(new Uri("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport"), null); + var saml2AuthenticationContext = new Saml2AuthenticationContext(new Uri("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport")); var saml2Statement = new Saml2AuthenticationStatement(saml2AuthenticationContext) { AuthenticationInstant = DateTime.Parse("2019-04-08T10:30:49Z"),