Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
<DocumentationFile>bin\Release\dk.nita.saml20.ext.audit.log4net.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.1\lib\net40-full\log4net.dll</HintPath>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\packages\log4net.2.0.12\lib\net45\log4net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
Expand All @@ -55,7 +57,6 @@
<ItemGroup>
<None Include="app.config" />
<None Include="dk.nita.saml20.ext.audit.log4net.nuspec" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\dk.nita.saml20\dk.nita.saml20.csproj">
Expand All @@ -64,6 +65,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="readme.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="log4net" version="2.0.10" targetFramework="net45" />
<package id="log4net" version="2.0.12" targetFramework="net472" />
</packages>
21 changes: 9 additions & 12 deletions src/dk.nita.saml20/dk.nita.test.saml20/Saml20/ArtifactTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public void ArtifactCreateParse()
Assert.That(typeCode == parsedTypeCode, "Original and parsed typeCode did not match");
Assert.That(endpointIndex == parsedEndpointIndex, "Original and parsed endpointIndex did not match");

for(int i = 0; i < 20; i++)
for (int i = 0; i < 20; i++)
{
if(sourceIdHash[i] != parsedSourceIdHash[i])
if (sourceIdHash[i] != parsedSourceIdHash[i])
Assert.Fail("Original and parsed sourceIdHash are not identical");
}

Expand All @@ -52,31 +52,30 @@ public void ArtifactCreateParse()
}

[Test]
[ExpectedException(typeof(ArgumentException))]
public void CreateError1()
{
Int16 typeCode = 4;
Int16 endpointIndex = 1;
byte[] sourceIdHash = new byte[19];
byte[] messageHandle = new byte[20];

ArtifactUtil.CreateArtifact(typeCode, endpointIndex, sourceIdHash, messageHandle);


Assert.Throws<ArgumentException>(() => ArtifactUtil.CreateArtifact(typeCode, endpointIndex, sourceIdHash, messageHandle));
}

[Test]
[ExpectedException(typeof(ArgumentException))]
public void CreateError2()
{
Int16 typeCode = 4;
Int16 endpointIndex = 1;
byte[] sourceIdHash = new byte[20];
byte[] messageHandle = new byte[19];

ArtifactUtil.CreateArtifact(typeCode, endpointIndex, sourceIdHash, messageHandle);
Assert.Throws<ArgumentException>(() => ArtifactUtil.CreateArtifact(typeCode, endpointIndex, sourceIdHash, messageHandle));
}

[Test]
[ExpectedException(typeof(ArgumentException))]
public void ParseError1()
{
Int16 parsedTypeCode = -1;
Expand All @@ -85,32 +84,30 @@ public void ParseError1()
byte[] parsedMessageHandle = new byte[20];
string artifact = string.Empty;

ArtifactUtil.ParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle);
Assert.Throws<ArgumentException>(() => ArtifactUtil.ParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle));

}

[Test]
[ExpectedException(typeof(ArgumentException))]
public void ParseError2()
{
Int16 parsedTypeCode = -1;
Int16 parsedEndpointIndex = -1;
byte[] parsedSourceIdHash = new byte[20];
byte[] parsedMessageHandle = new byte[19];
string artifact = string.Empty;
ArtifactUtil.ParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle);
Assert.Throws<ArgumentException>(() => ArtifactUtil.ParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle));
}

[Test]
[ExpectedException(typeof(ArgumentException))]
public void ParseError3()
{
Int16 parsedTypeCode = -1;
Int16 parsedEndpointIndex = -1;
byte[] parsedSourceIdHash = new byte[20];
byte[] parsedMessageHandle = new byte[20];
string artifact = string.Empty;
ArtifactUtil.ParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle);
Assert.Throws<ArgumentException>(() => ArtifactUtil.ParseArtifact(artifact, ref parsedTypeCode, ref parsedEndpointIndex, ref parsedSourceIdHash, ref parsedMessageHandle));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using NUnit.Framework;
using dk.nita.saml20;
using dk.nita.saml20.Validation;
using Assertion=dk.nita.saml20.Schema.Core.Assertion;
using Assertion = dk.nita.saml20.Schema.Core.Assertion;

namespace dk.nita.test.Saml20
{
Expand All @@ -22,7 +22,7 @@ public class DKSAML20ProfileValidationTest

public DKSAML20ProfileValidationTest()
{
_validator = new DKSaml20AssertionValidator(AssertionUtil.GetAudiences(),false);
_validator = new DKSaml20AssertionValidator(AssertionUtil.GetAudiences(), false);
}

#region Tests
Expand All @@ -41,7 +41,6 @@ public void TestRetrieveIssuer()
/// Test that EncryptedData element with the correct Type value is disallowed by the DK Saml 2.0 validation
/// </summary>
[Test]
[ExpectedException(typeof(DKSaml20FormatException), ExpectedMessage = "The DK-SAML 2.0 profile does not allow encrypted attributes.")]
public void AttributeStatement_Invalid_EncryptedAttribute_DKSaml20()
{
Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();
Expand All @@ -57,21 +56,23 @@ public void AttributeStatement_Invalid_EncryptedAttribute_DKSaml20()

XmlDocument doc = AssertionUtil.ConvertAssertion(saml20Assertion);
var assertion = new Saml20Assertion(doc.DocumentElement, null, false);
assertion.Validate(DateTime.MinValue);

Assert.Throws<DKSaml20FormatException>(
() => assertion.Validate(DateTime.MinValue),
"The DK-SAML 2.0 profile does not allow encrypted attributes.");
}

/// <summary>
/// Add an &lt;AuthzDecisionStatement&gt; to the list of statements and check that this is detected as a violation.
/// </summary>
[Test]
[ExpectedException(typeof(DKSaml20FormatException), ExpectedMessage = "The DK-SAML 2.0 profile requires exactly one \"AuthnStatement\" element and one \"AttributeStatement\" element.")]
public void AttributeStatement_Invalid_Statementtype()
{
Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();
AuthzDecisionStatement authzDecisionStatement = new AuthzDecisionStatement();
authzDecisionStatement.Decision = DecisionType.Permit;
authzDecisionStatement.Resource = "http://safewhere.net";
authzDecisionStatement.Action = new dk.nita.saml20.Schema.Core.Action[] { new dk.nita.saml20.Schema.Core.Action() };
authzDecisionStatement.Action = new dk.nita.saml20.Schema.Core.Action[] { new dk.nita.saml20.Schema.Core.Action() };
authzDecisionStatement.Action[0].Namespace = "http://actionns.com";
authzDecisionStatement.Action[0].Value = "value";

Expand All @@ -81,7 +82,10 @@ public void AttributeStatement_Invalid_Statementtype()
saml20Assertion.Items = statements.ToArray();

var assertion = new Saml20Assertion(AssertionUtil.ConvertAssertion(saml20Assertion).DocumentElement, null, false);
assertion.Validate(DateTime.MinValue);

Assert.Throws<DKSaml20FormatException>(
() => assertion.Validate(DateTime.MinValue),
"The DK-SAML 2.0 profile requires exactly one \"AuthnStatement\" element and one \"AttributeStatement\" element.");
}

/// <summary>
Expand All @@ -106,7 +110,7 @@ public void AttributeStatement_Invalid_Statementtype()
// saml20Assertion.Issuer.Format = "http://example.com";

// TestAssertion(saml20Assertion, "The DK-SAML 2.0 Profile does not allow the \"Issuer\" element to have any attributes.");

// saml20Assertion.Issuer.Format = null;
// saml20Assertion.Issuer.NameQualifier = "NameQualifier";

Expand All @@ -116,7 +120,7 @@ public void AttributeStatement_Invalid_Statementtype()
// saml20Assertion.Issuer.SPNameQualifier = "SPNameQualifier";

// TestAssertion(saml20Assertion, "The DK-SAML 2.0 Profile does not allow the \"Issuer\" element to have any attributes.");

// saml20Assertion.Issuer.SPNameQualifier = null;
// saml20Assertion.Issuer.SPProvidedID = "SPProvidedID";

Expand Down Expand Up @@ -156,8 +160,8 @@ public void Subject_Element()

Assert.That(saml20Assertion.Subject.Items.Length > 0);

SubjectConfirmation subjectConfirmation =
(SubjectConfirmation) Array.Find(saml20Assertion.Subject.Items, delegate(object item) { return item is SubjectConfirmation; });
SubjectConfirmation subjectConfirmation =
(SubjectConfirmation)Array.Find(saml20Assertion.Subject.Items, delegate (object item) { return item is SubjectConfirmation; });
Assert.IsNotNull(subjectConfirmation);
string originalMethod = subjectConfirmation.Method;
subjectConfirmation.Method = "IllegalMethod";
Expand All @@ -176,7 +180,7 @@ public void Subject_Element()
TestAssertion(saml20Assertion, "The DK-SAML 2.0 Profile requires that the \"SubjectConfirmationData\" element contains the \"NotOnOrAfter\" attribute.");
subjectConfirmation.SubjectConfirmationData.NotOnOrAfter = DateTime.UtcNow;

subjectConfirmation.SubjectConfirmationData.NotBefore = DateTime.UtcNow.Subtract(new TimeSpan(5,0,0,0));
subjectConfirmation.SubjectConfirmationData.NotBefore = DateTime.UtcNow.Subtract(new TimeSpan(5, 0, 0, 0));
TestAssertion(saml20Assertion, "The DK-SAML 2.0 Profile disallows the use of the \"NotBefore\" attribute of the \"SubjectConfirmationData\" element.");

subjectConfirmation.SubjectConfirmationData.NotBefore = null;
Expand All @@ -201,11 +205,11 @@ public void Conditions_Element()
List<ConditionAbstract> conditions =
new List<ConditionAbstract>(saml20Assertion.Conditions.Items);

int index = conditions.FindIndex(delegate(ConditionAbstract cond) { return cond is AudienceRestriction; });
Assert.That( index != -1);
int index = conditions.FindIndex(delegate (ConditionAbstract cond) { return cond is AudienceRestriction; });
Assert.That(index != -1);
conditions.RemoveAt(index);
// Add another condition to avoid an empty list of conditions.
conditions.Add( new OneTimeUse());
conditions.Add(new OneTimeUse());
saml20Assertion.Conditions.Items = conditions;

TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires that an \"AudienceRestriction\" element is present on the saml20Assertion.");
Expand All @@ -214,12 +218,12 @@ public void Conditions_Element()
/// <summary>
/// Verify the rules for the &lt;AuthnStatement&gt; element, which are outlined in section 7.1.7 of [DKSAML]
/// </summary>
[Test]
[Test]
public void AuthnStatement_Element()
{
Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();
AuthnStatement authnStmt =
(AuthnStatement)Array.Find(saml20Assertion.Items, delegate(StatementAbstract stmnt) { return stmnt is AuthnStatement; });
(AuthnStatement)Array.Find(saml20Assertion.Items, delegate (StatementAbstract stmnt) { return stmnt is AuthnStatement; });

// Mess around with the AuthnStatement.
{
Expand All @@ -230,9 +234,9 @@ public void AuthnStatement_Element()
}

{
int index =
Array.FindIndex(authnStmt.AuthnContext.Items,
delegate(object o) { return o is string && o.ToString() == "urn:oasis:names:tc:SAML:2.0:ac:classes:X509"; });
int index =
Array.FindIndex(authnStmt.AuthnContext.Items,
delegate (object o) { return o is string && o.ToString() == "urn:oasis:names:tc:SAML:2.0:ac:classes:X509"; });
object oldValue = authnStmt.AuthnContext.Items[index];
authnStmt.AuthnContext.Items[index] = "Hallelujagobble!!";
TestAssertion(saml20Assertion, "AuthnContextClassRef has a value which is not a wellformed absolute uri");
Expand All @@ -242,23 +246,23 @@ public void AuthnStatement_Element()
// Remove it.
saml20Assertion = AssertionUtil.GetBasicAssertion();
List<StatementAbstract> statements = new List<StatementAbstract>(saml20Assertion.Items);
statements.RemoveAll(delegate(StatementAbstract stmnt) { return stmnt is AuthnStatement; });
statements.RemoveAll(delegate (StatementAbstract stmnt) { return stmnt is AuthnStatement; });
saml20Assertion.Items = statements.ToArray();
TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires exactly one \"AuthnStatement\" element and one \"AttributeStatement\" element.");
}

/// <summary>
/// Verify the rules for the &lt;AttributeStatement&gt; element, which are outlined in section 7.1.8 of [DKSAML]
/// </summary>
[Test]
[Test]
public void AttributeStatement_Element()
{
{
Predicate<StatementAbstract> findAttributeStatement =
delegate(StatementAbstract stmnt) { return stmnt is AttributeStatement; };
delegate (StatementAbstract stmnt) { return stmnt is AttributeStatement; };
Assertion saml20Assertion = AssertionUtil.GetBasicAssertion();

AttributeStatement attributeStatement =
(AttributeStatement) Array.Find(saml20Assertion.Items, findAttributeStatement);
(AttributeStatement)Array.Find(saml20Assertion.Items, findAttributeStatement);

// Add an encrypted attribute.
EncryptedElement encAtt = new EncryptedElement();
Expand All @@ -270,14 +274,14 @@ public void AttributeStatement_Element()
TestAssertion(saml20Assertion, "The DK-SAML 2.0 profile does not allow encrypted attributes.");

// Add an attribute with the wrong nameformat.
// Attribute att = DKSaml20EmailAttribute.create("test@example.com");
// att.NameFormat = "http://example.com";
// attributeStatement.Items = new object[] { att };
// testAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires that an attribute's \"NameFormat\" element is urn:oasis:names:tc:SAML:2.0:attrname-format:uri.");
// Attribute att = DKSaml20EmailAttribute.create("test@example.com");
// att.NameFormat = "http://example.com";
// attributeStatement.Items = new object[] { att };
// testAssertion(saml20Assertion, "The DK-SAML 2.0 profile requires that an attribute's \"NameFormat\" element is urn:oasis:names:tc:SAML:2.0:attrname-format:uri.");

// Clear all the attributes.
attributeStatement.Items = new object[0];
TestAssertion(saml20Assertion, "AttributeStatement MUST contain at least one Attribute or EncryptedAttribute");
TestAssertion(saml20Assertion, "AttributeStatement MUST contain at least one Attribute or EncryptedAttribute");

// Remove it.
saml20Assertion = AssertionUtil.GetBasicAssertion();
Expand Down Expand Up @@ -310,8 +314,8 @@ private void TestAssertion(Assertion saml20Assertion, string exceptionMsg)
/// <param name="statements"></param>
/// <returns></returns>
private static AttributeStatement GetAttributeStatement(List<StatementAbstract> statements)
{
return (AttributeStatement) statements.Find(delegate(StatementAbstract ssa) { return ssa is AttributeStatement; });
{
return (AttributeStatement)statements.Find(delegate (StatementAbstract ssa) { return ssa is AttributeStatement; });
}
}
}
Loading