Skip to content

Commit b6ca196

Browse files
committed
Add apex-test-suite auto pulling and config travis CI
1 parent 509a483 commit b6ca196

File tree

4 files changed

+85
-39
lines changed

4 files changed

+85
-39
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
language : csharp
22
solution : ApiSecuritySolution.sln
3+
install:
4+
- nuget restore ApiSecuritySolution.sln
5+
- nuget install NUnit.Runners -Version 3.9.0 -OutputDirectory testrunner
6+
script:
7+
- xbuild /p:Configuration=Release ApiSecuritySolution.sln
8+
- mono ./testrunner/NUnit.Runners.3.9.0/tools/nunit-console.exe ./ApiUtilLibTest/bin/Debug/ApexUtilLibTest.dll
Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,33 @@
11
<Properties StartupConfiguration="{B6FD94F7-1689-4DAC-B823-0192E3CA3521}|Unit Tests">
2-
<MonoDevelop.Ide.Workbench ActiveDocument="ApiUtilLib/ApiAuthorization.cs">
2+
<MonoDevelop.Ide.Workbench ActiveDocument="ApiUtilLibTest/BaseService.cs">
33
<Files>
4-
<File FileName="ApiUtilLibTest/TestDataTest.cs" Line="287" Column="1" />
5-
<File FileName="ApiUtilLibTest/L1SignatureTest.cs" Line="23" Column="72" />
6-
<File FileName="ApiUtilLib/ApiAuthorization.cs" Line="120" Column="13" />
7-
<File FileName="ApiUtilLibTest/CommonExtensions.cs" Line="121" Column="26" />
8-
<File FileName="ApiUtilLibTest/BaseService.cs" Line="122" Column="1" />
9-
<File FileName="ApiUtilLibTest/L2SignatureTest.cs" Line="37" Column="74" />
10-
<File FileName="development Status" />
4+
<File FileName="ApiUtilLibTest/TestDataService.cs" Line="25" Column="10" />
5+
<File FileName="ApiUtilLibTest/BaseService.cs" Line="22" Column="48" />
6+
<File FileName="ApiUtilLibTest/TestDataTest.cs" Line="8" Column="1" />
117
</Files>
128
<Pads>
13-
<Pad Id="ProjectPad">
14-
<State name="__root__">
15-
<Node name="ApiSecuritySolution" expanded="True">
16-
<Node name="ApiUtilLib" expanded="True">
17-
<Node name="ApiAuthorization.cs" selected="True" />
18-
</Node>
19-
<Node name="ApiUtilLibTest" expanded="True" />
20-
</Node>
21-
</State>
22-
</Pad>
239
<Pad Id="MonoDevelop.UnitTesting.TestPad">
2410
<State name="__root__">
25-
<Node name="ApiSecuritySolution" expanded="True">
11+
<Node name="ApiSecuritySolution" expanded="True" selected="True">
2612
<Node name="ApiUtilLibTest" expanded="True">
2713
<Node name="ApexUtilLibTest" expanded="True">
28-
<Node name="TestDataTest" expanded="True">
29-
<Node name="GetL2Signature" selected="True" />
30-
</Node>
14+
<Node name="TestDataTest" expanded="True" />
15+
</Node>
16+
<Node name="ApiUtilLibTest" expanded="True">
17+
<Node name="L1SignatureTest" expanded="True" />
18+
<Node name="L2SignatureTest" expanded="True" />
3119
</Node>
3220
</Node>
3321
</Node>
3422
</State>
3523
</Pad>
3624
</Pads>
3725
</MonoDevelop.Ide.Workbench>
26+
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
27+
<MonoDevelop.Ide.ItemProperties.ApiUtilLibTest PreferredExecutionTarget="MonoDevelop.Default" />
3828
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
3929
<MonoDevelop.Ide.DebuggingService.Breakpoints>
40-
<BreakpointStore>
41-
<Breakpoint file="/Users/nsearch/OneDrive/Projects/APEXCSharp/development/ApiUtilLib/ApiAuthorization.cs" relfile="ApiUtilLib/ApiAuthorization.cs" line="196" column="1" />
42-
<Breakpoint file="/Users/nsearch/OneDrive/Projects/APEXCSharp/development/ApiUtilLib/ApiAuthorization.cs" relfile="ApiUtilLib/ApiAuthorization.cs" line="179" column="1" />
43-
<Breakpoint file="/Users/nsearch/OneDrive/Projects/APEXCSharp/development/ApiUtilLibTest/TestDataTest.cs" relfile="ApiUtilLibTest/TestDataTest.cs" line="241" column="1" />
44-
<Breakpoint file="/Users/nsearch/OneDrive/Projects/APEXCSharp/development/ApiUtilLibTest/TestDataTest.cs" relfile="ApiUtilLibTest/TestDataTest.cs" line="281" column="1" />
45-
<Breakpoint file="/Users/nsearch/OneDrive/Projects/APEXCSharp/development/ApiUtilLibTest/TestDataTest.cs" relfile="ApiUtilLibTest/TestDataTest.cs" line="285" column="1" />
46-
</BreakpointStore>
30+
<BreakpointStore />
4731
</MonoDevelop.Ide.DebuggingService.Breakpoints>
48-
<MonoDevelop.Ide.DebuggingService.PinnedWatches />
49-
<MonoDevelop.Ide.ItemProperties.ApiUtilLibTest PreferredExecutionTarget="MonoDevelop.Default" />
5032
<MultiItemStartupConfigurations />
5133
</Properties>

ApiUtilLibTest/ApiUtilLibTest.csproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\NUnit.3.10.1\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.10.1\build\NUnit.props')" />
3+
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
44
<PropertyGroup>
55
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -28,13 +28,15 @@
2828
</PropertyGroup>
2929
<ItemGroup>
3030
<Reference Include="System" />
31+
<Reference Include="Microsoft.CSharp" />
3132
<Reference Include="Newtonsoft.Json">
32-
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
33+
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
3334
</Reference>
34-
<Reference Include="Microsoft.CSharp" />
3535
<Reference Include="nunit.framework">
36-
<HintPath>..\packages\NUnit.3.10.1\lib\net45\nunit.framework.dll</HintPath>
36+
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
3737
</Reference>
38+
<Reference Include="System.IO.Compression" />
39+
<Reference Include="System.IO.Compression.FileSystem" />
3840
</ItemGroup>
3941
<ItemGroup>
4042
<Compile Include="BaseStringTest.cs" />

ApiUtilLibTest/BaseService.cs

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
using ApexUtilLib;
1+
using ApexUtilLib;
22
using ApiUtilLib;
33
using System;
44
using System.Collections.Generic;
55
using System.IO;
66
using System.Security.Cryptography;
77
using System.Text;
8+
using System.IO.Compression;
9+
using System.Reflection;
810

911
namespace ApexUtilLibTest
1012
{
1113
public class BaseService
1214
{
13-
internal string testDataPath = @"/Users/nsearch/OneDrive/Projects/GovTech/testData/";
14-
internal string testCertPath = @"/Users/nsearch/OneDrive/Projects/GovTech/";
15+
internal string apexTestSuitePath = "https://github.com/GovTechSG/test-suites-apex-api-security/archive/master.zip";
16+
internal string testDataPath = GetLocalPath("temp/test-suites-apex-api-security-master/testData/");
17+
internal string testCertPath = GetLocalPath("temp/test-suites-apex-api-security-master/");
1518

1619
internal ApiUtilLib.SignatureMethod signatureMethod { get; set; }
1720
internal ApiUtilLib.HttpMethod httpMethod { get; set; }
@@ -33,6 +36,59 @@ public class BaseService
3336

3437
public BaseService()
3538
{
39+
downloadFile(apexTestSuitePath, GetLocalPath("testSuite.zip"));
40+
}
41+
42+
43+
44+
internal static string GetLocalPath(string relativeFileName)
45+
{
46+
var localPath = Path.Combine(Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath), relativeFileName.Replace('/', Path.DirectorySeparatorChar));
47+
return localPath;
48+
}
49+
internal void downloadFile(string sourceURL, string downloadPath)
50+
{
51+
try
52+
{
53+
long fileSize = 0;
54+
int bufferSize = 1024;
55+
bufferSize *= 1000;
56+
long existLen = 0;
57+
System.IO.FileStream saveFileStream;
58+
saveFileStream = new System.IO.FileStream(downloadPath,
59+
System.IO.FileMode.Create,
60+
System.IO.FileAccess.Write,
61+
System.IO.FileShare.ReadWrite);
62+
63+
System.Net.HttpWebRequest httpReq;
64+
System.Net.HttpWebResponse httpRes;
65+
httpReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(sourceURL);
66+
httpReq.AddRange((int)existLen);
67+
System.IO.Stream resStream;
68+
httpRes = (System.Net.HttpWebResponse)httpReq.GetResponse();
69+
resStream = httpRes.GetResponseStream();
70+
71+
fileSize = httpRes.ContentLength;
72+
int byteSize;
73+
byte[] downBuffer = new byte[bufferSize];
74+
75+
while ((byteSize = resStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
76+
{
77+
saveFileStream.Write(downBuffer, 0, byteSize);
78+
}
79+
saveFileStream.Close();
80+
81+
if (System.IO.Directory.Exists(GetLocalPath("temp/")))
82+
{
83+
Directory.Delete(GetLocalPath("temp/"), true);
84+
}
85+
ZipFile.ExtractToDirectory(downloadPath, GetLocalPath("temp/"));
86+
}
87+
catch (Exception ex)
88+
{
89+
Console.WriteLine("Exception: " + ex);
90+
throw ex;
91+
}
3692
}
3793

3894
internal void SetDetaultParams(TestParam paramFile)
@@ -109,7 +165,7 @@ internal void SetApiList(Dictionary<object, object> data = null)
109165
}
110166
}
111167

112-
internal IEnumerable<TestParam>
168+
internal IEnumerable<TestParam>
113169
GetJsonFile(string fileName)
114170
{
115171
string path = testDataPath + fileName;

0 commit comments

Comments
 (0)