Skip to content

Commit

Permalink
Added unit test specifically for issue #218
Browse files Browse the repository at this point in the history
  • Loading branch information
jstedfast committed Jan 11, 2016
1 parent cda5ac1 commit 737a0a3
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
17 changes: 17 additions & 0 deletions UnitTests/DkimTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ public void TestVerifyGoogleMultipartRelatedDkimSignature ()
Assert.IsTrue (message.Verify (message.Headers[index], new DummyPublicKeyLocator (key)), "Failed to verify GMail signature.");
}

[Test]
public void TestVerifyGoogleMultipartWithoutEndBoundaryDkimSignature ()
{
var message = MimeMessage.Load (Path.Combine ("..", "..", "TestData", "dkim", "multipart-no-end-boundary.msg"));
int index = message.Headers.IndexOf (HeaderId.DkimSignature);
AsymmetricKeyParameter key;

// Note: you can use http://dkimcore.org/tools/dkimrecordcheck.html to get public keys manually
using (var stream = new StreamReader (Path.Combine ("..", "..", "TestData", "dkim", "gmail.pub"))) {
var reader = new PemReader (stream);

key = reader.ReadObject () as AsymmetricKeyParameter;
}

Assert.IsTrue (message.Verify (message.Headers[index], new DummyPublicKeyLocator (key)), "Failed to verify GMail signature.");
}

static void TestDkimSignVerify (MimeMessage message, DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm headerAlgorithm, DkimCanonicalizationAlgorithm bodyAlgorithm)
{
var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
Expand Down
54 changes: 54 additions & 0 deletions UnitTests/TestData/dkim/multipart-no-end-boundary.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Delivered-To: [email protected]
Received: by 10.202.87.23 with SMTP id l23csp2156992oib;
Mon, 11 Jan 2016 07:33:37 -0800 (PST)
X-Received: by 10.28.125.20 with SMTP id y20mr14315854wmc.19.1452526417231;
Mon, 11 Jan 2016 07:33:37 -0800 (PST)
Return-Path: <[email protected]>
Received: from mail-wm0-x22d.google.com (mail-wm0-x22d.google.com. [2a00:1450:400c:c09::22d])
by mx.google.com with ESMTPS id f16si37284738wjn.136.2016.01.11.07.33.37
for <[email protected]>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Mon, 11 Jan 2016 07:33:37 -0800 (PST)
Received-SPF: pass (google.com: domain of [email protected] designates 2a00:1450:400c:c09::22d as permitted sender) client-ip=2a00:1450:400c:c09::22d;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of [email protected] designates 2a00:1450:400c:c09::22d as permitted sender) [email protected];
dkim=pass [email protected];
dmarc=pass (p=NONE dis=NONE) header.from=gmail.com
Received: by mail-wm0-x22d.google.com with SMTP id f206so266381337wmf.0
for <[email protected]>; Mon, 11 Jan 2016 07:33:37 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=message-id:date:subject:from:to:content-type;
bh=5Cf5R557Rceump1cxPGJg6+EdeB9ebj51ZXgzDp3d7Y=;
b=FJtQKptyeDXuLuQEKcwVn65cen1xe9R+s450cMhP+8ZPPrHavrVgowmgbQozmh93Qf
lDRmJtt+m9GntHMMmZYjdFjEU+3h6iJ+T0NcBYgl0pNZ7TThZ769aWIry2e8HujgnmEW
QR3WD43/6J2ABSL6r3MetlUrcB87+lcnYvZwoOh/WQAazqZpefRaL/3wO63HgzJWi5mV
Ez9xG7cY+LbrFgEYOs63JL+yHtGTG9w6NpxzTYRw8zOAp3Lr7asGxDVpFZ7iSwhnEDKR
Nbwc7KJ29JPFr4eFHbvQME0256ys92bFhZsMmuDj3Bc65qu1MU1jnESEeoj4LHcVcnOL
KOHQ==
X-Received: by 10.28.55.76 with SMTP id e73mr15100383wma.53.1452526416961;
Mon, 11 Jan 2016 07:33:36 -0800 (PST)
Return-Path: <[email protected]>
Received: from Test ([127.0.0.1])
by smtp.gmail.com with ESMTPSA id dl8sm120393245wjb.29.2016.01.11.07.33.11
for <[email protected]>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Mon, 11 Jan 2016 07:33:35 -0800 (PST)
Message-ID: <[email protected]>
Date: Mon, 11 Jan 2016 16:32:47 +0100
Subject: Multipart message without closing boundary
From: "[email protected]" <[email protected]>
To: [email protected]
Content-Type: multipart/alternative; boundary=047d7bd761b6234d3005291030da

--047d7bd761b6234d3005291030da
Content-Type: text/plain; charset=UTF-8

Multipart message without closing boundary

--047d7bd761b6234d3005291030da
Content-Type: text/html; charset=UTF-8

<div dir="ltr">Multipart message without closing boundary<br></div>


1 change: 1 addition & 0 deletions UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<None Include="TestData\dkim\example.tinydns" />
<None Include="TestData\dkim\gmail.msg" />
<None Include="TestData\dkim\gmail.pub" />
<None Include="TestData\dkim\multipart-no-end-boundary.msg" />
<None Include="TestData\dkim\related.msg" />
<None Include="TestData\encoders\photo.b64" />
<None Include="TestData\encoders\photo.jpg" />
Expand Down

0 comments on commit 737a0a3

Please sign in to comment.