-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRequestRedirect.cs
86 lines (65 loc) · 2.93 KB
/
RequestRedirect.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
using HttpReverseProxy.Plugin.RequestRedirect;
using HttpReverseProxyLib.DataTypes;
using HttpReverseProxyLib.DataTypes.Enum;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestsPlugins;
namespace TestsPluginsHostmapping
{
[TestClass]
public class RequestRedirect
{
#region MEMBERS
private string tempInputFilePath;
#endregion
#region (DE)INIT
[TestInitialize]
public void TestInit()
{
this.tempInputFilePath = Path.GetTempFileName();
}
[TestCleanup]
public void TestClean()
{
TestsPlugins.HelperMethods.Inst.RemoveFile(this.tempInputFilePath);
}
#endregion
// 302||Temporary redirect||*google.c*||/path/to/file*.php||https://www.minary.io/
[TestMethod]
public void RequestRedirect_LoadConfig_Wildcard()
{
File.AppendAllText(this.tempInputFilePath, "302||Temporary redirect||*google.c*||/path/to/file*.php||https://www.minary.io/victims/hacked.php");
var conf = new Config();
conf.ParseConfigurationFile(this.tempInputFilePath);
Assert.IsTrue(Config.RequestRedirectRecords.Count == 1);
}
[TestMethod]
public void Request_redirect_success()
{
File.AppendAllText(this.tempInputFilePath, "302||Temporary redirect||*google.c*||/path/to/file*.php||https://www.minary.io/victims/hacked.php");
var conf = new Config();
var reqObj = TestsPlugins.HelperMethods.Inst.GenerateBasicRequest("http", "www.google.com", "/path/to/file/random.php");
var pluginRequestRedirect = new HttpReverseProxy.Plugin.RequestRedirect.RequestRedirect();
pluginRequestRedirect.PluginProperties.PluginHost = HelperMethods.Inst.GeneratePluginHost();
conf.ParseConfigurationFile(this.tempInputFilePath);
PluginInstruction instr = pluginRequestRedirect.OnPostClientHeadersRequest(reqObj);
Assert.IsTrue(Config.RequestRedirectRecords.Count == 1);
Assert.IsTrue(instr.Instruction == Instruction.RedirectToNewUrl);
Assert.IsTrue(instr.InstructionParameters.Status == "302");
Assert.IsTrue(instr.InstructionParameters.StatusDescription == "Temporary redirect");
}
[TestMethod]
public void Request_redirect_no()
{
File.AppendAllText(this.tempInputFilePath, "302||Temporary redirect||*google.c*||/path/to/file*.php||https://www.minary.io/victims/hacked.php");
var conf = new Config();
var reqObj = HelperMethods.Inst.GenerateBasicRequest("http", "www.google.com", "/index.php");
var pluginRequestRedirect = new HttpReverseProxy.Plugin.RequestRedirect.RequestRedirect();
pluginRequestRedirect.PluginProperties.PluginHost = HelperMethods.Inst.GeneratePluginHost();
conf.ParseConfigurationFile(this.tempInputFilePath);
PluginInstruction instr = pluginRequestRedirect.OnPostClientHeadersRequest(reqObj);
Assert.IsTrue(Config.RequestRedirectRecords.Count == 1);
Assert.IsTrue(instr.Instruction == Instruction.DoNothing);
}
}
}