Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,7 @@ internal static AuthenticationEventMetadata GetEventAndValidateSchema(string bod
{
try
{
if (!Helpers.IsJson(body))
{
throw new RequestValidationException(AuthenticationEventResource.Ex_Invalid_JsonPayload);
}
Helpers.ValidateJson(body);
}
catch (JsonException ex)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<data name="Ex_Context_Null" xml:space="preserve">
<value>ListenerFactoryContext is null</value>
</data>
<data name="Ex_Empty_Json" xml:space="preserve">
<value>JSON is null or empty.</value>
</data>
<data name="Ex_Event_Missing" xml:space="preserve">
<value>Cannot determine the event from payload, please check that the incoming payload is a valid JSON string and contains the event type.</value>
</data>
Expand Down Expand Up @@ -160,7 +163,7 @@
<value>Response validation failed, see inner exceptions.</value>
</data>
<data name="Ex_Invalid_Return" xml:space="preserve">
<value>Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return.</value>
<value>Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return</value>
</data>
<data name="Ex_Invalid_SchemaVersion" xml:space="preserve">
<value>Invalid version on Schema</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,7 @@ internal static AuthenticationEventJsonElement GetJsonObjectFromString(string re
{
try
{
if (!Helpers.IsJson(result))
{
throw new ResponseValidationException(AuthenticationEventResource.Ex_Invalid_Return);
}
Helpers.ValidateJson(result);
}
catch (JsonException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,16 @@ internal static HttpResponseMessage HttpJsonResponse(AuthenticationEventJsonElem

/// <summary>Determines whether the specified input is json.</summary>
/// <param name="input">The input.</param>
/// <returns>
/// <c>true</c> if the specified input is json; otherwise, <c>false</c>.</returns>
internal static bool IsJson(string input)
internal static void ValidateJson(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
throw new JsonException(AuthenticationEventResource.Ex_Empty_Json);
}

// try parsing input to json object
using var _ = JsonDocument.Parse(input);
return true;
}
// try parsing input to json object
using var _ = JsonDocument.Parse(input);
}

internal static AuthenticationEventAction GetEventActionForActionType(string actionType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static IEnumerable<object[]> TestPayloadScenarios()
{
Test = string.Empty,
Message = "Testing request without payload throws an error",
ExceptionMessage = "Invalid Json Payload"
ExceptionMessage = "Invalid Json Payload: JSON is null or empty."
}.ToArray;
yield return new TestCaseStructure()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public async Task Tests(TestTypes testType)
case TestTypes.NoAction:
return (Payloads.TokenIssuanceStart.TokenIssuanceStart.NoActionResponse, @"{'errors':['No Actions Found. Please supply atleast one action.']}", HttpStatusCode.InternalServerError);
case TestTypes.Empty:
return (string.Empty, @"{'errors':['Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return.']}", HttpStatusCode.InternalServerError);
return (string.Empty, @"{'errors':['Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return: JSON is null or empty.']}", HttpStatusCode.InternalServerError);
case TestTypes.ValidCloudEvent:
return (Payloads.TokenIssuanceStart.TokenIssuanceStart.ActionResponse, Payloads.TokenIssuanceStart.TokenIssuanceStart.ExpectedPayload, HttpStatusCode.OK);
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"errors": [ "Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return." ]
"errors": [ "Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return" ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private object GetResponseTypeObject(ResponseTypes responseType, StreamWriter st
case ResponseTypes.AuthEventResponse:
return (code: HttpStatusCode.OK, Payloads.TokenIssuanceStart.TokenIssuanceStart.ActionResponse);
case ResponseTypes.Unknown:
return (code: HttpStatusCode.InternalServerError, @"{'errors':['Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return.']}");
return (code: HttpStatusCode.InternalServerError, @"{'errors':['Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return']}");
default:
return (code: HttpStatusCode.BadRequest, string.Empty);
};
Expand Down