Beispiel #1
0
            public void ValidatesTransient()
            {
                var nameId = new NameId {
                    Format = Saml20Constants.NameIdentifierFormats.Transient
                };
                var validator = new Saml20NameIdValidator();

                nameId.Value = new string('f', 256);
                validator.ValidateNameId(nameId);

                nameId.Value = new string('f', 16);
                validator.ValidateNameId(nameId);
            }
Beispiel #2
0
            public void ValidatesWindowsDomainQualifiedName()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Windows
                };
                var validator = new Saml20NameIdValidator();

                // Act
                nameId.Value = "a";
                validator.ValidateNameId(nameId);

                nameId.Value = "b\a";
                validator.ValidateNameId(nameId);
            }
Beispiel #3
0
            public void ValidatesPersistent()
            {
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Persistent,
                    Value  = new string('f', 256)
                };
                var validator = new Saml20NameIdValidator();

                validator.ValidateNameId(nameId);
            }
Beispiel #4
0
            public void ThrowsExceptionWhenEmailValueContainsOnlyWhitespace()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Email,
                    Value  = " "
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Email Format attribute MUST contain a Value that contains more than whitespace characters");
            }
Beispiel #5
0
            public void ThrowsExceptionWhenTransientValueTooShort()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Transient,
                    Value  = new string('f', 15)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Transient Format attribute MUST have a Value with at least 16 characters (the equivalent of 128 bits)");
            }
Beispiel #6
0
            public void ThrowsExceptionWhenTransientValueTooLong()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Transient,
                    Value  = new string('f', 257)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Transient Format attribute MUST have a Value that contains no more than 256 characters");
            }
Beispiel #7
0
            public void ThrowsExceptionWhenPersistentValueEmpty()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Persistent,
                    Value  = string.Empty
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Persistent Format attribute MUST contain a Value that contains more than whitespace characters");
            }
Beispiel #8
0
            public void ThrowsExceptionWhenEntityLengthTooLong()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Entity,
                    Value  = new string('f', 1025)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Entity Format attribute MUST have a Value that contains no more than 1024 characters");
            }
Beispiel #9
0
            public void ValidatesEmail()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Email,
                    Value  = "*****@*****.**"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #10
0
            public void ThrowsExceptionWhenKerberosInvalidFormat()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                    Value  = @"a\b"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Kerberos Format attribute MUST contain a Value that contains a '@'");
            }
Beispiel #11
0
            public void ThrowsExceptionWhenPersistentValueEmpty()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Persistent,
                    Value  = string.Empty
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #12
0
            public void ThrowsExceptionWhenKerberosLessThanThreecharacters()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                    Value  = @"b"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #13
0
            public void ValidatesEntity()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Entity,
                    Value  = new string('f', 1024)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenX509SubjecNameValueContainsOnlyWhirespace()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.X509SubjectName,
                    Value  = " "
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId, false);
            }
Beispiel #15
0
            public void ThrowsExceptionWhenKerberosInvalidFormat()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                    Value  = @"a\b"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #16
0
            public void ThrowsExceptionWhenTransientValueTooShort()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Transient,
                    Value  = new string('f', 15)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #17
0
            public void ThrowsExceptionWhenKerberosLessThanThreecharacters()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                    Value  = @"b"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Kerberos Format attribute MUST contain a Value with at least 3 characters");
            }
Beispiel #18
0
            public void ThrowsExceptionWhenEmailValueContainsOnlyWhitespace()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Email,
                    Value  = " "
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenEntityLengthTooLong()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Entity,
                    Value  = new string('f', 1025)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId, false);
            }
            public void ThrowsExceptionWhenKerberosValueEmpty()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                    Value  = string.Empty
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId, false);
            }
            public void ThrowsExceptionWhenWindowsDomainQualifiedNameValueContainsOnlyWhitespace()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Windows,
                    Value  = " "
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId, false);
            }
Beispiel #22
0
            public void ThrowsExceptionWhenPersistentLengthTooLong()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Persistent,
                    Value  = new string('f', 257)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #23
0
            public void ValidatesKerberos()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Kerberos,
                    Value  = "a@b"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
Beispiel #24
0
            public void ThrowsExceptionWhenEntitySPProvidedId()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format       = Saml20Constants.NameIdentifierFormats.Entity,
                    Value        = new string('f', 1024),
                    SPProvidedID = "ksljdf"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId);
            }
            public void ThrowsExceptionWhenEntityNameQualifierSet()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format        = Saml20Constants.NameIdentifierFormats.Entity,
                    Value         = new string('f', 1024),
                    NameQualifier = "ksljdf"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                validator.ValidateNameId(nameId, false);
            }
Beispiel #26
0
            public void ThrowsExceptionWhenEntitySPProvidedId()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format       = Saml20Constants.NameIdentifierFormats.Entity,
                    Value        = new string('f', 1024),
                    SPProvidedID = "ksljdf"
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws <Saml20FormatException>(() => validator.ValidateNameId(nameId), "NameID with Entity Format attribute MUST NOT set the SPProvidedID attribute");
            }
            //ExpectedMessage = "NameID with Transient Format attribute MUST have a Value that contains no more than 256 characters")]
            public void ThrowsExceptionWhenTransientValueTooLong()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Transient,
                    Value  = new string('f', 257)
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    validator.ValidateNameId(nameId);
                });
            }
            //ExpectedMessage = "NameID with Persistent Format attribute MUST contain a Value that contains more than whitespace characters")]
            public void ThrowsExceptionWhenPersistentContainsOnlyWhitespace()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Persistent,
                    Value  = " "
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    validator.ValidateNameId(nameId);
                });
            }
            //ExpectedMessage = "NameID with Entity Format attribute MUST contain a Value that contains more than whitespace characters")]
            public void ThrowsExceptionWhenEntityValueEmpty()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Entity,
                    Value  = string.Empty
                };
                var validator = new Saml20NameIdValidator();

                // Act
                Assert.Throws(typeof(Saml20FormatException), () =>
                {
                    validator.ValidateNameId(nameId);
                });
            }
Beispiel #30
0
            public void ThrowsExceptionWhenEmailInvalidForm()
            {
                // Arrange
                var nameId = new NameId
                {
                    Format = Saml20Constants.NameIdentifierFormats.Email
                };
                var validator = new Saml20NameIdValidator();

                var invalidEmails = new[]
                {
                    "thisisnotavalid.email@ ",
                    "thisisnotavalidemail",
                    "thisisnotavalidemail.com",
                    "@thisisnotavalidemail.com",
                    " @thisisnotavalidemail.com",
                    "@ @thisisnotavalidemail.com",
                    " @ @thisisnotavalidemail.com",
                    " . @thisisnotavalidemail.com",
                    @"\. @thisisnotavalidemail.com",
                    @"\.\@thisisnotavalidemail.com",
                    @"a.\@thisisnotavalidemail.com",
                    @"<.>@thisisnotavalidemail.com",
                    @"<*****@*****.**",
                    "thisisnotavalid.email@",
                    "thisisnotavalid.email@ @",
                    "thisisnotavalid.email@ @ "
                };

                foreach (var email in invalidEmails)
                {
                    nameId.Value = email;

                    try
                    {
                        // Act
                        validator.ValidateNameId(nameId);

                        // Assert
                        Assert.Fail("Email address " + email + " is not supposed to be valid");
                    }
                    catch (Saml20FormatException sfe)
                    {
                        Assert.AreEqual(sfe.Message, "Value of NameID is not a valid email address according to the IETF RFC 2822 specification");
                    }
                }
            }