Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Bit.Core.Entities;
using Bit.Core.Enums;
using Bit.Core.Repositories;

using Bit.Core.Utilities;
namespace Bit.Infrastructure.IntegrationTest.AdminConsole;

/// <summary>
Expand All @@ -16,7 +16,7 @@ public static class OrganizationTestHelpers
{
public static Task<User> CreateTestUserAsync(this IUserRepository userRepository, string identifier = "test")
{
var id = Guid.NewGuid();
var id = CoreHelpers.GenerateComb();
return userRepository.CreateAsync(new User
{
Id = id,
Expand All @@ -34,7 +34,7 @@ public static Task<Organization> CreateTestOrganizationAsync(this IOrganizationR
int? seatCount = null,
string identifier = "test")
{
var id = Guid.NewGuid();
var id = CoreHelpers.GenerateComb();
return organizationRepository.CreateAsync(new Organization
{
Name = $"{identifier}-{id}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,6 @@ await collectionRepository.CreateAsync(collection,
Assert.Equal(2, users.Length);
Assert.Single(users, u => u.Id == orgUser1.Id && u.Manage && !u.HidePasswords && u.ReadOnly);
Assert.Single(users, u => u.Id == orgUser2.Id && !u.Manage && u.HidePasswords && !u.ReadOnly);

// Clean up data
await userRepository.DeleteAsync(user1);
await userRepository.DeleteAsync(user2);
await organizationRepository.DeleteAsync(organization);
await groupRepository.DeleteManyAsync([group1.Id, group2.Id]);
await organizationUserRepository.DeleteManyAsync([orgUser1.Id, orgUser2.Id]);
}

/// <remarks>
Expand Down Expand Up @@ -98,8 +91,5 @@ public async Task CreateAsync_WithNoAccess_Works(

Assert.Empty(actualAccess.Groups);
Assert.Empty(actualAccess.Users);

// Clean up
await organizationRepository.DeleteAsync(organization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ await collectionRepository.ReplaceAsync(collection,
Assert.Equal(2, users.Length);
Assert.Single(users, u => u.Id == orgUser2.Id && !u.Manage && !u.HidePasswords && u.ReadOnly);
Assert.Single(users, u => u.Id == orgUser3.Id && u.Manage && !u.HidePasswords && u.ReadOnly);

// Clean up data
await userRepository.DeleteAsync(user1);
await userRepository.DeleteAsync(user2);
await userRepository.DeleteAsync(user3);
await organizationRepository.DeleteAsync(organization);
}

/// <remarks>
Expand Down Expand Up @@ -141,10 +135,6 @@ await collectionRepository.CreateAsync(collection,

Assert.Empty(actualAccess.Groups);
Assert.Empty(actualAccess.Users);

// Clean up
await userRepository.DeleteAsync(user);
await organizationRepository.DeleteAsync(organization);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -205,10 +195,5 @@ await collectionRepository.CreateAsync(collection,
Assert.Equal(2, users.Length);
Assert.Single(users, u => u.Id == orgUser1.Id && u.Manage && !u.HidePasswords && u.ReadOnly);
Assert.Single(users, u => u.Id == orgUser2.Id && !u.Manage && u.HidePasswords && !u.ReadOnly);

// Clean up data
await userRepository.DeleteAsync(user1);
await userRepository.DeleteAsync(user2);
await organizationRepository.DeleteAsync(organization);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public static async Task CreatesDefaultCollections_Success(

// Assert
await AssertAllUsersHaveOneDefaultCollectionAsync(collectionRepository, resultOrganizationUsers, organization.Id);

await CleanupAsync(organizationRepository, userRepository, organization, resultOrganizationUsers);
}

public static async Task CreatesForNewUsersOnly_AndIgnoresExistingUsers(
Expand Down Expand Up @@ -72,8 +70,6 @@ await CreateUserForOrgAsync(userRepository, organizationUserRepository, organiza

// Assert
await AssertAllUsersHaveOneDefaultCollectionAsync(collectionRepository, affectedOrgUsers, organization.Id);

await CleanupAsync(organizationRepository, userRepository, organization, affectedOrgUsers);
}

public static async Task IgnoresAllExistingUsers(
Expand Down Expand Up @@ -101,8 +97,6 @@ public static async Task IgnoresAllExistingUsers(

// Assert - Original collections should remain unchanged, still only one per user
await AssertAllUsersHaveOneDefaultCollectionAsync(collectionRepository, resultOrganizationUsers, organization.Id);

await CleanupAsync(organizationRepository, userRepository, organization, resultOrganizationUsers);
}

private static async Task CreateUsersWithExistingDefaultCollectionsAsync(
Expand Down Expand Up @@ -141,18 +135,4 @@ private static async Task<OrganizationUser> CreateUserForOrgAsync(IUserRepositor

return orgUser;
}

private static async Task CleanupAsync(IOrganizationRepository organizationRepository,
IUserRepository userRepository,
Organization organization,
IEnumerable<OrganizationUser> organizationUsers)
{
await organizationRepository.DeleteAsync(organization);

await userRepository.DeleteManyAsync(
organizationUsers
.Where(organizationUser => organizationUser.UserId != null)
.Select(organizationUser => new User() { Id = organizationUser.UserId.Value })
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
Assert.Equal(2, result.Count);
Assert.Contains(result, org => org.Id == organization1.Id);
Assert.Contains(result, org => org.Id == organization2.Id);

// Clean up
await organizationRepository.DeleteAsync(organization1);
await organizationRepository.DeleteAsync(organization2);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -211,10 +207,7 @@
Assert.NotNull(updateResult);
Assert.Equal(organization.Id, updateResult.Id);
Assert.True(updateResult.SyncSeats);
Assert.Equal(requestDate.ToString("yyyy-MM-dd HH:mm:ss"), updateResult.RevisionDate.ToString("yyyy-MM-dd HH:mm:ss"));

Check warning on line 210 in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The behavior of 'DateTime.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'OrganizationRepositoryTests.IncrementSeatCountAsync_GivenOrganizationHasNotChangedSeatCountBefore_WhenUpdatingOrgSeats_ThenSubscriptionUpdateIsSaved(IOrganizationRepository)' with a call to 'DateTime.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 210 in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The behavior of 'DateTime.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'OrganizationRepositoryTests.IncrementSeatCountAsync_GivenOrganizationHasNotChangedSeatCountBefore_WhenUpdatingOrgSeats_ThenSubscriptionUpdateIsSaved(IOrganizationRepository)' with a call to 'DateTime.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

// Annul
await sutRepository.DeleteAsync(organization);
}

[DatabaseData, Theory]
Expand All @@ -236,10 +229,7 @@
Assert.NotNull(updateResult);
Assert.Equal(organization.Id, updateResult.Id);
Assert.True(updateResult.SyncSeats);
Assert.Equal(requestDate.ToString("yyyy-MM-dd HH:mm:ss"), updateResult.RevisionDate.ToString("yyyy-MM-dd HH:mm:ss"));

Check warning on line 232 in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The behavior of 'DateTime.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'OrganizationRepositoryTests.IncrementSeatCountAsync_GivenOrganizationHasChangedSeatCountBeforeAndRecordExists_WhenUpdatingOrgSeats_ThenSubscriptionUpdateIsSaved(IOrganizationRepository)' with a call to 'DateTime.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 232 in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The behavior of 'DateTime.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'OrganizationRepositoryTests.IncrementSeatCountAsync_GivenOrganizationHasChangedSeatCountBeforeAndRecordExists_WhenUpdatingOrgSeats_ThenSubscriptionUpdateIsSaved(IOrganizationRepository)' with a call to 'DateTime.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

// Annul
await sutRepository.DeleteAsync(organization);
}

[DatabaseData, Theory]
Expand All @@ -259,10 +249,7 @@
Assert.NotNull(updateResult);
Assert.Equal(organization.Id, updateResult.Id);
Assert.True(updateResult.SyncSeats);
Assert.Equal(requestDate.ToString("yyyy-MM-dd HH:mm:ss"), updateResult.RevisionDate.ToString("yyyy-MM-dd HH:mm:ss"));

Check warning on line 252 in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The behavior of 'DateTime.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'OrganizationRepositoryTests.GetOrganizationsForSubscriptionSyncAsync_GivenOrganizationHasChangedSeatCount_WhenGettingOrgsToUpdate_ThenReturnsOrgSubscriptionUpdate(IOrganizationRepository)' with a call to 'DateTime.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

Check warning on line 252 in test/Infrastructure.IntegrationTest/AdminConsole/Repositories/OrganizationRepositoryTests.cs

View workflow job for this annotation

GitHub Actions / Run tests

The behavior of 'DateTime.ToString(string)' could vary based on the current user's locale settings. Replace this call in 'OrganizationRepositoryTests.GetOrganizationsForSubscriptionSyncAsync_GivenOrganizationHasChangedSeatCount_WhenGettingOrgsToUpdate_ThenReturnsOrgSubscriptionUpdate(IOrganizationRepository)' with a call to 'DateTime.ToString(string, IFormatProvider)'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1305)

// Annul
await sutRepository.DeleteAsync(organization);
}

[DatabaseData, Theory]
Expand All @@ -281,9 +268,6 @@
// Assert
var result = (await sutRepository.GetOrganizationsForSubscriptionSyncAsync()).ToArray();
Assert.Null(result.FirstOrDefault(x => x.Id == organization.Id));

// Annul
await sutRepository.DeleteAsync(organization);
}

[DatabaseTheory, DatabaseData]
Expand Down Expand Up @@ -400,9 +384,6 @@
Assert.Equal(organization.UseDisableSmAdsForUsers, result.UseDisableSmAdsForUsers);
Assert.Equal(organization.UsePhishingBlocker, result.UsePhishingBlocker);
Assert.Equal(organization.UseMyItems, result.UseMyItems);

// Clean up
await organizationRepository.DeleteAsync(organization);
}

[Theory, DatabaseData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public async Task ReturnsDetails_WhenUserIsConfirmed(
Assert.Equal(organization.Id, result.OrganizationId);
Assert.Equal(user.Id, result.UserId);
Assert.Equal(OrganizationUserStatusType.Confirmed, result.Status);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -52,10 +48,6 @@ public async Task ReturnsDetails_WhenUserIsAccepted(
Assert.Equal(organization.Id, result.OrganizationId);
Assert.Equal(user.Id, result.UserId);
Assert.Equal(OrganizationUserStatusType.Accepted, result.Status);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -80,11 +72,6 @@ public async Task ReturnsDetailsAcrossMultipleOrganizations_WhenUserIsConfirmedO
Assert.Equal(2, results.Count);
Assert.Contains(results, r => r.OrganizationId == confirmedOrg.Id && r.Status == OrganizationUserStatusType.Confirmed);
Assert.Contains(results, r => r.OrganizationId == acceptedOrg.Id && r.Status == OrganizationUserStatusType.Accepted);

// Annul
await organizationRepository.DeleteAsync(confirmedOrg);
await organizationRepository.DeleteAsync(acceptedOrg);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -103,10 +90,6 @@ public async Task DoesNotReturnDetails_WhenUserIsInvited(

// Assert
Assert.DoesNotContain(results, r => r.OrganizationId == organization.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -125,10 +108,6 @@ public async Task DoesNotReturnDetails_WhenUserIsRevoked(

// Assert
Assert.DoesNotContain(results, r => r.OrganizationId == organization.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -149,9 +128,5 @@ public async Task DoesNotReturnDetails_ForOtherUsers(

// Assert
Assert.DoesNotContain(results, r => r.OrganizationId == organization.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteManyAsync([targetUser, otherUser]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1393,10 +1393,6 @@ public async Task ConfirmOrganizationUserAsync_WhenUserIsAccepted_ReturnsTrue(IO
Assert.NotNull(updatedUser);
Assert.Equal(OrganizationUserStatusType.Confirmed, updatedUser.Status);
Assert.Equal(key, updatedUser.Key);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -1426,10 +1422,6 @@ public async Task ConfirmOrganizationUserAsync_WhenUserIsAlreadyConfirmed_Return
var unchangedUser = await organizationUserRepository.GetByIdAsync(orgUser.Id);
Assert.NotNull(unchangedUser);
Assert.Equal(OrganizationUserStatusType.Confirmed, unchangedUser.Status);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -1460,10 +1452,6 @@ public async Task ConfirmOrganizationUserAsync_IsIdempotent_WhenCalledMultipleTi
var finalUser = await organizationUserRepository.GetByIdAsync(orgUser.Id);
Assert.NotNull(finalUser);
Assert.Equal(OrganizationUserStatusType.Confirmed, finalUser.Status);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ public async Task ReturnsPolicies_WhenUserIsConfirmed(

// Assert
Assert.Contains(results, p => p.Id == policy.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -62,10 +58,6 @@ public async Task ReturnsPolicies_WhenUserIsAccepted(

// Assert
Assert.Contains(results, p => p.Id == policy.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -102,11 +94,6 @@ public async Task ReturnsPoliciesAcrossMultipleOrganizations_WhenUserIsConfirmed
// Assert
Assert.Contains(results, p => p.Id == confirmedPolicy.Id);
Assert.Contains(results, p => p.Id == acceptedPolicy.Id);

// Annul
await organizationRepository.DeleteAsync(confirmedOrg);
await organizationRepository.DeleteAsync(acceptedOrg);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -139,10 +126,6 @@ await organizationUserRepository.CreateAsync(new OrganizationUser

// Assert
Assert.DoesNotContain(results, p => p.Id == policy.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand All @@ -168,10 +151,6 @@ public async Task DoesNotReturnPolicies_WhenUserIsRevoked(

// Assert
Assert.DoesNotContain(results, p => p.Id == policy.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteAsync(user);
}

[Theory, DatabaseData]
Expand Down Expand Up @@ -199,9 +178,5 @@ public async Task DoesNotReturnPolicies_ForOtherUsers(

// Assert
Assert.DoesNotContain(results, p => p.Id == policy.Id);

// Annul
await organizationRepository.DeleteAsync(organization);
await userRepository.DeleteManyAsync([targetUser, otherUser]);
}
}
Loading
Loading