Skip to content

Commit c4413cb

Browse files
Fix wrong path for api objects on Azure. Add unit test for that case. (#606)
* Add new test for Azure httphandler and API object. * Fix url casing for the test in order to reproduce error 500. * Add the fix made at #607 but keeping the conditional operator OR. (cherry picked from commit c1c90c3)
1 parent 0737022 commit c4413cb

File tree

8 files changed

+369
-1
lines changed

8 files changed

+369
-1
lines changed

dotnet/DotNetStandardClasses.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestMockDBAccess", "src\ext
200200
EndProject
201201
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GeneXus.Programs.Common", "src\extensions\Azure\test\GeneXus.Programs.Common\GeneXus.Programs.Common.csproj", "{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163}"
202202
EndProject
203+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "apiattractions", "src\extensions\Azure\test\apiattractions\apiattractions.csproj", "{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}"
204+
EndProject
203205
Global
204206
GlobalSection(SolutionConfigurationPlatforms) = preSolution
205207
Debug|Any CPU = Debug|Any CPU
@@ -486,6 +488,10 @@ Global
486488
{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163}.Debug|Any CPU.Build.0 = Debug|Any CPU
487489
{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163}.Release|Any CPU.ActiveCfg = Release|Any CPU
488490
{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163}.Release|Any CPU.Build.0 = Release|Any CPU
491+
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
492+
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
493+
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
494+
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3}.Release|Any CPU.Build.0 = Release|Any CPU
489495
EndGlobalSection
490496
GlobalSection(SolutionProperties) = preSolution
491497
HideSolutionNode = FALSE
@@ -582,6 +588,7 @@ Global
582588
{C16BD5A9-4412-4B91-BB70-5C88B7AAE675} = {5045873B-E7CF-4317-94C1-0EF8623D23FA}
583589
{B01A243D-C012-4BEB-BAA9-E1D9AC1468C8} = {C16BD5A9-4412-4B91-BB70-5C88B7AAE675}
584590
{DCEC0B38-93B6-4003-81E6-9FBC2BB4F163} = {7BA5A2CE-7992-4F87-9D84-91AE4D046F5A}
591+
{E85FDB0F-FA81-4CDD-8BF3-865269CE2DB3} = {7BA5A2CE-7992-4F87-9D84-91AE4D046F5A}
585592
EndGlobalSection
586593
GlobalSection(ExtensibilityGlobals) = postSolution
587594
SolutionGuid = {E18684C9-7D76-45CD-BF24-E3944B7F174C}

dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRouting.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ public Task ProcessRestRequest(HttpContext context)
188188

189189
string path = context.Request.Path.ToString();
190190
string actualPath = string.Empty;
191-
if (path.Contains($"/{restBaseURL}") || ServiceInPath(path, out actualPath) || (AzureRuntime && path.Contains(oauthRoute)))
191+
bool isServiceInPath = ServiceInPath(path, out actualPath);
192+
if (path.Contains($"/{restBaseURL}") || isServiceInPath || (AzureRuntime && path.Contains(oauthRoute)))
192193
{
193194
string controllerWithParms = string.Empty;
194195
if (!AzureRuntime)

dotnet/src/extensions/Azure/test/AzureFunctionsTest/AzureFunctionsTest.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<ItemGroup>
2020
<ProjectReference Include="..\..\Handlers\GeneXus.Deploy.AzureFunctions.Handlers.csproj" />
2121
<ProjectReference Include="..\amyprocedurehandler\amyprochandler.csproj" />
22+
<ProjectReference Include="..\apiattractions\apiattractions.csproj" />
2223
</ItemGroup>
2324

2425
<ItemGroup>
@@ -31,6 +32,9 @@
3132
<None Update="gxazmappings.json">
3233
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3334
</None>
35+
<None Update="private\apiattractions.grp.json">
36+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
37+
</None>
3438
<None Update="testhost.runtimeconfig.json">
3539
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
3640
</None>

dotnet/src/extensions/Azure/test/AzureFunctionsTest/HttpTriggerTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,42 @@ namespace Extensions.AzureFunctions.Test
1818
{
1919
public class HttpTriggerTest
2020
{
21+
[Fact]
22+
public void HttpApiObjectTest()
23+
{
24+
try
25+
{
26+
ServiceCollection serviceCollection = new ServiceCollection();
27+
serviceCollection.AddScoped<ILoggerFactory, LoggerFactory>();
28+
ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
29+
30+
Mock<FunctionContext> context = new Mock<FunctionContext>();
31+
context.SetupProperty(c => c.InstanceServices, serviceProvider);
32+
33+
context.SetupGet(c => c.FunctionId).Returns("6202c88748614a51851a40fa6a4366e6");
34+
context.SetupGet(c => c.FunctionDefinition.Name).Returns("listattractions");
35+
context.SetupGet(c => c.InvocationId).Returns("6a871dbc3cb74a9fa95f05ae63505c2c");
36+
37+
MockHttpRequestData request = new MockHttpRequestData(
38+
context.Object,
39+
new Uri("http://localhost/APIAttractions/ListAttractions"));
40+
41+
HttpTriggerHandler function = new HttpTriggerHandler(new GXRouting(String.Empty), null);
42+
HttpResponseData response = function.Run(request, context.Object);
43+
Assert.NotNull(response);
44+
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
45+
response.Body.Seek(0, SeekOrigin.Begin);
46+
StreamReader reader = new StreamReader(response.Body);
47+
string responseBody = reader.ReadToEnd();
48+
Assert.NotEmpty(responseBody);
49+
50+
}
51+
catch (Exception ex)
52+
{
53+
throw new Exception("Exception should not be thrown.", ex);
54+
}
55+
56+
}
2157
[Fact]
2258
public void HttpTest()
2359
{

dotnet/src/extensions/Azure/test/AzureFunctionsTest/private/apiattractions.grp.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"ObjectType":"ServiceGroup",
3+
"Name":"APIAttractions",
4+
"BasePath":"APIAttractions",
5+
"Mappings":
6+
[
7+
{
8+
"Name":"listattractions",
9+
"Bodystyle":"Wrapped",
10+
"VariableAlias": [],
11+
"ServiceMethod":"gxep_listattractions",
12+
"Implementation":"AttractionsDP",
13+
"Verb":"GET",
14+
"PathRegexp":"listattractions",
15+
"Path":"listattractions"
16+
17+
}]}
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
File: type_SdtAttractionOut_Attraction
3+
Description: AttractionOut
4+
Author: Nemo 🐠 for C# (.NET) version 17.0.10.160814
5+
Program type: Callable routine
6+
Main DBMS:
7+
*/
8+
using System;
9+
using System.Collections;
10+
using GeneXus.Utils;
11+
using GeneXus.Resources;
12+
using GeneXus.Application;
13+
using GeneXus.Metadata;
14+
using GeneXus.Cryptography;
15+
using GeneXus.Encryption;
16+
using GeneXus.Http.Client;
17+
using GeneXus.Http.Server;
18+
using System.Reflection;
19+
using System.Xml.Serialization;
20+
using System.Runtime.Serialization;
21+
22+
23+
namespace GeneXus.Programs
24+
{
25+
[XmlRoot(ElementName="Attraction")]
26+
[XmlType(TypeName="Attraction" , Namespace="TestServerlessGAM" )]
27+
[Serializable]
28+
public class SdtAttractionOut_Attraction : GxUserType
29+
{
30+
public SdtAttractionOut_Attraction( )
31+
{
32+
/* Constructor for serialization */
33+
gxTv_SdtAttractionOut_Attraction_Attractionname = "";
34+
35+
}
36+
37+
public SdtAttractionOut_Attraction(IGxContext context)
38+
{
39+
this.context = context;
40+
initialize();
41+
}
42+
43+
#region Json
44+
private static Hashtable mapper;
45+
public override string JsonMap(string value)
46+
{
47+
if (mapper == null)
48+
{
49+
mapper = new Hashtable();
50+
}
51+
return (string)mapper[value]; ;
52+
}
53+
54+
public override void ToJSON()
55+
{
56+
ToJSON(true) ;
57+
return;
58+
}
59+
60+
public override void ToJSON(bool includeState)
61+
{
62+
AddObjectProperty("AttractionId", gxTpr_Attractionid, false);
63+
64+
65+
AddObjectProperty("AttractionName", gxTpr_Attractionname, false);
66+
67+
return;
68+
}
69+
#endregion
70+
71+
#region Properties
72+
73+
[SoapElement(ElementName="AttractionId")]
74+
[XmlElement(ElementName="AttractionId")]
75+
public short gxTpr_Attractionid
76+
{
77+
get {
78+
return gxTv_SdtAttractionOut_Attraction_Attractionid;
79+
}
80+
set {
81+
gxTv_SdtAttractionOut_Attraction_Attractionid = value;
82+
SetDirty("Attractionid");
83+
}
84+
}
85+
86+
87+
88+
89+
[SoapElement(ElementName="AttractionName")]
90+
[XmlElement(ElementName="AttractionName")]
91+
public string gxTpr_Attractionname
92+
{
93+
get {
94+
return gxTv_SdtAttractionOut_Attraction_Attractionname;
95+
}
96+
set {
97+
gxTv_SdtAttractionOut_Attraction_Attractionname = value;
98+
SetDirty("Attractionname");
99+
}
100+
}
101+
102+
103+
104+
public override bool ShouldSerializeSdtJson()
105+
{
106+
return true;
107+
}
108+
109+
110+
111+
#endregion
112+
113+
#region Initialization
114+
115+
public void initialize( )
116+
{
117+
gxTv_SdtAttractionOut_Attraction_Attractionname = "";
118+
return ;
119+
}
120+
121+
122+
123+
#endregion
124+
125+
#region Declaration
126+
127+
protected short gxTv_SdtAttractionOut_Attraction_Attractionid;
128+
129+
130+
protected string gxTv_SdtAttractionOut_Attraction_Attractionname;
131+
132+
133+
134+
#endregion
135+
}
136+
#region Rest interface
137+
[DataContract(Name=@"Attraction", Namespace="TestServerlessGAM")]
138+
public class SdtAttractionOut_Attraction_RESTInterface : GxGenericCollectionItem<SdtAttractionOut_Attraction>, System.Web.SessionState.IRequiresSessionState
139+
{
140+
public SdtAttractionOut_Attraction_RESTInterface( ) : base()
141+
{
142+
}
143+
144+
public SdtAttractionOut_Attraction_RESTInterface( SdtAttractionOut_Attraction psdt ) : base(psdt)
145+
{
146+
}
147+
148+
#region Rest Properties
149+
[DataMember(Name="AttractionId", Order=0)]
150+
public short gxTpr_Attractionid
151+
{
152+
get {
153+
return sdt.gxTpr_Attractionid;
154+
155+
}
156+
set {
157+
sdt.gxTpr_Attractionid = value;
158+
}
159+
}
160+
161+
[DataMember(Name="AttractionName", Order=1)]
162+
public string gxTpr_Attractionname
163+
{
164+
get {
165+
return StringUtil.RTrim( sdt.gxTpr_Attractionname);
166+
167+
}
168+
set {
169+
sdt.gxTpr_Attractionname = value;
170+
}
171+
}
172+
173+
174+
#endregion
175+
176+
public SdtAttractionOut_Attraction sdt
177+
{
178+
get {
179+
return (SdtAttractionOut_Attraction)Sdt;
180+
}
181+
set {
182+
Sdt = value;
183+
}
184+
}
185+
186+
[OnDeserializing]
187+
void checkSdt( StreamingContext ctx )
188+
{
189+
if ( sdt == null )
190+
{
191+
sdt = new SdtAttractionOut_Attraction() ;
192+
}
193+
}
194+
}
195+
#endregion
196+
}

0 commit comments

Comments
 (0)