-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Abdulhakim/Do not allow null or empty actions #37737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
5424aae
Marked empty/null actions as failed
hakimms f647edd
replaced tabs with spaces
hakimms 0cee892
Updated spacing
hakimms b7b2811
Replaced tab with spaces
hakimms e340d15
Updates based on feedback
hakimms 03d26bb
Updated Validation Logic
hakimms b619a92
WIP Added test cases for OneOrMoreRequiredAttribute
hakimms 30cf830
Added test case for EnumberableItemsNotNull Attribute
hakimms f0ffd40
Feedback updates
hakimms d3201c3
Updates based on PR feedback
hakimms b55cad3
Sort 'using' lists and removed unapplicable data annotation
hakimms d746379
Adding necessary updates to merge with azure main
hakimms 00e3555
Removed xUnit reference now that we are using NUnit tests
hakimms cccac62
removed Update-Snippets.ps1 changes and will rebase
hakimms f0057ca
Removing requirement for response object in request to not perform ea…
hakimms 1bb04ec
Added null check and test for response before marking as failed
hakimms 201466c
Updated exception to validation exception and corrected test
hakimms 90b1200
Changed back to argument null exception
hakimms cad33d1
Added response validation exception type
hakimms c770602
Ran script to add partial class for ResponseValidationException
hakimms 1b07b17
Update sdk/entra/Microsoft.Azure.WebJobs.Extensions.AuthenticationEve…
hakimms 9748b34
Added period
hakimms File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...Azure.WebJobs.Extensions.AuthenticationEvents/src/AuthenticationEventResource.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...Jobs.Extensions.AuthenticationEvents/src/Common/Exceptions/ResponseValidationException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents | ||
| { | ||
| /// <summary> | ||
| /// Exception class for response validations | ||
| /// </summary> | ||
| public class ResponseValidationException : Exception | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ResponseValidationException"/> class. | ||
| /// </summary> | ||
| /// <param name="message"></param> | ||
| public ResponseValidationException(string message) | ||
| : base(message) { } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ResponseValidationException"/> class. | ||
| /// </summary> | ||
| /// <param name="message"></param> | ||
| /// <param name="innerException"></param> | ||
| public ResponseValidationException(string message, Exception innerException) | ||
| : base(message, innerException) { } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...tensions.AuthenticationEvents/src/Framework/Validators/EnumerableItemsNotNullAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Framework.Validators | ||
| { | ||
| /// <summary>Validator to ensure that a type value is enumerable and contains no null items.</summary> | ||
| [AttributeUsage(AttributeTargets.Property)] | ||
| internal class EnumerableItemsNotNullAttribute : ValidationAttribute | ||
| { | ||
| /// <summary>Initializes a new instance of the <see cref="EnumerableItemsNotNullAttribute" /> class.</summary> | ||
| public EnumerableItemsNotNullAttribute() | ||
| : base(AuthenticationEventResource.Ex_Null_Action_Items) | ||
| { | ||
| } | ||
|
|
||
| /// <summary>Returns true if the value is not null, is IEnumerable and no items are null.</summary> | ||
| /// <param name="value">The value of the object to validate.</param> | ||
| /// <returns>true if the specified value is valid; otherwise, false.</returns> | ||
| public override bool IsValid(object value) | ||
| { | ||
| return value is not null | ||
| && value is IEnumerable<object> obj | ||
| && !obj.Any(x => x == null); | ||
| } | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...bs.Extensions.AuthenticationEvents/src/Framework/Validators/OneOrMoreRequiredAttribute.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using System.Linq; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Framework.Validators | ||
| { | ||
| /// <summary>Validator to ensure that a type value is enumerable and contains at least one item.</summary> | ||
| [AttributeUsage(AttributeTargets.Property)] | ||
| internal class OneOrMoreRequiredAttribute : ValidationAttribute | ||
| { | ||
| /// <summary>Initializes a new instance of the <see cref="OneOrMoreRequiredAttribute" /> class.</summary> | ||
| public OneOrMoreRequiredAttribute() | ||
| : base(AuthenticationEventResource.Ex_No_Action) | ||
| { | ||
| } | ||
|
|
||
| /// <summary>Returns true if the value is not null, is IEnumerable and contains at lease one item.</summary> | ||
| /// <param name="value">The value of the object to validate.</param> | ||
| /// <returns>true if the specified value is valid; otherwise, false.</returns> | ||
| public override bool IsValid(object value) | ||
| { | ||
| return value is not null | ||
| && value is IEnumerable<object> obj | ||
| && obj.Any(); | ||
| } | ||
| } | ||
| } |
91 changes: 91 additions & 0 deletions
91
...s.AuthenticationEvents/tests/Framework/Validators/EnumerableItemsNotNullAttributeTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using System.Collections.Generic; | ||
| using System.ComponentModel.DataAnnotations; | ||
| using Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Framework.Validators; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Microsoft.Azure.WebJobs.Extensions.AuthenticationEvents.Tests.Framework.Validators | ||
| { | ||
| [TestFixture] | ||
| /// <summary> | ||
| /// This class will test OneOrMoreRequiredAttribute | ||
| /// </summary> | ||
| public class EnumerableItemsNotNullAttributeTests | ||
| { | ||
| [Test] | ||
| [TestCaseSource(nameof(TestScenarios))] | ||
| public void EnumberableItemsNotNullIsValidWithTestCase(object testObject, string message, bool success) | ||
| { | ||
| DummyClass dummyObj = new() { Obj = testObject }; | ||
|
|
||
| if (success == false) | ||
| { | ||
| Assert.Throws<ValidationException>(() => Validator.ValidateObject(dummyObj, new ValidationContext(dummyObj), true), AuthenticationEventResource.Ex_Null_Action_Items); | ||
| } | ||
| else | ||
| { | ||
| Assert.DoesNotThrow(() => Validator.ValidateObject(dummyObj, new ValidationContext(dummyObj), true)); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Class that holds the attribute we want to test | ||
| /// </summary> | ||
| private class DummyClass | ||
| { | ||
| [EnumerableItemsNotNull] | ||
| public object Obj { get; set; } | ||
| } | ||
|
|
||
| private static IEnumerable<object[]> TestScenarios() | ||
| { | ||
| #region Invalid | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = null, | ||
| Message = "Testing null", | ||
| }.ToArray; | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new object(), | ||
| Message = "Testing object", | ||
| }.ToArray; | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new List<object>() { null }, | ||
| Message = "Testing object list with null item", | ||
| }.ToArray; | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new List<object>() { new(), null, new() }, | ||
| Message = "Testing object list with multiple items with one null", | ||
| }.ToArray; | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new object[1], | ||
| Message = "Testing single null item array", | ||
| }.ToArray; | ||
| #endregion | ||
|
|
||
| #region Valid | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new List<object>() { new(), new() }, | ||
| Message = "Testing list of objects", | ||
| Success = true, | ||
| }.ToArray; | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new List<object>(), | ||
| Message = "Testing initialized object", | ||
| Success = true, | ||
| }.ToArray; | ||
| yield return new TestCaseStructure() | ||
| { | ||
| Test = new object[0], | ||
| Message = "Testing empty array", | ||
| Success = true, | ||
| }.ToArray; | ||
| #endregion | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.