Skip to content

Commit 62929c1

Browse files
committed
fix tests
1 parent f3bf743 commit 62929c1

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

src/Service.Tests/CosmosTests/MutationTests.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,12 @@ public async Task MutationMissingRequiredPartitionKeyValueReturnError()
257257
/// It throws permission denied error if role doesn't have permission to perform the operation
258258
/// </summary>
259259
[TestMethod]
260-
[DataRow("field-mutation-with-read-permission", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE)] // exclude and include fields
261-
[DataRow("authenticated", null)] // full permission
262-
[DataRow("only-create-role", "The mutation operation createEarth was successful but the current user is unauthorized to view the response due to lack of read permissions")] // if only create permission is there
263-
[DataRow("wildcard-exclude-fields-role", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE)] // exclude wildcard
264-
[DataRow("only-update-role", "The current user is not authorized to access this resource" )] // if create permission is not there
260+
[DataRow("field-mutation-with-read-permission", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE, DisplayName = " exclude and include fields")]
261+
[DataRow("authenticated", null, DisplayName = "full permission")]
262+
[DataRow("only-create-role", "The mutation operation createEarth was successful " +
263+
"but the current user is unauthorized to view the response due to lack of read permissions", DisplayName = "if only create permission is there")]
264+
[DataRow("wildcard-exclude-fields-role", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE, DisplayName = "exclude wildcard")]
265+
[DataRow("only-update-role", "The current user is not authorized to access this resource", DisplayName = "if create permission is not there")]
265266
public async Task CreateItemWithAuthPermissions(string roleName, string expectedErrorMessage)
266267
{
267268
// Run mutation Add Earth;
@@ -296,11 +297,12 @@ public async Task CreateItemWithAuthPermissions(string roleName, string expected
296297
/// It throws permission denied error if role doesn't have permission to perform the operation
297298
/// </summary>
298299
[TestMethod]
299-
[DataRow("field-mutation-with-read-permission", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE)] // exclude and include fields
300-
[DataRow("authenticated", null)] // full permission
301-
[DataRow("only-update-role", "The mutation operation updateEarth was successful but the current user is unauthorized to view the response due to lack of read permissions")] // if only update permission is there
302-
[DataRow("wildcard-exclude-fields-role", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE)] // exclude wildcard
303-
[DataRow("only-create-role", "The current user is not authorized to access this resource")] // if update permission is not there
300+
[DataRow("field-mutation-with-read-permission", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE, DisplayName = "exclude and include fields")]
301+
[DataRow("authenticated", null, DisplayName = "full permission")]
302+
[DataRow("only-update-role", "The mutation operation updateEarth was successful " +
303+
"but the current user is unauthorized to view the response due to lack of read permissions", DisplayName = "if only update permission is there")]
304+
[DataRow("wildcard-exclude-fields-role", DataApiBuilderException.GRAPHQL_MUTATION_FIELD_AUTHZ_FAILURE, DisplayName = "exclude wildcard")]
305+
[DataRow("only-create-role", "The current user is not authorized to access this resource", DisplayName = "if update permission is not there")]
304306
public async Task UpdateItemWithAuthPermissions(string roleName, string expectedErrorMessage)
305307
{
306308
// Create an item with "Authenticated" role
@@ -361,11 +363,13 @@ public async Task UpdateItemWithAuthPermissions(string roleName, string expected
361363
/// It throws permission denied error if role doesn't have permission to perform the operation
362364
/// </summary>
363365
[TestMethod]
364-
[DataRow("field-mutation-with-read-permission", null)] // exclude and include fields. Response is BLANK.
365-
[DataRow("authenticated", null)] // full permission. Response is BLANK
366-
[DataRow("only-delete-role", "The mutation operation deleteEarth was successful but the current user is unauthorized to view the response due to lack of read permissions")] // if only update permission is there
367-
[DataRow("wildcard-exclude-fields-role", "The mutation operation deleteEarth was successful but the current user is unauthorized to view the response due to lack of read permissions")] // exclude wildcard
368-
[DataRow("only-create-role", "The current user is not authorized to access this resource")] // if update permission is not there
366+
[DataRow("field-mutation-with-read-permission", null, DisplayName = " exclude and include fields. Response is BLANK")]
367+
[DataRow("authenticated", null, DisplayName = "full permission. Response is BLANK")]
368+
[DataRow("only-delete-role", "The mutation operation deleteEarth was successful " +
369+
"but the current user is unauthorized to view the response due to lack of read permissions", DisplayName = "if only update permission is there")]
370+
[DataRow("wildcard-exclude-fields-role", "The mutation operation deleteEarth was successful " +
371+
"but the current user is unauthorized to view the response due to lack of read permissions", DisplayName = "exclude wildcard")]
372+
[DataRow("only-create-role", "The current user is not authorized to access this resource", DisplayName = "if update permission is not there")]
369373
public async Task DeleteItemWithAuthPermissions(string roleName, string expectedErrorMessage)
370374
{
371375
// Create an item with "Authenticated" role

src/Service.Tests/CosmosTests/QueryFilterTests.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,7 @@ public async Task TestStringFiltersOnTwoLevelNestedArrayType()
176176
"JOIN d IN b.moreAttributes " +
177177
"WHERE d.name = \"moonattr0\"";
178178

179-
await ExecuteAndValidateResult(
180-
_graphQLQueryName,
181-
gqlQuery,
182-
dbQueryWithJoin,
183-
authToken: AuthTestHelper.CreateStaticWebAppsEasyAuthToken(specificRole: AuthorizationType.Authenticated.ToString()));
179+
await ExecuteAndValidateResult(_graphQLQueryName, gqlQuery, dbQueryWithJoin);
184180
}
185181

186182
/// <summary>
@@ -266,8 +262,9 @@ public async Task TestStringMultiFiltersOnArrayTypeWithOrCondition()
266262
await ExecuteAndValidateResult(_graphQLQueryName, gqlQuery, dbQueryWithJoin);
267263
}
268264

269-
private async Task ExecuteAndValidateResult(string graphQLQueryName, string gqlQuery, string dbQuery, string authToken = null)
265+
private async Task ExecuteAndValidateResult(string graphQLQueryName, string gqlQuery, string dbQuery)
270266
{
267+
string authToken = AuthTestHelper.CreateStaticWebAppsEasyAuthToken(specificRole: AuthorizationType.Authenticated.ToString());
271268
JsonElement actual = await ExecuteGraphQLRequestAsync(graphQLQueryName, query: gqlQuery, authToken: authToken);
272269
JsonDocument expected = await ExecuteCosmosRequestAsync(dbQuery, _pageSize, null, _containerName);
273270
ValidateResults(actual.GetProperty("items"), expected.RootElement);
@@ -916,7 +913,7 @@ public async Task TestQueryFilterFieldAuth_UnauthorizedField()
916913
}
917914
}
918915
}";
919-
string clientRoleHeader = AuthorizationType.Anonymous.ToString();
916+
string clientRoleHeader = "limited-read-role";
920917
JsonElement response = await ExecuteGraphQLRequestAsync(
921918
queryName: "earths",
922919
query: gqlQuery,
@@ -974,7 +971,8 @@ public async Task TestQueryFilterNestedFieldAuth_AuthorizedNestedField()
974971
}
975972
}";
976973

977-
JsonElement actual = await ExecuteGraphQLRequestAsync(_graphQLQueryName, query: gqlQuery);
974+
string authToken = AuthTestHelper.CreateStaticWebAppsEasyAuthToken(specificRole: AuthorizationType.Authenticated.ToString());
975+
JsonElement actual = await ExecuteGraphQLRequestAsync(_graphQLQueryName, query: gqlQuery, authToken: authToken);
978976
Assert.AreEqual(actual.GetProperty("items")[0].GetProperty("earth").GetProperty("id").ToString(), _idList[0]);
979977
}
980978

@@ -1000,7 +998,7 @@ public async Task TestQueryFilterNestedFieldAuth_UnauthorizedNestedField()
1000998
}
1001999
}";
10021000

1003-
string clientRoleHeader = AuthorizationType.Anonymous.ToString();
1001+
string clientRoleHeader = "limited-read-role";
10041002
JsonElement response = await ExecuteGraphQLRequestAsync(
10051003
queryName: _graphQLQueryName,
10061004
query: gqlQuery,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,23 @@
293293
}
294294
]
295295
},
296+
{
297+
"role": "limited-read-role",
298+
"actions": [
299+
{
300+
"action": "read",
301+
"fields": {
302+
"exclude": [
303+
"name"
304+
],
305+
"include": [
306+
"id",
307+
"type"
308+
]
309+
}
310+
}
311+
]
312+
},
296313
{
297314
"role": "field-mutation-with-read-permission",
298315
"actions": [

0 commit comments

Comments
 (0)