Skip to content

Commit

Permalink
Added tests for the HTTP Server Security feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
silvioprog committed Jun 4, 2019
1 parent d0d0c59 commit 4557106
Show file tree
Hide file tree
Showing 5 changed files with 445 additions and 12 deletions.
18 changes: 15 additions & 3 deletions Test/AllTests.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<Projects Include="Test_HTTPResponse.dproj">
<Dependencies/>
</Projects>
<Projects Include="Test_HTTPServer.dproj">
<Dependencies/>
</Projects>
<Projects Include="Test_HTTPUploads.dproj">
<Dependencies/>
</Projects>
Expand Down Expand Up @@ -71,6 +74,15 @@
<Target Name="Test_HTTPResponse:Make">
<MSBuild Projects="Test_HTTPResponse.dproj" Targets="Make"/>
</Target>
<Target Name="Test_HTTPServer">
<MSBuild Projects="Test_HTTPServer.dproj"/>
</Target>
<Target Name="Test_HTTPServer:Clean">
<MSBuild Projects="Test_HTTPServer.dproj" Targets="Clean"/>
</Target>
<Target Name="Test_HTTPServer:Make">
<MSBuild Projects="Test_HTTPServer.dproj" Targets="Make"/>
</Target>
<Target Name="Test_HTTPUploads">
<MSBuild Projects="Test_HTTPUploads.dproj"/>
</Target>
Expand Down Expand Up @@ -144,13 +156,13 @@
<MSBuild Projects="Test_Utility.dproj" Targets="Make"/>
</Target>
<Target Name="Build">
<CallTarget Targets="Test_HTTPAuthentication;Test_HTTPRequest;Test_HTTPResponse;Test_HTTPUploads;Test_LibraryLoader;Test_libsagui;Test_MediaTypes;Test_Reader;Test_String;Test_StringMap;Test_Utility"/>
<CallTarget Targets="Test_HTTPAuthentication;Test_HTTPRequest;Test_HTTPResponse;Test_HTTPServer;Test_HTTPUploads;Test_LibraryLoader;Test_libsagui;Test_MediaTypes;Test_Reader;Test_String;Test_StringMap;Test_Utility"/>
</Target>
<Target Name="Clean">
<CallTarget Targets="Test_HTTPAuthentication:Clean;Test_HTTPRequest:Clean;Test_HTTPResponse:Clean;Test_HTTPUploads:Clean;Test_LibraryLoader:Clean;Test_libsagui:Clean;Test_MediaTypes:Clean;Test_Reader:Clean;Test_String:Clean;Test_StringMap:Clean;Test_Utility:Clean"/>
<CallTarget Targets="Test_HTTPAuthentication:Clean;Test_HTTPRequest:Clean;Test_HTTPResponse:Clean;Test_HTTPServer:Clean;Test_HTTPUploads:Clean;Test_LibraryLoader:Clean;Test_libsagui:Clean;Test_MediaTypes:Clean;Test_Reader:Clean;Test_String:Clean;Test_StringMap:Clean;Test_Utility:Clean"/>
</Target>
<Target Name="Make">
<CallTarget Targets="Test_HTTPAuthentication:Make;Test_HTTPRequest:Make;Test_HTTPResponse:Make;Test_HTTPUploads:Make;Test_LibraryLoader:Make;Test_libsagui:Make;Test_MediaTypes:Make;Test_Reader:Make;Test_String:Make;Test_StringMap:Make;Test_Utility:Make"/>
<CallTarget Targets="Test_HTTPAuthentication:Make;Test_HTTPRequest:Make;Test_HTTPResponse:Make;Test_HTTPServer:Make;Test_HTTPUploads:Make;Test_LibraryLoader:Make;Test_libsagui:Make;Test_MediaTypes:Make;Test_Reader:Make;Test_String:Make;Test_StringMap:Make;Test_Utility:Make"/>
</Target>
<Import Project="$(BDS)\Bin\CodeGear.Group.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Group.Targets')"/>
</Project>
22 changes: 13 additions & 9 deletions Test/AllTests.lpg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectGroup FileVersion="1">
<Targets Count="11">
<Targets Count="12">
<Target0 FileName="Test_HTTPAuthentication.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
Expand All @@ -14,38 +14,42 @@
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target2>
<Target3 FileName="Test_HTTPUploads.lpi">
<Target3 FileName="Test_HTTPServer.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target3>
<Target4 FileName="Test_LibraryLoader.lpi">
<Target4 FileName="Test_HTTPUploads.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target4>
<Target5 FileName="Test_libsagui.lpi">
<Target5 FileName="Test_LibraryLoader.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target5>
<Target6 FileName="Test_MediaTypes.lpi">
<Target6 FileName="Test_libsagui.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target6>
<Target7 FileName="Test_Reader.lpi">
<Target7 FileName="Test_MediaTypes.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target7>
<Target8 FileName="Test_String.lpi">
<Target8 FileName="Test_Reader.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target8>
<Target9 FileName="Test_StringMap.lpi">
<Target9 FileName="Test_String.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target9>
<Target10 FileName="Test_Utility.lpi">
<Target10 FileName="Test_StringMap.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target10>
<Target11 FileName="Test_Utility.lpi">
<BuildModes Count="1"/>
<Mode1 Name="Default"/>
</Target11>
</Targets>
</ProjectGroup>
</CONFIG>
229 changes: 229 additions & 0 deletions Test/Test_HTTPServer.dpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
(* _ _
* | |__ _ __ ___ ___ | | __
* | '_ \| '__/ _ \ / _ \| |/ /
* | |_) | | | (_) | (_) | <
* |_.__/|_| \___/ \___/|_|\_\
*
* Microframework which helps to develop web Pascal applications.
*
* Copyright (c) 2012-2019 Silvio Clecio <[email protected]>
*
* This file is part of Brook framework.
*
* Brook framework is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any laterbroo version.
*
* Brook framework is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Brook framework. If not, see <http://www.gnu.org/licenses/>.
*)

program Test_HTTPServer;

{$I Tests.inc}

uses
SysUtils,
{$IFDEF VER3_0_0}
FPC300Fixes,
{$ENDIF}
BrookLibraryLoader,
BrookHTTPServer,
Test;

procedure Test_HTTPServerSecurityAssign;
var
S, D: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
D := TBrookHTTPServerSecurity.Create;
try
Assert(D.PrivateKey.IsEmpty);
Assert(D.PrivatePassword.IsEmpty);
Assert(D.Certificate.IsEmpty);
Assert(D.Trust.IsEmpty);
Assert(D.DHParams.IsEmpty);
S.PrivateKey := 'fake_pkey';
S.PrivatePassword := 'fake_ppass';
S.Certificate := 'fake_cert';
S.Trust := 'fake_trust';
S.DHParams := 'fake_dhparams';
D.Assign(S);
Assert(D.PrivateKey = 'fake_pkey');
Assert(D.PrivatePassword = 'fake_ppass');
Assert(D.Certificate = 'fake_cert');
Assert(D.Trust = 'fake_trust');
Assert(D.DHParams = 'fake_dhparams');
finally
S.Free;
D.Free;
end;
end;

procedure Test_HTTPServerSecurityClear;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
S.Active := True;
S.PrivateKey := 'fake_pkey';
S.PrivatePassword := 'fake_ppass';
S.Certificate := 'fake_cert';
S.Trust := 'fake_trust';
S.DHParams := 'fake_dhparams';
Assert(S.Active);
Assert(not S.PrivateKey.IsEmpty);
Assert(not S.PrivatePassword.IsEmpty);
Assert(not S.Certificate.IsEmpty);
Assert(not S.Trust.IsEmpty);
Assert(not S.DHParams.IsEmpty);
S.Clear;
Assert(not S.Active);
Assert(S.PrivateKey.IsEmpty);
Assert(S.PrivatePassword.IsEmpty);
Assert(S.Certificate.IsEmpty);
Assert(S.Trust.IsEmpty);
Assert(S.DHParams.IsEmpty);
finally
S.Free;
end;
end;

procedure DoHTTPServerSecurityValidateError(const AArgs: array of const);
begin
TBrookHTTPServerSecurity(AArgs[0].VObject).Validate;
end;

procedure Test_HTTPServerSecurityValidate;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
S.PrivateKey := 'fake_pkey';
S.Certificate := 'fake_cert';
Assert(not S.PrivateKey.IsEmpty);
Assert(not S.Certificate.IsEmpty);

S.PrivateKey := '';
AssertExcept(DoHTTPServerSecurityValidateError, EBrookHTTPServerSecurity,
SBrookEmptyPrivateKey, [S]);
S.PrivateKey := 'fake_pkey';
S.Certificate := '';
AssertExcept(DoHTTPServerSecurityValidateError, EBrookHTTPServerSecurity,
SBrookEmptyCertificate, [S]);
finally
S.Free;
end;
end;

procedure Test_HTTPServerSecurityActive;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
Assert(not S.Active);
S.Active := not S.Active;
Assert(S.Active);
finally
S.Free;
end;
end;

procedure Test_HTTPServerSecurityPrivateKey;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
Assert(S.PrivateKey.IsEmpty);
S.PrivateKey := 'fake_pkey';
Assert(S.PrivateKey = 'fake_pkey');
finally
S.Free;
end;
end;

procedure Test_HTTPServerSecurityPrivatePassword;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
Assert(S.PrivatePassword.IsEmpty);
S.PrivatePassword := 'fake_ppass';
Assert(S.PrivatePassword = 'fake_ppass');
finally
S.Free;
end;
end;

procedure Test_HTTPServerSecurityCertificate;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
Assert(S.Certificate.IsEmpty);
S.Certificate := 'fake_cert';
Assert(S.Certificate = 'fake_cert');
finally
S.Free;
end;
end;

procedure Test_HTTPServerSecurityTrust;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
Assert(S.Trust.IsEmpty);
S.Trust := 'fake_trust';
Assert(S.Trust = 'fake_trust');
finally
S.Free;
end;
end;

procedure Test_HTTPServerSecurityDHParams;
var
S: TBrookHTTPServerSecurity;
begin
S := TBrookHTTPServerSecurity.Create;
try
Assert(S.DHParams.IsEmpty);
S.DHParams := 'fake_dhparams';
Assert(S.DHParams = 'fake_dhparams');
finally
S.Free;
end;
end;

begin
{$IF (NOT DEFINED(FPC)) AND DEFINED(DEBUG)}
ReportMemoryLeaksOnShutdown := True;
{$ENDIF}
TBrookLibraryLoader.Load;
try
Test_HTTPServerSecurityAssign;
Test_HTTPServerSecurityClear;
Test_HTTPServerSecurityValidate;
Test_HTTPServerSecurityActive;
Test_HTTPServerSecurityPrivateKey;
Test_HTTPServerSecurityPrivatePassword;
Test_HTTPServerSecurityCertificate;
Test_HTTPServerSecurityTrust;
Test_HTTPServerSecurityDHParams;
finally
TBrookLibraryLoader.Unload;
end;
end.
Loading

0 comments on commit 4557106

Please sign in to comment.