From e4adb69a6f7667db6cb32b8b8e6b3fc76bb82e95 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Tue, 1 Nov 2022 18:19:31 -0700 Subject: [PATCH 01/12] fix orderby for null int types --- ConfigGenerators/MsSqlCommands.txt | 3 ++- ConfigGenerators/MySqlCommands.txt | 3 ++- ConfigGenerators/PostgreSqlCommands.txt | 3 ++- .../SqlTests/RestApiTests/Find/FindApiTestBase.cs | 15 +++++++++++++++ .../RestApiTests/Find/MsSqlFindApiTests.cs | 6 ++++++ .../RestApiTests/Find/MySqlFindApiTests.cs | 11 +++++++++++ .../RestApiTests/Find/PostgreSqlFindApiTests.cs | 10 ++++++++++ .../SqlTests/RestApiTests/RestApiTestBase.cs | 2 ++ src/Service/Resolvers/BaseSqlQueryBuilder.cs | 9 +++++++-- .../Sql Query Structures/SqlQueryStructure.cs | 5 +++-- src/Service/Resolvers/SqlPaginationUtil.cs | 3 ++- 11 files changed, 62 insertions(+), 8 deletions(-) diff --git a/ConfigGenerators/MsSqlCommands.txt b/ConfigGenerators/MsSqlCommands.txt index b9101408b5..41a507c4c9 100644 --- a/ConfigGenerators/MsSqlCommands.txt +++ b/ConfigGenerators/MsSqlCommands.txt @@ -1,4 +1,4 @@ -init --config "dab-config.MsSql.json" --database-type mssql --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +init --config "dab-config.MsSql.json" --database-type mssql --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" add Publisher --config "dab-config.MsSql.json" --source publishers --permissions "anonymous:read" add Stock --config "dab-config.MsSql.json" --source stocks --permissions "anonymous:create,read,update" add Book --config "dab-config.MsSql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" @@ -23,6 +23,7 @@ add ArtOfWar --config "dab-config.MsSql.json" --source "aow" --rest true --permi add series --config "dab-config.MsSql.json" --source "series" --permissions "anonymous:*" add GetBooks --config "dab-config.MsSql.json" --source "get_books" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql false add GetBook --config "dab-config.MsSql.json" --source "get_book_by_id" --source.type "stored-procedure" --permissions "anonymous:read" --rest true --graphql false +add TypeTable --config "dab-config.MsSql.json" --source "type_table" --source.type "table" --permissions "anonymous:read" --rest true --graphql true update Publisher --config "dab-config.MsSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many update Publisher --config "dab-config.MsSql.json" --permissions "policy_tester_01:create,delete" update Publisher --config "dab-config.MsSql.json" --permissions "policy_tester_01:update" --fields.include "*" diff --git a/ConfigGenerators/MySqlCommands.txt b/ConfigGenerators/MySqlCommands.txt index d8c0012975..d86d967fdd 100644 --- a/ConfigGenerators/MySqlCommands.txt +++ b/ConfigGenerators/MySqlCommands.txt @@ -1,4 +1,4 @@ -init --config "dab-config.MySql.json" --database-type mysql --connection-string "server=localhost;database=datagatewaytest;Allow User Variables=true;uid=root;pwd=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +init --config "dab-config.MySql.json" --database-type mysql --connection-string "server=localhost;database=datagatewaytest;Allow User Variables=true;uid=root;pwd=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" add Publisher --config "dab-config.MySql.json" --source publishers --permissions "anonymous:read" add Stock --config "dab-config.MySql.json" --source stocks --permissions "anonymous:create,read,update" add Book --config "dab-config.MySql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" @@ -21,6 +21,7 @@ add Notebook --config "dab-config.MySql.json" --source "notebooks" --permissions add Journal --config "dab-config.MySql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete" add ArtOfWar --config "dab-config.MySql.json" --source "aow" --rest true --permissions "anonymous:*" add series --config "dab-config.MySql.json" --source "series" --permissions "anonymous:*" +add TypeTable --config "dab-config.MySql.json" --source "type_table" --source.type "table" --permissions "anonymous:read" --rest true --graphql true update Publisher --config "dab-config.MySql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many update Publisher --config "dab-config.MySql.json" --permissions "policy_tester_01:create,delete" update Publisher --config "dab-config.MySql.json" --permissions "policy_tester_01:update" --fields.include "*" diff --git a/ConfigGenerators/PostgreSqlCommands.txt b/ConfigGenerators/PostgreSqlCommands.txt index 08475bf737..329bc0ca79 100644 --- a/ConfigGenerators/PostgreSqlCommands.txt +++ b/ConfigGenerators/PostgreSqlCommands.txt @@ -1,4 +1,4 @@ -init --config "dab-config.PostgreSql.json" --database-type postgresql --connection-string "Host=localhost;Database=datagatewaytest;username=REPLACEME;password=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +init --config "dab-config.PostgreSql.json" --database-type postgresql --connection-string "Host=localhost;Database=datagatewaytest;username=REPLACEME;password=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" add Publisher --config "dab-config.PostgreSql.json" --source publishers --permissions "anonymous:read" add Stock --config "dab-config.PostgreSql.json" --source stocks --permissions "anonymous:create,read,update" add Book --config "dab-config.PostgreSql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" @@ -18,6 +18,7 @@ add Notebook --config "dab-config.PostgreSql.json" --source "notebooks" --permis add Journal --config "dab-config.PostgreSql.json" --source "journals" --rest true --graphql true --permissions "policy_tester_noupdate:create,delete" add ArtOfWar --config "dab-config.PostgreSql.json" --source "aow" --rest true --permissions "anonymous:*" add series --config "dab-config.PostgreSql.json" --source "series" --permissions "anonymous:*" +add TypeTable --config "dab-config.PostgreSql.json" --source "type_table" --source.type "table" --permissions "anonymous:read" --rest true --graphql true update Publisher --config "dab-config.PostgreSql.json" --permissions "authenticated:create,read,update,delete" --rest true --graphql true --relationship books --target.entity Book --cardinality many update Publisher --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:create,delete" update Publisher --config "dab-config.PostgreSql.json" --permissions "policy_tester_01:update" --fields.include "*" diff --git a/src/Service.Tests/SqlTests/RestApiTests/Find/FindApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Find/FindApiTestBase.cs index 52fa3eb162..7727171488 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Find/FindApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Find/FindApiTestBase.cs @@ -525,6 +525,21 @@ await SetupAndRunRestApiTest( ); } + /// + /// Tests the REST Api for Find operation using sorting + /// with integer type and null values. + /// + [TestMethod] + public async Task FindTestWithIntTypeNullValuesOrderByAsc() + { + await SetupAndRunRestApiTest( + primaryKeyRoute: string.Empty, + queryString: "?$orderby=int_types", + entityNameOrPath: _integrationTypeEntity, + sqlQuery: GetQuery(nameof(FindTestWithIntTypeNullValuesOrderByAsc)) + ); + } + /// /// Tests the REST Api for Find operation for all records. /// order by title in ascending order. diff --git a/src/Service.Tests/SqlTests/RestApiTests/Find/MsSqlFindApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Find/MsSqlFindApiTests.cs index f2d4c2c2b8..dfdb816cce 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Find/MsSqlFindApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Find/MsSqlFindApiTests.cs @@ -254,6 +254,12 @@ public class MsSqlFindApiTests : FindApiTestBase $"ORDER BY book_id asc, id asc " + $"FOR JSON PATH, INCLUDE_NULL_VALUES" }, + { + "FindTestWithIntTypeNullValuesOrderByAsc", + $"SELECT * FROM type_table " + + $"ORDER BY int_types asc, id asc " + + $"FOR JSON PATH, INCLUDE_NULL_VALUES" + }, { "FindTestWithQueryStringAllFieldsOrderByAsc", $"SELECT * FROM { _integrationTableName } " + diff --git a/src/Service.Tests/SqlTests/RestApiTests/Find/MySqlFindApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Find/MySqlFindApiTests.cs index 1d56a294ee..396c5802f7 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Find/MySqlFindApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Find/MySqlFindApiTests.cs @@ -478,6 +478,17 @@ SELECT JSON_ARRAYAGG(JSON_OBJECT('id', id, 'content', content, 'book_id', book_i LIMIT 1 ) AS subq" }, + { + "FindTestWithIntTypeNullValuesOrderByAsc", + @" + SELECT JSON_ARRAYAGG(JSON_OBJECT('id', id, 'title', title, 'publisher_id', publisher_id)) AS data + FROM ( + SELECT * + FROM " + _integrationTypeTable + @" + ORDER BY int_types asc, id asc + LIMIT 100 + ) AS subq" + }, { "FindTestWithQueryStringAllFieldsOrderByAsc", @" diff --git a/src/Service.Tests/SqlTests/RestApiTests/Find/PostgreSqlFindApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Find/PostgreSqlFindApiTests.cs index 34f0697d47..93e5f35401 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Find/PostgreSqlFindApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Find/PostgreSqlFindApiTests.cs @@ -371,6 +371,16 @@ LIMIT 1 ) AS subq " }, + { + "FindTestWithIntTypeNullValuesOrderByAsc", + @" + SELECT json_agg(to_jsonb(subq)) AS data + FROM ( + SELECT * + FROM " + _integrationTypeTable + @" + ORDER BY int_types asc, id asc + ) AS subq" + }, { "FindTestWithQueryStringAllFieldsOrderByAsc", @" diff --git a/src/Service.Tests/SqlTests/RestApiTests/RestApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/RestApiTestBase.cs index b180aebe58..6f8a5d9df1 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/RestApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/RestApiTestBase.cs @@ -42,6 +42,8 @@ public abstract class RestApiTestBase : SqlTestBase protected static readonly string _integrationProcedureFindOne_ProcName = "get_book_by_id"; protected static readonly string _integrationMappingDifferentEntityPath = "plants"; protected static readonly string _Composite_NonAutoGenPK_EntityPath = "commodities"; + protected static readonly string _integrationTypeEntity = "TypeTable"; + protected static readonly string _integrationTypeTable = "type_table"; public abstract string GetQuery(string key); } diff --git a/src/Service/Resolvers/BaseSqlQueryBuilder.cs b/src/Service/Resolvers/BaseSqlQueryBuilder.cs index cf1b567829..3eb87d9195 100644 --- a/src/Service/Resolvers/BaseSqlQueryBuilder.cs +++ b/src/Service/Resolvers/BaseSqlQueryBuilder.cs @@ -72,8 +72,13 @@ private string MakePaginationInequality(List columns, int unti StringBuilder result = new(); for (int i = 0; i <= untilIndex; i++) { - string op = i == untilIndex ? GetComparisonFromDirection(columns[i].Direction) : "="; - result.Append($"{Build(columns[i], printDirection: false)} {op} {columns[i].ParamName}"); + // Combine op and param to accomodate "is NULL" which is used for + // params that have value of NULL. + string opAndParam = i == untilIndex ? + $"{GetComparisonFromDirection(columns[i].Direction)} {columns[i].ParamName}" : + columns[i].Value is not null ? + $"= {columns[i].ParamName}" : "is NULL"; + result.Append($"{Build(columns[i], printDirection: false)} {opAndParam}"); if (i < untilIndex) { diff --git a/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs b/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs index adf02230bd..9b46bc5ed3 100644 --- a/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs +++ b/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs @@ -513,8 +513,9 @@ public void AddPaginationPredicate(IEnumerable afterJsonValues foreach (PaginationColumn column in afterJsonValues) { column.TableAlias = TableAlias; - column.ParamName = "@" + MakeParamWithValue( - GetParamAsColumnSystemType(column.Value!.ToString()!, column.ColumnName)); + column.ParamName = column.Value is not null ? + "@" + MakeParamWithValue(GetParamAsColumnSystemType(column.Value!.ToString()!, column.ColumnName)) : + "@" + MakeParamWithValue(null); } } catch (ArgumentException ex) diff --git a/src/Service/Resolvers/SqlPaginationUtil.cs b/src/Service/Resolvers/SqlPaginationUtil.cs index 2a6745c034..d597d3883b 100644 --- a/src/Service/Resolvers/SqlPaginationUtil.cs +++ b/src/Service/Resolvers/SqlPaginationUtil.cs @@ -374,10 +374,11 @@ private static string GetExposedColumnName(string entityName, string backingColu /// Resolves a JsonElement representing a variable to the appropriate type /// /// - public static object ResolveJsonElementToScalarVariable(JsonElement element) => element.ValueKind switch + public static object? ResolveJsonElementToScalarVariable(JsonElement element) => element.ValueKind switch { JsonValueKind.String => element.GetString()!, JsonValueKind.Number => element.GetInt64(), + JsonValueKind.Null => null, JsonValueKind.True => true, JsonValueKind.False => false, _ => throw new ArgumentException("Unexpected JsonElement value"), From 656db5bb471eb6596b55f2c4ca7b479bed52a686 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 01:00:09 -0800 Subject: [PATCH 02/12] upgrading to 5.0.1 and fixing namespace collisions with Azure --- src/Directory.Packages.props | 2 +- .../GraphQLMutationAuthorizationUnitTests.cs | 10 +-- .../Helpers/GraphQLTestHelpers.cs | 6 +- .../GraphQLBuilder/MutationBuilderTests.cs | 10 +-- src/Service.Tests/SqlTests/SqlTestBase.cs | 14 ++-- src/Service.Tests/SqlTests/SqlTestHelper.cs | 12 ++-- .../Authorization/AuthorizationResolver.cs | 46 ++++++------- .../Authorization/RestAuthorizationHandler.cs | 24 +++---- .../Configurations/RuntimeConfigValidator.cs | 20 +++--- src/Service/Controllers/RestController.cs | 22 +++--- src/Service/Models/CosmosOperationMetadata.cs | 2 +- .../DeleteRequestContext.cs | 2 +- .../RestRequestContexts/FindRequestContext.cs | 2 +- .../InsertRequestContext.cs | 2 +- .../RestRequestContexts/RestRequestContext.cs | 2 +- .../StoredProcedureRequestContext.cs | 4 +- .../UpsertRequestContext.cs | 2 +- .../Resolvers/AuthorizationPolicyHelpers.cs | 2 +- src/Service/Resolvers/CosmosMutationEngine.cs | 8 +-- .../Sql Query Structures/SqlQueryStructure.cs | 2 +- .../Resolvers/SqlExistsQueryStructure.cs | 2 +- src/Service/Resolvers/SqlMutationEngine.cs | 68 +++++++++---------- src/Service/Resolvers/SqlQueryEngine.cs | 2 +- src/Service/Services/GraphQLSchemaCreator.cs | 2 +- src/Service/Services/RequestValidator.cs | 2 +- src/Service/Services/RestService.cs | 58 ++++++++-------- 26 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 69aaba2d61..34b54f4177 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -17,7 +17,7 @@ - + diff --git a/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationUnitTests.cs b/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationUnitTests.cs index 8c37572df9..6f92eed803 100644 --- a/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationUnitTests.cs +++ b/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationUnitTests.cs @@ -20,14 +20,14 @@ public class GraphQLMutationAuthorizationUnitTests /// /// /// - [DataRow(Operation.Create, new string[] { }, "", + [DataRow(Config.Operation.Create, new string[] { }, "", DisplayName = "No Roles -> Expects no objectTypeDefinition created")] - [DataRow(Operation.Create, new string[] { "role1" }, @"@authorize(roles: [""role1""])", + [DataRow(Config.Operation.Create, new string[] { "role1" }, @"@authorize(roles: [""role1""])", DisplayName = "One Role added to Authorize Directive")] - [DataRow(Operation.Create, new string[] { "role1", "role2" }, @"@authorize(roles: [""role1"",""role2""])", + [DataRow(Config.Operation.Create, new string[] { "role1", "role2" }, @"@authorize(roles: [""role1"",""role2""])", DisplayName = "Two Roles added to Authorize Directive")] [DataTestMethod] - public void AuthorizeDirectiveAddedForMutation(Operation operationType, string[] rolesDefinedInPermissions, string expectedAuthorizeDirective) + public void AuthorizeDirectiveAddedForMutation(Config.Operation operationType, string[] rolesDefinedInPermissions, string expectedAuthorizeDirective) { string gql = @" @@ -43,7 +43,7 @@ type Foo @model(name: ""Foo""){ entities: new Dictionary { { "Foo", GraphQLTestHelpers.GenerateEmptyEntity() } }, entityPermissionsMap: GraphQLTestHelpers.CreateStubEntityPermissionsMap( entityNames: new string[] { "Foo" }, - operations: new Operation[] { operationType }, + operations: new Config.Operation[] { operationType }, roles: rolesDefinedInPermissions) ); diff --git a/src/Service.Tests/GraphQLBuilder/Helpers/GraphQLTestHelpers.cs b/src/Service.Tests/GraphQLBuilder/Helpers/GraphQLTestHelpers.cs index 35bfdfc951..df4a3c8e35 100644 --- a/src/Service.Tests/GraphQLBuilder/Helpers/GraphQLTestHelpers.cs +++ b/src/Service.Tests/GraphQLBuilder/Helpers/GraphQLTestHelpers.cs @@ -47,14 +47,14 @@ type People @model(name:""People"") { /// Actions performed on entity to resolve authorization permissions. /// Collection of role names allowed to perform action on entity. /// EntityPermissionsMap Key/Value collection. - public static Dictionary CreateStubEntityPermissionsMap(string[] entityNames, IEnumerable operations, IEnumerable roles) + public static Dictionary CreateStubEntityPermissionsMap(string[] entityNames, IEnumerable operations, IEnumerable roles) { EntityMetadata entityMetadata = new() { - OperationToRolesMap = new Dictionary>() + OperationToRolesMap = new Dictionary>() }; - foreach (Operation operation in operations) + foreach (Config.Operation operation in operations) { entityMetadata.OperationToRolesMap.Add(operation, roles.ToList()); } diff --git a/src/Service.Tests/GraphQLBuilder/MutationBuilderTests.cs b/src/Service.Tests/GraphQLBuilder/MutationBuilderTests.cs index c98c08260c..1a00198355 100644 --- a/src/Service.Tests/GraphQLBuilder/MutationBuilderTests.cs +++ b/src/Service.Tests/GraphQLBuilder/MutationBuilderTests.cs @@ -29,7 +29,7 @@ public void SetupEntityPermissionsMap() { _entityPermissions = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "Foo", "Baz", "Bar" }, - new Operation[] { Operation.Create, Operation.Update, Operation.Delete }, + new Config.Operation[] { Config.Operation.Create, Config.Operation.Update, Config.Operation.Delete }, new string[] { "anonymous", "authenticated" } ); } @@ -64,7 +64,7 @@ type Foo @model(name:""Foo"") { Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "Foo" }, - new Operation[] { Operation.Create }, + new Config.Operation[] { Config.Operation.Create }, roles); DocumentNode mutationRoot = MutationBuilder.Build(root, DatabaseType.cosmos, @@ -605,7 +605,7 @@ type Foo @model(name:""Foo"") { Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "Foo" }, - new Operation[] { Operation.Delete }, + new Config.Operation[] { Config.Operation.Delete }, roles); DocumentNode mutationRoot = MutationBuilder.Build(root, DatabaseType.cosmos, @@ -711,7 +711,7 @@ type Foo @model(name:""Foo"") { Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "Foo" }, - new Operation[] { Operation.Update }, + new Config.Operation[] { Config.Operation.Update }, roles); DocumentNode mutationRoot = MutationBuilder.Build( root, @@ -959,7 +959,7 @@ string expectedName DocumentNode root = Utf8GraphQLParser.Parse(gql); Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { entityName }, - new Operation[] { Operation.Create, Operation.Update, Operation.Delete }, + new Config.Operation[] { Config.Operation.Create, Config.Operation.Update, Config.Operation.Delete }, new string[] { "anonymous", "authenticated" }); Entity entity = (singularName is not null) diff --git a/src/Service.Tests/SqlTests/SqlTestBase.cs b/src/Service.Tests/SqlTests/SqlTestBase.cs index 2d6cd68a11..008029b0cd 100644 --- a/src/Service.Tests/SqlTests/SqlTestBase.cs +++ b/src/Service.Tests/SqlTests/SqlTestBase.cs @@ -346,7 +346,7 @@ protected static async Task SetupAndRunRestApiTest( string queryString, string entityNameOrPath, string sqlQuery, - Operation operationType = Operation.Read, + Config.Operation operationType = Config.Operation.Read, string restPath = "api", IHeaderDictionary headers = null, string requestBody = null, @@ -422,11 +422,11 @@ protected static async Task SetupAndRunRestApiTest( // Initial DELETE request results in 204 no content, no exception thrown. // Subsequent DELETE requests result in 404, which result in an exception. string expected; - if ((operationType is Operation.Delete || - operationType is Operation.Upsert || - operationType is Operation.UpsertIncremental || - operationType is Operation.Update || - operationType is Operation.UpdateIncremental) + if ((operationType is Config.Operation.Delete || + operationType is Config.Operation.Upsert || + operationType is Config.Operation.UpsertIncremental || + operationType is Config.Operation.Update || + operationType is Config.Operation.UpdateIncremental) && response.StatusCode == HttpStatusCode.NoContent ) { @@ -452,7 +452,7 @@ operationType is Operation.Update || string dbResult = await GetDatabaseResultAsync(sqlQuery, expectJson); // For FIND requests, null result signifies an empty result set - dbResult = (operationType is Operation.Read && dbResult is null) ? "[]" : dbResult; + dbResult = (operationType is Config.Operation.Read && dbResult is null) ? "[]" : dbResult; expected = $"{{\"{SqlTestHelper.jsonResultTopLevelKey}\":" + $"{FormatExpectedValue(dbResult)}{ExpectedNextLinkIfAny(paginated, baseUrl, $"{expectedAfterQueryString}")}}}"; } diff --git a/src/Service.Tests/SqlTests/SqlTestHelper.cs b/src/Service.Tests/SqlTests/SqlTestHelper.cs index ba56f7698c..6dbb0f774c 100644 --- a/src/Service.Tests/SqlTests/SqlTestHelper.cs +++ b/src/Service.Tests/SqlTests/SqlTestHelper.cs @@ -153,19 +153,19 @@ public static async Task VerifyResultAsync( /// The operation to be executed on the entity. /// /// - public static HttpMethod GetHttpMethodFromOperation(Operation operationType) + public static HttpMethod GetHttpMethodFromOperation(Config.Operation operationType) { switch (operationType) { - case Operation.Read: + case Config.Operation.Read: return HttpMethod.Get; - case Operation.Insert: + case Config.Operation.Insert: return HttpMethod.Post; - case Operation.Delete: + case Config.Operation.Delete: return HttpMethod.Delete; - case Operation.Upsert: + case Config.Operation.Upsert: return HttpMethod.Put; - case Operation.UpsertIncremental: + case Config.Operation.UpsertIncremental: return HttpMethod.Patch; default: throw new DataApiBuilderException( diff --git a/src/Service/Authorization/AuthorizationResolver.cs b/src/Service/Authorization/AuthorizationResolver.cs index ceba4d9d01..bd87f1306c 100644 --- a/src/Service/Authorization/AuthorizationResolver.cs +++ b/src/Service/Authorization/AuthorizationResolver.cs @@ -102,7 +102,7 @@ public bool IsValidRoleContext(HttpContext httpContext) } /// - public bool AreRoleAndOperationDefinedForEntity(string entityName, string roleName, Operation operation) + public bool AreRoleAndOperationDefinedForEntity(string entityName, string roleName, Config.Operation operation) { if (EntityPermissionsMap.TryGetValue(entityName, out EntityMetadata? valueOfEntityToRole)) { @@ -119,7 +119,7 @@ public bool AreRoleAndOperationDefinedForEntity(string entityName, string roleNa } /// - public bool AreColumnsAllowedForOperation(string entityName, string roleName, Operation operation, IEnumerable columns) + public bool AreColumnsAllowedForOperation(string entityName, string roleName, Config.Operation operation, IEnumerable columns) { // Columns.Count() will never be zero because this method is called after a check ensures Count() > 0 Assert.IsFalse(columns.Count() == 0, message: "columns.Count() should be greater than 0."); @@ -159,7 +159,7 @@ public bool AreColumnsAllowedForOperation(string entityName, string roleName, Op } /// - public string ProcessDBPolicy(string entityName, string roleName, Operation operation, HttpContext httpContext) + public string ProcessDBPolicy(string entityName, string roleName, Config.Operation operation, HttpContext httpContext) { string dBpolicyWithClaimTypes = GetDBPolicyForRequest(entityName, roleName, operation); @@ -184,7 +184,7 @@ public string ProcessDBPolicy(string entityName, string roleName, Operation oper /// Role defined in client role header. /// Operation type: create, read, update, delete. /// Policy string if a policy exists in config. - private string GetDBPolicyForRequest(string entityName, string roleName, Operation operation) + private string GetDBPolicyForRequest(string entityName, string roleName, Config.Operation operation) { if (!EntityPermissionsMap[entityName].RoleToOperationMap.TryGetValue(roleName, out RoleMetadata? roleMetadata)) { @@ -226,7 +226,7 @@ public void SetEntityPermissionMap(RuntimeConfig? runtimeConfig) object[] Operations = permission.Operations; foreach (JsonElement operationElement in Operations) { - Operation operation = Operation.None; + Config.Operation operation = Config.Operation.None; OperationMetadata operationToColumn = new(); // Use a hashset to store all the backing field names @@ -239,7 +239,7 @@ public void SetEntityPermissionMap(RuntimeConfig? runtimeConfig) if (operationElement.ValueKind is JsonValueKind.String) { string operationName = operationElement.ToString(); - operation = AuthorizationResolver.WILDCARD.Equals(operationName) ? Operation.All : Enum.Parse(operationName, ignoreCase: true); + operation = AuthorizationResolver.WILDCARD.Equals(operationName) ? Config.Operation.All : Enum.Parse(operationName, ignoreCase: true); operationToColumn.Included.UnionWith(allTableColumns); allowedColumns.UnionWith(allTableColumns); } @@ -302,8 +302,8 @@ public void SetEntityPermissionMap(RuntimeConfig? runtimeConfig) // so that it doesn't need to be evaluated per request. PopulateAllowedExposedColumns(operationToColumn.AllowedExposedColumns, entityName, allowedColumns); - IEnumerable operations = GetAllOperations(operation); - foreach (Operation crudOperation in operations) + IEnumerable operations = GetAllOperations(operation); + foreach (Config.Operation crudOperation in operations) { // Try to add the opElement to the map if not present. // Builds up mapping: i.e. Operation.Create permitted in {Role1, Role2, ..., RoleN} @@ -361,9 +361,9 @@ private static void CopyOverPermissionsFromAnonymousToAuthenticatedRole( entityToRoleMap.RoleToOperationMap[ROLE_AUTHENTICATED] = entityToRoleMap.RoleToOperationMap[ROLE_ANONYMOUS]; // Copy over OperationToRolesMap for authenticated role from anonymous role. - Dictionary allowedOperationMap = + Dictionary allowedOperationMap = entityToRoleMap.RoleToOperationMap[ROLE_ANONYMOUS].OperationToColumnMap; - foreach (Operation operation in allowedOperationMap.Keys) + foreach (Config.Operation operation in allowedOperationMap.Keys) { entityToRoleMap.OperationToRolesMap[operation].Add(ROLE_AUTHENTICATED); } @@ -371,9 +371,9 @@ private static void CopyOverPermissionsFromAnonymousToAuthenticatedRole( // Copy over FieldToRolesMap for authenticated role from anonymous role. foreach (string allowedColumnInAnonymousRole in allowedColumnsForAnonymousRole) { - Dictionary> allowedOperationsForField = + Dictionary> allowedOperationsForField = entityToRoleMap.FieldToRolesMap[allowedColumnInAnonymousRole]; - foreach (Operation operation in allowedOperationsForField.Keys) + foreach (Config.Operation operation in allowedOperationsForField.Keys) { if (allowedOperationsForField[operation].Contains(ROLE_ANONYMOUS)) { @@ -389,9 +389,9 @@ private static void CopyOverPermissionsFromAnonymousToAuthenticatedRole( /// /// operation type. /// IEnumerable of all available operations. - public static IEnumerable GetAllOperations(Operation operation) + public static IEnumerable GetAllOperations(Config.Operation operation) { - return operation is Operation.All ? PermissionOperation.ValidPermissionOperations : new List { operation }; + return operation is Config.Operation.All ? PermissionOperation.ValidPermissionOperations : new List { operation }; } /// @@ -420,7 +420,7 @@ private void PopulateAllowedExposedColumns(HashSet allowedExposedColumns } /// - public IEnumerable GetAllowedExposedColumns(string entityName, string roleName, Operation operation) + public IEnumerable GetAllowedExposedColumns(string entityName, string roleName, Config.Operation operation) { return EntityPermissionsMap[entityName].RoleToOperationMap[roleName].OperationToColumnMap[operation].AllowedExposedColumns; } @@ -590,7 +590,7 @@ public IEnumerable GetRolesForEntity(string entityName) /// Entity to lookup permissions /// Operation to lookup applicable roles /// Collection of roles. - public IEnumerable GetRolesForOperation(string entityName, Operation operation) + public IEnumerable GetRolesForOperation(string entityName, Config.Operation operation) { if (EntityPermissionsMap[entityName].OperationToRolesMap.TryGetValue(operation, out List? roleList) && roleList is not null) { @@ -608,7 +608,7 @@ public IEnumerable GetRolesForOperation(string entityName, Operation ope /// Field to lookup operation permissions /// Specific operation to get collection of roles /// Collection of role names allowed to perform operation on Entity's field. - public IEnumerable GetRolesForField(string entityName, string field, Operation operation) + public IEnumerable GetRolesForField(string entityName, string field, Config.Operation operation) { return EntityPermissionsMap[entityName].FieldToRolesMap[field][operation]; } @@ -638,14 +638,14 @@ private IEnumerable ResolveEntityDefinitionColumns(string entityName) /// There are only four possible operations /// /// - private static Dictionary> CreateOperationToRoleMap() + private static Dictionary> CreateOperationToRoleMap() { - return new Dictionary>() + return new Dictionary>() { - { Operation.Create, new List()}, - { Operation.Read, new List()}, - { Operation.Update, new List()}, - { Operation.Delete, new List()} + { Config.Operation.Create, new List()}, + { Config.Operation.Read, new List()}, + { Config.Operation.Update, new List()}, + { Config.Operation.Delete, new List()} }; } diff --git a/src/Service/Authorization/RestAuthorizationHandler.cs b/src/Service/Authorization/RestAuthorizationHandler.cs index 0a83055350..7cf82b406e 100644 --- a/src/Service/Authorization/RestAuthorizationHandler.cs +++ b/src/Service/Authorization/RestAuthorizationHandler.cs @@ -102,9 +102,9 @@ public Task HandleAsync(AuthorizationHandlerContext context) } string roleName = httpContext.Request.Headers[AuthorizationResolver.CLIENT_ROLE_HEADER]; - IEnumerable operations = HttpVerbToOperations(httpContext.Request.Method); + IEnumerable operations = HttpVerbToOperations(httpContext.Request.Method); - foreach (Operation operation in operations) + foreach (Config.Operation operation in operations) { bool isAuthorized = _authorizationResolver.AreRoleAndOperationDefinedForEntity(entityName, roleName, operation); if (!isAuthorized) @@ -142,12 +142,12 @@ public Task HandleAsync(AuthorizationHandlerContext context) string entityName = restContext.EntityName; string roleName = httpContext.Request.Headers[AuthorizationResolver.CLIENT_ROLE_HEADER]; - IEnumerable operations = HttpVerbToOperations(httpContext.Request.Method); + IEnumerable operations = HttpVerbToOperations(httpContext.Request.Method); // Delete operations do not have column level restrictions. // If the operation is allowed for the role, the column requirement is implicitly successful, // and the authorization check can be short circuited here. - if (operations.Count() == 1 && operations.Contains(Operation.Delete)) + if (operations.Count() == 1 && operations.Contains(Config.Operation.Delete)) { context.Succeed(requirement); return Task.CompletedTask; @@ -160,7 +160,7 @@ public Task HandleAsync(AuthorizationHandlerContext context) // otherwise, just one operation is checked. // PUT and PATCH resolve to operations 'Create' and 'Update'. // A user must fulfill all operations' permissions requirements to proceed. - foreach (Operation operation in operations) + foreach (Config.Operation operation in operations) { // Get a list of all columns present in a request that need to be authorized. IEnumerable columnsToCheck = restContext.CumulativeColumns; @@ -175,14 +175,14 @@ public Task HandleAsync(AuthorizationHandlerContext context) // Find operations with no column filter in the query string will have FieldsToBeReturned == 0. // Then, the "allowed columns" resolved, will be set on FieldsToBeReturned. // When FieldsToBeReturned is originally >=1 column, the field is NOT modified here. - if (restContext.FieldsToBeReturned.Count == 0 && restContext.OperationType == Operation.Read) + if (restContext.FieldsToBeReturned.Count == 0 && restContext.OperationType == Config.Operation.Read) { // Union performed to avoid duplicate field names in FieldsToBeReturned. IEnumerable fieldsReturnedForFind = _authorizationResolver.GetAllowedExposedColumns(entityName, roleName, operation); restContext.UpdateReturnFields(fieldsReturnedForFind); } } - else if (columnsToCheck.Count() == 0 && restContext.OperationType is Operation.Read) + else if (columnsToCheck.Count() == 0 && restContext.OperationType is Config.Operation.Read) { // - Find operations typically return all metadata of a database record. // This check resolves all 'included' columns defined in permissions @@ -220,19 +220,19 @@ public Task HandleAsync(AuthorizationHandlerContext context) /// /// /// A collection of Operation types resolved from the http verb type of the request. - private static IEnumerable HttpVerbToOperations(string httpVerb) + private static IEnumerable HttpVerbToOperations(string httpVerb) { switch (httpVerb) { case HttpConstants.POST: - return new List(new Operation[] { Operation.Create }); + return new List(new Config.Operation[] { Config.Operation.Create }); case HttpConstants.PUT: case HttpConstants.PATCH: - return new List(new Operation[] { Operation.Create, Operation.Update }); + return new List(new Config.Operation[] { Config.Operation.Create, Config.Operation.Update }); case HttpConstants.DELETE: - return new List(new Operation[] { Operation.Delete }); + return new List(new Config.Operation[] { Config.Operation.Delete }); case HttpConstants.GET: - return new List(new Operation[] { Operation.Read }); + return new List(new Config.Operation[] { Config.Operation.Read }); default: throw new DataApiBuilderException( message: "Unsupported operation type.", diff --git a/src/Service/Configurations/RuntimeConfigValidator.cs b/src/Service/Configurations/RuntimeConfigValidator.cs index 06cf1cc85b..d664c037af 100644 --- a/src/Service/Configurations/RuntimeConfigValidator.cs +++ b/src/Service/Configurations/RuntimeConfigValidator.cs @@ -341,7 +341,7 @@ public void ValidatePermissionsInConfig(RuntimeConfig runtimeConfig) { string roleName = permissionSetting.Role; Object[] actions = permissionSetting.Operations; - List operationsList = new(); + List operationsList = new(); foreach (Object action in actions) { if (action is null) @@ -350,16 +350,16 @@ public void ValidatePermissionsInConfig(RuntimeConfig runtimeConfig) } // Evaluate actionOp as the current operation to be validated. - Operation actionOp; + Config.Operation actionOp; JsonElement actionJsonElement = JsonSerializer.SerializeToElement(action); if ((actionJsonElement!).ValueKind is JsonValueKind.String) { string actionName = action.ToString()!; if (AuthorizationResolver.WILDCARD.Equals(actionName)) { - actionOp = Operation.All; + actionOp = Config.Operation.All; } - else if (!Enum.TryParse(actionName, ignoreCase: true, out actionOp) || + else if (!Enum.TryParse(actionName, ignoreCase: true, out actionOp) || !IsValidPermissionAction(actionOp)) { throw GetInvalidActionException(entityName, roleName, actionName); @@ -410,7 +410,7 @@ public void ValidatePermissionsInConfig(RuntimeConfig runtimeConfig) // If thats the case with both of them, we specify 'included' in error. string misconfiguredColumnSet = configOperation.Fields.Include.Contains(AuthorizationResolver.WILDCARD) && configOperation.Fields.Include.Count > 1 ? "included" : "excluded"; - string actionName = actionOp is Operation.All ? "*" : actionOp.ToString(); + string actionName = actionOp is Config.Operation.All ? "*" : actionOp.ToString(); throw new DataApiBuilderException( message: $"No other field can be present with wildcard in the {misconfiguredColumnSet} set for:" + $" entity:{entityName}, role:{permissionSetting.Role}, action:{actionName}", @@ -446,7 +446,7 @@ public void ValidatePermissionsInConfig(RuntimeConfig runtimeConfig) if (entity.ObjectType is SourceType.StoredProcedure) { if ((operationsList.Count > 1) - || (operationsList.Count is 1 && operationsList[0] is Operation.All)) + || (operationsList.Count is 1 && operationsList[0] is Config.Operation.All)) { throw new DataApiBuilderException( message: $"Invalid Operations for Entity: {entityName}. " + @@ -469,7 +469,7 @@ public void ValidatePermissionsInConfig(RuntimeConfig runtimeConfig) /// public bool IsValidDatabasePolicyForAction(PermissionOperation permission) { - return !(permission.Policy?.Database != null && permission.Name == Operation.Create); + return !(permission.Policy?.Database != null && permission.Name == Config.Operation.Create); } /// @@ -599,7 +599,7 @@ public void ValidateStoredProceduresInConfig(RuntimeConfig runtimeConfig, ISqlMe entityName, dbObject, JsonSerializer.SerializeToElement(entity.Parameters), - Operation.All); + Config.Operation.All); try { RequestValidator.ValidateStoredProcedureRequestContext(sqRequestContext, sqlMetadataProvider); @@ -809,9 +809,9 @@ private static DataApiBuilderException GetInvalidActionException(string entityNa /// /// /// Boolean value indicating whether the action is valid or not. - public static bool IsValidPermissionAction(Operation action) + public static bool IsValidPermissionAction(Config.Operation action) { - return action is Operation.All || PermissionOperation.ValidPermissionOperations.Contains(action); + return action is Config.Operation.All || PermissionOperation.ValidPermissionOperations.Contains(action); } } } diff --git a/src/Service/Controllers/RestController.cs b/src/Service/Controllers/RestController.cs index 0d62cf61bf..15d97a2fa3 100644 --- a/src/Service/Controllers/RestController.cs +++ b/src/Service/Controllers/RestController.cs @@ -85,7 +85,7 @@ public async Task Find( { return await HandleOperation( route, - Operation.Read); + Config.Operation.Read); } /// @@ -103,7 +103,7 @@ public async Task Insert( { return await HandleOperation( route, - Operation.Insert); + Config.Operation.Insert); } /// @@ -123,7 +123,7 @@ public async Task Delete( { return await HandleOperation( route, - Operation.Delete); + Config.Operation.Delete); } /// @@ -143,7 +143,7 @@ public async Task Upsert( { return await HandleOperation( route, - DeterminePatchPutSemantics(Operation.Upsert)); + DeterminePatchPutSemantics(Config.Operation.Upsert)); } /// @@ -163,7 +163,7 @@ public async Task UpsertIncremental( { return await HandleOperation( route, - DeterminePatchPutSemantics(Operation.UpsertIncremental)); + DeterminePatchPutSemantics(Config.Operation.UpsertIncremental)); } /// @@ -173,7 +173,7 @@ public async Task UpsertIncremental( /// The kind of operation to handle. private async Task HandleOperation( string route, - Operation operationType) + Config.Operation operationType) { try { @@ -253,7 +253,7 @@ private async Task HandleOperation( /// /// opertion to be used. /// correct opertion based on headers. - private Operation DeterminePatchPutSemantics(Operation operation) + private Config.Operation DeterminePatchPutSemantics(Config.Operation operation) { if (HttpContext.Request.Headers.ContainsKey("If-Match")) @@ -267,11 +267,11 @@ private Operation DeterminePatchPutSemantics(Operation operation) switch (operation) { - case Operation.Upsert: - operation = Operation.Update; + case Config.Operation.Upsert: + operation = Config.Operation.Update; break; - case Operation.UpsertIncremental: - operation = Operation.UpdateIncremental; + case Config.Operation.UpsertIncremental: + operation = Config.Operation.UpdateIncremental; break; } } diff --git a/src/Service/Models/CosmosOperationMetadata.cs b/src/Service/Models/CosmosOperationMetadata.cs index d5f9bcaa56..6ea7f00cb4 100644 --- a/src/Service/Models/CosmosOperationMetadata.cs +++ b/src/Service/Models/CosmosOperationMetadata.cs @@ -8,5 +8,5 @@ namespace Azure.DataApiBuilder.Service.Models /// Name of the database /// Name of the container /// Type of operation to perform - record CosmosOperationMetadata(string DatabaseName, string ContainerName, Operation OperationType); + record CosmosOperationMetadata(string DatabaseName, string ContainerName, Config.Operation OperationType); } diff --git a/src/Service/Models/RestRequestContexts/DeleteRequestContext.cs b/src/Service/Models/RestRequestContexts/DeleteRequestContext.cs index cb1685e9f9..61996798ac 100644 --- a/src/Service/Models/RestRequestContexts/DeleteRequestContext.cs +++ b/src/Service/Models/RestRequestContexts/DeleteRequestContext.cs @@ -18,7 +18,7 @@ public DeleteRequestContext(string entityName, DatabaseObject dbo, bool isList) PrimaryKeyValuePairs = new(); FieldValuePairsInBody = new(); IsMany = isList; - OperationType = Operation.Delete; + OperationType = Config.Operation.Delete; } } } diff --git a/src/Service/Models/RestRequestContexts/FindRequestContext.cs b/src/Service/Models/RestRequestContexts/FindRequestContext.cs index e7ab5022b7..8d175c1dd7 100644 --- a/src/Service/Models/RestRequestContexts/FindRequestContext.cs +++ b/src/Service/Models/RestRequestContexts/FindRequestContext.cs @@ -19,7 +19,7 @@ public FindRequestContext(string entityName, DatabaseObject dbo, bool isList) PrimaryKeyValuePairs = new(); FieldValuePairsInBody = new(); IsMany = isList; - OperationType = Operation.Read; + OperationType = Config.Operation.Read; } } diff --git a/src/Service/Models/RestRequestContexts/InsertRequestContext.cs b/src/Service/Models/RestRequestContexts/InsertRequestContext.cs index 30617ff73b..9ef5c52ced 100644 --- a/src/Service/Models/RestRequestContexts/InsertRequestContext.cs +++ b/src/Service/Models/RestRequestContexts/InsertRequestContext.cs @@ -16,7 +16,7 @@ public InsertRequestContext( string entityName, DatabaseObject dbo, JsonElement insertPayloadRoot, - Operation operationType) + Config.Operation operationType) : base(entityName, dbo) { FieldsToBeReturned = new(); diff --git a/src/Service/Models/RestRequestContexts/RestRequestContext.cs b/src/Service/Models/RestRequestContexts/RestRequestContext.cs index 72b00d4195..07c2ee7632 100644 --- a/src/Service/Models/RestRequestContexts/RestRequestContext.cs +++ b/src/Service/Models/RestRequestContexts/RestRequestContext.cs @@ -101,7 +101,7 @@ protected RestRequestContext(string entityName, DatabaseObject dbo) /// /// The database engine operation type this request is. /// - public Operation OperationType { get; set; } + public Config.Operation OperationType { get; set; } /// /// A collection of all unique column names present in the request. diff --git a/src/Service/Models/RestRequestContexts/StoredProcedureRequestContext.cs b/src/Service/Models/RestRequestContexts/StoredProcedureRequestContext.cs index bae8791b39..ff092db13b 100644 --- a/src/Service/Models/RestRequestContexts/StoredProcedureRequestContext.cs +++ b/src/Service/Models/RestRequestContexts/StoredProcedureRequestContext.cs @@ -24,7 +24,7 @@ public StoredProcedureRequestContext( string entityName, DatabaseObject dbo, JsonElement? requestPayloadRoot, - Operation operationType) + Config.Operation operationType) : base(entityName, dbo) { FieldsToBeReturned = new(); @@ -40,7 +40,7 @@ public StoredProcedureRequestContext( /// public void PopulateResolvedParameters() { - if (OperationType is Operation.Read) + if (OperationType is Config.Operation.Read) { // Query string may have malformed/null keys, if so just ignore them ResolvedParameters = ParsedQueryString.Cast() diff --git a/src/Service/Models/RestRequestContexts/UpsertRequestContext.cs b/src/Service/Models/RestRequestContexts/UpsertRequestContext.cs index f862a8a08e..ee460ef331 100644 --- a/src/Service/Models/RestRequestContexts/UpsertRequestContext.cs +++ b/src/Service/Models/RestRequestContexts/UpsertRequestContext.cs @@ -16,7 +16,7 @@ public UpsertRequestContext( string entityName, DatabaseObject dbo, JsonElement insertPayloadRoot, - Operation operationType) + Config.Operation operationType) : base(entityName, dbo) { FieldsToBeReturned = new(); diff --git a/src/Service/Resolvers/AuthorizationPolicyHelpers.cs b/src/Service/Resolvers/AuthorizationPolicyHelpers.cs index 70821e554c..03f73e8457 100644 --- a/src/Service/Resolvers/AuthorizationPolicyHelpers.cs +++ b/src/Service/Resolvers/AuthorizationPolicyHelpers.cs @@ -28,7 +28,7 @@ public static class AuthorizationPolicyHelpers /// Used to lookup authorization policies. /// Provides helper method to process ODataFilterClause. public static void ProcessAuthorizationPolicies( - Operation operationType, + Config.Operation operationType, BaseSqlQueryStructure queryStructure, HttpContext context, IAuthorizationResolver authorizationResolver, diff --git a/src/Service/Resolvers/CosmosMutationEngine.cs b/src/Service/Resolvers/CosmosMutationEngine.cs index eb61ad6671..b8933f3d67 100644 --- a/src/Service/Resolvers/CosmosMutationEngine.cs +++ b/src/Service/Resolvers/CosmosMutationEngine.cs @@ -57,9 +57,9 @@ private async Task ExecuteAsync(IDictionary queryArgs, ItemResponse? response = resolver.OperationType switch { - Operation.UpdateGraphQL => await HandleUpdateAsync(queryArgs, container), - Operation.Create => await HandleCreateAsync(queryArgs, container), - Operation.Delete => await HandleDeleteAsync(queryArgs, container), + Config.Operation.UpdateGraphQL => await HandleUpdateAsync(queryArgs, container), + Config.Operation.Create => await HandleCreateAsync(queryArgs, container), + Config.Operation.Delete => await HandleDeleteAsync(queryArgs, container), _ => throw new NotSupportedException($"unsupported operation type: {resolver.OperationType}") }; @@ -236,7 +236,7 @@ public async Task> ExecuteAsync(IMiddlewareContex string containerName = _metadataProvider.GetDatabaseObjectName(entityName); string graphqlMutationName = context.Selection.Field.Name.Value; - Operation mutationOperation = + Config.Operation mutationOperation = MutationBuilder.DetermineMutationOperationTypeBasedOnInputType(graphqlMutationName); CosmosOperationMetadata mutation = new(databaseName, containerName, mutationOperation); diff --git a/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs b/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs index 380002c13f..1747c3796a 100644 --- a/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs +++ b/src/Service/Resolvers/Sql Query Structures/SqlQueryStructure.cs @@ -354,7 +354,7 @@ private SqlQueryStructure( HttpContext httpContext = (HttpContext)httpContextValue!; // Process Authorization Policy of the entity being processed. - AuthorizationPolicyHelpers.ProcessAuthorizationPolicies(Operation.Read, queryStructure: this, httpContext, authorizationResolver, sqlMetadataProvider); + AuthorizationPolicyHelpers.ProcessAuthorizationPolicies(Config.Operation.Read, queryStructure: this, httpContext, authorizationResolver, sqlMetadataProvider); if (outputType.IsNonNullType()) { diff --git a/src/Service/Resolvers/SqlExistsQueryStructure.cs b/src/Service/Resolvers/SqlExistsQueryStructure.cs index 1ec2a2897c..c0556eb044 100644 --- a/src/Service/Resolvers/SqlExistsQueryStructure.cs +++ b/src/Service/Resolvers/SqlExistsQueryStructure.cs @@ -48,7 +48,7 @@ public SqlExistsQueryStructure( // This adds any required DBPolicyPredicates to this Exists query structure. AuthorizationPolicyHelpers.ProcessAuthorizationPolicies( - Operation.Read, + Config.Operation.Read, queryStructure: this, httpContext, authorizationResolver, diff --git a/src/Service/Resolvers/SqlMutationEngine.cs b/src/Service/Resolvers/SqlMutationEngine.cs index 0861aec793..01a43a5466 100644 --- a/src/Service/Resolvers/SqlMutationEngine.cs +++ b/src/Service/Resolvers/SqlMutationEngine.cs @@ -86,13 +86,13 @@ public async Task> ExecuteAsync(IMiddlewareContex } Tuple? result = null; - Operation mutationOperation = + Config.Operation mutationOperation = MutationBuilder.DetermineMutationOperationTypeBasedOnInputType(graphqlMutationName); // If authorization fails, an exception will be thrown and request execution halts. AuthorizeMutationFields(context, parameters, entityName, mutationOperation); - if (mutationOperation is Operation.Delete) + if (mutationOperation is Config.Operation.Delete) { // compute the mutation result before removing the element, // since typical GraphQL delete mutations return the metadata of the deleted item. @@ -175,10 +175,10 @@ await _queryExecutor.ExecuteQueryAsync( // to each action, with data always from the first result set, as there may be arbitrarily many. switch (context.OperationType) { - case Operation.Delete: + case Config.Operation.Delete: // Returns a 204 No Content so long as the stored procedure executes without error return new NoContentResult(); - case Operation.Insert: + case Config.Operation.Insert: // Returns a 201 Created with whatever the first result set is returned from the procedure // A "correctly" configured stored procedure would INSERT INTO ... OUTPUT ... VALUES as the first and only result set if (resultRowAndProperties is not null && @@ -196,10 +196,10 @@ await _queryExecutor.ExecuteQueryAsync( } ); } - case Operation.Update: - case Operation.UpdateIncremental: - case Operation.Upsert: - case Operation.UpsertIncremental: + case Config.Operation.Update: + case Config.Operation.UpdateIncremental: + case Config.Operation.Upsert: + case Config.Operation.UpsertIncremental: // Since we cannot check if anything was created, just return a 200 Ok response with first result set output // A "correctly" configured stored procedure would UPDATE ... SET ... OUTPUT as the first and only result set if (resultRowAndProperties is not null && @@ -235,7 +235,7 @@ await _queryExecutor.ExecuteQueryAsync( { Dictionary parameters = PrepareParameters(context); - if (context.OperationType is Operation.Delete) + if (context.OperationType is Config.Operation.Delete) { Dictionary? resultProperties = await PerformDeleteOperation( @@ -251,7 +251,7 @@ await PerformDeleteOperation( return new NoContentResult(); } } - else if (context.OperationType is Operation.Upsert || context.OperationType is Operation.UpsertIncremental) + else if (context.OperationType is Config.Operation.Upsert || context.OperationType is Config.Operation.UpsertIncremental) { Tuple?, Dictionary>? resultRowAndProperties = await PerformUpsertOperation( @@ -292,7 +292,7 @@ await PerformMutationOperation( context.OperationType, parameters); - if (context.OperationType is Operation.Insert) + if (context.OperationType is Config.Operation.Insert) { if (resultRowAndProperties is null || resultRowAndProperties.Item1 is null) { @@ -307,7 +307,7 @@ await PerformMutationOperation( return new CreatedResult(location: primaryKeyRoute, OkMutationResponse(resultRow).Value); } - if (context.OperationType is Operation.Update || context.OperationType is Operation.UpdateIncremental) + if (context.OperationType is Config.Operation.Update || context.OperationType is Config.Operation.UpdateIncremental) { // Nothing to update means we throw Exception if (resultRowAndProperties is null || @@ -362,7 +362,7 @@ private static OkObjectResult OkMutationResponse(Dictionary? re private async Task?, Dictionary>?> PerformMutationOperation( string entityName, - Operation operationType, + Config.Operation operationType, IDictionary parameters, IMiddlewareContext? context = null) { @@ -370,8 +370,8 @@ private static OkObjectResult OkMutationResponse(Dictionary? re Dictionary queryParameters; switch (operationType) { - case Operation.Insert: - case Operation.Create: + case Config.Operation.Insert: + case Config.Operation.Create: SqlInsertStructure insertQueryStruct = context is null ? new( entityName, @@ -388,7 +388,7 @@ private static OkObjectResult OkMutationResponse(Dictionary? re queryString = _queryBuilder.Build(insertQueryStruct); queryParameters = insertQueryStruct.Parameters; break; - case Operation.Update: + case Config.Operation.Update: SqlUpdateStructure updateStructure = new( entityName, _sqlMetadataProvider, @@ -399,7 +399,7 @@ private static OkObjectResult OkMutationResponse(Dictionary? re queryString = _queryBuilder.Build(updateStructure); queryParameters = updateStructure.Parameters; break; - case Operation.UpdateIncremental: + case Config.Operation.UpdateIncremental: SqlUpdateStructure updateIncrementalStructure = new( entityName, _sqlMetadataProvider, @@ -410,7 +410,7 @@ private static OkObjectResult OkMutationResponse(Dictionary? re queryString = _queryBuilder.Build(updateIncrementalStructure); queryParameters = updateIncrementalStructure.Parameters; break; - case Operation.UpdateGraphQL: + case Config.Operation.UpdateGraphQL: if (context is null) { throw new ArgumentNullException("Context should not be null for a GraphQL operation."); @@ -424,7 +424,7 @@ private static OkObjectResult OkMutationResponse(Dictionary? re _gQLFilterParser, parameters); AuthorizationPolicyHelpers.ProcessAuthorizationPolicies( - Operation.Update, + Config.Operation.Update, updateGraphQLStructure, _httpContextAccessor.HttpContext!, _authorizationResolver, @@ -501,7 +501,7 @@ private async Task?> _gQLFilterParser, parameters); AuthorizationPolicyHelpers.ProcessAuthorizationPolicies( - Operation.Delete, + Config.Operation.Delete, deleteStructure, _httpContextAccessor.HttpContext!, _authorizationResolver, @@ -536,10 +536,10 @@ private async Task?> { string queryString; Dictionary queryParameters; - Operation operationType = context.OperationType; + Config.Operation operationType = context.OperationType; string entityName = context.EntityName; - if (operationType is Operation.Upsert) + if (operationType is Config.Operation.Upsert) { SqlUpsertQueryStructure upsertStructure = new( entityName, @@ -618,14 +618,14 @@ public string ConstructPrimaryKeyRoute(RestRequestContext context, Dictionary parameters, string entityName, - Operation mutationOperation) + Config.Operation mutationOperation) { string role = string.Empty; if (context.ContextData.TryGetValue(key: AuthorizationResolver.CLIENT_ROLE_HEADER, out object? value)) @@ -686,7 +686,7 @@ public void AuthorizeMutationFields( } List inputArgumentKeys; - if (mutationOperation != Operation.Delete) + if (mutationOperation != Config.Operation.Delete) { inputArgumentKeys = BaseSqlQueryStructure.GetSubArgumentNamesFromGQLMutArguments(MutationBuilder.INPUT_ARGUMENT_NAME, parameters); } @@ -699,13 +699,13 @@ public void AuthorizeMutationFields( switch (mutationOperation) { - case Operation.UpdateGraphQL: - isAuthorized = _authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: role, operation: Operation.Update, inputArgumentKeys); + case Config.Operation.UpdateGraphQL: + isAuthorized = _authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: role, operation: Config.Operation.Update, inputArgumentKeys); break; - case Operation.Create: - isAuthorized = _authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: role, operation: Operation.Create, inputArgumentKeys); + case Config.Operation.Create: + isAuthorized = _authorizationResolver.AreColumnsAllowedForOperation(entityName, roleName: role, operation: Config.Operation.Create, inputArgumentKeys); break; - case Operation.Delete: + case Config.Operation.Delete: // Delete operations are not checked for authorization on field level, // and instead at the mutation level and would be rejected before this time in the pipeline. // Continuing on with operation. diff --git a/src/Service/Resolvers/SqlQueryEngine.cs b/src/Service/Resolvers/SqlQueryEngine.cs index 8a43c12474..a6c5522096 100644 --- a/src/Service/Resolvers/SqlQueryEngine.cs +++ b/src/Service/Resolvers/SqlQueryEngine.cs @@ -108,7 +108,7 @@ public async Task, IMetadata>> ExecuteListAsync( // checking if role has read permission on the result _authorizationResolver.EntityPermissionsMap.TryGetValue(context.Field.Name.Value, out EntityMetadata entityMetadata); string role = context.ContextData[CLIENT_ROLE_HEADER].ToString(); - bool IsReadAllowed = entityMetadata.RoleToOperationMap[role].OperationToColumnMap.ContainsKey(Operation.Read); + bool IsReadAllowed = entityMetadata.RoleToOperationMap[role].OperationToColumnMap.ContainsKey(Config.Operation.Read); return new Tuple, IMetadata>( FormatStoredProcedureResultAsJsonList(IsReadAllowed, await ExecuteAsync(sqlExecuteStructure)), diff --git a/src/Service/Services/GraphQLSchemaCreator.cs b/src/Service/Services/GraphQLSchemaCreator.cs index bed327e6ee..bcd4091496 100644 --- a/src/Service/Services/GraphQLSchemaCreator.cs +++ b/src/Service/Services/GraphQLSchemaCreator.cs @@ -149,7 +149,7 @@ DatabaseType.postgresql or foreach (string column in sourceDefinition.Columns.Keys) { - IEnumerable roles = _authorizationResolver.GetRolesForField(entityName, field: column, operation: Operation.Read); + IEnumerable roles = _authorizationResolver.GetRolesForField(entityName, field: column, operation: Config.Operation.Read); if (!rolesAllowedForFields.TryAdd(key: column, value: roles)) { throw new DataApiBuilderException( diff --git a/src/Service/Services/RequestValidator.cs b/src/Service/Services/RequestValidator.cs index c842421e5b..85bea062fb 100644 --- a/src/Service/Services/RequestValidator.cs +++ b/src/Service/Services/RequestValidator.cs @@ -385,7 +385,7 @@ public static void ValidateUpsertRequestContext( } } - bool isReplacementUpdate = (upsertRequestCtx.OperationType == Operation.Upsert) ? true : false; + bool isReplacementUpdate = (upsertRequestCtx.OperationType == Config.Operation.Upsert) ? true : false; if (ValidateColumn(column.Value, exposedName!, fieldsInRequestBody, isReplacementUpdate)) { unValidatedFields.Remove(exposedName!); diff --git a/src/Service/Services/RestService.cs b/src/Service/Services/RestService.cs index b658918b15..3c32a77d38 100644 --- a/src/Service/Services/RestService.cs +++ b/src/Service/Services/RestService.cs @@ -59,7 +59,7 @@ RuntimeConfigProvider runtimeConfigProvider /// The primary key route. e.g. customerName/Xyz/saleOrderId/123 public async Task ExecuteAsync( string entityName, - Operation operationType, + Config.Operation operationType, string? primaryKeyRoute) { RequestValidator.ValidateEntity(entityName, _sqlMetadataProvider.EntityToDatabaseObject.Keys); @@ -93,13 +93,13 @@ RuntimeConfigProvider runtimeConfigProvider { switch (operationType) { - case Operation.Read: + case Config.Operation.Read: context = new FindRequestContext( entityName, dbo: dbObject, isList: string.IsNullOrEmpty(primaryKeyRoute)); break; - case Operation.Insert: + case Config.Operation.Insert: JsonElement insertPayloadRoot = RequestValidator.ValidateInsertRequest(queryString, requestBody); context = new InsertRequestContext( entityName, @@ -114,16 +114,16 @@ RuntimeConfigProvider runtimeConfigProvider } break; - case Operation.Delete: + case Config.Operation.Delete: RequestValidator.ValidateDeleteRequest(primaryKeyRoute); context = new DeleteRequestContext(entityName, dbo: dbObject, isList: false); break; - case Operation.Update: - case Operation.UpdateIncremental: - case Operation.Upsert: - case Operation.UpsertIncremental: + case Config.Operation.Update: + case Config.Operation.UpdateIncremental: + case Config.Operation.Upsert: + case Config.Operation.UpsertIncremental: JsonElement upsertPayloadRoot = RequestValidator.ValidateUpdateOrUpsertRequest(primaryKeyRoute, requestBody); context = new UpsertRequestContext( entityName, @@ -160,7 +160,7 @@ RuntimeConfigProvider runtimeConfigProvider } string role = GetHttpContext().Request.Headers[AuthorizationResolver.CLIENT_ROLE_HEADER]; - Operation operation = HttpVerbToOperations(GetHttpContext().Request.Method); + Config.Operation operation = HttpVerbToOperations(GetHttpContext().Request.Method); string dbPolicy = _authorizationResolver.ProcessDBPolicy(entityName, role, operation, GetHttpContext()); if (!string.IsNullOrEmpty(dbPolicy)) { @@ -189,14 +189,14 @@ RuntimeConfigProvider runtimeConfigProvider switch (operationType) { - case Operation.Read: + case Config.Operation.Read: return await DispatchQuery(context); - case Operation.Insert: - case Operation.Delete: - case Operation.Update: - case Operation.UpdateIncremental: - case Operation.Upsert: - case Operation.UpsertIncremental: + case Config.Operation.Insert: + case Config.Operation.Delete: + case Config.Operation.Update: + case Config.Operation.UpdateIncremental: + case Config.Operation.Upsert: + case Config.Operation.UpsertIncremental: return await DispatchMutation(context); default: throw new NotSupportedException("This operation is not yet supported."); @@ -233,7 +233,7 @@ private Task DispatchQuery(RestRequestContext context) /// /// Helper method to populate the context in case the database object for this request is a stored procedure /// - private void PopulateStoredProcedureContext(Operation operationType, + private void PopulateStoredProcedureContext(Config.Operation operationType, DatabaseObject dbObject, string entityName, string queryString, @@ -244,7 +244,7 @@ private void PopulateStoredProcedureContext(Operation operationType, switch (operationType) { - case Operation.Read: + case Config.Operation.Read: // Parameters passed in query string, request body is ignored for find requests context = new StoredProcedureRequestContext( entityName, @@ -262,12 +262,12 @@ private void PopulateStoredProcedureContext(Operation operationType, } break; - case Operation.Insert: - case Operation.Delete: - case Operation.Update: - case Operation.UpdateIncremental: - case Operation.Upsert: - case Operation.UpsertIncremental: + case Config.Operation.Insert: + case Config.Operation.Delete: + case Config.Operation.Update: + case Config.Operation.UpdateIncremental: + case Config.Operation.Upsert: + case Config.Operation.UpsertIncremental: // Stored procedure call is semantically identical for all methods except Find, so we can // effectively reuse the ValidateInsertRequest - throws error if query string is nonempty // and parses the body into json @@ -393,21 +393,21 @@ public async Task AuthorizationCheckForRequirementAsync(object? resource, IAutho /// /// /// The CRUD operation for the given httpverb. - public static Operation HttpVerbToOperations(string httpVerbName) + public static Config.Operation HttpVerbToOperations(string httpVerbName) { switch (httpVerbName) { case "POST": - return Operation.Create; + return Config.Operation.Create; case "PUT": case "PATCH": // Please refer to the use of this method, which is to look out for policy based on crud operation type. // Since create doesn't have filter predicates, PUT/PATCH would resolve to update operation. - return Operation.Update; + return Config.Operation.Update; case "DELETE": - return Operation.Delete; + return Config.Operation.Delete; case "GET": - return Operation.Read; + return Config.Operation.Read; default: throw new DataApiBuilderException( message: "Unsupported operation type.", From c38708a751adc4036fc4bed7a77cc38029e322c8 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 01:30:58 -0800 Subject: [PATCH 03/12] format --- .../Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs | 1 - .../SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs | 1 - .../SqlTests/RestApiTests/Insert/InsertApiTestBase.cs | 1 - .../SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs | 1 - .../SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs | 1 - .../SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs | 1 - .../SqlTests/RestApiTests/Patch/PatchApiTestBase.cs | 1 - src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs | 1 - src/Service/Authorization/RestAuthorizationHandler.cs | 1 - src/Service/Controllers/RestController.cs | 1 - src/Service/Models/CosmosOperationMetadata.cs | 2 -- src/Service/Models/MutationResolver.cs | 2 -- src/Service/Resolvers/AuthorizationPolicyHelpers.cs | 1 - src/Service/Resolvers/CosmosMutationEngine.cs | 1 - src/Service/Resolvers/SqlExistsQueryStructure.cs | 1 - 15 files changed, 17 deletions(-) diff --git a/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs b/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs index a39b1860ef..a31877fa37 100644 --- a/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs +++ b/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using Azure.DataApiBuilder.Auth; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Authorization; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.GraphQLBuilder.Mutations; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs index 49455026d8..7170ad92eb 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs @@ -1,6 +1,5 @@ using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs index 1a49aa068d..04bf222eef 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs @@ -1,6 +1,5 @@ using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs index 28b06777db..edd26ba50f 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs index 638cdc9b22..07e5b4c3ee 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs index 00d1a03c92..5741955dcc 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs index 10bf6869bd..1a7b05d4f8 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Services; using Microsoft.AspNetCore.Http; diff --git a/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs index 880619a5d3..a2f00f33cb 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Services; using Microsoft.AspNetCore.Http; diff --git a/src/Service/Authorization/RestAuthorizationHandler.cs b/src/Service/Authorization/RestAuthorizationHandler.cs index 7cf82b406e..e11d1b9aac 100644 --- a/src/Service/Authorization/RestAuthorizationHandler.cs +++ b/src/Service/Authorization/RestAuthorizationHandler.cs @@ -4,7 +4,6 @@ using System.Net; using System.Threading.Tasks; using Azure.DataApiBuilder.Auth; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Models; using Microsoft.AspNetCore.Authorization; diff --git a/src/Service/Controllers/RestController.cs b/src/Service/Controllers/RestController.cs index 15d97a2fa3..0f4abf9846 100644 --- a/src/Service/Controllers/RestController.cs +++ b/src/Service/Controllers/RestController.cs @@ -1,7 +1,6 @@ using System; using System.Net; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Services; using Microsoft.AspNetCore.Http; diff --git a/src/Service/Models/CosmosOperationMetadata.cs b/src/Service/Models/CosmosOperationMetadata.cs index 6ea7f00cb4..5d9bb4d0a5 100644 --- a/src/Service/Models/CosmosOperationMetadata.cs +++ b/src/Service/Models/CosmosOperationMetadata.cs @@ -1,5 +1,3 @@ -using Azure.DataApiBuilder.Config; - namespace Azure.DataApiBuilder.Service.Models { /// diff --git a/src/Service/Models/MutationResolver.cs b/src/Service/Models/MutationResolver.cs index 6864959088..86e9ede1c1 100644 --- a/src/Service/Models/MutationResolver.cs +++ b/src/Service/Models/MutationResolver.cs @@ -1,5 +1,3 @@ -using Azure.DataApiBuilder.Config; - namespace Azure.DataApiBuilder.Service.Models { public record MutationResolver(string Id, Operation OperationType, string DatabaseName, string ContainerName, string Fields, string Table); diff --git a/src/Service/Resolvers/AuthorizationPolicyHelpers.cs b/src/Service/Resolvers/AuthorizationPolicyHelpers.cs index 03f73e8457..e5cb562ec7 100644 --- a/src/Service/Resolvers/AuthorizationPolicyHelpers.cs +++ b/src/Service/Resolvers/AuthorizationPolicyHelpers.cs @@ -1,5 +1,4 @@ using Azure.DataApiBuilder.Auth; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Authorization; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Parsers; diff --git a/src/Service/Resolvers/CosmosMutationEngine.cs b/src/Service/Resolvers/CosmosMutationEngine.cs index b8933f3d67..d1379fc7b5 100644 --- a/src/Service/Resolvers/CosmosMutationEngine.cs +++ b/src/Service/Resolvers/CosmosMutationEngine.cs @@ -4,7 +4,6 @@ using System.Net; using System.Text.Json; using System.Threading.Tasks; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.GraphQLBuilder.Mutations; using Azure.DataApiBuilder.Service.GraphQLBuilder.Queries; diff --git a/src/Service/Resolvers/SqlExistsQueryStructure.cs b/src/Service/Resolvers/SqlExistsQueryStructure.cs index c0556eb044..dba7ae231a 100644 --- a/src/Service/Resolvers/SqlExistsQueryStructure.cs +++ b/src/Service/Resolvers/SqlExistsQueryStructure.cs @@ -1,6 +1,5 @@ using System.Collections.Generic; using Azure.DataApiBuilder.Auth; -using Azure.DataApiBuilder.Config; using Azure.DataApiBuilder.Service.Exceptions; using Azure.DataApiBuilder.Service.Models; using Azure.DataApiBuilder.Service.Services; From e0e55814833e57940917f95af2979b26e4a759a6 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 01:50:12 -0800 Subject: [PATCH 04/12] some collissions in tests fixed --- .../Authorization/AuthorizationHelpers.cs | 2 +- .../AuthorizationResolverUnitTests.cs | 178 +++++++++--------- .../Unittests/ConfigValidationUnitTests.cs | 52 ++--- 3 files changed, 116 insertions(+), 116 deletions(-) diff --git a/src/Service.Tests/Authorization/AuthorizationHelpers.cs b/src/Service.Tests/Authorization/AuthorizationHelpers.cs index d6166f4ace..efd4fca93c 100644 --- a/src/Service.Tests/Authorization/AuthorizationHelpers.cs +++ b/src/Service.Tests/Authorization/AuthorizationHelpers.cs @@ -60,7 +60,7 @@ public static RuntimeConfig InitRuntimeConfig( string entityName = TEST_ENTITY, object? entitySource = null, string roleName = "Reader", - Operation operation = Operation.Create, + Config.Operation operation = Config.Operation.Create, HashSet? includedCols = null, HashSet? excludedCols = null, string? databasePolicy = null, diff --git a/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs b/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs index 4120279d5b..d803635657 100644 --- a/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs +++ b/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs @@ -22,7 +22,7 @@ public class AuthorizationResolverUnitTests { private const string TEST_ENTITY = "SampleEntity"; private const string TEST_ROLE = "Writer"; - private const Operation TEST_OPERATION = Operation.Create; + private const Config.Operation TEST_OPERATION = Config.Operation.Create; private const string TEST_AUTHENTICATION_TYPE = "TestAuth"; private const string TEST_CLAIMTYPE_NAME = "TestName"; @@ -99,14 +99,14 @@ public void NoRoleHeader_RoleContextTest() /// Request operation does not match an operation defined for role (role has >=1 defined operation) -> INVALID /// [DataTestMethod] - [DataRow("Writer", Operation.Create, "Writer", Operation.Create, true)] - [DataRow("Reader", Operation.Create, "Reader", Operation.None, false)] - [DataRow("Writer", Operation.Create, "Writer", Operation.Update, false)] + [DataRow("Writer", Config.Operation.Create, "Writer", Config.Operation.Create, true)] + [DataRow("Reader", Config.Operation.Create, "Reader", Config.Operation.None, false)] + [DataRow("Writer", Config.Operation.Create, "Writer", Config.Operation.Update, false)] public void AreRoleAndOperationDefinedForEntityTest( string configRole, - Operation configOperation, + Config.Operation configOperation, string roleName, - Operation operation, + Config.Operation operation, bool expected) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( @@ -131,7 +131,7 @@ public void TestWildcardOperation() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.All); + operation: Config.Operation.All); // Override the permission operations to be a list of operations for wildcard // instead of a list of objects created by InitRuntimeConfig() @@ -143,10 +143,10 @@ public void TestWildcardOperation() Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.All)); + Config.Operation.All)); // The wildcard operation should be expanded to all the explicit operations. - foreach (Operation operation in PermissionOperation.ValidPermissionOperations) + foreach (Config.Operation operation in PermissionOperation.ValidPermissionOperations) { Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, @@ -165,8 +165,8 @@ public void TestWildcardOperation() } // Validate that the authorization check fails because the operations are invalid. - Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, TEST_ROLE, Operation.Insert)); - Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, TEST_ROLE, Operation.Upsert)); + Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, TEST_ROLE, Config.Operation.Insert)); + Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, TEST_ROLE, Config.Operation.Upsert)); } /// @@ -186,12 +186,12 @@ public void TestRoleAndOperationCombination() exclude: null); PermissionOperation readAction = new( - Name: Operation.Read, + Name: Config.Operation.Read, Fields: fieldsForRole, Policy: null); PermissionOperation updateAction = new( - Name: Operation.Update, + Name: Config.Operation.Update, Fields: fieldsForRole, Policy: null); @@ -228,37 +228,37 @@ public void TestRoleAndOperationCombination() Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_ONLY_ROLE, - Operation.Read)); + Config.Operation.Read)); Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_ONLY_ROLE, - Operation.Update)); + Config.Operation.Update)); Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_ONLY_ROLE, - Operation.Create)); + Config.Operation.Create)); Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_ONLY_ROLE, - Operation.Delete)); + Config.Operation.Delete)); // Verify that read only role has permission for read/update and nothing else. Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_AND_UPDATE_ROLE, - Operation.Read)); + Config.Operation.Read)); Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_AND_UPDATE_ROLE, - Operation.Update)); + Config.Operation.Update)); Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_AND_UPDATE_ROLE, - Operation.Create)); + Config.Operation.Create)); Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, READ_AND_UPDATE_ROLE, - Operation.Delete)); + Config.Operation.Delete)); List expectedRolesForRead = new() { READ_ONLY_ROLE, READ_AND_UPDATE_ROLE }; List expectedRolesForUpdate = new() { READ_AND_UPDATE_ROLE }; @@ -266,22 +266,22 @@ public void TestRoleAndOperationCombination() IEnumerable actualReadRolesForCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, "col1", - Operation.Read); + Config.Operation.Read); CollectionAssert.AreEquivalent(expectedRolesForRead, actualReadRolesForCol1.ToList()); IEnumerable actualUpdateRolesForCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, "col1", - Operation.Update); + Config.Operation.Update); CollectionAssert.AreEquivalent(expectedRolesForUpdate, actualUpdateRolesForCol1.ToList()); IEnumerable actualRolesForRead = IAuthorizationResolver.GetRolesForOperation( AuthorizationHelpers.TEST_ENTITY, - Operation.Read, + Config.Operation.Read, authZResolver.EntityPermissionsMap); CollectionAssert.AreEquivalent(expectedRolesForRead, actualRolesForRead.ToList()); IEnumerable actualRolesForUpdate = IAuthorizationResolver.GetRolesForOperation( AuthorizationHelpers.TEST_ENTITY, - Operation.Update, + Config.Operation.Update, authZResolver.EntityPermissionsMap); CollectionAssert.AreEquivalent(expectedRolesForUpdate, actualRolesForUpdate.ToList()); } @@ -296,13 +296,13 @@ public void TestAuthenticatedRoleWhenAnonymousRoleIsDefined() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationResolver.ROLE_ANONYMOUS, - operation: Operation.Create); + operation: Config.Operation.Create); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); - foreach (Operation operation in PermissionOperation.ValidPermissionOperations) + foreach (Config.Operation operation in PermissionOperation.ValidPermissionOperations) { - if (operation is Operation.Create) + if (operation is Config.Operation.Create) { // Create operation should be defined for anonymous role. Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity( @@ -335,13 +335,13 @@ public void TestAuthenticatedRoleWhenAnonymousRoleIsDefined() // Anonymous role's permissions are copied over for authenticated role only. // Assert by checking for an arbitrary role. Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, - AuthorizationHelpers.TEST_ROLE, Operation.Create)); + AuthorizationHelpers.TEST_ROLE, Config.Operation.Create)); // Assert that the create operation has both anonymous, authenticated roles. List expectedRolesForCreate = new() { AuthorizationResolver.ROLE_AUTHENTICATED, AuthorizationResolver.ROLE_ANONYMOUS }; IEnumerable actualRolesForCreate = IAuthorizationResolver.GetRolesForOperation( AuthorizationHelpers.TEST_ENTITY, - Operation.Create, + Config.Operation.Create, authZResolver.EntityPermissionsMap); CollectionAssert.AreEquivalent(expectedRolesForCreate, actualRolesForCreate.ToList()); @@ -351,14 +351,14 @@ public void TestAuthenticatedRoleWhenAnonymousRoleIsDefined() AuthorizationResolver.ROLE_AUTHENTICATED }; IEnumerable actualRolesForCreateCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, - "col1", Operation.Create); + "col1", Config.Operation.Create); CollectionAssert.AreEquivalent(expectedRolesForCreateCol1, actualRolesForCreateCol1.ToList()); // Assert that the col1 field with read operation has no role. List expectedRolesForReadCol1 = new(); IEnumerable actualRolesForReadCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, - "col1", Operation.Read); + "col1", Config.Operation.Read); CollectionAssert.AreEquivalent(expectedRolesForReadCol1, actualRolesForReadCol1.ToList()); } @@ -372,7 +372,7 @@ public void TestAuthenticatedRoleWhenAnonymousRoleIsNotDefined() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create); + operation: Config.Operation.Create); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); @@ -380,20 +380,20 @@ public void TestAuthenticatedRoleWhenAnonymousRoleIsNotDefined() Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create)); + Config.Operation.Create)); // Create operation should not be defined for authenticated role, // because neither authenticated nor anonymous role is defined. Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationResolver.ROLE_AUTHENTICATED, - Operation.Create)); + Config.Operation.Create)); // Assert that the Create operation has only test_role. List expectedRolesForCreate = new() { AuthorizationHelpers.TEST_ROLE }; IEnumerable actualRolesForCreate = IAuthorizationResolver.GetRolesForOperation( AuthorizationHelpers.TEST_ENTITY, - Operation.Create, + Config.Operation.Create, authZResolver.EntityPermissionsMap); CollectionAssert.AreEquivalent(expectedRolesForCreate, actualRolesForCreate.ToList()); @@ -402,7 +402,7 @@ public void TestAuthenticatedRoleWhenAnonymousRoleIsNotDefined() List expectedRolesForCreateCol1 = new() { AuthorizationHelpers.TEST_ROLE }; IEnumerable actualRolesForCreateCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, - "col1", Operation.Create); + "col1", Config.Operation.Create); CollectionAssert.AreEquivalent(expectedRolesForCreateCol1, actualRolesForCreateCol1.ToList()); } @@ -418,12 +418,12 @@ public void TestAuthenticatedRoleWhenBothAnonymousAndAuthenticatedAreDefined() exclude: null); PermissionOperation readAction = new( - Name: Operation.Read, + Name: Config.Operation.Read, Fields: fieldsForRole, Policy: null); PermissionOperation updateAction = new( - Name: Operation.Update, + Name: Config.Operation.Update, Fields: fieldsForRole, Policy: null); @@ -459,11 +459,11 @@ public void TestAuthenticatedRoleWhenBothAnonymousAndAuthenticatedAreDefined() // Assert that for the role authenticated, only the Read operation is allowed. // The Update operation is not allowed even though update is allowed for the role anonymous. Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, - AuthorizationResolver.ROLE_AUTHENTICATED, Operation.Read)); + AuthorizationResolver.ROLE_AUTHENTICATED, Config.Operation.Read)); Assert.IsTrue(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, - AuthorizationResolver.ROLE_ANONYMOUS, Operation.Update)); + AuthorizationResolver.ROLE_ANONYMOUS, Config.Operation.Update)); Assert.IsFalse(authZResolver.AreRoleAndOperationDefinedForEntity(AuthorizationHelpers.TEST_ENTITY, - AuthorizationResolver.ROLE_AUTHENTICATED, Operation.Delete)); + AuthorizationResolver.ROLE_AUTHENTICATED, Config.Operation.Delete)); // Assert that the read operation has both anonymous and authenticated role. List expectedRolesForRead = new() { @@ -471,7 +471,7 @@ public void TestAuthenticatedRoleWhenBothAnonymousAndAuthenticatedAreDefined() AuthorizationResolver.ROLE_AUTHENTICATED }; IEnumerable actualRolesForRead = IAuthorizationResolver.GetRolesForOperation( AuthorizationHelpers.TEST_ENTITY, - Operation.Read, + Config.Operation.Read, authZResolver.EntityPermissionsMap); CollectionAssert.AreEquivalent(expectedRolesForRead, actualRolesForRead.ToList()); @@ -479,7 +479,7 @@ public void TestAuthenticatedRoleWhenBothAnonymousAndAuthenticatedAreDefined() List expectedRolesForUpdate = new() { AuthorizationResolver.ROLE_ANONYMOUS }; IEnumerable actualRolesForUpdate = IAuthorizationResolver.GetRolesForOperation( AuthorizationHelpers.TEST_ENTITY, - Operation.Update, + Config.Operation.Update, authZResolver.EntityPermissionsMap); CollectionAssert.AreEquivalent(expectedRolesForUpdate, actualRolesForUpdate.ToList()); @@ -489,14 +489,14 @@ public void TestAuthenticatedRoleWhenBothAnonymousAndAuthenticatedAreDefined() AuthorizationResolver.ROLE_AUTHENTICATED }; IEnumerable actualRolesForReadCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, - "col1", Operation.Read); + "col1", Config.Operation.Read); CollectionAssert.AreEquivalent(expectedRolesForReadCol1, actualRolesForReadCol1.ToList()); // Assert that the col1 field with Update operation has only anonymous roles. List expectedRolesForUpdateCol1 = new() { AuthorizationResolver.ROLE_ANONYMOUS }; IEnumerable actualRolesForUpdateCol1 = authZResolver.GetRolesForField( AuthorizationHelpers.TEST_ENTITY, - "col1", Operation.Update); + "col1", Config.Operation.Update); CollectionAssert.AreEquivalent(expectedRolesForUpdateCol1, actualRolesForUpdateCol1.ToList()); } @@ -508,12 +508,12 @@ public void TestAuthenticatedRoleWhenBothAnonymousAndAuthenticatedAreDefined() /// The operation configured for the configRole. /// The roleName which is to be checked for the permission. [DataTestMethod] - [DataRow("Writer", Operation.Create, "wRiTeR", DisplayName = "role wRiTeR checked against Writer")] - [DataRow("Reader", Operation.Read, "READER", DisplayName = "role READER checked against Reader")] - [DataRow("Writer", Operation.Create, "WrIter", DisplayName = "role WrIter checked against Writer")] + [DataRow("Writer", Config.Operation.Create, "wRiTeR", DisplayName = "role wRiTeR checked against Writer")] + [DataRow("Reader", Config.Operation.Read, "READER", DisplayName = "role READER checked against Reader")] + [DataRow("Writer", Config.Operation.Create, "WrIter", DisplayName = "role WrIter checked against Writer")] public void AreRoleAndOperationDefinedForEntityTestForDifferentlyCasedRole( string configRole, - Operation operation, + Config.Operation operation, string roleNameToCheck ) { @@ -544,7 +544,7 @@ public void ExplicitIncludeColumn() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: includedColumns ); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); @@ -552,28 +552,28 @@ public void ExplicitIncludeColumn() Assert.IsTrue(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, includedColumns)); // Not allow column. Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, new List { "col4" })); // Mix of allow and not allow. Should result in not allow. Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, new List { "col3", "col4" })); // Column does not exist Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, new List { "col5", "col6" })); } @@ -591,7 +591,7 @@ public void ExplicitIncludeAndExcludeColumns() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: includeColumns, excludedCols: excludeColumns ); @@ -601,27 +601,27 @@ public void ExplicitIncludeAndExcludeColumns() Assert.IsTrue(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, includeColumns)); Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, excludeColumns)); // Not exist column in the inclusion or exclusion list Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, new List { "col4" })); // Mix of allow and not allow. Should result in not allow. Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, new List { "col1", "col3" })); } @@ -638,7 +638,7 @@ public void ColumnExclusionWithSameColumnInclusion() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: includedColumns, excludedCols: excludedColumns ); @@ -649,7 +649,7 @@ public void ColumnExclusionWithSameColumnInclusion() Assert.IsTrue(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, new List { "col2" })); // Col1 should NOT to included since it is in exclusion list. @@ -657,13 +657,13 @@ public void ColumnExclusionWithSameColumnInclusion() Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, new List { "col1" })); Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, excludedColumns)); } @@ -676,7 +676,7 @@ public void WildcardColumnInclusion() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: new HashSet { AuthorizationResolver.WILDCARD } ); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); @@ -686,7 +686,7 @@ public void WildcardColumnInclusion() Assert.IsTrue(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedColumns)); } @@ -703,7 +703,7 @@ public void WildcardColumnInclusionWithExplictExclusion() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: new HashSet { AuthorizationResolver.WILDCARD }, excludedCols: excludedColumns ); @@ -712,12 +712,12 @@ public void WildcardColumnInclusionWithExplictExclusion() Assert.IsTrue(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedColumns)); Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, excludedColumns)); } @@ -732,7 +732,7 @@ public void WildcardColumnExclusion() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, excludedCols: new HashSet { AuthorizationResolver.WILDCARD } ); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); @@ -740,7 +740,7 @@ public void WildcardColumnExclusion() Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, excludedColumns)); } @@ -757,7 +757,7 @@ public void WildcardColumnExclusionWithExplicitColumnInclusion() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: includedColumns, excludedCols: new HashSet { AuthorizationResolver.WILDCARD } ); @@ -766,12 +766,12 @@ public void WildcardColumnExclusionWithExplicitColumnInclusion() Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedColumns)); Assert.IsFalse(authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, excludedColumns)); } @@ -789,14 +789,14 @@ public void CheckIncludeAndExcludeColumnForWildcardOperation() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.All, + operation: Config.Operation.All, includedCols: includeColumns, excludedCols: excludeColumns ); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); - foreach (Operation operation in PermissionOperation.ValidPermissionOperations) + foreach (Config.Operation operation in PermissionOperation.ValidPermissionOperations) { // Validate that the authorization check passes for valid CRUD operations // because columns are accessbile or inaccessible. @@ -827,7 +827,7 @@ public void AreColumnsAllowedForOperationWithMissingFieldProperty(bool expected, RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create + operation: Config.Operation.Create ); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); @@ -837,7 +837,7 @@ public void AreColumnsAllowedForOperationWithMissingFieldProperty(bool expected, authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create, + Config.Operation.Create, new List(columnsToCheck))); } @@ -861,13 +861,13 @@ public void TestAuthenticatedRoleForColumnPermissionsWhenAnonymousRoleIsDefined( RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationResolver.ROLE_ANONYMOUS, - operation: Operation.All, + operation: Config.Operation.All, includedCols: new HashSet(includeCols), excludedCols: new HashSet(excludeCols)); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); - foreach (Operation operation in PermissionOperation.ValidPermissionOperations) + foreach (Config.Operation operation in PermissionOperation.ValidPermissionOperations) { Assert.AreEqual(expected, authZResolver.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, @@ -889,14 +889,14 @@ public void TestAuthenticatedRoleForColumnPermissionsWhenAnonymousRoleIsDefined( /// Columns to be checked for access. /// Expected booolean result for the relevant method call. [DataTestMethod] - [DataRow(Operation.All, "Writer", new string[] { "col1", "col2" }, new string[] { "col3" }, "WRITER", + [DataRow(Config.Operation.All, "Writer", new string[] { "col1", "col2" }, new string[] { "col3" }, "WRITER", new string[] { "col1", "col2" }, true, DisplayName = "Case insensitive role writer")] - [DataRow(Operation.Read, "Reader", new string[] { "col1", "col3", "col4" }, new string[] { "col3" }, "reADeR", + [DataRow(Config.Operation.Read, "Reader", new string[] { "col1", "col3", "col4" }, new string[] { "col3" }, "reADeR", new string[] { "col1", "col3" }, false, DisplayName = "Case insensitive role reader")] - [DataRow(Operation.Create, "Creator", new string[] { "col1", "col2" }, new string[] { "col3", "col4" }, "CREator", + [DataRow(Config.Operation.Create, "Creator", new string[] { "col1", "col2" }, new string[] { "col3", "col4" }, "CREator", new string[] { "col1", "col2" }, true, DisplayName = "Case insensitive role creator")] public void AreColumnsAllowedForOperationWithRoleWithDifferentCasing( - Operation operation, + Config.Operation operation, string configRole, string[] columnsToInclude, string[] columnsToExclude, @@ -913,9 +913,9 @@ public void AreColumnsAllowedForOperationWithRoleWithDifferentCasing( ); AuthorizationResolver authZResolver = AuthorizationHelpers.InitAuthorizationResolver(runtimeConfig); - List operations = AuthorizationResolver.GetAllOperations(operation).ToList(); + List operations = AuthorizationResolver.GetAllOperations(operation).ToList(); - foreach (Operation testOperation in operations) + foreach (Config.Operation testOperation in operations) { // Assert that the expected result and the returned result are equal. Assert.AreEqual(expected, @@ -1163,8 +1163,8 @@ public void ParsePolicyWithDuplicateUserClaims(bool exceptionExpected, params st public void GetDBPolicyTest( string clientRole, string configuredRole, - Operation requestOperation, - Operation configuredOperation, + Config.Operation requestOperation, + Config.Operation configuredOperation, string policy, bool expectPolicy) { @@ -1214,7 +1214,7 @@ public void GetDBPolicyTest( public static RuntimeConfig InitRuntimeConfig( string entityName = "SampleEntity", string roleName = "Reader", - Operation operation = Operation.Create, + Config.Operation operation = Config.Operation.Create, HashSet? includedCols = null, HashSet? excludedCols = null, string? requestPolicy = null, diff --git a/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs b/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs index a04b4b1221..d4c6e332e9 100644 --- a/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs +++ b/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs @@ -34,7 +34,7 @@ public void InaccessibleFieldRequestedByPolicy(string dbPolicy) RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: new HashSet { "*" }, excludedCols: new HashSet { "id", "email" }, databasePolicy: dbPolicy @@ -112,10 +112,10 @@ public void InvalidCRUDForStoredProcedure(object[] operations, bool isValid) /// Database policy. /// The action to be validated. [DataTestMethod] - [DataRow("@claims.id eq @item.col1", Operation.Insert, DisplayName = "Invalid action Insert specified in config")] - [DataRow("@claims.id eq @item.col2", Operation.Upsert, DisplayName = "Invalid action Upsert specified in config")] - [DataRow("@claims.id eq @item.col3", Operation.UpsertIncremental, DisplayName = "Invalid action UpsertIncremental specified in config")] - public void InvalidActionSpecifiedForARole(string dbPolicy, Operation action) + [DataRow("@claims.id eq @item.col1", Config.Operation.Insert, DisplayName = "Invalid action Insert specified in config")] + [DataRow("@claims.id eq @item.col2", Config.Operation.Upsert, DisplayName = "Invalid action Upsert specified in config")] + [DataRow("@claims.id eq @item.col3", Config.Operation.UpsertIncremental, DisplayName = "Invalid action UpsertIncremental specified in config")] + public void InvalidActionSpecifiedForARole(string dbPolicy, Config.Operation action) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -143,12 +143,12 @@ public void InvalidActionSpecifiedForARole(string dbPolicy, Operation action) /// Whether an error is expected. [DataTestMethod] [DataRow("1 eq @item.col1", Operation.Create, true, DisplayName = "Database Policy defined for Create fails")] - [DataRow("", Operation.Create, true, DisplayName = "Database Policy left empty for Create fails")] - [DataRow(null, Operation.Create, false, DisplayName = "Database Policy NOT defined for Create passes")] - [DataRow("1 eq @item.col2", Operation.Read, false, DisplayName = "Database Policy defined for Read passes")] - [DataRow("2 eq @item.col3", Operation.Update, false, DisplayName = "Database Policy defined for Update passes")] - [DataRow("2 eq @item.col3", Operation.Delete, false, DisplayName = "Database Policy defined for Delete passes")] - public void AddDatabasePolicyToCreateOperationPermission(string dbPolicy, Operation action, bool errorExpected) + [DataRow("", Config.Operation.Create, true, DisplayName = "Database Policy left empty for Create fails")] + [DataRow(null, Config.Operation.Create, false, DisplayName = "Database Policy NOT defined for Create passes")] + [DataRow("1 eq @item.col2", Config.Operation.Read, false, DisplayName = "Database Policy defined for Read passes")] + [DataRow("2 eq @item.col3", Config.Operation.Update, false, DisplayName = "Database Policy defined for Update passes")] + [DataRow("2 eq @item.col3", Config.Operation.Delete, false, DisplayName = "Database Policy defined for Delete passes")] + public void AddDatabasePolicyToCreateOperationPermission(string dbPolicy, Config.Operation action, bool errorExpected) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -547,7 +547,7 @@ public void EmptyClaimTypeSuppliedInPolicy(string dbPolicy) RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: new HashSet { "col1", "col2", "col3" }, databasePolicy: dbPolicy ); @@ -579,7 +579,7 @@ public void ParseInvalidDbPolicyWithInvalidClaimTypeFormat(string policy) RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.Create, + operation: Config.Operation.Create, includedCols: new HashSet { "col1", "col2", "col3" }, databasePolicy: policy ); @@ -602,11 +602,11 @@ public void ParseInvalidDbPolicyWithInvalidClaimTypeFormat(string policy) /// The action for which database policy is defined. /// Boolean value indicating whether an exception is expected or not. [DataTestMethod] - [DataRow("StaticWebApps", "@claims.userId eq @item.col2", Operation.Read, false, DisplayName = "SWA- Database Policy defined for Read passes")] - [DataRow("staticwebapps", "@claims.userDetails eq @item.col3", Operation.Update, false, DisplayName = "SWA- Database Policy defined for Update passes")] - [DataRow("StaticWebAPPs", "@claims.email eq @item.col3", Operation.Delete, true, DisplayName = "SWA- Database Policy defined for Delete fails")] - [DataRow("appService", "@claims.email eq @item.col3", Operation.Delete, false, DisplayName = "AppService- Database Policy defined for Delete passes")] - public void TestInvalidClaimsForStaticWebApps(string authProvider, string dbPolicy, Operation action, bool errorExpected) + [DataRow("StaticWebApps", "@claims.userId eq @item.col2", Config.Operation.Read, false, DisplayName = "SWA- Database Policy defined for Read passes")] + [DataRow("staticwebapps", "@claims.userDetails eq @item.col3", Config.Operation.Update, false, DisplayName = "SWA- Database Policy defined for Update passes")] + [DataRow("StaticWebAPPs", "@claims.email eq @item.col3", Config.Operation.Delete, true, DisplayName = "SWA- Database Policy defined for Delete fails")] + [DataRow("appService", "@claims.email eq @item.col3", Config.Operation.Delete, false, DisplayName = "AppService- Database Policy defined for Delete passes")] + public void TestInvalidClaimsForStaticWebApps(string authProvider, string dbPolicy, Config.Operation action, bool errorExpected) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -640,7 +640,7 @@ public void WildcardActionSpecifiedForARole() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: AuthorizationHelpers.TEST_ROLE, - operation: Operation.All, + operation: Config.Operation.All, includedCols: new HashSet { "col1", "col2", "col3" } ); RuntimeConfigValidator configValidator = AuthenticationConfigValidatorUnitTests.GetMockConfigValidator(ref runtimeConfig); @@ -654,9 +654,9 @@ public void WildcardActionSpecifiedForARole() /// in it. /// [DataTestMethod] - [DataRow(Operation.Create, DisplayName = "Wildcard Field with another field in included set and create action")] - [DataRow(Operation.Update, DisplayName = "Wildcard Field with another field in included set and update action")] - public void WildCardAndOtherFieldsPresentInIncludeSet(Operation actionOp) + [DataRow(Config.Operation.Create, DisplayName = "Wildcard Field with another field in included set and create action")] + [DataRow(Config.Operation.Update, DisplayName = "Wildcard Field with another field in included set and update action")] + public void WildCardAndOtherFieldsPresentInIncludeSet(Config.Operation actionOp) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -677,9 +677,9 @@ public void WildCardAndOtherFieldsPresentInIncludeSet(Operation actionOp) } [DataTestMethod] - [DataRow(Operation.Create, DisplayName = "Wildcard Field with another field in excluded set and create action")] - [DataRow(Operation.Update, DisplayName = "Wildcard Field with another field in excluded set and update action")] - public void WildCardAndOtherFieldsPresentInExcludeSet(Operation actionOp) + [DataRow(Config.Operation.Create, DisplayName = "Wildcard Field with another field in excluded set and create action")] + [DataRow(Config.Operation.Update, DisplayName = "Wildcard Field with another field in excluded set and update action")] + public void WildCardAndOtherFieldsPresentInExcludeSet(Config.Operation actionOp) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -1135,7 +1135,7 @@ object graphQLdetails ) { PermissionOperation actionForRole = new( - Name: Operation.Create, + Name: Config.Operation.Create, Fields: null, Policy: null); From b0f1b7bef22cb1c5e677c8e9e0e79a5ebd16c33e Mon Sep 17 00:00:00 2001 From: aaronburtle <93220300+aaronburtle@users.noreply.github.com> Date: Wed, 7 Dec 2022 01:54:10 -0800 Subject: [PATCH 05/12] Update MsSqlCommands.txt --- ConfigGenerators/MsSqlCommands.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigGenerators/MsSqlCommands.txt b/ConfigGenerators/MsSqlCommands.txt index a8cffb1464..a7b87c5afa 100644 --- a/ConfigGenerators/MsSqlCommands.txt +++ b/ConfigGenerators/MsSqlCommands.txt @@ -1,4 +1,4 @@ -init --config "dab-config.MsSql.json" --database-type mssql --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +init --config "dab-config.MsSql.json" --database-type mssql --connection-string "Server=tcp:127.0.0.1,1433;Persist Security Info=False;User ID=sa;Password=REPLACEME;MultipleActiveResultSets=False;Connection Timeout=5;" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" add Publisher --config "dab-config.MsSql.json" --source publishers --permissions "anonymous:read" add Stock --config "dab-config.MsSql.json" --source stocks --permissions "anonymous:create,read,update" add Book --config "dab-config.MsSql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" From d9877277944487b16085c80983da87c976650de0 Mon Sep 17 00:00:00 2001 From: aaronburtle <93220300+aaronburtle@users.noreply.github.com> Date: Wed, 7 Dec 2022 01:54:26 -0800 Subject: [PATCH 06/12] Update MySqlCommands.txt --- ConfigGenerators/MySqlCommands.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigGenerators/MySqlCommands.txt b/ConfigGenerators/MySqlCommands.txt index ff62781d90..52aa23a7a0 100644 --- a/ConfigGenerators/MySqlCommands.txt +++ b/ConfigGenerators/MySqlCommands.txt @@ -1,4 +1,4 @@ -init --config "dab-config.MySql.json" --database-type mysql --connection-string "server=localhost;database=datagatewaytest;Allow User Variables=true;uid=root;pwd=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +init --config "dab-config.MySql.json" --database-type mysql --connection-string "server=localhost;database=datagatewaytest;Allow User Variables=true;uid=root;pwd=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" add Publisher --config "dab-config.MySql.json" --source publishers --permissions "anonymous:read" add Stock --config "dab-config.MySql.json" --source stocks --permissions "anonymous:create,read,update" add Book --config "dab-config.MySql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" From 0bac5997e3d0dc79442612b006578b0a25aa97a1 Mon Sep 17 00:00:00 2001 From: aaronburtle <93220300+aaronburtle@users.noreply.github.com> Date: Wed, 7 Dec 2022 01:54:45 -0800 Subject: [PATCH 07/12] Update PostgreSqlCommands.txt --- ConfigGenerators/PostgreSqlCommands.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ConfigGenerators/PostgreSqlCommands.txt b/ConfigGenerators/PostgreSqlCommands.txt index d65f5e61f2..a7cafb7a82 100644 --- a/ConfigGenerators/PostgreSqlCommands.txt +++ b/ConfigGenerators/PostgreSqlCommands.txt @@ -1,4 +1,4 @@ -init --config "dab-config.PostgreSql.json" --database-type postgresql --connection-string "Host=localhost;Database=datagatewaytest;username=REPLACEME;password=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" +init --config "dab-config.PostgreSql.json" --database-type postgresql --connection-string "Host=localhost;Database=datagatewaytest;username=REPLACEME;password=REPLACEME" --host-mode Development --authenticate-devmode-requests false --cors-origin "http://localhost:5000" add Publisher --config "dab-config.PostgreSql.json" --source publishers --permissions "anonymous:read" add Stock --config "dab-config.PostgreSql.json" --source stocks --permissions "anonymous:create,read,update" add Book --config "dab-config.PostgreSql.json" --source books --permissions "anonymous:create,read,update,delete" --graphql "book:books" From b1eac39fb8bb60d40ff1cbd745300ed7b09ce20c Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 02:01:21 -0800 Subject: [PATCH 08/12] format --- src/Service.Tests/Unittests/ConfigValidationUnitTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs b/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs index d4c6e332e9..ed727e3b60 100644 --- a/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs +++ b/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs @@ -115,7 +115,7 @@ public void InvalidCRUDForStoredProcedure(object[] operations, bool isValid) [DataRow("@claims.id eq @item.col1", Config.Operation.Insert, DisplayName = "Invalid action Insert specified in config")] [DataRow("@claims.id eq @item.col2", Config.Operation.Upsert, DisplayName = "Invalid action Upsert specified in config")] [DataRow("@claims.id eq @item.col3", Config.Operation.UpsertIncremental, DisplayName = "Invalid action UpsertIncremental specified in config")] - public void InvalidActionSpecifiedForARole(string dbPolicy, Config.Operation action) + public void InvalidActionSpecifiedForARole(string dbPolicy, Config.Operation action) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -148,7 +148,7 @@ public void InvalidActionSpecifiedForARole(string dbPolicy, Config.Operation ac [DataRow("1 eq @item.col2", Config.Operation.Read, false, DisplayName = "Database Policy defined for Read passes")] [DataRow("2 eq @item.col3", Config.Operation.Update, false, DisplayName = "Database Policy defined for Update passes")] [DataRow("2 eq @item.col3", Config.Operation.Delete, false, DisplayName = "Database Policy defined for Delete passes")] - public void AddDatabasePolicyToCreateOperationPermission(string dbPolicy, Config.Operation action, bool errorExpected) + public void AddDatabasePolicyToCreateOperationPermission(string dbPolicy, Config.Operation action, bool errorExpected) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, @@ -606,7 +606,7 @@ public void ParseInvalidDbPolicyWithInvalidClaimTypeFormat(string policy) [DataRow("staticwebapps", "@claims.userDetails eq @item.col3", Config.Operation.Update, false, DisplayName = "SWA- Database Policy defined for Update passes")] [DataRow("StaticWebAPPs", "@claims.email eq @item.col3", Config.Operation.Delete, true, DisplayName = "SWA- Database Policy defined for Delete fails")] [DataRow("appService", "@claims.email eq @item.col3", Config.Operation.Delete, false, DisplayName = "AppService- Database Policy defined for Delete passes")] - public void TestInvalidClaimsForStaticWebApps(string authProvider, string dbPolicy, Config.Operation action, bool errorExpected) + public void TestInvalidClaimsForStaticWebApps(string authProvider, string dbPolicy, Config.Operation action, bool errorExpected) { RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, From ba3b40909dc1d4c136c18dccf6d32f6431c6b976 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 02:09:25 -0800 Subject: [PATCH 09/12] fixed some collisions in test --- .../Authorization/AuthorizationResolverUnitTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs b/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs index d803635657..8a2fd8806e 100644 --- a/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs +++ b/src/Service.Tests/Authorization/AuthorizationResolverUnitTests.cs @@ -1150,15 +1150,15 @@ public void ParsePolicyWithDuplicateUserClaims(bool exceptionExpected, params st // no predicates need to be added to the database query generated for the request. // When a value is returned as a result, the execution behaved as expected. [DataTestMethod] - [DataRow("anonymous", "anonymous", Operation.Read, Operation.Read, "id eq 1", true, + [DataRow("anonymous", "anonymous", Config.Operation.Read, Config.Operation.Read, "id eq 1", true, DisplayName = "Fetch Policy for existing system role - anonymous")] - [DataRow("authenticated", "authenticated", Operation.Update, Operation.Update, "id eq 1", true, + [DataRow("authenticated", "authenticated", Config.Operation.Update, Config.Operation.Update, "id eq 1", true, DisplayName = "Fetch Policy for existing system role - authenticated")] - [DataRow("anonymous", "anonymous", Operation.Read, Operation.Read, null, false, + [DataRow("anonymous", "anonymous", Config.Operation.Read, Config.Operation.Read, null, false, DisplayName = "Fetch Policy for existing role, no policy object defined in config.")] - [DataRow("anonymous", "authenticated", Operation.Read, Operation.Read, "id eq 1", false, + [DataRow("anonymous", "authenticated", Config.Operation.Read, Config.Operation.Read, "id eq 1", false, DisplayName = "Fetch Policy for non-configured role")] - [DataRow("anonymous", "anonymous", Operation.Read, Operation.Create, "id eq 1", false, + [DataRow("anonymous", "anonymous", Config.Operation.Read, Config.Operation.Create, "id eq 1", false, DisplayName = "Fetch Policy for non-configured operation")] public void GetDBPolicyTest( string clientRole, From 7ad79ccf7d2b7216868d116cfab23172f8bdea68 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 02:14:44 -0800 Subject: [PATCH 10/12] fixed a collision in test --- src/Service.Tests/Unittests/ConfigValidationUnitTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs b/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs index ed727e3b60..39f7836015 100644 --- a/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs +++ b/src/Service.Tests/Unittests/ConfigValidationUnitTests.cs @@ -142,7 +142,7 @@ public void InvalidActionSpecifiedForARole(string dbPolicy, Config.Operation act /// The action to be validated. /// Whether an error is expected. [DataTestMethod] - [DataRow("1 eq @item.col1", Operation.Create, true, DisplayName = "Database Policy defined for Create fails")] + [DataRow("1 eq @item.col1", Config.Operation.Create, true, DisplayName = "Database Policy defined for Create fails")] [DataRow("", Config.Operation.Create, true, DisplayName = "Database Policy left empty for Create fails")] [DataRow(null, Config.Operation.Create, false, DisplayName = "Database Policy NOT defined for Create passes")] [DataRow("1 eq @item.col2", Config.Operation.Read, false, DisplayName = "Database Policy defined for Read passes")] From dc1556885855d8ebec5fad919d3177d2cf14d512 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 02:30:24 -0800 Subject: [PATCH 11/12] fixed some collisions in tests --- .../GraphQLMutationAuthorizationTests.cs | 2 +- .../GraphQLQueryAuthorizationUnitTests.cs | 2 +- .../REST/RestAuthorizationHandlerUnitTests.cs | 14 ++-- .../Configuration/ConfigurationTests.cs | 12 ++-- src/Service.Tests/CosmosTests/TestBase.cs | 2 +- .../GraphQLBuilder/QueryBuilderTests.cs | 8 +-- .../RestApiTests/Delete/DeleteApiTestBase.cs | 22 +++---- .../RestApiTests/Insert/InsertApiTestBase.cs | 46 ++++++------- .../Insert/MsSqlInsertApiTests.cs | 2 +- .../Insert/MySqlInsertApiTests.cs | 2 +- .../Insert/PostgreSqlInsertApiTests.cs | 2 +- .../RestApiTests/Patch/PatchApiTestBase.cs | 48 +++++++------- .../RestApiTests/Put/PutApiTestBase.cs | 64 +++++++++---------- .../Unittests/RequestContextUnitTests.cs | 4 +- 14 files changed, 115 insertions(+), 115 deletions(-) diff --git a/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs b/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs index a31877fa37..7c49e9f961 100644 --- a/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs +++ b/src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs @@ -115,7 +115,7 @@ private static SqlMutationEngine SetupTestFixture(bool isAuthorized) _authorizationResolver.Setup(x => x.AreColumnsAllowedForOperation( It.IsAny(), It.IsAny(), - It.IsAny(), + It.IsAny(), It.IsAny>() )).Returns(isAuthorized); diff --git a/src/Service.Tests/Authorization/GraphQL/GraphQLQueryAuthorizationUnitTests.cs b/src/Service.Tests/Authorization/GraphQL/GraphQLQueryAuthorizationUnitTests.cs index 5ba4625012..cd24ee5d4e 100644 --- a/src/Service.Tests/Authorization/GraphQL/GraphQLQueryAuthorizationUnitTests.cs +++ b/src/Service.Tests/Authorization/GraphQL/GraphQLQueryAuthorizationUnitTests.cs @@ -40,7 +40,7 @@ type Foo @model(name: ""Foo""){ inputTypes: new(), GraphQLTestHelpers.CreateStubEntityPermissionsMap( entityNames: new string[] { "Foo" }, - operations: new Operation[] { Operation.Read }, + operations: new Config.Operation[] { Config.Operation.Read }, roles: rolesDefinedInPermissions) ); diff --git a/src/Service.Tests/Authorization/REST/RestAuthorizationHandlerUnitTests.cs b/src/Service.Tests/Authorization/REST/RestAuthorizationHandlerUnitTests.cs index 31d6d29a74..30ea8a474f 100644 --- a/src/Service.Tests/Authorization/REST/RestAuthorizationHandlerUnitTests.cs +++ b/src/Service.Tests/Authorization/REST/RestAuthorizationHandlerUnitTests.cs @@ -147,22 +147,22 @@ public async Task EntityRoleOperationPermissionsRequirementTest( authorizationResolver.Setup(x => x.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Create + Config.Operation.Create )).Returns(isValidCreateRoleOperation); authorizationResolver.Setup(x => x.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Read + Config.Operation.Read )).Returns(isValidReadRoleOperation); authorizationResolver.Setup(x => x.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Update + Config.Operation.Update )).Returns(isValidUpdateRoleOperation); authorizationResolver.Setup(x => x.AreRoleAndOperationDefinedForEntity( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Delete + Config.Operation.Delete )).Returns(isValidDeleteRoleOperation); HttpContext httpContext = CreateHttpContext(httpMethod); @@ -257,13 +257,13 @@ public async Task FindColumnPermissionsTests(string[] columnsRequestedInput, authorizationResolver.Setup(x => x.AreColumnsAllowedForOperation( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Read, + Config.Operation.Read, It.IsAny>() // Can be any IEnumerable, as find request result field list is depedent on AllowedColumns. )).Returns(areColumnsAllowed); authorizationResolver.Setup(x => x.GetAllowedExposedColumns( AuthorizationHelpers.TEST_ENTITY, AuthorizationHelpers.TEST_ROLE, - Operation.Read + Config.Operation.Read )).Returns(allowedColumns); string httpMethod = HttpConstants.GET; @@ -365,7 +365,7 @@ private static AuthorizationResolver SetupAuthResolverWithWildcardOperation() RuntimeConfig runtimeConfig = AuthorizationHelpers.InitRuntimeConfig( entityName: AuthorizationHelpers.TEST_ENTITY, roleName: "admin", - operation: Operation.All); + operation: Config.Operation.All); // Override the operation to be a list of string for wildcard instead of a list of object created by InitRuntimeConfig() // diff --git a/src/Service.Tests/Configuration/ConfigurationTests.cs b/src/Service.Tests/Configuration/ConfigurationTests.cs index 7965fed602..472cc8e418 100644 --- a/src/Service.Tests/Configuration/ConfigurationTests.cs +++ b/src/Service.Tests/Configuration/ConfigurationTests.cs @@ -166,7 +166,7 @@ public void TestCorrectSerializationOfSourceObject( entityName: "MyEntity", entitySource: entitySource, roleName: "Anonymous", - operation: Operation.All, + operation: Config.Operation.All, includedCols: null, excludedCols: null, databasePolicy: null @@ -272,7 +272,7 @@ public async Task TestSqlSettingPostStartupConfigurations() entityName: POST_STARTUP_CONFIG_ENTITY, entitySource: POST_STARTUP_CONFIG_ENTITY_SOURCE, roleName: POST_STARTUP_CONFIG_ROLE, - operation: Operation.Read, + operation: Config.OperationRead, includedCols: new HashSet() { "*" }); ConfigurationPostParameters config = GetPostStartupConfigParams(MSSQL_ENVIRONMENT, configuration); @@ -535,8 +535,8 @@ private static void ConfigFileDeserializationValidationHelper(string jsonString) foreach (object operation in permission.Operations) { HashSet allowedActions = - new() { Operation.All, Operation.Create, Operation.Read, - Operation.Update, Operation.Delete }; + new() { Config.Operation.All, Config.Operation.Create, Config.Operation.Read, + Config.Operation.Update, Config.Operation.Delete }; Assert.IsTrue(((JsonElement)operation).ValueKind == JsonValueKind.String || ((JsonElement)operation).ValueKind == JsonValueKind.Object); if (((JsonElement)operation).ValueKind == JsonValueKind.Object) @@ -551,7 +551,7 @@ private static void ConfigFileDeserializationValidationHelper(string jsonString) } else { - Operation name = AuthorizationResolver.WILDCARD.Equals(operation.ToString()) ? Operation.All : ((JsonElement)operation).Deserialize(RuntimeConfig.SerializerOptions); + Operation name = AuthorizationResolver.WILDCARD.Equals(operation.ToString()) ? Config.OperationAll : ((JsonElement)operation).Deserialize(RuntimeConfig.SerializerOptions); Assert.IsTrue(allowedActions.Contains(name)); } } @@ -1098,7 +1098,7 @@ public static RuntimeConfig InitMinimalRuntimeConfig(Dictionary GetEntityPermissionsMap(string { return GraphQLTestHelpers.CreateStubEntityPermissionsMap( entityNames: entities, - operations: new Operation[] { Operation.Create, Operation.Read, Operation.Update, Operation.Delete }, + operations: new Config.Operation[] { Config.Operation.Create, Config.Operation.Read, Config.Operation.Update, Config.Operation.Delete }, roles: new string[] { "anonymous", "authenticated" } ); } diff --git a/src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs b/src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs index e7c2655ec7..a27b16d9a4 100644 --- a/src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs +++ b/src/Service.Tests/GraphQLBuilder/QueryBuilderTests.cs @@ -28,7 +28,7 @@ public void SetupEntityPermissionsMap() { _entityPermissions = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "Foo" }, - new Operation[] { Operation.Read }, + new Config.Operation[] { Config.Operation.Read }, new string[] { "anonymous", "authenticated" } ); } @@ -57,7 +57,7 @@ type Foo @model(name:""Foo"") { Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "Foo" }, - new Operation[] { Operation.Read }, + new Config.Operation[] { Config.Operation.Read }, roles); DocumentNode queryRoot = QueryBuilder.Build( root, @@ -132,7 +132,7 @@ type foo @model(name:""foo"") { Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "foo" }, - new Operation[] { Operation.Read }, + new Operation[] { Config.Operation.Read }, roles); DocumentNode queryRoot = QueryBuilder.Build( root, @@ -334,7 +334,7 @@ string expectedNameInDescription Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { entityName }, - new Operation[] { Operation.Read }, + new Operation[] { Config.Operation.Read }, new string[] { "anonymous", "authenticated" }); Entity entity = (singularName is not null) diff --git a/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs index 7170ad92eb..63f0bbad88 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Delete/DeleteApiTestBase.cs @@ -31,7 +31,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: null, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: null, expectedStatusCode: HttpStatusCode.NoContent ); @@ -54,7 +54,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationMappingEntity, sqlQuery: null, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: null, expectedStatusCode: HttpStatusCode.NoContent ); @@ -78,7 +78,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationUniqueCharactersEntity, sqlQuery: null, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: null, expectedStatusCode: HttpStatusCode.NoContent ); @@ -98,7 +98,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_all_books, sqlQuery: null, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: null, expectedStatusCode: HttpStatusCode.NoContent ); @@ -109,7 +109,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_subset_stocks, sqlQuery: null, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: null, expectedStatusCode: HttpStatusCode.NoContent ); @@ -133,7 +133,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: string.Empty, exceptionExpected: true, expectedErrorMessage: "Not Found", @@ -157,7 +157,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: string.Empty, exceptionExpected: true, expectedErrorMessage: "The request is invalid since the primary keys: title requested were not found in the entity definition.", @@ -180,7 +180,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: string.Empty, exceptionExpected: true, expectedErrorMessage: RequestValidator.PRIMARY_KEY_NOT_PROVIDED_ERR_MESSAGE, @@ -201,7 +201,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: string.Empty, exceptionExpected: true, expectedErrorMessage: "Parameter \"{}\" cannot be resolved as column \"id\" with type \"Int32\".", @@ -232,7 +232,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: string.Empty, exceptionExpected: true, expectedErrorMessage: message, @@ -255,7 +255,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _composite_subset_bookPub, sqlQuery: null, - operationType: Operation.Delete, + operationType: Config.Operation.Delete, requestBody: null, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs index 04bf222eef..b81348beda 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/InsertApiTestBase.cs @@ -31,7 +31,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(nameof(InsertOneTest)), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -50,7 +50,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("InsertOneInCompositeNonAutoGenPKTest"), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -76,7 +76,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_all_books, sqlQuery: GetQuery("InsertOneInBooksViewAll"), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created ); @@ -96,7 +96,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_subset_stocks, sqlQuery: GetQuery("InsertOneInStocksViewSelected"), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created ); @@ -123,7 +123,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationUniqueCharactersEntity, sqlQuery: GetQuery(nameof(InsertOneUniqueCharactersTest)), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -150,7 +150,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationMappingEntity, sqlQuery: GetQuery(nameof(InsertOneWithMappingTest)), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -176,7 +176,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _entityWithCompositePrimaryKey, sqlQuery: GetQuery(nameof(InsertOneInCompositeKeyTableTest)), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -193,7 +193,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _entityWithCompositePrimaryKey, sqlQuery: GetQuery("InsertOneInDefaultTestTable"), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -218,7 +218,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("InsertOneWithNullFieldValue"), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -249,7 +249,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(query), - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -274,7 +274,7 @@ await SetupAndRunRestApiTest( queryString: "?/id/5001", entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: RequestValidator.QUERY_STRING_INVALID_USAGE_ERR_MESSAGE, @@ -299,7 +299,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: RequestValidator.BATCH_MUTATION_UNSUPPORTED_ERR_MESSAGE, @@ -325,7 +325,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Parameter \"[1234,4321]\" cannot be resolved as column \"publisher_id\" with type \"Int32\".", @@ -348,7 +348,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Missing field in body: title.", @@ -373,7 +373,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Field not allowed in body: id.", @@ -398,7 +398,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Missing field in body: id.", @@ -425,7 +425,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: null, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Parameter \"StringFailsToCastToInt\" cannot be resolved as column \"publisher_id\" with type \"Int32\".", @@ -451,7 +451,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Missing field in body: title.", @@ -470,7 +470,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Missing field in body: categoryName.", @@ -496,7 +496,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid value for field piecesRequired in request body.", @@ -517,7 +517,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid value for field categoryName in request body.", @@ -548,7 +548,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationBrokenMappingEntity, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, exceptionExpected: true, requestBody: requestBody, expectedErrorMessage: "Invalid request body. Contained unexpected fields in body: hazards", @@ -578,7 +578,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _composite_subset_bookPub, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, exceptionExpected: true, requestBody: requestBody, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs index edd26ba50f..6f8e90c263 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/MsSqlInsertApiTests.cs @@ -169,7 +169,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs index 07e5b4c3ee..caeaa23149 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/MySqlInsertApiTests.cs @@ -180,7 +180,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs b/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs index 5741955dcc..bdd2200239 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Insert/PostgreSqlInsertApiTests.cs @@ -205,7 +205,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Insert, + operationType: Config.Operation.Insert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs index 1a7b05d4f8..6b3847610f 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Patch/PatchApiTestBase.cs @@ -40,7 +40,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Insert_Nulled_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -58,7 +58,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Update_Nulled_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -88,7 +88,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationUniqueCharactersEntity, sqlQuery: GetQuery(nameof(PatchOne_Insert_UniqueCharacters_Test)), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -117,7 +117,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: GetQuery(nameof(PatchOne_Insert_NonAutoGenPK_Test)), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -136,7 +136,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Insert_CompositeNonAutoGenPK_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -155,7 +155,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Insert_Empty_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -172,7 +172,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Insert_Default_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -191,7 +191,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationMappingEntity, sqlQuery: GetQuery("PatchOne_Insert_Mapping_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -218,7 +218,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_subset_stocks, sqlQuery: GetQuery("PatchOneInsertInStocksViewSelected"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: string.Empty @@ -243,7 +243,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(nameof(PatchOne_Update_Test)), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -258,7 +258,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _entityWithCompositePrimaryKey, sqlQuery: GetQuery("PatchOne_Update_Default_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -273,7 +273,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Update_CompositeNonAutoGenPK_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -289,7 +289,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PatchOne_Update_Empty_Test"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -315,7 +315,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_subset_stocks, sqlQuery: GetQuery("PatchOneUpdateStocksViewSelected"), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -341,7 +341,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(nameof(PatchOne_Update_IfMatchHeaders_Test)), - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, headers: new HeaderDictionary(headerDictionary), requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK @@ -372,7 +372,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: null, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: $"Cannot perform INSERT and could not find {_integrationEntityName} with primary key to perform UPDATE on.", @@ -401,7 +401,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: null, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: $"Cannot perform INSERT and could not find {_integration_NonAutoGenPK_EntityName} with primary key to perform UPDATE on.", @@ -432,7 +432,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, headers: new HeaderDictionary(headerDictionary), requestBody: requestBody, exceptionExpected: true, @@ -464,7 +464,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationBrokenMappingEntity, sqlQuery: string.Empty, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, exceptionExpected: true, requestBody: requestBody, expectedErrorMessage: "Invalid request body. Either insufficient or extra fields supplied.", @@ -495,7 +495,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid value for field categoryName in request body.", @@ -515,7 +515,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid value for field categoryName in request body.", @@ -540,7 +540,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: null, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Parameter \"StringFailsToCastToInt\" cannot be resolved as column \"publisher_id\" with type \"Int32\".", @@ -567,7 +567,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: string.Empty, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: RequestValidator.PRIMARY_KEY_NOT_PROVIDED_ERR_MESSAGE, @@ -596,7 +596,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _composite_subset_bookPub, sqlQuery: string.Empty, - operationType: Operation.UpsertIncremental, + operationType: Config.Operation.UpsertIncremental, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs b/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs index a2f00f33cb..3df0c07bba 100644 --- a/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs +++ b/src/Service.Tests/SqlTests/RestApiTests/Put/PutApiTestBase.cs @@ -37,7 +37,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(nameof(PutOne_Update_Test)), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -53,7 +53,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _entityWithCompositePrimaryKey, sqlQuery: GetQuery("PutOne_Update_Default_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -71,7 +71,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Update_CompositeNonAutoGenPK_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -90,7 +90,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Update_NullOutMissingField_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -108,7 +108,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Update_Empty_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -135,7 +135,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(nameof(PutOne_Update_IfMatchHeaders_Test)), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, headers: new HeaderDictionary(headerDictionary), requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK @@ -163,7 +163,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: GetQuery(nameof(PutOne_Insert_Test)), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -184,7 +184,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: GetQuery("PutOne_Insert_Nullable_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -206,7 +206,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_AutoGenNonPK_EntityName, sqlQuery: GetQuery("PutOne_Insert_AutoGenNonPK_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -225,7 +225,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Insert_CompositeNonAutoGenPK_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -242,7 +242,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Insert_Default_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -261,7 +261,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Insert_Empty_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -289,7 +289,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_subset_stocks, sqlQuery: GetQuery("PutOneInsertInStocksViewSelected"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created ); @@ -318,7 +318,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Insert_Nulled_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.Created, expectedLocationHeader: expectedLocationHeader @@ -339,7 +339,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: GetQuery("PutOne_Update_Nulled_Test"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -364,7 +364,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _simple_subset_stocks, sqlQuery: GetQuery("PutOneUpdateStocksViewSelected"), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -391,7 +391,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationMappingEntity, sqlQuery: GetQuery(nameof(PutOne_Update_With_Mapping_Test)), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -420,7 +420,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integrationEntityName, sqlQuery: GetQuery(query), - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedStatusCode: HttpStatusCode.OK ); @@ -445,7 +445,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Missing field in body: categoryName.", @@ -470,7 +470,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, @@ -498,7 +498,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid request body. Missing field in body: publisher_id.", @@ -528,7 +528,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: $"Cannot perform INSERT and could not find {_integrationEntityName} with primary key to perform UPDATE on.", @@ -550,7 +550,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _entityWithCompositePrimaryKey, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: $"Cannot perform INSERT and could not find {_entityWithCompositePrimaryKey} with primary key to perform UPDATE on.", @@ -578,7 +578,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: $"Invalid request body. Missing field in body: publisher_id.", @@ -596,7 +596,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: $"Invalid request body. Missing field in body: categoryName.", @@ -623,7 +623,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_AutoGenNonPK_EntityName, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, expectedErrorMessage: @"Invalid request body. Either insufficient or extra fields supplied.", expectedStatusCode: HttpStatusCode.BadRequest @@ -652,7 +652,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, headers: new HeaderDictionary(headerDictionary), requestBody: requestBody, exceptionExpected: true, @@ -681,7 +681,7 @@ await SetupAndRunRestApiTest( queryString: null, entityNameOrPath: _integration_NonAutoGenPK_EntityName, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: RequestValidator.PRIMARY_KEY_NOT_PROVIDED_ERR_MESSAGE, @@ -707,7 +707,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _integrationEntityName, sqlQuery: null, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Parameter \"StringFailsToCastToInt\" cannot be resolved as column \"publisher_id\" with type \"Int32\".", @@ -736,7 +736,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid value for field categoryName in request body.", @@ -756,7 +756,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _Composite_NonAutoGenPK_EntityPath, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: "Invalid value for field categoryName in request body.", @@ -785,7 +785,7 @@ await SetupAndRunRestApiTest( queryString: string.Empty, entityNameOrPath: _composite_subset_bookPub, sqlQuery: string.Empty, - operationType: Operation.Upsert, + operationType: Config.Operation.Upsert, requestBody: requestBody, exceptionExpected: true, expectedErrorMessage: expectedErrorMessage, diff --git a/src/Service.Tests/Unittests/RequestContextUnitTests.cs b/src/Service.Tests/Unittests/RequestContextUnitTests.cs index 5fe6ff52a3..b459af0b8f 100644 --- a/src/Service.Tests/Unittests/RequestContextUnitTests.cs +++ b/src/Service.Tests/Unittests/RequestContextUnitTests.cs @@ -39,7 +39,7 @@ public void ExceptionOnInsertPayloadFailDeserialization() InsertRequestContext context = new(entityName: string.Empty, dbo: _defaultDbObject, insertPayloadRoot: payload, - operationType: Operation.Insert); + operationType: Config.Operation.Insert); Assert.Fail(); } catch (DataApiBuilderException e) @@ -64,7 +64,7 @@ public void EmptyInsertPayloadTest() InsertRequestContext context = new(entityName: string.Empty, dbo: _defaultDbObject, insertPayloadRoot: payload, - operationType: Operation.Insert); + operationType: Config.Operation.Insert); Assert.AreEqual(0, context.FieldValuePairsInBody.Count); } } From 4f98f051b815589186492d9077f8fcba6faea4d0 Mon Sep 17 00:00:00 2001 From: aaron burtle Date: Wed, 7 Dec 2022 02:40:44 -0800 Subject: [PATCH 12/12] fixed some collisions in test --- .../Configuration/ConfigurationTests.cs | 8 ++++---- .../GraphQLBuilder/QueryBuilderTests.cs | 4 ++-- src/Service.Tests/TestHelper.cs | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Service.Tests/Configuration/ConfigurationTests.cs b/src/Service.Tests/Configuration/ConfigurationTests.cs index 472cc8e418..5d1ecec4bf 100644 --- a/src/Service.Tests/Configuration/ConfigurationTests.cs +++ b/src/Service.Tests/Configuration/ConfigurationTests.cs @@ -272,7 +272,7 @@ public async Task TestSqlSettingPostStartupConfigurations() entityName: POST_STARTUP_CONFIG_ENTITY, entitySource: POST_STARTUP_CONFIG_ENTITY_SOURCE, roleName: POST_STARTUP_CONFIG_ROLE, - operation: Config.OperationRead, + operation: Config.Operation.Read, includedCols: new HashSet() { "*" }); ConfigurationPostParameters config = GetPostStartupConfigParams(MSSQL_ENVIRONMENT, configuration); @@ -534,7 +534,7 @@ private static void ConfigFileDeserializationValidationHelper(string jsonString) { foreach (object operation in permission.Operations) { - HashSet allowedActions = + HashSet allowedActions = new() { Config.Operation.All, Config.Operation.Create, Config.Operation.Read, Config.Operation.Update, Config.Operation.Delete }; Assert.IsTrue(((JsonElement)operation).ValueKind == JsonValueKind.String || @@ -551,7 +551,7 @@ private static void ConfigFileDeserializationValidationHelper(string jsonString) } else { - Operation name = AuthorizationResolver.WILDCARD.Equals(operation.ToString()) ? Config.OperationAll : ((JsonElement)operation).Deserialize(RuntimeConfig.SerializerOptions); + Config.Operation name = AuthorizationResolver.WILDCARD.Equals(operation.ToString()) ? Config.Operation.All : ((JsonElement)operation).Deserialize(RuntimeConfig.SerializerOptions); Assert.IsTrue(allowedActions.Contains(name)); } } @@ -1098,7 +1098,7 @@ public static RuntimeConfig InitMinimalRuntimeConfig(Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { "foo" }, - new Operation[] { Config.Operation.Read }, + new Config.Operation[] { Config.Operation.Read }, roles); DocumentNode queryRoot = QueryBuilder.Build( root, @@ -334,7 +334,7 @@ string expectedNameInDescription Dictionary entityPermissionsMap = GraphQLTestHelpers.CreateStubEntityPermissionsMap( new string[] { entityName }, - new Operation[] { Config.Operation.Read }, + new Config.Operation[] { Config.Operation.Read }, new string[] { "anonymous", "authenticated" }); Entity entity = (singularName is not null) diff --git a/src/Service.Tests/TestHelper.cs b/src/Service.Tests/TestHelper.cs index 1f29130395..491361bea4 100644 --- a/src/Service.Tests/TestHelper.cs +++ b/src/Service.Tests/TestHelper.cs @@ -141,18 +141,18 @@ public static void AddMissingEntitiesToConfig(RuntimeConfig config, string entit { ""role"": ""anonymous"", ""actions"": [" + - $" \"{Operation.Create.ToString().ToLower()}\"," + - $" \"{Operation.Read.ToString().ToLower()}\"," + - $" \"{Operation.Delete.ToString().ToLower()}\"," + - $" \"{Operation.Update.ToString().ToLower()}\" ]" + + $" \"{Config.Operation.Create.ToString().ToLower()}\"," + + $" \"{Config.Operation.Read.ToString().ToLower()}\"," + + $" \"{Config.Operation.Delete.ToString().ToLower()}\"," + + $" \"{Config.Operation.Update.ToString().ToLower()}\" ]" + @"}, { ""role"": ""authenticated"", ""actions"": [" + - $" \"{Operation.Create.ToString().ToLower()}\"," + - $" \"{Operation.Read.ToString().ToLower()}\"," + - $" \"{Operation.Delete.ToString().ToLower()}\"," + - $" \"{Operation.Update.ToString().ToLower()}\" ]" + + $" \"{Config.Operation.Create.ToString().ToLower()}\"," + + $" \"{Config.Operation.Read.ToString().ToLower()}\"," + + $" \"{Config.Operation.Delete.ToString().ToLower()}\"," + + $" \"{Config.Operation.Update.ToString().ToLower()}\" ]" + @"} ] }";