Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
Titanium-Web-Proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Titanium-Web-Proxy
Commits
8b8fba1f
Commit
8b8fba1f
authored
Oct 07, 2016
by
Joakim Brännström
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for multiple zero-port end points for the same address
Also fixed a compare-by-reference-bug
parent
4ff5a28b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
1 deletion
+93
-1
ProxyServerTests.cs
Tests/Titanium.Web.Proxy.UnitTests/ProxyServerTests.cs
+91
-0
Titanium.Web.Proxy.UnitTests.csproj
...m.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj
+1
-0
ProxyServer.cs
Titanium.Web.Proxy/ProxyServer.cs
+1
-1
No files found.
Tests/Titanium.Web.Proxy.UnitTests/ProxyServerTests.cs
0 → 100644
View file @
8b8fba1f
using
System
;
using
System.Net
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.UnitTests
{
[
TestClass
]
public
class
ProxyServerTests
{
[
TestMethod
]
public
void
GivenOneEndpointIsAlreadyAddedToAddress_WhenAddingNewEndpointToExistingAddress_ThenExceptionIsThrown
()
{
// Arrange
var
proxy
=
new
ProxyServer
();
const
int
port
=
9999
;
var
firstIpAddress
=
IPAddress
.
Parse
(
"127.0.0.1"
);
var
secondIpAddress
=
IPAddress
.
Parse
(
"127.0.0.1"
);
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
firstIpAddress
,
port
,
false
));
// Act
try
{
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
secondIpAddress
,
port
,
false
));
}
catch
(
Exception
exc
)
{
// Assert
StringAssert
.
Contains
(
exc
.
Message
,
"Cannot add another endpoint to same port"
);
return
;
}
Assert
.
Fail
(
"An exception should be thrown by now"
);
}
[
TestMethod
]
public
void
GivenOneEndpointIsAlreadyAddedToAddress_WhenAddingNewEndpointToExistingAddress_ThenTwoEndpointsExists
()
{
// Arrange
var
proxy
=
new
ProxyServer
();
const
int
port
=
9999
;
var
firstIpAddress
=
IPAddress
.
Parse
(
"127.0.0.1"
);
var
secondIpAddress
=
IPAddress
.
Parse
(
"192.168.1.1"
);
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
firstIpAddress
,
port
,
false
));
// Act
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
secondIpAddress
,
port
,
false
));
// Assert
Assert
.
AreEqual
(
2
,
proxy
.
ProxyEndPoints
.
Count
);
}
[
TestMethod
]
public
void
GivenOneEndpointIsAlreadyAddedToPort_WhenAddingNewEndpointToExistingPort_ThenExceptionIsThrown
()
{
// Arrange
var
proxy
=
new
ProxyServer
();
const
int
port
=
9999
;
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
IPAddress
.
Loopback
,
port
,
false
));
// Act
try
{
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
IPAddress
.
Loopback
,
port
,
false
));
}
catch
(
Exception
exc
)
{
// Assert
StringAssert
.
Contains
(
exc
.
Message
,
"Cannot add another endpoint to same port"
);
return
;
}
Assert
.
Fail
(
"An exception should be thrown by now"
);
}
[
TestMethod
]
public
void
GivenOneEndpointIsAlreadyAddedToZeroPort_WhenAddingNewEndpointToExistingPort_ThenTwoEndpointsExists
()
{
// Arrange
var
proxy
=
new
ProxyServer
();
const
int
port
=
0
;
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
IPAddress
.
Loopback
,
port
,
false
));
// Act
proxy
.
AddEndPoint
(
new
ExplicitProxyEndPoint
(
IPAddress
.
Loopback
,
port
,
false
));
// Assert
Assert
.
AreEqual
(
2
,
proxy
.
ProxyEndPoints
.
Count
);
}
}
}
Tests/Titanium.Web.Proxy.UnitTests/Titanium.Web.Proxy.UnitTests.csproj
View file @
8b8fba1f
...
@@ -52,6 +52,7 @@
...
@@ -52,6 +52,7 @@
<ItemGroup>
<ItemGroup>
<Compile
Include=
"CertificateManagerTests.cs"
/>
<Compile
Include=
"CertificateManagerTests.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"ProxyServerTests.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\..\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj"
>
<ProjectReference
Include=
"..\..\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj"
>
...
...
Titanium.Web.Proxy/ProxyServer.cs
View file @
8b8fba1f
...
@@ -214,7 +214,7 @@ namespace Titanium.Web.Proxy
...
@@ -214,7 +214,7 @@ namespace Titanium.Web.Proxy
/// <param name="endPoint"></param>
/// <param name="endPoint"></param>
public
void
AddEndPoint
(
ProxyEndPoint
endPoint
)
public
void
AddEndPoint
(
ProxyEndPoint
endPoint
)
{
{
if
(
ProxyEndPoints
.
Any
(
x
=>
x
.
IpAddress
==
endPoint
.
IpAddress
&&
x
.
Port
==
endPoint
.
Port
))
if
(
ProxyEndPoints
.
Any
(
x
=>
x
.
IpAddress
.
Equals
(
endPoint
.
IpAddress
)
&&
endPoint
.
Port
!=
0
&&
x
.
Port
==
endPoint
.
Port
))
{
{
throw
new
Exception
(
"Cannot add another endpoint to same port & ip address"
);
throw
new
Exception
(
"Cannot add another endpoint to same port & ip address"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment