Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filling gaps in config validation for rest settings for entities #1496

Merged
merged 271 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
271 commits
Select commit Hold shift + click to select a range
4dfe671
Update entity tests refactored
aaronpowell Apr 22, 2023
7e4b6bb
Implementing e2e tests for the CLI
aaronpowell Apr 28, 2023
6f132a9
Implementing the utils tests with some refactors of the test to make …
aaronpowell Apr 28, 2023
fb6ca7a
Refactoring Service.Tests to compile with new config
aaronpowell May 1, 2023
df3303d
Fixing tests for GraphQL Mutation builder
aaronpowell May 1, 2023
da34a2a
Fixing GraphQL Builder query tests
aaronpowell May 1, 2023
71ba1e4
Fixing SQL schema converter tests
aaronpowell May 1, 2023
9f23567
Initialising a config for db exception parser tests
aaronpowell May 1, 2023
279396c
Proper serialization of the JSON config
aaronpowell May 1, 2023
7cbe6f9
SQL Query executor tests updated
aaronpowell May 1, 2023
86cd881
This test should read the config from disk since it connects to the DB
aaronpowell May 2, 2023
325389b
Refactoring the connection string parsing tests
aaronpowell May 2, 2023
a2dd947
Improving the Entity REST option deserialization
aaronpowell May 2, 2023
aefb744
More decoupling of tests from static/shared state
aaronpowell May 2, 2023
bd410ad
Fixing an expectation on how the config was loaded
aaronpowell May 2, 2023
aa58d83
Changing how the JSON deserialization is handled
aaronpowell May 2, 2023
a291a31
Fixing the ConfigValidator tests
aaronpowell May 2, 2023
9c9e0cb
Fixing how to make a mock RuntimeConfigProvider
aaronpowell May 2, 2023
804b909
Making the runtime smarter about what file to load
aaronpowell May 2, 2023
15e30bb
Found problem in serialization of EntityGraphQLOptions
aaronpowell May 2, 2023
9488bf0
Refactoring the Cosmos tests
aaronpowell May 3, 2023
a188248
Fixing mapping for singular GraphQL names
aaronpowell May 3, 2023
18544d2
Fixing some spelling mistakes
aaronpowell May 3, 2023
39bd25e
Reverting the automatic singularization of GraphQL entities as that w…
aaronpowell May 3, 2023
c145799
Fixing some problems in the CLI tests.
aaronpowell May 3, 2023
a5796fe
Update snapshots to reflect the recent refactoring
aaronpowell May 3, 2023
01b9ea1
ensuring snapshots folder is included
aaronpowell May 3, 2023
5fb1977
Formatting code to meet standards
aaronpowell May 3, 2023
6c0ec55
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 3, 2023
9ad3420
TEMPORARY COMMIT
aaronpowell May 3, 2023
1aa102e
Reverting temporary commit
aaronpowell May 3, 2023
00321aa
Fixing compile errors from the merge
aaronpowell May 3, 2023
a23eff3
Result of a bad merge - didn't provide dbObjects
aaronpowell May 3, 2023
7bc18ad
null handling permissions and setting sproc params
aaronpowell May 3, 2023
9d0a91e
WIP
aaronpowell May 4, 2023
5ea4f8c
Merge branch 'tmp' into aaronpowell/new-config-engine
aaronpowell May 4, 2023
5efe7ac
Fixing compiler error and namespacing
aaronpowell May 4, 2023
20d922c
Code formatting
aaronpowell May 4, 2023
90e52e2
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 4, 2023
7a62f05
Fixing some compiler errors from merge
aaronpowell May 4, 2023
0b0b222
Fixing CORS test and making it a snapshot test
aaronpowell May 4, 2023
f3fe6e9
Flipping the tests so when REST or GraphQL CLI options are
aaronpowell May 4, 2023
9f54391
Updating snapshots to reflect new defaults in REST/GraphQL
aaronpowell May 4, 2023
dcf5b23
Renaming the converter factory
aaronpowell May 4, 2023
aa8a002
Improving how env var replacement happens on deserialization
aaronpowell May 4, 2023
35a42d2
Fixing some locations where we shouldn't be deserializing with env re…
aaronpowell May 5, 2023
bbf1130
adding some useful messages to Assert.IsTrue failures
aaronpowell May 5, 2023
1c8585d
Enabling strict mode for snapshooter to avoid generating snapshots on…
aaronpowell May 5, 2023
46d00ca
Default EntityActionFields should be null as they aren't required
aaronpowell May 8, 2023
82e3560
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 8, 2023
409c267
Reintroducing the regressed functionality around events on config loa…
aaronpowell May 8, 2023
b7bf774
Adding missing snapshots and fixing env loading
aaronpowell May 8, 2023
3715cdc
Removing old cold and unsetting fake connection string from env vars
aaronpowell May 8, 2023
5fb961e
Ensuring DAB env vars are properly cleaned up after test runs
aaronpowell May 9, 2023
ed4d382
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 9, 2023
a2b2b9e
Fixing bad merge
aaronpowell May 9, 2023
5bd313b
Fixing snapshot test
aaronpowell May 9, 2023
8f64458
Improving how we ignore connection strings in snapshots
aaronpowell May 9, 2023
4da577e
really basic diff displayer to help debugging
aaronpowell May 11, 2023
6c353c0
snapshots should be in build output maybe
aaronpowell May 11, 2023
06ea3f3
file name doesn't include path
aaronpowell May 11, 2023
6bc70c1
more work on the simple diff engine
aaronpowell May 11, 2023
4007897
really verbose error message
aaronpowell May 11, 2023
cff3dfd
fixing snapshots to match how config is formatted when tests run
aaronpowell May 11, 2023
ab6c9e9
cleaning up usings
aaronpowell May 11, 2023
594fcf3
regenerating the cosmos config using the cli
aaronpowell May 11, 2023
3638234
More improvements to the default CosmosDB_NoSQL config
aaronpowell May 11, 2023
a0ff6ae
Disabling REST at an entity for CosmosDB
aaronpowell May 11, 2023
9a82332
Fixing cosmosdb deserialization snapshot
aaronpowell May 11, 2023
9c563fc
Fixing formatting
aaronpowell May 11, 2023
bdda7ea
Maybe making the diff display a bit better
aaronpowell May 11, 2023
541c68b
Updated snapshots
aaronpowell May 11, 2023
08fbf38
Fixing Config Merge test
aaronpowell May 11, 2023
ea9ca6e
improving the test assert flow
aaronpowell May 11, 2023
b927fba
Removing Snapshooter from CLI tests
aaronpowell May 12, 2023
c0bb22d
Removed snapshooter from Service.Tests for VerifyTest
aaronpowell May 12, 2023
69eb552
Remove package version for Snapshooter
aaronpowell May 12, 2023
38530a0
Updating build pipeline to publish verify test output on failure
aaronpowell May 12, 2023
2df5524
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 12, 2023
e3577c6
Adding validation for duplicate rest paths for entity
ayush3797 May 14, 2023
767f52f
Adding unit test for duplicate rest path for entities
ayush3797 May 14, 2023
c6a3401
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 15, 2023
0352c74
Bad merge on the cosmos config
aaronpowell May 15, 2023
bc49a91
Wasn't properly cloning existing permissions on update
aaronpowell May 15, 2023
79cb250
Fixing env var testing by creating a new mock application host
aaronpowell May 15, 2023
ba288c9
Fixing broken config for cosmos and some auth pipeline
aaronpowell May 15, 2023
da3a0e5
Handing that the model directive might not match entity in config
aaronpowell May 15, 2023
2b7df8d
Fixing verification test
aaronpowell May 15, 2023
81569c0
Using a params has for verify names
aaronpowell May 15, 2023
1a02421
Need to mock a method call
aaronpowell May 15, 2023
ecc96ce
Adding diffplex for better test debugging
aaronpowell May 15, 2023
095b7db
snapshot updated
aaronpowell May 15, 2023
9b118d6
Fixing test
aaronpowell May 15, 2023
27de7a9
Removing mstest from core service
aaronpowell May 15, 2023
33f191e
Disallowing empty/null rest path for entity
ayush3797 May 15, 2023
98d157f
rest methods can be an array of strings of valid rest operations only
ayush3797 May 15, 2023
2f2fdf1
rest methods can only be present for stored procedures
ayush3797 May 15, 2023
b169c77
Adding constants for rest props: path/methods
ayush3797 May 15, 2023
34a3f84
path can only be string/bool
ayush3797 May 15, 2023
12c3b48
Seperating validations for methods and path
ayush3797 May 15, 2023
857a378
Expanding the Create DB policy test coverage
aaronpowell May 15, 2023
23cef46
Adding unit tests for rest path
ayush3797 May 15, 2023
5735d51
removing extra blank lines
ayush3797 May 15, 2023
b3dd45c
Serialization of json schema property was wrong
aaronpowell May 15, 2023
04da726
Improving the dynamic config loading via endpoint
aaronpowell May 16, 2023
9294aa2
Need a new line in the command script for config generation
aaronpowell May 16, 2023
14158c4
Config file regenerated
aaronpowell May 16, 2023
10bdaa8
Updated verified runtime config
aaronpowell May 16, 2023
b7ea176
Bad merge dropped DateTimeOffset support
aaronpowell May 16, 2023
286f4d5
Don't need to unpack sproc props from JSON anymore
aaronpowell May 16, 2023
522fc92
Ensuring right config is loaded and serialized properly
aaronpowell May 16, 2023
6d9f9d6
Fixing generated config
aaronpowell May 16, 2023
7e7a058
Better handling of lazy loading config files
aaronpowell May 16, 2023
bd9205b
Upsert not Update...
aaronpowell May 16, 2023
520c63a
Reverting change on how config file name is set
aaronpowell May 16, 2023
5de42bb
Fixing the DataRow attribute usage
aaronpowell May 16, 2023
7a429c0
Updating PostgreSQL and MySQL configs + snapshots
aaronpowell May 16, 2023
a480127
new hashing algo to meet SDL
aaronpowell May 16, 2023
a987ece
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 16, 2023
32cdec4
Removing the runtime env setting
aaronpowell May 16, 2023
69fc419
Adding more validations and tests for rest methods
ayush3797 May 16, 2023
d724fb6
nits
ayush3797 May 16, 2023
1906fc7
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 May 16, 2023
e42c700
Moving snapshots into their own folder for easier PR reviews
aaronpowell May 17, 2023
7e96d51
Undoing launch file changes
aaronpowell May 17, 2023
75c0c03
Flag around UseHttpsRedirection
aaronpowell May 17, 2023
9174fda
addressing comments
ayush3797 May 17, 2023
a2aeec8
Fixed bug - incorrectly parsing boolean rest.path for entity
ayush3797 May 17, 2023
28caf7e
adding more validation scenarios
ayush3797 May 17, 2023
dd0151a
consider rest path/entityName only when rest endpoint is enabled for …
ayush3797 May 17, 2023
c2cf953
disable unique path validation when rest endpoint is disabled globally
ayush3797 May 17, 2023
eff9a24
checking for whitespaces at the start
ayush3797 May 17, 2023
5ac9304
Apply suggestions from code review
aaronpowell May 18, 2023
d855aed
Update src/Service.GraphQLBuilder/GraphQLStoredProcedureBuilder.cs
aaronpowell May 18, 2023
9c0e207
Fixing a bad merge from code review and making Entities a ReadOnlyDic…
aaronpowell May 18, 2023
7988bad
Moving file up per review
aaronpowell May 18, 2023
8aa1f4b
Describing the logger
aaronpowell May 18, 2023
f3996f5
Adding doc comments for the RuntimeConfigLoader and Provider
aaronpowell May 18, 2023
f36a660
EntityType -> EntitySourceType for more obvious naming
aaronpowell May 18, 2023
cbea153
More doc comments describing types
aaronpowell May 18, 2023
5b8dc9a
removing blank line
ayush3797 May 18, 2023
22237bf
Removing the use of magic strings for data source options
aaronpowell May 19, 2023
8e48c71
Reverting a change where I dropped an enum and used a string
aaronpowell May 19, 2023
56f241f
Expanding the check to cover whitespace as well.
aaronpowell May 19, 2023
08293d6
Adding <inheritdoc /> for converter types
aaronpowell May 19, 2023
0173cbb
Fixing based on PR review feedback
aaronpowell May 22, 2023
7f0a6d7
More clarity on what files are being added
aaronpowell May 23, 2023
e3c1390
Merge branch 'aaronpowell/new-config-engine' of https://github.com/Az…
aaronpowell May 23, 2023
bba1ace
Fixing whitespace
aaronpowell May 25, 2023
964b6d8
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 25, 2023
556a381
Little tweak of if test
aaronpowell May 25, 2023
a4bb129
Updating Verify.MSTest to 20.1.0
aaronpowell May 25, 2023
34f4acf
Cleaned up verify test output
aaronpowell May 25, 2023
2e3c864
Fixing usage of default params
aaronpowell May 26, 2023
36c9b57
Moving the new types for the config to their own folder/namespace
aaronpowell May 26, 2023
055545e
formatting fix
aaronpowell May 26, 2023
ca7ce2b
Forgot to add this snapshot
aaronpowell May 26, 2023
6411614
More missing snapshots
aaronpowell May 26, 2023
19b4bb5
Update src/Config/DatabasePrimitives/DatabaseObject.cs
aaronpowell May 29, 2023
33cda15
Addressing the potentially incorrect naming of a param
aaronpowell May 29, 2023
fe8c79c
Moving away from Enum.Parse as it's not the most optimal in our codebase
aaronpowell May 29, 2023
e429969
adding a comment to explain why we reparse the dictionary
aaronpowell May 29, 2023
2a77d1e
Cleanup from code review
aaronpowell May 29, 2023
5c3e632
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 May 29, 2023
4c7857c
performing rest validations irrespective of whether rest is enabled o…
ayush3797 May 29, 2023
7b35d50
Merge branch 'dev/agarwalayush/fillingGapsInConfigValidation' of http…
ayush3797 May 29, 2023
b7639d9
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell May 31, 2023
dd20173
Updating System.IO.Abstractions
aaronpowell May 31, 2023
cc6f202
Clearing up the message
aaronpowell Jun 1, 2023
89b69ce
Updated the method docs
aaronpowell Jun 1, 2023
56875c8
Incorporating review feedback
aaronpowell Jun 1, 2023
304a3b5
Incorporating review feedback
aaronpowell Jun 1, 2023
9dca707
Using null when it was expected
aaronpowell Jun 2, 2023
f306f3a
Fixing verify tests
aaronpowell Jun 2, 2023
8600e69
linting
aaronpowell Jun 2, 2023
2f66399
Fixing verify tests
aaronpowell Jun 2, 2023
bde04c5
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jun 5, 2023
d2c03fb
resolving cmts
ayush3797 Jun 5, 2023
93ae51d
Merge branch 'dev/agarwalayush/fillingGapsInConfigValidation' of http…
ayush3797 Jun 5, 2023
7849be5
doing validations for rest only when endpoint is enabled
ayush3797 Jun 5, 2023
1956633
fixing test
ayush3797 Jun 5, 2023
e58c1c5
null check for rest methods
ayush3797 Jun 5, 2023
6c7c554
Adding test for conflict between rest path and entity name
ayush3797 Jun 6, 2023
85d4a85
Apply suggestions from code review
aaronpowell Jun 8, 2023
3e065b9
Removing the methods if REST is disabled for an entity
aaronpowell Jun 9, 2023
25407f6
Little clean up on these two converters
aaronpowell Jun 9, 2023
736af07
Fixing comment
aaronpowell Jun 9, 2023
4acb6cc
Bringing back comment explaining why Exlude isn't nullable
aaronpowell Jun 9, 2023
be78085
naming nullable fields
aaronpowell Jun 9, 2023
66b1526
Code optimisation
aaronpowell Jun 9, 2023
4b7d684
Pluralisation should only happen when creating the RuntimeEntities type
aaronpowell Jun 9, 2023
86fd0f8
Correct implementation of the JSON schema for REST path values
aaronpowell Jun 9, 2023
09df26f
Expanding doc comments
aaronpowell Jun 9, 2023
42df27f
Null handling
aaronpowell Jun 9, 2023
afeb272
Using string.Empty properly
aaronpowell Jun 9, 2023
7330fe5
Expanding abbreviation
aaronpowell Jun 9, 2023
da68eee
Changed from code review
aaronpowell Jun 9, 2023
5b9813f
Addressing feedback from PR review
aaronpowell Jun 13, 2023
e27eba9
Addressing feedback from PR review
aaronpowell Jun 13, 2023
59eca73
Removing unused enum member and code cleanup from review
aaronpowell Jun 13, 2023
d68af6d
Adding better logic to determine the right number value to use
aaronpowell Jun 13, 2023
e857f3e
Missed setting late config for new initialization endpoint
aaronpowell Jun 15, 2023
bbb04f7
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jun 19, 2023
04c9207
rest entity validation only performed when entity.rest=true
ayush3797 Jun 19, 2023
a8e87ab
adding unit tests
ayush3797 Jun 19, 2023
d706a95
fixing logic
ayush3797 Jun 19, 2023
f98b205
fixing summary
ayush3797 Jun 19, 2023
f63c50c
Removing unused doccomment
aaronpowell Jun 20, 2023
38afc1f
Adding a comment to explain why singular/plural might end up empty st…
aaronpowell Jun 20, 2023
fe51c01
Using the local variable
aaronpowell Jun 21, 2023
07ed782
Code review update
aaronpowell Jun 21, 2023
11c5a81
Code review update
aaronpowell Jun 21, 2023
78b76bc
Turns out that I should read the docs properly, step goes AFTER tests…
aaronpowell Jun 21, 2023
24f6e49
Error handling for when there's no database that can be determined fo…
aaronpowell Jun 21, 2023
b8fc53e
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell Jun 21, 2023
0419531
Checked for wrong auth type
aaronpowell Jun 21, 2023
2cbd53c
Addressing latest PR feedback
aaronpowell Jun 22, 2023
59456c5
Making the EntitySource.Type nullable (#1530)
aaronpowell Jun 22, 2023
e78ad79
Better usage of Verify and ensuring test cleanup
aaronpowell Jun 23, 2023
f44565d
Splitting the tests from data drive to separate tests
aaronpowell Jun 23, 2023
c333318
Avoiding reading to the end in case the process hadn't finished. Only…
aaronpowell Jun 23, 2023
11eb639
Removing cli config name precedence setting
aaronpowell Jun 23, 2023
a7ae343
Disabling a test temporarily, see comment on test for insights
aaronpowell Jun 23, 2023
d6b6dd4
Merge branch 'main' into aaronpowell/new-config-engine
aaronpowell Jun 23, 2023
9f51554
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jun 26, 2023
f128532
code review update
aaronpowell Jun 27, 2023
3824eff
Merge branch 'aaronpowell/new-config-engine' of https://github.com/Az…
aaronpowell Jun 27, 2023
66358e5
Handling non-model GraphQL types in Cosmos
aaronpowell Jun 29, 2023
c41a9f3
Fixing formatting
aaronpowell Jun 29, 2023
bfbe695
Resolving conflicts initial progress
ayush3797 Jun 29, 2023
9deccda
fixed config validation tests
ayush3797 Jun 29, 2023
03e20dc
skipping methods validation
ayush3797 Jun 29, 2023
6d65483
formatting fix
ayush3797 Jun 29, 2023
72c8b84
resolving conflicts
ayush3797 Jun 30, 2023
83f51b0
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jul 4, 2023
8714d68
reverting change
ayush3797 Jul 4, 2023
f0aba3c
resolving comments
ayush3797 Jul 6, 2023
3e8eec5
adding more tests
ayush3797 Jul 6, 2023
05aecf1
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jul 6, 2023
b0c99c9
adding tests for invalid characters in entityname
ayush3797 Jul 6, 2023
ca3c444
moving constants to EntityRestOptions class
ayush3797 Jul 7, 2023
0d82c38
removing cmt
ayush3797 Jul 7, 2023
7f4181a
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jul 10, 2023
381a893
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jul 10, 2023
c6f71fa
removing constants
ayush3797 Jul 11, 2023
38e361f
Merge branch 'main' into dev/agarwalayush/fillingGapsInConfigValidation
ayush3797 Jul 11, 2023
78b7d45
typo
ayush3797 Jul 11, 2023
7276e28
Merge branch 'dev/agarwalayush/fillingGapsInConfigValidation' of http…
ayush3797 Jul 11, 2023
3179632
doing rest validation only when enabled
ayush3797 Jul 12, 2023
addbc1c
adding more tests
ayush3797 Jul 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Config/ObjectModel/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public record Entity(
EntityRestOptions Rest,
EntityPermission[] Permissions,
Dictionary<string, string>? Mappings,
Dictionary<string, EntityRelationship>? Relationships);
Dictionary<string, EntityRelationship>? Relationships)
{
public const string PROPERTY_PATH = "path";
public const string PROPERTY_METHODS = "methods";
}
99 changes: 81 additions & 18 deletions src/Core/Configurations/RuntimeConfigValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public class RuntimeConfigValidator : IConfigValidator
// The claimType is invalid if there is a match found.
private static readonly Regex _invalidClaimCharsRgx = new(_invalidClaimChars, RegexOptions.Compiled);

// "Reserved characters as defined in RFC3986 are not allowed to be present in the
// REST/GraphQL custom path because they are not acceptable to be present in URIs.
// " Refer here: https://www.rfc-editor.org/rfc/rfc3986#page-12.
private static readonly string _invalidPathChars = @"[\.:\?#/\[\]@!$&'()\*\+,;=]+";
// Reserved characters as defined in RFC3986 are not allowed to be present in the
// REST/GraphQL URI path because they are not acceptable to be present in URIs.
// Refer here: https://www.rfc-editor.org/rfc/rfc3986#page-12.
private static readonly string _invalidUriCharacters = @"[\.:\?#/\[\]@!$&'()\*\+,;=]+";

// Regex to validate rest/graphql custom path prefix.
public static readonly Regex _invalidApiPathCharsRgx = new(_invalidPathChars, RegexOptions.Compiled);
// Regex to validate rest/graphql URI path components.
public static readonly Regex _invalidUriCharactersRgx = new(_invalidUriCharacters, RegexOptions.Compiled);

// Regex used to extract all claimTypes in policy. It finds all the substrings which are
// of the form @claims.*** delimited by space character,end of the line or end of the string.
Expand Down Expand Up @@ -77,11 +77,14 @@ public void ValidateConfig()

// Running these graphQL validations only in development mode to ensure
// fast startup of engine in production mode.
if (runtimeConfig.Runtime.GraphQL.Enabled
&& runtimeConfig.Runtime.Host.Mode is HostMode.Development)
if (runtimeConfig.Runtime.Host.Mode is HostMode.Development)
{
ValidateEntityNamesInConfig(runtimeConfig.Entities);
ValidateEntitiesDoNotGenerateDuplicateQueriesOrMutation(runtimeConfig.Entities);
ValidateEntityConfiguration(runtimeConfig);

if (runtimeConfig.Runtime.GraphQL.Enabled)
{
ValidateEntitiesDoNotGenerateDuplicateQueriesOrMutation(runtimeConfig.Entities);
}
}
}

Expand Down Expand Up @@ -226,25 +229,85 @@ public static void ValidateEntitiesDoNotGenerateDuplicateQueriesOrMutation(Runti
}

/// <summary>
/// Check whether the entity name defined in runtime config only contains
/// characters allowed for GraphQL names.
/// Does not perform validation for entities which do not
/// Check whether the entity configuration defined in runtime config only contains characters allowed for GraphQL names
/// and other validations related to rest path and methods configured for the entity.
/// The GraphQL validation is not performed for entities which do not
/// have GraphQL configuration: when entity.GraphQL == false or null.
/// </summary>
/// <seealso cref="https://spec.graphql.org/October2021/#Name"/>
/// <param name="entityCollection">The runtime entities to process.</param>
public static void ValidateEntityNamesInConfig(RuntimeEntities entityCollection)
/// <param name="runtimeConfig">The runtime configuration.</param>
public static void ValidateEntityConfiguration(RuntimeConfig runtimeConfig)
{
foreach ((string _, Entity entity) in entityCollection)
// Stores the unique rest paths configured for different entities present in the config.
HashSet<string> restPathsForEntities = new();

foreach ((string entityName, Entity entity) in runtimeConfig.Entities)
{
if (entity.GraphQL.Enabled)
if (runtimeConfig.Runtime.Rest.Enabled)
{
// By default we assume Rest is enabled for the entity.
bool isRestEnabledForEntity = true;

// If no custom rest path is defined for the entity, we default it to the entityName.
string pathForEntity = entityName;
if (entity.Rest is not null)
{
pathForEntity = entity.Rest.Path is not null ? entity.Rest.Path.TrimStart('/') : entityName;
isRestEnabledForEntity = entity.Rest.Enabled;

// Since 'path' is an optional property, we skip validation if its absent.
ValidateRestPathSettingsForEntity(entityName, pathForEntity);
}

if (isRestEnabledForEntity && !restPathsForEntities.Add(pathForEntity))
{
// Presence of multiple entities having the same rest path configured causes conflict.
throw new DataApiBuilderException(
message: $"The rest path: {pathForEntity} specified for entity: {entityName} is already used by another entity.",
statusCode: HttpStatusCode.ServiceUnavailable,
subStatusCode: DataApiBuilderException.SubStatusCodes.ConfigValidationError
);
}
}

// If GraphQL endpoint is enabled globally and at entity level, then only we perform the validations related to it.
if (runtimeConfig.Runtime.GraphQL.Enabled && entity.GraphQL is not null && entity.GraphQL.Enabled)
{
ValidateNameRequirements(entity.GraphQL.Singular);
ValidateNameRequirements(entity.GraphQL.Plural);
}
}
}

/// <summary>
/// Helper method to validate that the rest path property for the entity is correctly configured.
/// The rest path should not be null/empty and should not contain any reserved characters.
/// </summary>
/// <param name="entityName">Name of the entity.</param>
/// <param name="pathForEntity">The rest path for the entity.</param>
/// <exception cref="DataApiBuilderException">Throws exception when rest path contains an unexpected value.</exception>
private static void ValidateRestPathSettingsForEntity(string entityName, string pathForEntity)
{
if (string.IsNullOrEmpty(pathForEntity))
{
// The rest 'path' cannot be empty.
throw new DataApiBuilderException(
message: $"The rest path for entity: {entityName} cannot be empty.",
statusCode: HttpStatusCode.ServiceUnavailable,
subStatusCode: DataApiBuilderException.SubStatusCodes.ConfigValidationError
);
}

if (_invalidUriCharactersRgx.IsMatch(pathForEntity))
{
throw new DataApiBuilderException(
message: $"The rest path: {pathForEntity} for entity: {entityName} contains one or more reserved characters.",
statusCode: HttpStatusCode.ServiceUnavailable,
subStatusCode: DataApiBuilderException.SubStatusCodes.ConfigValidationError
);
}
}

private static void ValidateNameRequirements(string entityName)
{
if (GraphQLNaming.ViolatesNamePrefixRequirements(entityName) ||
Expand Down Expand Up @@ -363,7 +426,7 @@ private static void ValidateApiPath(string apiPath, ApiType apiType)
/// <exception cref="DataApiBuilderException"></exception>
public static void DoApiPathInvalidCharCheck(string apiPath, ApiType apiType)
{
if (_invalidApiPathCharsRgx.IsMatch(apiPath))
if (_invalidUriCharactersRgx.IsMatch(apiPath))
{
string errorMessage = INVALID_GRAPHQL_PATH_WITH_RESERVED_CHAR_ERR_MSG;
if (apiType == ApiType.REST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public static Entity GenerateEmptyEntity(string entityName)
{
return new Entity(
Source: new($"{SCHEMA_NAME}.{TABLE_NAME}", EntitySourceType.Table, null, null),
Rest: new(EntityRestOptions.DEFAULT_SUPPORTED_VERBS),
Rest: new(new SupportedHttpVerb[] { }),
GraphQL: new(entityName, ""),
Permissions: Array.Empty<EntityPermission>(),
Relationships: new(),
Expand Down
Loading