public void CanConvertToString()
            {
                // Arrange
                var now       = DateTime.Parse("2015-02-04T20:43:40.8618531Z");
                var localtime = now.ToString("o");

                // Act
                var result = Saml20Utils.ToUtcString(now);

                // Assert
                Assert.AreEqual("2015-02-04T20:43:40.8618531Z", result);
            }
Exemple #2
0
            public void CanConvertToString()
            {
                // Arrange
                var now       = DateTime.UtcNow;
                var localtime = now.ToString("o");

                // Act
                var result = Saml20Utils.ToUtcString(now);

                // Assert
                Assert.AreEqual(localtime, result);
            }
Exemple #3
0
            public void CanConvertToString()
            {
                // Arrange
                var now       = DateTime.UtcNow;
                var localtime = now.ToString("o");

                // Act
                var result = Saml20Utils.ToUtcString(now);

                // Correct for XML UTC dropping trailing 0
                if (result.Length != localtime.Length)
                {
                    var zeroPad = new string('0', localtime.Length - result.Length);
                    result = result.Substring(0, result.Length - 1) + zeroPad + "Z";
                }

                // Assert
                Assert.AreEqual(localtime, result);
            }
Exemple #4
0
        /// <summary>
        /// If both conditions.NotBefore and conditions.NotOnOrAfter are specified, NotBefore
        /// MUST BE less than NotOnOrAfter
        /// </summary>
        /// <param name="conditions">The conditions.</param>
        /// <exception cref="Saml20FormatException">If <param name="conditions"/>.NotBefore is not less than <paramref name="conditions"/>.NotOnOrAfter</exception>
        private static void ValidateConditionsInterval(Conditions conditions)
        {
            // No settings? No restrictions
            if (conditions.NotBefore == null && conditions.NotOnOrAfter == null)
            {
                return;
            }

            if (conditions.NotBefore != null && conditions.NotOnOrAfter != null && conditions.NotBefore.Value >= conditions.NotOnOrAfter.Value)
            {
                throw new Saml20FormatException(string.Format("NotBefore {0} MUST BE less than NotOnOrAfter {1} on Conditions", Saml20Utils.ToUtcString(conditions.NotBefore.Value), Saml20Utils.ToUtcString(conditions.NotOnOrAfter.Value)));
            }
        }
Exemple #5
0
        /// <summary>
        /// Validate SubjectConfirmationData.
        /// </summary>
        /// <param name="subjectConfirmationData">The subject confirmation data.</param>
        /// <remarks>
        /// [SAML2.0 standard] section 2.4.1.2
        /// </remarks>
        public void ValidateSubjectConfirmationData(SubjectConfirmationData subjectConfirmationData)
        {
            // If present it must be anyUri
            if (subjectConfirmationData.Recipient != null)
            {
                if (!Uri.IsWellFormedUriString(subjectConfirmationData.Recipient, UriKind.Absolute))
                {
                    throw new Saml20FormatException("Recipient of SubjectConfirmationData must be a wellformed absolute URI.");
                }
            }

            // NotBefore MUST BE striclty less than NotOnOrAfter if they are both set
            if (subjectConfirmationData.NotBefore != null && subjectConfirmationData.NotOnOrAfter != null && !(subjectConfirmationData.NotBefore < subjectConfirmationData.NotOnOrAfter))
            {
                throw new Saml20FormatException(string.Format("NotBefore {0} MUST BE less than NotOnOrAfter {1} on SubjectConfirmationData", Saml20Utils.ToUtcString(subjectConfirmationData.NotBefore.Value), Saml20Utils.ToUtcString(subjectConfirmationData.NotOnOrAfter.Value)));
            }

            // Make sure the extension-attributes are namespace-qualified and do not use reserved namespaces
            if (subjectConfirmationData.AnyAttr != null)
            {
                _anyAttrValidator.ValidateXmlAnyAttributes(subjectConfirmationData.AnyAttr);
            }

            // Standards-defined extension type which has stricter rules than it's base type
            if (subjectConfirmationData is KeyInfoConfirmationData)
            {
                _keyInfoValidator.ValidateKeyInfo(subjectConfirmationData);
            }
        }