mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
[AC-1139] Changed GroupAuthorizationHandler and OrganizationUserAuthorizationHandler to fail if no OrganizationId is passed as a parameter
This commit is contained in:
@ -45,6 +45,7 @@ public class GroupAuthorizationHandler : AuthorizationHandler<GroupOperationRequ
|
|||||||
|
|
||||||
if (requirement.OrganizationId == default)
|
if (requirement.OrganizationId == default)
|
||||||
{
|
{
|
||||||
|
context.Fail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ public class OrganizationUserAuthorizationHandler : AuthorizationHandler<Organiz
|
|||||||
|
|
||||||
if (requirement.OrganizationId == default)
|
if (requirement.OrganizationId == default)
|
||||||
{
|
{
|
||||||
|
context.Fail();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ public class GroupAuthorizationHandlerTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(OrganizationUserType.User)]
|
[BitAutoData(OrganizationUserType.User)]
|
||||||
[BitAutoData(OrganizationUserType.Custom)]
|
[BitAutoData(OrganizationUserType.Custom)]
|
||||||
public async Task CanReadAllAsync_WhenMissingAccess_Failure(
|
public async Task CanReadAllAsync_WhenMissingPermissions_NoSuccess(
|
||||||
OrganizationUserType userType,
|
OrganizationUserType userType,
|
||||||
SutProvider<GroupAuthorizationHandler> sutProvider,
|
SutProvider<GroupAuthorizationHandler> sutProvider,
|
||||||
CurrentContextOrganization organization)
|
CurrentContextOrganization organization)
|
||||||
@ -140,25 +140,7 @@ public class GroupAuthorizationHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleRequirementAsync_MissingUserId_Failure(
|
public async Task CanReadAllAsync_WhenMissingOrgAccess_NoSuccess(
|
||||||
Guid organizationId,
|
|
||||||
SutProvider<GroupAuthorizationHandler> sutProvider)
|
|
||||||
{
|
|
||||||
var context = new AuthorizationHandlerContext(
|
|
||||||
new[] { GroupOperations.ReadAll(organizationId) },
|
|
||||||
new ClaimsPrincipal(),
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
// Simulate missing user id
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns((Guid?)null);
|
|
||||||
|
|
||||||
await sutProvider.Sut.HandleAsync(context);
|
|
||||||
Assert.False(context.HasSucceeded);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
|
||||||
public async Task HandleRequirementAsync_MissingOrg_Failure(
|
|
||||||
Guid userId,
|
Guid userId,
|
||||||
Guid organizationId,
|
Guid organizationId,
|
||||||
SutProvider<GroupAuthorizationHandler> sutProvider)
|
SutProvider<GroupAuthorizationHandler> sutProvider)
|
||||||
@ -177,7 +159,26 @@ public class GroupAuthorizationHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleRequirementAsync_NoSpecifiedOrgId_NoSuccessOrFailure(
|
public async Task HandleRequirementAsync_MissingUserId_Failure(
|
||||||
|
Guid organizationId,
|
||||||
|
SutProvider<GroupAuthorizationHandler> sutProvider)
|
||||||
|
{
|
||||||
|
var context = new AuthorizationHandlerContext(
|
||||||
|
new[] { GroupOperations.ReadAll(organizationId) },
|
||||||
|
new ClaimsPrincipal(),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
// Simulate missing user id
|
||||||
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns((Guid?)null);
|
||||||
|
|
||||||
|
await sutProvider.Sut.HandleAsync(context);
|
||||||
|
Assert.False(context.HasSucceeded);
|
||||||
|
Assert.True(context.HasFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task HandleRequirementAsync_NoSpecifiedOrgId_Failure(
|
||||||
SutProvider<GroupAuthorizationHandler> sutProvider)
|
SutProvider<GroupAuthorizationHandler> sutProvider)
|
||||||
{
|
{
|
||||||
var context = new AuthorizationHandlerContext(
|
var context = new AuthorizationHandlerContext(
|
||||||
@ -191,6 +192,6 @@ public class GroupAuthorizationHandlerTests
|
|||||||
await sutProvider.Sut.HandleAsync(context);
|
await sutProvider.Sut.HandleAsync(context);
|
||||||
|
|
||||||
Assert.False(context.HasSucceeded);
|
Assert.False(context.HasSucceeded);
|
||||||
Assert.False(context.HasFailed);
|
Assert.True(context.HasFailed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class OrganizationUserAuthorizationHandlerTests
|
|||||||
[Theory]
|
[Theory]
|
||||||
[BitAutoData(OrganizationUserType.User)]
|
[BitAutoData(OrganizationUserType.User)]
|
||||||
[BitAutoData(OrganizationUserType.Custom)]
|
[BitAutoData(OrganizationUserType.Custom)]
|
||||||
public async Task CanReadAllAsync_WhenMissingAccess_Failure(
|
public async Task CanReadAllAsync_WhenMissingPermissions_NoSuccess(
|
||||||
OrganizationUserType userType,
|
OrganizationUserType userType,
|
||||||
SutProvider<OrganizationUserAuthorizationHandler> sutProvider,
|
SutProvider<OrganizationUserAuthorizationHandler> sutProvider,
|
||||||
CurrentContextOrganization organization)
|
CurrentContextOrganization organization)
|
||||||
@ -139,25 +139,7 @@ public class OrganizationUserAuthorizationHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleRequirementAsync_MissingUserId_Failure(
|
public async Task HandleRequirementAsync_WhenMissingOrgAccess_NoSuccess(
|
||||||
Guid organizationId,
|
|
||||||
SutProvider<OrganizationUserAuthorizationHandler> sutProvider)
|
|
||||||
{
|
|
||||||
var context = new AuthorizationHandlerContext(
|
|
||||||
new[] { OrganizationUserOperations.ReadAll(organizationId) },
|
|
||||||
new ClaimsPrincipal(),
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
// Simulate missing user id
|
|
||||||
sutProvider.GetDependency<ICurrentContext>().UserId.Returns((Guid?)null);
|
|
||||||
|
|
||||||
await sutProvider.Sut.HandleAsync(context);
|
|
||||||
Assert.False(context.HasSucceeded);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
|
||||||
public async Task HandleRequirementAsync_MissingOrg_Failure(
|
|
||||||
Guid userId,
|
Guid userId,
|
||||||
Guid organizationId,
|
Guid organizationId,
|
||||||
SutProvider<OrganizationUserAuthorizationHandler> sutProvider)
|
SutProvider<OrganizationUserAuthorizationHandler> sutProvider)
|
||||||
@ -176,7 +158,25 @@ public class OrganizationUserAuthorizationHandlerTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Theory, BitAutoData]
|
[Theory, BitAutoData]
|
||||||
public async Task HandleRequirementAsync_NoSpecifiedOrgId_NoSuccessOrFailure(
|
public async Task HandleRequirementAsync_MissingUserId_Failure(
|
||||||
|
Guid organizationId,
|
||||||
|
SutProvider<OrganizationUserAuthorizationHandler> sutProvider)
|
||||||
|
{
|
||||||
|
var context = new AuthorizationHandlerContext(
|
||||||
|
new[] { OrganizationUserOperations.ReadAll(organizationId) },
|
||||||
|
new ClaimsPrincipal(),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
// Simulate missing user id
|
||||||
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns((Guid?)null);
|
||||||
|
|
||||||
|
await sutProvider.Sut.HandleAsync(context);
|
||||||
|
Assert.True(context.HasFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory, BitAutoData]
|
||||||
|
public async Task HandleRequirementAsync_NoSpecifiedOrgId_Failure(
|
||||||
SutProvider<OrganizationUserAuthorizationHandler> sutProvider)
|
SutProvider<OrganizationUserAuthorizationHandler> sutProvider)
|
||||||
{
|
{
|
||||||
var context = new AuthorizationHandlerContext(
|
var context = new AuthorizationHandlerContext(
|
||||||
@ -189,7 +189,6 @@ public class OrganizationUserAuthorizationHandlerTests
|
|||||||
|
|
||||||
await sutProvider.Sut.HandleAsync(context);
|
await sutProvider.Sut.HandleAsync(context);
|
||||||
|
|
||||||
Assert.False(context.HasSucceeded);
|
Assert.True(context.HasFailed);
|
||||||
Assert.False(context.HasFailed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user