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
e4f3e7d5
Commit
e4f3e7d5
authored
Nov 02, 2018
by
justcoding121
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
setup integration tests for continous integration
parent
487ecbdf
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
135 deletions
+110
-135
build.ps1
.build/build.ps1
+13
-1
InterceptionTests.cs
.../Titanium.Web.Proxy.IntegrationTests/InterceptionTests.cs
+43
-14
ProxyTestController.cs
...itanium.Web.Proxy.IntegrationTests/ProxyTestController.cs
+0
-105
SslTests.cs
tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
+28
-14
Titanium.Web.Proxy.IntegrationTests.csproj
...tegrationTests/Titanium.Web.Proxy.IntegrationTests.csproj
+7
-1
TestHelper.cs
...tanium.Web.Proxy.IntegrationTests/Utilities/TestHelper.cs
+19
-0
No files found.
.build/build.ps1
View file @
e4f3e7d5
...
...
@@ -35,7 +35,7 @@ $MSBuild -replace ' ', '` '
FormatTaskName
((
"-"
*
25
)
+
"[{0}]"
+
(
"-"
*
25
))
#default task
Task default -depends Clean, Build, Document, Package
Task default -depends Clean, Build, Document, Package
, PrepareIntegrationTest
#cleans obj, b
Task Clean
{
...
...
@@ -123,3 +123,15 @@ Task Document -depends Build {
Task Package -depends Document
{
exec
{
.
$NuGet
pack
"
$SolutionRoot
\
$ProjectName
\
$ProjectName
.nuspec"
-Properties
Configuration
=
$Configuration
-OutputDirectory
"
$RepoRoot
"
-Version
"
$Version
"
}
}
#install root cetificate needed for integration tests
Task PrepareIntegrationTest
{
$pfx
=
new-object
System.Security.Cryptography.X509Certificates.X509Certificate2
$certPath
=
"
$Here
\lib\root-certificate-for-integration-test.pfx"
$pfxPass
=
""
$pfx
.import
(
$certPath
,
$pfxPass
,
"Exportable,PersistKeySet"
)
$store
=
new-object
System.Security.Cryptography.X509Certificates.X509Store
([
System.Security.Cryptography.X509Certificates.StoreName]::Root,
"localmachine"
)
$store
.open
(
"MaxAllowed"
)
$store
.add
(
$pfx
)
$store
.close
()
}
\ No newline at end of file
tests/Titanium.Web.Proxy.IntegrationTests/InterceptionTests.cs
View file @
e4f3e7d5
using
System
;
using
System.Net
;
using
System.Net.Http
;
using
System.Net.Mime
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.IntegrationTests
{
...
...
@@ -11,36 +12,64 @@ namespace Titanium.Web.Proxy.IntegrationTests
public
class
InterceptionTests
{
[
TestMethod
]
public
void
CanInterceptPost
Requests
()
public
async
Task
Can_Intercept_Post_
Requests
()
{
string
testUrl
=
"http://interceptthis.com"
;
int
proxyPort
=
8086
;
var
proxy
=
new
ProxyTestController
();
proxy
.
StartProxy
(
proxyPort
);
using
(
var
client
=
CreateHttpClient
(
testUrl
,
proxyPort
))
using
(
var
client
=
TestHelper
.
CreateHttpClient
(
testUrl
,
proxyPort
))
{
var
response
=
client
.
PostAsync
(
new
Uri
(
testUrl
),
new
StringContent
(
"hello!"
)).
Result
;
var
response
=
await
client
.
PostAsync
(
new
Uri
(
testUrl
),
new
StringContent
(
"hello!"
))
;
Assert
.
AreEqual
(
HttpStatusCode
.
OK
,
response
.
StatusCode
);
var
body
=
response
.
Content
.
ReadAsStringAsync
().
Result
;
var
body
=
await
response
.
Content
.
ReadAsStringAsync
()
;
Assert
.
IsTrue
(
body
.
Contains
(
"TitaniumWebProxy-Stopped!!"
));
}
}
private
HttpClient
CreateHttpClient
(
string
url
,
int
localProxyPort
)
private
class
ProxyTestController
{
var
handler
=
new
HttpClientHandler
private
readonly
ProxyServer
proxyServer
;
public
ProxyTestController
()
{
Proxy
=
new
WebProxy
(
$"http://localhost:
{
localProxyPort
}
"
,
false
),
UseProxy
=
true
}
;
proxyServer
=
new
ProxyServer
();
proxyServer
.
CertificateManager
.
RootCertificateName
=
"root-certificate-for-integration-test.pfx"
;
}
var
client
=
new
HttpClient
(
handler
);
public
void
StartProxy
(
int
proxyPort
)
{
proxyServer
.
BeforeRequest
+=
OnRequest
;
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
proxyPort
,
true
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
Start
();
}
return
client
;
}
public
void
Stop
()
{
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
Stop
();
proxyServer
.
Dispose
();
}
public
async
Task
OnRequest
(
object
sender
,
SessionEventArgs
e
)
{
if
(
e
.
WebSession
.
Request
.
Url
.
Contains
(
"interceptthis.com"
))
{
if
(
e
.
WebSession
.
Request
.
HasBody
)
{
var
body
=
await
e
.
GetRequestBodyAsString
();
}
e
.
Ok
(
"<html><body>TitaniumWebProxy-Stopped!!</body></html>"
);
return
;
}
await
Task
.
FromResult
(
0
);
}
}
}
}
\ No newline at end of file
tests/Titanium.Web.Proxy.IntegrationTests/ProxyTestController.cs
deleted
100644 → 0
View file @
487ecbdf
using
System
;
using
System.Diagnostics
;
using
System.Net
;
using
System.Net.Security
;
using
System.Threading.Tasks
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.IntegrationTests
{
public
class
ProxyTestController
{
private
readonly
ProxyServer
proxyServer
;
public
ProxyTestController
()
{
proxyServer
=
new
ProxyServer
();
}
public
void
StartProxy
(
int
proxyPort
)
{
proxyServer
.
BeforeRequest
+=
OnRequest
;
proxyServer
.
BeforeResponse
+=
OnResponse
;
proxyServer
.
ServerCertificateValidationCallback
+=
OnCertificateValidation
;
proxyServer
.
ClientCertificateSelectionCallback
+=
OnCertificateSelection
;
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
proxyPort
,
true
);
// An explicit endpoint is where the client knows about the existance of a proxy
// So client sends request in a proxy friendly manner
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
Start
();
foreach
(
var
endPoint
in
proxyServer
.
ProxyEndPoints
)
{
Console
.
WriteLine
(
"Listening on '{0}' endpoint at Ip {1} and port: {2} "
,
endPoint
.
GetType
().
Name
,
endPoint
.
IpAddress
,
endPoint
.
Port
);
}
}
public
void
Stop
()
{
proxyServer
.
BeforeRequest
-=
OnRequest
;
proxyServer
.
BeforeResponse
-=
OnResponse
;
proxyServer
.
ServerCertificateValidationCallback
-=
OnCertificateValidation
;
proxyServer
.
ClientCertificateSelectionCallback
-=
OnCertificateSelection
;
proxyServer
.
Stop
();
}
// intecept & cancel, redirect or update requests
public
async
Task
OnRequest
(
object
sender
,
SessionEventArgs
e
)
{
Debug
.
WriteLine
(
e
.
WebSession
.
Request
.
Url
);
if
(
e
.
WebSession
.
Request
.
Url
.
Contains
(
"interceptthis.com"
))
{
if
(
e
.
WebSession
.
Request
.
HasBody
)
{
var
body
=
await
e
.
GetRequestBodyAsString
();
}
e
.
Ok
(
"<html><body>TitaniumWebProxy-Stopped!!</body></html>"
);
return
;
}
await
Task
.
FromResult
(
0
);
}
// Modify response
public
async
Task
OnResponse
(
object
sender
,
SessionEventArgs
e
)
{
await
Task
.
FromResult
(
0
);
}
/// <summary>
/// Allows overriding default certificate validation logic
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public
Task
OnCertificateValidation
(
object
sender
,
CertificateValidationEventArgs
e
)
{
// set IsValid to true/false based on Certificate Errors
if
(
e
.
SslPolicyErrors
==
SslPolicyErrors
.
None
)
{
e
.
IsValid
=
true
;
}
return
Task
.
FromResult
(
0
);
}
/// <summary>
/// Allows overriding default client certificate selection logic during mutual authentication
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public
Task
OnCertificateSelection
(
object
sender
,
CertificateSelectionEventArgs
e
)
{
// set e.clientCertificate to override
return
Task
.
FromResult
(
0
);
}
}
}
\ No newline at end of file
tests/Titanium.Web.Proxy.IntegrationTests/SslTests.cs
View file @
e4f3e7d5
using
System
;
using
System.Net
;
using
System.Net.Http
;
using
System.Net.Security
;
using
System.Threading.Tasks
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Titanium.Web.Proxy.EventArguments
;
using
Titanium.Web.Proxy.Models
;
namespace
Titanium.Web.Proxy.IntegrationTests
{
[
TestClass
]
public
class
SslTests
{
//[TestMethod]
//disable this test until CI is prepared to handle
public
void
TestSsl
()
[
TestMethod
]
public
async
Task
TestSsl
()
{
// expand this to stress test to find
// why in long run proxy becomes unresponsive as per issue #184
string
testUrl
=
"https://google.com"
;
int
proxyPort
=
8086
;
var
proxy
=
new
ProxyTestController
();
proxy
.
StartProxy
(
proxyPort
);
using
(
var
client
=
CreateHttpClient
(
testUrl
,
proxyPort
))
using
(
var
client
=
TestHelper
.
CreateHttpClient
(
testUrl
,
proxyPort
))
{
var
response
=
client
.
GetAsync
(
new
Uri
(
testUrl
)).
Result
;
var
response
=
await
client
.
GetAsync
(
new
Uri
(
testUrl
))
;
}
}
private
HttpClient
CreateHttpClient
(
string
url
,
int
localProxyPort
)
private
class
ProxyTestController
{
var
handler
=
new
HttpClientHandler
private
readonly
ProxyServer
proxyServer
;
public
ProxyTestController
()
{
Proxy
=
new
WebProxy
(
$"http://localhost:
{
localProxyPort
}
"
,
false
),
UseProxy
=
true
}
;
proxyServer
=
new
ProxyServer
();
proxyServer
.
CertificateManager
.
RootCertificateName
=
"root-certificate-for-integration-test.pfx"
;
}
var
client
=
new
HttpClient
(
handler
);
public
void
StartProxy
(
int
proxyPort
)
{
var
explicitEndPoint
=
new
ExplicitProxyEndPoint
(
IPAddress
.
Any
,
proxyPort
,
true
);
proxyServer
.
AddEndPoint
(
explicitEndPoint
);
proxyServer
.
Start
();
}
public
void
Stop
()
{
proxyServer
.
Stop
();
proxyServer
.
Dispose
();
}
return
client
;
}
}
}
tests/Titanium.Web.Proxy.IntegrationTests/Titanium.Web.Proxy.IntegrationTests.csproj
View file @
e4f3e7d5
...
...
@@ -71,9 +71,9 @@
</Choose>
<ItemGroup>
<Compile
Include=
"InterceptionTests.cs"
/>
<Compile
Include=
"ProxyTestController.cs"
/>
<Compile
Include=
"SslTests.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Utilities\TestHelper.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\..\src\Titanium.Web.Proxy\Titanium.Web.Proxy.csproj"
>
...
...
@@ -81,6 +81,12 @@
<Name>
Titanium.Web.Proxy
</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None
Include=
"..\..\.build\lib\root-certificate-for-integration-test.pfx"
>
<Link>
root-certificate-for-integration-test.pfx
</Link>
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
</ItemGroup>
<Choose>
<When
Condition=
"'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'"
>
<ItemGroup>
...
...
tests/Titanium.Web.Proxy.IntegrationTests/Utilities/TestHelper.cs
0 → 100644
View file @
e4f3e7d5
using
System.Net
;
using
System.Net.Http
;
namespace
Titanium.Web.Proxy.IntegrationTests
{
public
static
class
TestHelper
{
public
static
HttpClient
CreateHttpClient
(
string
url
,
int
localProxyPort
)
{
var
handler
=
new
HttpClientHandler
{
Proxy
=
new
WebProxy
(
$"http://localhost:
{
localProxyPort
}
"
,
false
),
UseProxy
=
true
};
return
new
HttpClient
(
handler
);
}
}
}
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