Skip to content

Commit 4c05d57

Browse files
authored
[ADMINAPI-1314] - POST to profile with line breaks returns 400 with nice description (#377)
* POST to profile with line breaks returns 400 with nice description * Remove e2e test added * Adds http file for Profiles
1 parent 6443d40 commit 4c05d57

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

Application/EdFi.Ods.AdminApi/Features/RequestLoggingMiddleware.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,22 @@ public async Task Invoke(HttpContext context)
180180
await response.WriteAsync(JsonSerializer.Serialize(new { message = message }));
181181
break;
182182

183+
case BadHttpRequestException:
184+
_logger.Error(
185+
JsonSerializer.Serialize(
186+
new
187+
{
188+
message = "The request body contains malformed JSON. Please ensure your data is properly formatted and try again.",
189+
error = new { ex.Message, ex.StackTrace },
190+
traceId = context.TraceIdentifier
191+
}
192+
),
193+
ex
194+
);
195+
response.StatusCode = (int)HttpStatusCode.BadRequest;
196+
await response.WriteAsync(JsonSerializer.Serialize(new { message = "The request body contains malformed JSON. Please ensure your data is properly formatted and try again." }));
197+
break;
198+
183199
default:
184200
_logger.Error(
185201
JsonSerializer.Serialize(

docs/http/profiles.http

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# This file is intended for use with Admin API 2 running in multi-tenant mode,
2+
# along with ODS/API 7.x in multi-tenant mode. It assumes there are two
3+
# different tenants named "tenant1" and "tenant2". Each has only one ODS
4+
# instance.
5+
6+
@adminapi_url=https://localhost:7214
7+
# @adminapi_url=https://localhost/adminapi
8+
9+
@adminapi_client=adminapi_client2
10+
@adminapi_secret=adminapi_SECRET_2025_rftyguhijkotgyhuijok
11+
12+
### Register a new client
13+
POST {{adminapi_url}}/connect/register
14+
Content-Type: application/x-www-form-urlencoded
15+
Tenant: tenant2
16+
17+
ClientId={{adminapi_client}}&ClientSecret={{adminapi_secret}}&DisplayName=Admin+API+{{adminapi_client}}
18+
19+
### Get a token
20+
# @name tokenRequest
21+
POST {{adminapi_url}}/connect/token
22+
Content-Type: application/x-www-form-urlencoded
23+
Authorization: basic {{adminapi_client}}:{{adminapi_secret}}
24+
Tenant: tenant2
25+
26+
grant_type=client_credentials&scope=edfi_admin_api/full_access
27+
28+
###
29+
@token={{tokenRequest.response.body.access_token}}
30+
31+
32+
### Get profiles
33+
GET {{adminapi_url}}/v2/profiles
34+
Content-Type: application/json
35+
Authorization: bearer {{token}}
36+
37+
### Create profile 1
38+
POST {{adminapi_url}}/v2/profiles
39+
Content-Type: application/json
40+
Authorization: bearer {{token}}
41+
42+
{
43+
"name": "profile1",
44+
"definition": "<Profile name=\"profile1\">
45+
<Resource name=\"School\">
46+
<ReadContentType memberSelection=\"ExcludeOnly\">
47+
<Property name=\"NameOfInstitution\" />
48+
<Property name=\"OperationalStatusDescriptor\" />
49+
<Property name=\"CharterApprovalSchoolYearTypeReference\" />
50+
<Property name=\"SchoolType\" />
51+
<Property name=\"AdministrativeFundingControlDescriptor\" />
52+
<Collection name=\"EducationOrganizationAddresses\" memberSelection=\"IncludeAll\" />
53+
<Collection name=\"SchoolCategories\" memberSelection=\"IncludeAll\" />
54+
</ReadContentType>
55+
</Resource>
56+
</Profile>"
57+
}
58+
59+
# Given the line breaks it should return 400 with a descriptive error message:
60+
# {
61+
# "message": "The request body contains malformed JSON. Please ensure your data is properly formatted and try again."
62+
# }
63+
64+
65+
### Create profile 2
66+
POST {{adminapi_url}}/v2/profiles
67+
Content-Type: application/json
68+
Authorization: bearer {{token}}
69+
70+
{
71+
"name": "profile1",
72+
"definition": "<Profile name=\"profile1\"><Resource name=\"School\"><ReadContentType memberSelection=\"ExcludeOnly\"><Property name=\"NameOfInstitution\" /><Property name=\"OperationalStatusDescriptor\" /> <Property name=\"CharterApprovalSchoolYearTypeReference\" /><Property name=\"SchoolType\" /><Property name=\"AdministrativeFundingControlDescriptor\" /><Collection name=\"EducationOrganizationAddresses\" memberSelection=\"IncludeAll\" /><Collection name=\"SchoolCategories\" memberSelection=\"IncludeAll\" /></ReadContentType></Resource></Profile>"
73+
}
74+
75+

0 commit comments

Comments
 (0)