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

Fix issue when graphql is true and include permission is WILDCARD #1501

Merged
merged 9 commits into from
May 24, 2023
4 changes: 3 additions & 1 deletion config-generators/cosmosdb_nosql-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ add Earth --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.earth" -
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:create" --fields.include "id" --fields.exclude "name"
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "id,type" --fields.exclude "name"
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:update" --fields.exclude "*"
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete"
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete"
add Sun --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.sun" --permissions "anonymous:create,update,delete" --graphql true
update Sun --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "*"
1 change: 1 addition & 0 deletions src/Config/RuntimeConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public void MapGraphQLSingularTypeToEntityName(ILogger? logger)
if (entity.GraphQL is null || entity.GraphQL is true)
{
// Use entity name since GraphQL type unavailable
GraphQLSingularTypeToEntityNameMap.TryAdd(entityName, entityName);
logger?.LogInformation($"GraphQL type for {entityName} is {entityName}");
}
}
Expand Down
24 changes: 23 additions & 1 deletion src/Service.Tests/CosmosTests/QueryFilterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void TestFixtureSetup(TestContext context)
OverrideEntityContainer("Planet", _containerName);
OverrideEntityContainer("Earth", _containerName);
OverrideEntityContainer("StarAlias", _containerName);
OverrideEntityContainer("TagAlias", _containerName);
OverrideEntityContainer("Sun", _containerName);
}

/// <summary>
Expand Down Expand Up @@ -834,6 +834,28 @@ public async Task TestQueryFieldAuthConflictingWithFilterFieldAuth_Unauthorized(
string errorMessage = response.ToString();
Assert.IsTrue(errorMessage.Contains("The current user is not authorized to access this resource."));
}

/// <summary>
/// Tests that the field level query filter succeeds requests
/// when GraphQL is set to ture without setting singular type in runtime config and
/// when include fields are WILDCARD,
/// all the columns are able to be retrieved for authorization validation.
/// </summary>
[TestMethod]
public async Task TestQueryFilterFieldAuthWithoutSingularType()
{
string gqlQuery = @"{
suns(first: 1, " + QueryBuilder.FILTER_FIELD_NAME + @" : {id : {eq : """ + _idList[0] + @"""}})
{
items {
id
}
}
}";

string dbQuery = $"SELECT top 1 c.id FROM c where c.id = \"{_idList[0]}\"";
await ExecuteAndValidateResult("suns", gqlQuery, dbQuery);
}
#endregion

[ClassCleanup]
Expand Down
5 changes: 5 additions & 0 deletions src/Service.Tests/CosmosTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ type Earth @model(name:""Earth"") {
id : ID,
name : String,
type: String @authorize(roles: [""authenticated""])
}

type Sun @model(name:""Sun"") {
id : ID,
name : String
}";

private static string[] _planets = { "Earth", "Mars", "Jupiter", "Tatooine", "Endor", "Dagobah", "Hoth", "Bespin", "Spec%ial" };
Expand Down
22 changes: 22 additions & 0 deletions src/Service.Tests/dab-config.CosmosDb_NoSql.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@
}
}
},
"Sun": {
"source": "graphqldb.sun",
"permissions": [
{
"role": "anonymous",
"actions": [
"create",
{
"action": "read",
"fields": {
"include": [
"*"
]
}
},
"update",
"delete"
]
}
],
"graphql": true
},
"Moon": {
"source": "graphqldb.moon",
"permissions": [
Expand Down