|
19 | 19 | using Bit.Core.Models.Business; |
20 | 20 | using Bit.Core.Models.Data; |
21 | 21 | using Bit.Core.Models.Data.Organizations.OrganizationUsers; |
| 22 | +using Bit.Core.Models.StaticStore; |
22 | 23 | using Bit.Core.OrganizationFeatures.OrganizationSubscriptions.Interface; |
23 | 24 | using Bit.Core.Repositories; |
24 | 25 | using Bit.Core.Services; |
| 26 | +using Bit.Core.Settings; |
25 | 27 | using Bit.Core.Test.Billing.Mocks.Plans; |
26 | 28 | using Bit.Test.Common.AutoFixture; |
27 | 29 | using Bit.Test.Common.AutoFixture.Attributes; |
@@ -1046,4 +1048,137 @@ await sutProvider.GetDependency<IMailService>() |
1046 | 1048 | Arg.Any<int>(), |
1047 | 1049 | Arg.Any<IEnumerable<string>>()); |
1048 | 1050 | } |
| 1051 | + |
| 1052 | + [Theory] |
| 1053 | + [BitAutoData] |
| 1054 | + public async Task InviteScimOrganizationUserAsync_WhenSelfHostedAndPlanIsNull_ThenInviteSucceeds( |
| 1055 | + MailAddress address, |
| 1056 | + Organization organization, |
| 1057 | + OrganizationUser orgUser, |
| 1058 | + FakeTimeProvider timeProvider, |
| 1059 | + string externalId, |
| 1060 | + SutProvider<InviteOrganizationUsersCommand> sutProvider) |
| 1061 | + { |
| 1062 | + // Arrange |
| 1063 | + orgUser.Email = address.Address; |
| 1064 | + |
| 1065 | + sutProvider.GetDependency<IPricingClient>() |
| 1066 | + .GetPlan(organization.PlanType) |
| 1067 | + .Returns((Plan?)null); |
| 1068 | + |
| 1069 | + sutProvider.GetDependency<IGlobalSettings>() |
| 1070 | + .SelfHosted.Returns(true); |
| 1071 | + |
| 1072 | + var inviteOrganization = new InviteOrganization(organization, null); |
| 1073 | + |
| 1074 | + var request = new InviteOrganizationUsersRequest( |
| 1075 | + invites: [ |
| 1076 | + new OrganizationUserInviteCommandModel( |
| 1077 | + email: orgUser.Email, |
| 1078 | + assignedCollections: [], |
| 1079 | + groups: [], |
| 1080 | + type: OrganizationUserType.User, |
| 1081 | + permissions: new Permissions(), |
| 1082 | + externalId: externalId, |
| 1083 | + accessSecretsManager: false) |
| 1084 | + ], |
| 1085 | + organization: organization, |
| 1086 | + performedBy: Guid.Empty, |
| 1087 | + performedAt: timeProvider.GetUtcNow()); |
| 1088 | + |
| 1089 | + var validationRequest = new InviteOrganizationUsersValidationRequest |
| 1090 | + { |
| 1091 | + Invites = request.Invites, |
| 1092 | + InviteOrganization = inviteOrganization, |
| 1093 | + PerformedBy = Guid.Empty, |
| 1094 | + PerformedAt = request.PerformedAt, |
| 1095 | + OccupiedPmSeats = 0, |
| 1096 | + OccupiedSmSeats = 0, |
| 1097 | + PasswordManagerSubscriptionUpdate = new PasswordManagerSubscriptionUpdate(inviteOrganization, 0, 0) |
| 1098 | + }; |
| 1099 | + |
| 1100 | + sutProvider.GetDependency<IOrganizationUserRepository>() |
| 1101 | + .SelectKnownEmailsAsync(organization.Id, Arg.Any<IEnumerable<string>>(), false) |
| 1102 | + .Returns([]); |
| 1103 | + |
| 1104 | + sutProvider.GetDependency<IOrganizationRepository>() |
| 1105 | + .GetByIdAsync(organization.Id) |
| 1106 | + .Returns(organization); |
| 1107 | + |
| 1108 | + sutProvider.GetDependency<IInviteUsersValidator>() |
| 1109 | + .ValidateAsync(Arg.Any<InviteOrganizationUsersValidationRequest>()) |
| 1110 | + .Returns(new Valid<InviteOrganizationUsersValidationRequest>(validationRequest)); |
| 1111 | + |
| 1112 | + sutProvider.GetDependency<IOrganizationRepository>() |
| 1113 | + .GetOccupiedSeatCountByOrganizationIdAsync(organization.Id) |
| 1114 | + .Returns(new OrganizationSeatCounts { Sponsored = 0, Users = 0 }); |
| 1115 | + |
| 1116 | + sutProvider.GetDependency<IOrganizationUserRepository>() |
| 1117 | + .GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id) |
| 1118 | + .Returns(0); |
| 1119 | + |
| 1120 | + // Act |
| 1121 | + var result = await sutProvider.Sut.InviteScimOrganizationUserAsync(request); |
| 1122 | + |
| 1123 | + // Assert |
| 1124 | + Assert.IsType<Success<ScimInviteOrganizationUsersResponse>>(result); |
| 1125 | + |
| 1126 | + await sutProvider.GetDependency<IOrganizationUserRepository>() |
| 1127 | + .Received(1) |
| 1128 | + .CreateManyAsync(Arg.Is<IEnumerable<CreateOrganizationUser>>(users => |
| 1129 | + users.Any(u => u.OrganizationUser.Email == orgUser.Email))); |
| 1130 | + } |
| 1131 | + |
| 1132 | + [Theory] |
| 1133 | + [BitAutoData] |
| 1134 | + public async Task InviteScimOrganizationUserAsync_WhenNotSelfHostedAndPlanIsNull_ThenFailureIsReturned( |
| 1135 | + MailAddress address, |
| 1136 | + Organization organization, |
| 1137 | + OrganizationUser orgUser, |
| 1138 | + FakeTimeProvider timeProvider, |
| 1139 | + string externalId, |
| 1140 | + SutProvider<InviteOrganizationUsersCommand> sutProvider) |
| 1141 | + { |
| 1142 | + // Arrange |
| 1143 | + orgUser.Email = address.Address; |
| 1144 | + |
| 1145 | + sutProvider.GetDependency<IPricingClient>() |
| 1146 | + .GetPlan(organization.PlanType) |
| 1147 | + .Returns((Plan?)null); |
| 1148 | + |
| 1149 | + sutProvider.GetDependency<IGlobalSettings>() |
| 1150 | + .SelfHosted.Returns(false); |
| 1151 | + |
| 1152 | + var request = new InviteOrganizationUsersRequest( |
| 1153 | + invites: [ |
| 1154 | + new OrganizationUserInviteCommandModel( |
| 1155 | + email: orgUser.Email, |
| 1156 | + assignedCollections: [], |
| 1157 | + groups: [], |
| 1158 | + type: OrganizationUserType.User, |
| 1159 | + permissions: new Permissions(), |
| 1160 | + externalId: externalId, |
| 1161 | + accessSecretsManager: false) |
| 1162 | + ], |
| 1163 | + organization: organization, |
| 1164 | + performedBy: Guid.Empty, |
| 1165 | + performedAt: timeProvider.GetUtcNow()); |
| 1166 | + |
| 1167 | + // Act |
| 1168 | + var result = await sutProvider.Sut.InviteScimOrganizationUserAsync(request); |
| 1169 | + |
| 1170 | + // Assert |
| 1171 | + Assert.IsType<Failure<ScimInviteOrganizationUsersResponse>>(result); |
| 1172 | + Assert.Equal( |
| 1173 | + "Organization plan could not be found.", |
| 1174 | + (result as Failure<ScimInviteOrganizationUsersResponse>)!.Error.Message); |
| 1175 | + |
| 1176 | + await sutProvider.GetDependency<IOrganizationUserRepository>() |
| 1177 | + .DidNotReceive() |
| 1178 | + .CreateManyAsync(Arg.Any<IEnumerable<CreateOrganizationUser>>()); |
| 1179 | + |
| 1180 | + await sutProvider.GetDependency<ISendOrganizationInvitesCommand>() |
| 1181 | + .DidNotReceive() |
| 1182 | + .SendInvitesAsync(Arg.Any<SendInvitesRequest>()); |
| 1183 | + } |
1049 | 1184 | } |
0 commit comments