Skip to content

Commit 61de247

Browse files
authored
Release0.7 with bug fix (#1516)
## Why make this change? - This is for cherry-pick the bug fix from main into the release 0.7 ## What is this change? Here is the PR merged in main for the fix. #1501
1 parent 2bd0a13 commit 61de247

File tree

5 files changed

+90
-2
lines changed

5 files changed

+90
-2
lines changed

config-generators/cosmosdb_nosql-commands.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ add Earth --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.earth" -
1212
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:create" --fields.include "id" --fields.exclude "name"
1313
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "id,type" --fields.exclude "name"
1414
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:update" --fields.exclude "*"
15-
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete"
15+
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete"
16+
add Sun --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.sun" --permissions "anonymous:create,update,delete" --graphql true
17+
update Sun --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "*" --fields.exclude "name"

src/Config/RuntimeConfig.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public void MapGraphQLSingularTypeToEntityName(ILogger? logger)
237237
if (entity.GraphQL is null || entity.GraphQL is true)
238238
{
239239
// Use entity name since GraphQL type unavailable
240+
GraphQLSingularTypeToEntityNameMap.TryAdd(entityName, entityName);
240241
logger?.LogInformation($"GraphQL type for {entityName} is {entityName}");
241242
}
242243
}

src/Service.Tests/CosmosTests/QueryFilterTests.cs

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void TestFixtureSetup(TestContext context)
3636
OverrideEntityContainer("Planet", _containerName);
3737
OverrideEntityContainer("Earth", _containerName);
3838
OverrideEntityContainer("StarAlias", _containerName);
39-
OverrideEntityContainer("TagAlias", _containerName);
39+
OverrideEntityContainer("Sun", _containerName);
4040
}
4141

4242
/// <summary>
@@ -834,6 +834,61 @@ public async Task TestQueryFieldAuthConflictingWithFilterFieldAuth_Unauthorized(
834834
string errorMessage = response.ToString();
835835
Assert.IsTrue(errorMessage.Contains("The current user is not authorized to access this resource."));
836836
}
837+
838+
/// <summary>
839+
/// Tests that the field level query filter succeeds requests
840+
/// when GraphQL is set to true without setting singular type in runtime config and
841+
/// when include fields are WILDCARD,
842+
/// all the columns are able to be retrieved for authorization validation.
843+
/// </summary>
844+
[TestMethod]
845+
public async Task TestQueryFilterFieldAuthWithoutSingularType()
846+
{
847+
string gqlQuery = @"{
848+
suns(first: 1, " + QueryBuilder.FILTER_FIELD_NAME + @" : {id : {eq : """ + _idList[0] + @"""}})
849+
{
850+
items {
851+
id
852+
name
853+
}
854+
}
855+
}";
856+
857+
string dbQuery = $"SELECT top 1 c.id, c.name FROM c where c.id = \"{_idList[0]}\"";
858+
await ExecuteAndValidateResult("suns", gqlQuery, dbQuery);
859+
}
860+
861+
/// <summary>
862+
/// Tests that the field level query filter failed authorization validation
863+
/// when include fields are WILDCARD and exclude fields specifies fields,
864+
/// exclude fields takes precedence over include fields.
865+
/// </summary>
866+
[TestMethod]
867+
public async Task TestQueryFilterFieldAuth_ExcludeTakesPredecence()
868+
{
869+
string gqlQuery = @"{
870+
suns(first: 1, " + QueryBuilder.FILTER_FIELD_NAME + @" : {name : {eq : ""test name""}})
871+
{
872+
items {
873+
id
874+
name
875+
}
876+
}
877+
}";
878+
879+
string clientRoleHeader = AuthorizationType.Anonymous.ToString();
880+
JsonElement response = await ExecuteGraphQLRequestAsync(
881+
queryName: "suns",
882+
query: gqlQuery,
883+
variables: new() { { "name", "test name" } },
884+
authToken: AuthTestHelper.CreateStaticWebAppsEasyAuthToken(specificRole: clientRoleHeader),
885+
clientRoleHeader: clientRoleHeader);
886+
887+
// Validate the result contains the GraphQL authorization error code.
888+
string errorMessage = response.ToString();
889+
Assert.IsTrue(errorMessage.Contains(DataApiBuilderException.GRAPHQL_FILTER_FIELD_AUTHZ_FAILURE));
890+
891+
}
837892
#endregion
838893

839894
[ClassCleanup]

src/Service.Tests/CosmosTests/TestBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ type Earth @model(name:""Earth"") {
7272
id : ID,
7373
name : String,
7474
type: String @authorize(roles: [""authenticated""])
75+
}
76+
77+
type Sun @model(name:""Sun"") {
78+
id : ID,
79+
name : String
7580
}";
7681

7782
private static string[] _planets = { "Earth", "Mars", "Jupiter", "Tatooine", "Endor", "Dagobah", "Hoth", "Bespin", "Spec%ial" };

src/Service.Tests/dab-config.CosmosDb_NoSql.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,31 @@
148148
}
149149
}
150150
},
151+
"Sun": {
152+
"source": "graphqldb.sun",
153+
"permissions": [
154+
{
155+
"role": "anonymous",
156+
"actions": [
157+
"create",
158+
{
159+
"action": "read",
160+
"fields": {
161+
"include": [
162+
"*"
163+
],
164+
"exclude": [
165+
"name"
166+
]
167+
}
168+
},
169+
"update",
170+
"delete"
171+
]
172+
}
173+
],
174+
"graphql": true
175+
},
151176
"Moon": {
152177
"source": "graphqldb.moon",
153178
"permissions": [

0 commit comments

Comments
 (0)