mirror of
https://github.com/bitwarden/server.git
synced 2025-05-20 11:04:31 -05:00
Fix bug preventing user from leaving org (#1721)
This commit is contained in:
parent
9f96e4ce90
commit
2dc29e51d1
@ -385,9 +385,10 @@ namespace Bit.Api.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ssoConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(orgGuidId);
|
var ssoConfig = await _ssoConfigRepository.GetByOrganizationIdAsync(orgGuidId);
|
||||||
if (ssoConfig?.GetData()?.KeyConnectorEnabled == true)
|
if (ssoConfig?.GetData()?.KeyConnectorEnabled == true &&
|
||||||
|
_currentContext.User.UsesKeyConnector)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("You cannot leave an Organization that is using Key Connector.");
|
throw new BadRequestException("You cannot leave this Organization because you are using its Key Connector.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var userId = _userService.GetProperUserId(User);
|
var userId = _userService.GetProperUserId(User);
|
||||||
|
@ -54,8 +54,8 @@ namespace Bit.Api.Test.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, AutoData]
|
[Theory, AutoData]
|
||||||
public async Task OrganizationsController_WhenUserTriestoLeaveOrganizationUsingKeyConnector_Throws(
|
public async Task OrganizationsController_UserCannotLeaveOrganizationThatProvidesKeyConnector(
|
||||||
Guid orgId)
|
Guid orgId, User user)
|
||||||
{
|
{
|
||||||
var ssoConfig = new SsoConfig
|
var ssoConfig = new SsoConfig
|
||||||
{
|
{
|
||||||
@ -68,18 +68,50 @@ namespace Bit.Api.Test.Controllers
|
|||||||
OrganizationId = orgId,
|
OrganizationId = orgId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
user.UsesKeyConnector = true;
|
||||||
|
|
||||||
_currentContext.OrganizationUser(orgId).Returns(true);
|
_currentContext.OrganizationUser(orgId).Returns(true);
|
||||||
_ssoConfigRepository.GetByOrganizationIdAsync(orgId).Returns(ssoConfig);
|
_ssoConfigRepository.GetByOrganizationIdAsync(orgId).Returns(ssoConfig);
|
||||||
_userService.GetProperUserId(Arg.Any<ClaimsPrincipal>()).Returns(new Guid());
|
_userService.GetProperUserId(Arg.Any<ClaimsPrincipal>()).Returns(user.Id);
|
||||||
|
_currentContext.User.Returns(user);
|
||||||
|
|
||||||
var exception = await Assert.ThrowsAsync<BadRequestException>(
|
var exception = await Assert.ThrowsAsync<BadRequestException>(
|
||||||
() => _sut.Leave(orgId.ToString()));
|
() => _sut.Leave(orgId.ToString()));
|
||||||
|
|
||||||
Assert.Contains("You cannot leave an Organization that is using Key Connector.",
|
Assert.Contains("You cannot leave this Organization because you are using its Key Connector.",
|
||||||
exception.Message);
|
exception.Message);
|
||||||
|
|
||||||
await _organizationService.DidNotReceiveWithAnyArgs().DeleteUserAsync(default, default);
|
await _organizationService.DidNotReceiveWithAnyArgs().DeleteUserAsync(default, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineAutoData(true, false)]
|
||||||
|
[InlineAutoData(false, true)]
|
||||||
|
[InlineAutoData(false, false)]
|
||||||
|
public async Task OrganizationsController_UserCanLeaveOrganizationThatDoesntProvideKeyConnector(
|
||||||
|
bool keyConnectorEnabled, bool userUsesKeyConnector, Guid orgId, User user)
|
||||||
|
{
|
||||||
|
var ssoConfig = new SsoConfig
|
||||||
|
{
|
||||||
|
Id = default,
|
||||||
|
Data = new SsoConfigurationData
|
||||||
|
{
|
||||||
|
KeyConnectorEnabled = keyConnectorEnabled,
|
||||||
|
}.Serialize(),
|
||||||
|
Enabled = true,
|
||||||
|
OrganizationId = orgId,
|
||||||
|
};
|
||||||
|
|
||||||
|
user.UsesKeyConnector = userUsesKeyConnector;
|
||||||
|
|
||||||
|
_currentContext.OrganizationUser(orgId).Returns(true);
|
||||||
|
_ssoConfigRepository.GetByOrganizationIdAsync(orgId).Returns(ssoConfig);
|
||||||
|
_userService.GetProperUserId(Arg.Any<ClaimsPrincipal>()).Returns(user.Id);
|
||||||
|
_currentContext.User.Returns(user);
|
||||||
|
|
||||||
|
await _organizationService.DeleteUserAsync(orgId, user.Id);
|
||||||
|
await _organizationService.Received(1).DeleteUserAsync(orgId, user.Id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user