-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathSpfEvaluationTests.cs
More file actions
79 lines (70 loc) · 2.29 KB
/
SpfEvaluationTests.cs
File metadata and controls
79 lines (70 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Waher.Networking.DNS;
using Waher.Persistence;
using Waher.Persistence.Files;
using Waher.Persistence.Serialization;
using Waher.Runtime.Inventory;
namespace Waher.Security.SPF.Test
{
[TestClass]
public class SpfEvaluationTests
{
private static FilesProvider filesProvider = null;
[AssemblyInitialize]
public static async Task AssemblyInitialize(TestContext _)
{
Types.Initialize(
typeof(Database).Assembly,
typeof(FilesProvider).Assembly,
typeof(ObjectSerializer).Assembly,
typeof(DnsResolver).Assembly);
filesProvider = await FilesProvider.CreateAsync("Data", "Default", 8192, 10000, 8192, Encoding.UTF8, 10000, true);
Database.Register(filesProvider);
}
[AssemblyCleanup]
public static async Task AssemblyCleanup()
{
if (filesProvider is not null)
{
await filesProvider.DisposeAsync();
filesProvider = null;
}
}
[TestMethod]
public async Task Test_01_SPF_Evaluation_1()
{
KeyValuePair<SpfResult, string> Result = await SpfResolver.CheckHost(
IPAddress.Parse("20.105.198.113"), "cybercity.online",
"testaccount@cybercity.online", "smtp.outgoing.loopia.se", "cybercity.online");
Assert.AreEqual(SpfResult.Pass, Result.Key, Result.Value);
}
[TestMethod]
public async Task Test_02_SPF_Evaluation_2()
{
await TestSpfString("v=spf1 include:_spf.google.com ~all",
"mobilgirot.com", "testaccount@mobilgirot.com",
IPAddress.Parse("209.85.221.49"), "mail-wr1-f49.google.com",
"cybercity.online");
}
[TestMethod]
public async Task Test_03_SPF_Evaluation_3()
{
await TestSpfString("v=spf1 ptr:yahoo.com ~all",
"att.net", "testaccount@att.net",
IPAddress.Parse("74.6.128.85"), "sonic312-23.consmr.mail.bf2.yahoo.com",
"cybercity.online");
}
private static async Task TestSpfString(string SpfString, string Domain,
string Sender, IPAddress Address, string CallerHost, string Host)
{
KeyValuePair<SpfResult, string> Result = await SpfResolver.CheckHost(
Address, Domain, Sender, CallerHost, Host,
new SpfExpression(Domain, false, SpfString));
Assert.AreEqual(SpfResult.Pass, Result.Key, Result.Value);
}
}
}