Skip to content

Commit

Permalink
https://github.com/danieleteti/delphimvcframework/issues/338
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleteti committed Mar 8, 2020
1 parent ac9f3bc commit ab2c92c
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 18 deletions.
2 changes: 1 addition & 1 deletion sources/MVCFramework.Commons.pas
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ TMVCConstants = record
LAST_AUTHORIZATION_HEADER_VALUE = '__DMVC_LAST_AUTHORIZATION_HEADER_VALUE_';
SSE_RETRY_DEFAULT = 100;
SSE_LAST_EVENT_ID = 'Last-Event-ID';
URL_MAPPED_PARAMS_ALLOWED_CHARS = ' àèéùòì''"@\[\]\{\}\(\)\=;&#\.:!\_\/,%\w\d\x2D\x3A';
URL_MAPPED_PARAMS_ALLOWED_CHARS = ' àèéùòì''"@\[\]\{\}\(\)\=;&#\.:!\_,%\w\d\x2D\x3A';
OneMiB = 1048576;
OneKiB = 1024;
DEFAULT_MAX_REQUEST_SIZE = OneMiB * 5; // 5 MiB
Expand Down
45 changes: 37 additions & 8 deletions unittests/general/Several/FrameworkTestsU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ TTestRouting = class(TObject)
[Test]
procedure TestComplexRoutings;
[Test]
procedure TestIssue338;
[Test]
procedure TestProduceRoutings;
[Test]
procedure TestProduceRoutingsWithExplicitCharset;
Expand Down Expand Up @@ -204,16 +206,13 @@ implementation
MVCFramework.Serializer.Commons,
MVCFramework.HMAC, System.Diagnostics,

{$IF CompilerVersion < 27}

{$IF CompilerVersion < 27}
Data.DBXJSON,

{$ELSE}

{$ELSE}
System.JSON,

{$ENDIF}

{$ENDIF}
TestServerControllerU, System.Classes,
MVCFramework.DuckTyping, System.IOUtils, MVCFramework.SystemJSONUtils,
IdGlobal;
Expand Down Expand Up @@ -440,6 +439,36 @@ procedure TTestRouting.TestComplexRoutings;
end;
end;

procedure TTestRouting.TestIssue338;
var
Params: TMVCRequestParamsTable;
ResponseContentType: string;
ResponseContentEncoding: string;
begin
// https://github.com/danieleteti/delphimvcframework/issues/338
Params := TMVCRequestParamsTable.Create;
try
Params.Clear;
Assert.isTrue(FRouter.ExecuteRouting('/projectid/pictures/imageuuid', httpGET,
'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params,
ResponseContentType, ResponseContentEncoding));
Assert.areEqual('GetImage', FRouter.MethodToCall.Name);
Assert.areEqual(2, Params.Count);
Assert.areEqual('projectid', Params['projectid']);
Assert.areEqual('imageuuid', Params['imageuuid']);

Params.Clear;
Assert.isTrue(FRouter.ExecuteRouting('/projectid', httpGET,
'text/plain', 'text/plain', FControllers, 'text/plain', TMVCMediaType.TEXT_PLAIN, Params,
ResponseContentType, ResponseContentEncoding));
Assert.areEqual('GetProject', FRouter.MethodToCall.Name);
Assert.areEqual(1, Params.Count);
Assert.areEqual('projectid', Params['projectid']);
finally
Params.Free;
end;
end;

// procedure TTestMappers.TestDataSetToJSONArray;
// var
// ds: TClientDataSet;
Expand Down Expand Up @@ -1139,8 +1168,8 @@ procedure TTestRouting.TestReservedIPs;
// this test just tests the IP2Long implementation
for I := low(RESERVED_IPS) to high(RESERVED_IPS) do
begin
Assert.AreEqual(IPv4ToUInt32(RESERVED_IPS[I][1]), IP2Long(RESERVED_IPS[I][1]));
Assert.AreEqual(IPv4ToUInt32(RESERVED_IPS[I][2]), IP2Long(RESERVED_IPS[I][2]));
Assert.areEqual(IPv4ToUInt32(RESERVED_IPS[I][1]), IP2Long(RESERVED_IPS[I][1]));
Assert.areEqual(IPv4ToUInt32(RESERVED_IPS[I][2]), IP2Long(RESERVED_IPS[I][2]));
end;
end;

Expand Down
6 changes: 3 additions & 3 deletions unittests/general/Several/LiveServerTestU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ TServerTest = class(TBaseServerTest)

public
[Test]
[TestCase('request url /fault', '/fault')]
[TestCase('request url /fault2', '/fault2')]
[TestCase('request url /fault', '/exception/fault')]
[TestCase('request url /fault2', '/exception/fault2')]
procedure TestControllerWithExceptionInCreate(const URLSegment: string);

[Test]
Expand Down Expand Up @@ -1537,7 +1537,7 @@ procedure TServerTest.TestTypedString1;
lValues[3] := '"daniele teti"';
lValues[4] := '"daniele" "teti"';
lValues[5] := '"daniele" "teti"!';
lValues[6] := ' _\"daniele" "teti"!/_ ';
lValues[6] := ' _\"daniele" "teti"!_ ';

for s in lValues do
begin
Expand Down
6 changes: 3 additions & 3 deletions unittests/general/Several/RESTAdapterTestsU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Delphi MVC Framework
//
// Copyright (c) 2010-2017 Daniele Teti and the DMVCFramework Team
// Copyright (c) 2010-2020 Daniele Teti and the DMVCFramework Team
//
// https://github.com/danieleteti/delphimvcframework
//
Expand Down Expand Up @@ -69,7 +69,7 @@ interface

[Headers('Accept', 'application/json')]
[Headers('ContentType', 'application/json')]
[RESTResource(HttpGet, '/testconsumejson')]
[RESTResource(HttpGet, '/adapter/testconsumejson')]
function HeadersApplicationJSON: TJSONValue;

[Headers('Accept', 'text/plain')]
Expand All @@ -79,7 +79,7 @@ interface

[Headers('Accept', 'text/plain')]
[Headers('ContentType', 'text/plain')]
[RESTResource(HttpGet, '/testconsumejson')]
[RESTResource(HttpGet, '/adapter/testconsumejson')]
function ApplicationJSONWithTextPlainHeader: IRESTResponse;

end;
Expand Down
24 changes: 21 additions & 3 deletions unittests/general/TestServer/TestServerControllerU.pas
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ TTestServerController = class(TMVCController)
[MVCProduces('text/plain', 'utf-8')]
procedure TestConsumesProducesText;

[MVCPath('/testconsumejson')]
[MVCPath('/adapter/testconsumejson')]
[MVCHTTPMethod([httpGET])]
[MVCConsumes('application/json')]
[MVCProduces('application/json', 'utf-8')]
Expand Down Expand Up @@ -221,6 +221,14 @@ TTestServerController = class(TMVCController)
[MVCHTTPMethod([httpGET])]
[MVCPath('/responses/nocontent')]
procedure TestResponseNoContent;

[MVCHTTPMethod([httpGET])]
[MVCPath('/($projectid)')]
procedure GetProject;

[MVCHTTPMethod([httpGET])]
[MVCPath('/($projectid)/pictures/($imageuuid)')]
procedure GetImage;
end;

[MVCPath('/private')]
Expand All @@ -235,15 +243,15 @@ TTestPrivateServerController = class(TMVCController)
procedure OnlyRole2;
end;

[MVCPath('/fault')]
[MVCPath('/exception/fault')]
TTestFaultController = class(TMVCController)
public
[MVCPath]
procedure NeverExecuted;
constructor Create; override;
end;

[MVCPath('/fault2')]
[MVCPath('/exception/fault2')]
TTestFault2Controller = class(TTestFaultController)
public
[MVCPath]
Expand Down Expand Up @@ -340,6 +348,16 @@ procedure TTestServerController.GenerateCookies;

end;

procedure TTestServerController.GetImage;
begin
// do nothing
end;

procedure TTestServerController.GetProject;
begin
// do nothing
end;

procedure TTestServerController.Login;
begin
if Context.SessionStarted then
Expand Down

0 comments on commit ab2c92c

Please sign in to comment.