From 917e77234a9b12530fe34475927220bf37914d29 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Tue, 25 Jul 2023 09:47:16 -0700 Subject: [PATCH 1/7] Removed xUnit reference now that we are using NUnit tests --- .../Validators/EnumerableItemsNotNullAttribute.cs | 2 +- ....WebJobs.Extensions.AuthenticationEvents.Tests.csproj | 9 --------- .../tests/TestAuthResponse.cs | 1 - 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/Validators/EnumerableItemsNotNullAttribute.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/Validators/EnumerableItemsNotNullAttribute.cs index d88c1b0f84b86..6b40a28d8ae7f 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/Validators/EnumerableItemsNotNullAttribute.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/Validators/EnumerableItemsNotNullAttribute.cs @@ -25,7 +25,7 @@ public override bool IsValid(object value) { return value is not null && value is IEnumerable obj - && !obj.Where(x => x == null).Any(); + && !obj.Any(x => x == null); } } } diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj index a503f1ddaabf9..7aa64202abf1b 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj @@ -30,15 +30,6 @@ - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestAuthResponse.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestAuthResponse.cs index af5386edc19f0..7ee0fca1aaecc 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestAuthResponse.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestAuthResponse.cs @@ -4,7 +4,6 @@ namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests { - internal class TestAuthResponse : AuthenticationEventResponse { internal TestAuthResponse(HttpStatusCode code, string content) From 792663d31c1ee68019a91266b933b20817dbfdb3 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Tue, 25 Jul 2023 10:31:25 -0700 Subject: [PATCH 2/7] removed Update-Snippets.ps1 changes and will rebase --- .../api/Azure.Identity.BrokeredAuthentication.net462.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/sdk/identity/Azure.Identity.BrokeredAuthentication/api/Azure.Identity.BrokeredAuthentication.net462.cs b/sdk/identity/Azure.Identity.BrokeredAuthentication/api/Azure.Identity.BrokeredAuthentication.net462.cs index 9016acddfe994..e981f65bb80bb 100644 --- a/sdk/identity/Azure.Identity.BrokeredAuthentication/api/Azure.Identity.BrokeredAuthentication.net462.cs +++ b/sdk/identity/Azure.Identity.BrokeredAuthentication/api/Azure.Identity.BrokeredAuthentication.net462.cs @@ -3,12 +3,10 @@ namespace Azure.Identity.BrokeredAuthentication public partial class InteractiveBrowserCredentialBrokerOptions : Azure.Identity.InteractiveBrowserCredentialOptions { public InteractiveBrowserCredentialBrokerOptions(System.IntPtr parentWindowHandle) { } - public bool? IsMsaPassthroughEnabled { get { throw null; } set { } } } public partial class SharedTokenCacheCredentialBrokerOptions : Azure.Identity.SharedTokenCacheCredentialOptions { public SharedTokenCacheCredentialBrokerOptions() { } public SharedTokenCacheCredentialBrokerOptions(Azure.Identity.TokenCachePersistenceOptions tokenCacheOptions) { } - public bool? IsMsaPassthroughEnabled { get { throw null; } set { } } } } From e675951c13bfd09c88b81328349ef60edd3bdda4 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Tue, 25 Jul 2023 16:57:04 -0700 Subject: [PATCH 3/7] Removing requirement for response object in request to not perform early validation --- .../src/Framework/AuthenticationEventMetadata.cs | 4 ++-- .../src/Framework/AuthenticationEventRequest.cs | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventMetadata.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventMetadata.cs index ee88005d97fd3..73045caaa86dd 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventMetadata.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventMetadata.cs @@ -54,8 +54,6 @@ internal AuthenticationEventRequestBase CreateEventRequest(HttpRequestMessage re // ResponseSchema ?? string.Empty, ResponseTemplate ?? string.Empty); - responseInfo.SetValue(eventRequest, eventResponse); - if (args != null && args.Length != 0) { eventRequest.InstanceCreated(args); @@ -76,6 +74,8 @@ internal AuthenticationEventRequestBase CreateEventRequest(HttpRequestMessage re Helpers.ValidateGraph(eventRequest); } + responseInfo.SetValue(eventRequest, eventResponse); + return eventRequest; } diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs index 3b85f06dcdcaf..86da0c269be0f 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs @@ -23,7 +23,6 @@ internal AuthenticationEventRequest(HttpRequestMessage request) : base(request) /// The response. /// [JsonPropertyName("response")] - [Required] public TResponse Response { get; set; } /// Gets or sets the related EventData model. From a7052f0b87f1b29f168194f16acd1b86a4b2c448 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Wed, 26 Jul 2023 18:29:26 -0700 Subject: [PATCH 4/7] Added null check and test for response before marking as failed --- .../Framework/AuthenticationEventRequest.cs | 9 ++++++++- .../src/Framework/CloudEventRequest.cs | 5 +++-- ...tensions.AuthenticationEvents.Tests.csproj | 1 + .../tests/MiscTests.cs | 19 +++++++++++++++++++ .../TokenIssuanceStart/NullResponse.json | 3 +++ .../TokenIssuanceStart/TokenIssuanceStart.cs | 10 ++++++++++ 6 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs index 86da0c269be0f..8285222f53b27 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/AuthenticationEventRequest.cs @@ -14,7 +14,9 @@ namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Framework /// The EventData model related to the request. /// /// - public abstract class AuthenticationEventRequest : AuthenticationEventRequestBase where TResponse : AuthenticationEventResponse where TData : AuthenticationEventData + public abstract class AuthenticationEventRequest : AuthenticationEventRequestBase + where TResponse : AuthenticationEventResponse , new() + where TData : AuthenticationEventData { /// Initializes a new instance of the class. /// The request. @@ -61,6 +63,11 @@ public async override Task Completed() internal override Task Failed(Exception exception, bool internalError) { + if (Response == null) + { + Response = new TResponse(); + } + Response.MarkAsFailed(exception, internalError); return Task.FromResult((TResponse)Response); } diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/CloudEventRequest.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/CloudEventRequest.cs index ffffe33e2fc7d..92c9fe97bdb5d 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/CloudEventRequest.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Framework/CloudEventRequest.cs @@ -2,7 +2,6 @@ // Licensed under the MIT License. using Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Framework.Validators; -using System.ComponentModel.DataAnnotations; using System.Net.Http; using System.Text.Json.Serialization; @@ -11,7 +10,9 @@ namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Framework /// Abstract class that wraps any request that relies on cloud events. /// The Cloud Event Response. /// The Cloud Event Data. - public abstract class CloudEventRequest : AuthenticationEventRequest where TResponse : AuthenticationEventResponse where TData : CloudEventData + public abstract class CloudEventRequest : AuthenticationEventRequest + where TResponse : AuthenticationEventResponse, new() + where TData : CloudEventData { /// Gets or sets the source. /// The source. diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj index 7aa64202abf1b..1847cb5ee0107 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.csproj @@ -19,6 +19,7 @@ + diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/MiscTests.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/MiscTests.cs index 8d4d86384dcc8..110ff1bce0c62 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/MiscTests.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/MiscTests.cs @@ -63,6 +63,25 @@ public async Task TokenIssuanceStartObjectModelTest() Assert.True(TestHelper.DoesPayloadMatch(Payload.TokenIssuanceStart.ExpectedPayload, httpResponseMessage.Content.ReadAsStringAsync().Result)); } + /// Tests the OnTokenIssuanceStart request and response object model when the response is set to null + [Test] + [Description("Tests the OnTokenIssuanceStart request and response object model when the response is set to null")] + public async Task TokenIssuanceStartObjectModelNullResponseTest() + { + HttpResponseMessage httpResponseMessage = await TestHelper.EventResponseBaseTest(eventsResponseHandler => + { + if (eventsResponseHandler.Request is TokenIssuanceStartRequest request) + { + request.Response = null; + + eventsResponseHandler.SetValueAsync(request.Completed().Result, CancellationToken.None); + } + }); + + Assert.AreEqual(HttpStatusCode.InternalServerError, httpResponseMessage.StatusCode); + Assert.True(DoesPayloadMatch(Payload.TokenIssuanceStart.NullResponsePayload, httpResponseMessage.Content.ReadAsStringAsync().Result)); + } + [Test] [TestCase(ActionTestTypes.NullClaims)] [TestCase(ActionTestTypes.EmptyClaims)] diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json new file mode 100644 index 0000000000000..1308c230128a2 --- /dev/null +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json @@ -0,0 +1,3 @@ +{ + "errors":["Value cannot be null. (Parameter 'Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return.')"] +} diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/TokenIssuanceStart.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/TokenIssuanceStart.cs index db63a1fc699c3..da1ef66f10166 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/TokenIssuanceStart.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/TokenIssuanceStart.cs @@ -60,5 +60,15 @@ public static string TokenIssuanceStartQueryParameter return PayloadHelper.GetPayload("TokenIssuanceStart.QueryParameters.json"); } } + + /// Gets the payload error message when response is set to null + /// The payload with error message + public static string NullResponsePayload + { + get + { + return PayloadHelper.GetPayload("TokenIssuanceStart.NullResponse.json"); + } + } } } From b7e74c7182c75a48314fb07b2463ea5c9301fed5 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Thu, 27 Jul 2023 13:08:10 -0700 Subject: [PATCH 5/7] Updated exception to validation exception and corrected test --- .../src/AuthenticationEventResponseHandler.cs | 4 +-- .../TokenIssuanceStart/NullResponse.json | 2 +- .../tests/TestHelper.cs | 34 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs index 7512c9b5fdc0a..fd810afb63c13 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs @@ -57,7 +57,7 @@ public Task SetValueAsync(object result, CancellationToken cancellationToken) { if (result == null) { - throw new ArgumentNullException(AuthenticationEventResource.Ex_Invalid_Return); + throw new ValidationException(AuthenticationEventResource.Ex_Invalid_Return); } if (result is AuthenticationEventResponse action) @@ -83,7 +83,7 @@ public Task SetValueAsync(object result, CancellationToken cancellationToken) } catch (Exception ex) { - Response = Request.Failed(ex, !(ex is ValidationException)).Result; + Response = Request.Failed(ex, true).Result; } return Task.CompletedTask; diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json index 1308c230128a2..bfa3fc136c4a6 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json @@ -1,3 +1,3 @@ { - "errors":["Value cannot be null. (Parameter '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." ] } diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestHelper.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestHelper.cs index 123c62cc0efbb..2e23dec80bd1b 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestHelper.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/TestHelper.cs @@ -342,7 +342,7 @@ public static (TokenIssuanceAction action, HttpStatusCode expectReturnCode, stri { case ActionTestTypes.NullClaims: return (new ProvideClaimsForToken(null), - HttpStatusCode.BadRequest, + HttpStatusCode.InternalServerError, "{\"errors\":[\"TokenIssuanceStartResponse: ProvideClaimsForToken: The Claims field is required.\"]}"); case ActionTestTypes.EmptyClaims: return (new ProvideClaimsForToken(), @@ -350,36 +350,36 @@ public static (TokenIssuanceAction action, HttpStatusCode expectReturnCode, stri "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{}}]}}"); case ActionTestTypes.NullClaimId: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim(null, string.Empty) }), - HttpStatusCode.BadRequest, - "{\"errors\":[\"TokenIssuanceStartResponse: ProvideClaimsForToken: TokenClaim: The Id field is required.\"]}"); + HttpStatusCode.InternalServerError, + "{\"errors\":[\"TokenIssuanceStartResponse: ProvideClaimsForToken: TokenClaim: The Id field is required.\"]}"); case ActionTestTypes.EmptyClaimsId: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim(String.Empty, string.Empty) }), - HttpStatusCode.BadRequest, - "{\"errors\":[\"TokenIssuanceStartResponse: ProvideClaimsForToken: TokenClaim: The Id field is required.\"]}"); + HttpStatusCode.InternalServerError, + "{\"errors\":[\"TokenIssuanceStartResponse: ProvideClaimsForToken: TokenClaim: The Id field is required.\"]}"); case ActionTestTypes.EmptyValueString: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim("key", string.Empty) }), - HttpStatusCode.OK, - "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":\"\"}}]}}"); + HttpStatusCode.OK, + "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":\"\"}}]}}"); case ActionTestTypes.NullValue: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim("key", null) }), - HttpStatusCode.OK, - "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":null}}]}}"); + HttpStatusCode.OK, + "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":null}}]}}"); case ActionTestTypes.EmptyValueArray: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim("key", new string[] { }) }), - HttpStatusCode.OK, - "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":[]}}]}}"); + HttpStatusCode.OK, + "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":[]}}]}}"); case ActionTestTypes.EmptyValueStringArray: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim("key", new string[] { String.Empty, String.Empty }) }), - HttpStatusCode.OK, - "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":[\"\",\"\"]}}]}}"); + HttpStatusCode.OK, + "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":[\"\",\"\"]}}]}}"); case ActionTestTypes.EmptyMixedArray: return (new ProvideClaimsForToken(new TokenClaim[] { new TokenClaim("key", new string[] { String.Empty, null, " " }) }), - HttpStatusCode.OK, - "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":[\"\",null,\" \"]}}]}}"); + HttpStatusCode.OK, + "{\"data\":{\"@odata.type\":\"microsoft.graph.onTokenIssuanceStartResponseData\",\"actions\":[{\"@odata.type\":\"microsoft.graph.tokenIssuanceStart.provideClaimsForToken\",\"claims\":{\"key\":[\"\",null,\" \"]}}]}}"); case ActionTestTypes.NullActionItems: return (null, - HttpStatusCode.BadRequest, - "{\"errors\":[\"TokenIssuanceStartResponse: Actions can not contain null items\"]}"); + HttpStatusCode.InternalServerError, + "{\"errors\":[\"TokenIssuanceStartResponse: Actions can not contain null items\"]}"); default: return (null, HttpStatusCode.InternalServerError, From 657622716ca4fdb01564810e44afdbe356a10e04 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Thu, 27 Jul 2023 17:42:24 -0700 Subject: [PATCH 6/7] Changed back to argument null exception --- .../src/AuthenticationEventResponseHandler.cs | 2 +- .../tests/Payloads/TokenIssuanceStart/NullResponse.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs index fd810afb63c13..664f34b5274d9 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs @@ -57,7 +57,7 @@ public Task SetValueAsync(object result, CancellationToken cancellationToken) { if (result == null) { - throw new ValidationException(AuthenticationEventResource.Ex_Invalid_Return); + throw new ArgumentNullException("AuthenticationEventResponseHandler", AuthenticationEventResource.Ex_Invalid_Return); } if (result is AuthenticationEventResponse action) diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json index bfa3fc136c4a6..20d91a5f4b7cf 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json @@ -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. (Parameter 'AuthenticationEventResponseHandler')" ] } From 4cd4fc59dff2cdb406e08d646aba674636eb5e57 Mon Sep 17 00:00:00 2001 From: Abdul Hakim Date: Fri, 28 Jul 2023 13:10:44 -0700 Subject: [PATCH 7/7] Added response validation exception type --- .../src/AuthenticationEventResponseHandler.cs | 2 +- .../Exceptions/ResponseValidationException.cs | 28 +++++++++++++++++++ .../TokenIssuanceStart/NullResponse.json | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Common/Exceptions/ResponseValidationException.cs diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs index 664f34b5274d9..043dbc2b1eb06 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResponseHandler.cs @@ -57,7 +57,7 @@ public Task SetValueAsync(object result, CancellationToken cancellationToken) { if (result == null) { - throw new ArgumentNullException("AuthenticationEventResponseHandler", AuthenticationEventResource.Ex_Invalid_Return); + throw new ResponseValidationException(AuthenticationEventResource.Ex_Invalid_Return); } if (result is AuthenticationEventResponse action) diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Common/Exceptions/ResponseValidationException.cs b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Common/Exceptions/ResponseValidationException.cs new file mode 100644 index 0000000000000..b567483e68a7d --- /dev/null +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/src/Common/Exceptions/ResponseValidationException.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; + +namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents +{ + /// + /// Exception class for response validations + /// + public class ResponseValidationException : Exception + { + /// + /// Initializes a new instance of the class. + /// + /// + public ResponseValidationException(string message) + : base(message) { } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + public ResponseValidationException(string message, Exception innerException) + : base(message, innerException) { } + } +} diff --git a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json index 20d91a5f4b7cf..bfa3fc136c4a6 100644 --- a/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json +++ b/sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents/tests/Payloads/TokenIssuanceStart/NullResponse.json @@ -1,3 +1,3 @@ { - "errors": [ "Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return. (Parameter 'AuthenticationEventResponseHandler')" ] + "errors": [ "Return type is invalid, please return either an AuthEventResponse, HttpResponse, HttpResponseMessage or string in your function return." ] }