-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHostMapping.cs
92 lines (69 loc) · 2.35 KB
/
HostMapping.cs
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
80
81
82
83
84
85
86
87
88
89
90
91
92
using HttpReverseProxy.Plugin.HostMapping;
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestsPlugins;
namespace TestsPluginsHostmapping
{
[TestClass]
public class HostMapping
{
#region MEMBERS
private string pathInputFile;
#endregion
#region (DE)INIT
[TestInitialize]
public void TestInit()
{
this.pathInputFile = Path.GetTempFileName();
}
[TestCleanup]
public void TestClean()
{
if (File.Exists(this.pathInputFile))
{
try
{
File.Delete(this.pathInputFile);
}
catch (Exception ex)
{
Console.WriteLine($"TestClean(EXC): {ex.Message}");
}
}
}
#endregion
[TestMethod]
public void HostMapping_LoadConfig_Wildcard()
{
File.AppendAllText(this.pathInputFile, "*oogle.c*||www.altavista.com");
var conf = new Config();
conf.ParseConfigurationFile(this.pathInputFile);
Assert.IsTrue(Config.MappingsHostWildcards.Count == 1);
Assert.IsTrue(Config.MappingsHostname.Count == 0);
}
[TestMethod]
public void HostMapping_LoadConfig_FixHostname()
{
File.AppendAllText(this.pathInputFile, $"google.com||www.altavista.com{Environment.NewLine}www.google.com||www.altavista.com");
var conf = new Config();
conf.ParseConfigurationFile(this.pathInputFile);
Assert.IsTrue(Config.MappingsHostWildcards.Count == 0);
Assert.IsTrue(Config.MappingsHostname.Count == 2);
}
[TestMethod]
public void HostRegex_Find()
{
File.AppendAllText(this.pathInputFile, $"*oogle.c*||www.altavista.com{Environment.NewLine}*20min.ch||watson.ch");
var conf = new Config();
var reqObj = HelperMethods.Inst.GenerateBasicRequest("http", "www.google.com", "/");
var pluginHostMapping = new HttpReverseProxy.Plugin.HostMapping.HostMapping();
pluginHostMapping.PluginProperties.PluginHost = HelperMethods.Inst.GeneratePluginHost();
conf.ParseConfigurationFile(this.pathInputFile);
pluginHostMapping.OnPostClientHeadersRequest(reqObj);
Assert.IsTrue(Config.MappingsHostWildcards.Count == 2);
Assert.IsTrue(reqObj.ClientRequestObj.Host == "www.altavista.com");
Assert.IsTrue(reqObj.ClientRequestObj.ClientRequestHeaders["Host"][0] == "www.altavista.com");
}
}
}