Skip to content

Commit

Permalink
OData#1645 okay this is the easy part, now I get to hunt down where t…
Browse files Browse the repository at this point in the history
…he injection occurs
  • Loading branch information
kccarter76 committed Jun 29, 2020
1 parent 1b6c9bf commit 34c5ec9
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Microsoft.AspNet.OData.Query
[ODataQueryParameterBinding]
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Relies on many ODataLib classes.")]
public partial class ODataQueryOptions
: IODataQueryOptions
{
private static readonly MethodInfo _limitResultsGenericMethod = typeof(ODataQueryOptions).GetMethods(BindingFlags.Public | BindingFlags.Static)
.Single(mi => mi.Name == "LimitResults" && mi.ContainsGenericParameters && mi.GetParameters().Length == 4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Net.Http.Headers;
using Microsoft.AspNet.OData.Common;
using Microsoft.AspNet.OData.Formatter;
using Microsoft.AspNet.OData.Interfaces;

namespace Microsoft.AspNet.OData.Query
{
Expand All @@ -13,7 +14,9 @@ namespace Microsoft.AspNet.OData.Query
/// Currently this only supports $filter, $orderby, $top, $skip.
/// </summary>
[ODataQueryParameterBinding]
public partial class ODataQueryOptions<TEntity> : ODataQueryOptions
public partial class ODataQueryOptions<TEntity>
: ODataQueryOptions
, IODataQueryOptions<TEntity>
{
/// <summary>
/// Gets the <see cref="ETag{TEntity}"/> from IfMatch header.
Expand Down
149 changes: 149 additions & 0 deletions src/Microsoft.AspNetCore.OData/Interfaces/IODataQueryOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using Microsoft.AspNet.OData.Formatter;
using Microsoft.AspNet.OData.Query;
using Microsoft.AspNet.OData.Query.Validators;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Microsoft.AspNet.OData.Interfaces
{
/// <summary>
/// This defines a composite OData query options that can be used to perform query composition.
/// Currently this only supports $filter, $orderby, $top, $skip, and $count.
/// </summary>
public interface IODataQueryOptions
{
/// <summary>
/// Gets the given <see cref="ODataQueryContext"/>
/// </summary>
ODataQueryContext Context { get; }
/// <summary>
/// Gets the raw string of all the OData query options
/// </summary>
ODataRawQueryOptions RawValues { get; }
/// <summary>
/// Gets the <see cref="SelectExpandQueryOption"/>.
/// </summary>
SelectExpandQueryOption SelectExpand { get; }
/// <summary>
/// Gets the <see cref="ApplyQueryOption"/>.
/// </summary>
ApplyQueryOption Apply { get; }
/// <summary>
/// Gets the <see cref="FilterQueryOption"/>.
/// </summary>
FilterQueryOption Filter { get; }
/// <summary>
/// Gets the <see cref="OrderByQueryOption"/>.
/// </summary>
OrderByQueryOption OrderBy { get; }
/// <summary>
/// Gets the <see cref="SkipQueryOption"/>.
/// </summary>
SkipQueryOption Skip { get; }

/// <summary>
/// Gets the <see cref="SkipTokenQueryOption"/>.
/// </summary>
SkipTokenQueryOption SkipToken { get; }

/// <summary>
/// Gets the <see cref="TopQueryOption"/>.
/// </summary>
TopQueryOption Top { get; }

/// <summary>
/// Gets the <see cref="CountQueryOption"/>.
/// </summary>
CountQueryOption Count { get; }

/// <summary>
/// Gets or sets the query validator.
/// </summary>
ODataQueryValidator Validator { get; set; }

/// <summary>
/// Gets the <see cref="ETag"/> from IfMatch header.
/// </summary>
ETag IfMatch { get; }

/// <summary>
/// Gets the <see cref="ETag"/> from IfNoneMatch header.
/// </summary>
ETag IfNoneMatch { get; }

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
IQueryable ApplyTo(IQueryable query);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
IQueryable ApplyTo(IQueryable query, AllowedQueryOptions ignoreQueryOptions);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <param name="querySettings">The settings to use in query composition.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings, AllowedQueryOptions ignoreQueryOptions);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="query">The original <see cref="IQueryable"/>.</param>
/// <param name="querySettings">The settings to use in query composition.</param>
/// <returns>The new <see cref="IQueryable"/> after the query has been applied to.</returns>
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "These are simple conversion function and cannot be split up.")]
IQueryable ApplyTo(IQueryable query, ODataQuerySettings querySettings);

/// <summary>
/// Apply the individual query to the given IQueryable in the right order.
/// </summary>
/// <param name="entity">The original entity.</param>
/// <param name="querySettings">The <see cref="ODataQuerySettings"/> that contains all the query application related settings.</param>
/// <param name="ignoreQueryOptions">The query parameters that are already applied in queries.</param>
/// <returns>The new entity after the $select and $expand query has been applied to.</returns>
/// <remarks>Only $select and $expand query options can be applied on single entities. This method throws if the query contains any other
/// query options.</remarks>
object ApplyTo(object entity, ODataQuerySettings querySettings, AllowedQueryOptions ignoreQueryOptions);

/// <summary>
/// Applies the query to the given entity using the given <see cref="ODataQuerySettings"/>.
/// </summary>
/// <param name="entity">The original entity.</param>
/// <param name="querySettings">The <see cref="ODataQuerySettings"/> that contains all the query application related settings.</param>
/// <returns>The new entity after the $select and $expand query has been applied to.</returns>
/// <remarks>Only $select and $expand query options can be applied on single entities. This method throws if the query contains any other
/// query options.</remarks>
object ApplyTo(object entity, ODataQuerySettings querySettings);

/// <summary>
/// Generates the Stable OrderBy query option based on the existing OrderBy and other query options.
/// </summary>
/// <returns>An order by query option that ensures stable ordering of the results.</returns>
OrderByQueryOption GenerateStableOrder();

/// <summary>
/// Check if the given query option is the supported query option.
/// </summary>
/// <param name="queryOptionName">The name of the query option.</param>
/// <returns>Returns <c>true</c> if the query option is the supported query option.</returns>
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Need lower case string here.")]
bool IsSupportedQueryOption(string queryOptionName);

/// <summary>
/// Validate all OData queries, including $skip, $top, $orderby and $filter, based on the given <paramref name="validationSettings"/>.
/// It throws an ODataException if validation failed.
/// </summary>
/// <param name="validationSettings">The <see cref="ODataValidationSettings"/> instance which contains all the validation settings.</param>
void Validate(ODataValidationSettings validationSettings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Microsoft.AspNet.OData.Formatter;
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.AspNet.OData.Interfaces
{
/// <summary>
/// This defines a composite OData query options that can be used to perform query composition.
/// Currently this only supports $filter, $orderby, $top, $skip.
/// </summary>
public interface IODataQueryOptions<TEntity>
: IODataQueryOptions
{
/// <summary>
/// Gets the <see cref="ETag{TEntity}"/> from IfMatch header.
/// </summary>
new ETag<TEntity> IfMatch { get; }

/// <summary>
/// Gets the <see cref="ETag{TEntity}"/> from IfNoneMatch header.
/// </summary>
new ETag<TEntity> IfNoneMatch { get; }
}
}

0 comments on commit 34c5ec9

Please sign in to comment.