Skip to content

Commit dd1b3bc

Browse files
Added unit test for actionable email viewer group access through email group rather than just direct email recipient
1 parent c83c6ae commit dd1b3bc

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

Service/GroupMembershipManagement/Hosts/WebApi/WebApi.Tests/NotificationsControllerTests.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@ public async Task GetNotificationCard_HandleNotFoundTestAsync()
367367
}
368368

369369
/// <summary>
370-
/// /notifications/{id}/card - Get card for a notification that no longer exists
370+
/// /notifications/{id}/card - Get unauthorized card for a notification with a user who is not an owner nor in the actionable message viewer group
371371
/// </summary>
372372
[TestMethod]
373-
public async Task GetNotificationCard_HandleUserNotGroupOwnerTestAsync()
373+
public async Task GetNotificationCard_HandleUserNotGroupOwnerOrInViewerGroupTestAsync()
374374
{
375375
var claims = new List<Claim>
376376
{
@@ -388,6 +388,35 @@ public async Task GetNotificationCard_HandleUserNotGroupOwnerTestAsync()
388388
ValidateUnauthorizedCard(result.Content);
389389
}
390390

391+
/// <summary>
392+
/// /notifications/{id}/card - Get valid card for a notification with a user who is not an owner but is in the actionable message viewer group
393+
/// </summary>
394+
[TestMethod]
395+
public async Task GetNotificationCard_HandleUserNotGroupOwnerButInViewerGroupTestAsync()
396+
{
397+
var userObjectId = Guid.NewGuid().ToString();
398+
399+
_graphGroupRepository.Setup(x => x.IsEmailRecipientOwnerOfGroupAsync(
400+
It.Is<string>(s => s == userObjectId), It.IsAny<Guid>()))
401+
.ReturnsAsync(true);
402+
403+
var claims = new List<Claim>
404+
{
405+
new Claim(ClaimTypes.Upn, userObjectId),
406+
};
407+
408+
_tokenValidationResult.ActionPerformer = userObjectId;
409+
_notificationsController.ControllerContext = CreateControllerContext(claims, "mockBearerToken");
410+
411+
var response = await _notificationsController.GetCardAsync(_thresholdNotification.Id);
412+
var result = response.Result as ContentResult;
413+
414+
Assert.IsNotNull(response);
415+
Assert.IsNotNull(result?.Content);
416+
Assert.AreEqual("application/json", result.ContentType);
417+
ValidateUnresolvedCard(result.Content);
418+
}
419+
391420
/// <summary>
392421
/// /notifications/{id}/card - Get card for a resolved notification
393422
/// </summary>

0 commit comments

Comments
 (0)