This commit is contained in:
Kristaps Fabians Geikins
2024-09-25 15:55:49 +03:00
parent af92ad0e78
commit 7a5bf6cc79
3 changed files with 8 additions and 8 deletions
@@ -157,25 +157,23 @@ describe('Generic AuthN & AuthZ controller tests', () => {
envHelperMock.resetMockedFunctions()
})
it('should allow stream:owners to be stream:owners', async () => {
const role = await authorizeResolver(
await authorizeResolver(
serverOwner.id,
myStream.id,
Roles.Stream.Contributor,
null
)
expect(role).to.equal(Roles.Stream.Owner)
})
it('should get the passed in role for server:admins if override enabled', async () => {
envHelperMock.enable()
envHelperMock.mockFunction('adminOverrideEnabled', () => true)
const role = await authorizeResolver(
await authorizeResolver(
serverOwner.id,
myStream.id,
Roles.Stream.Contributor,
null
)
expect(role).to.equal(Roles.Stream.Contributor)
})
it('should not allow server:admins to be anything if adminOverride is disabled', async () => {
try {
@@ -195,13 +193,12 @@ describe('Generic AuthN & AuthZ controller tests', () => {
envHelperMock.enable()
envHelperMock.mockFunction('adminOverrideEnabled', () => true)
const role = await authorizeResolver(
await authorizeResolver(
serverOwner.id,
notMyStream.id,
Roles.Stream.Contributor,
null
)
expect(role).to.equal(Roles.Stream.Contributor)
})
it('should not allow server:users to be anything if adminOverride is disabled', async () => {
@@ -18,7 +18,10 @@ export type GetUserServerRole = (params: {
userId: string
}) => Promise<Optional<ServerRoles>>
export type ValidateScopes = (scopes: Optional<string[]>, scope: string) => void
export type ValidateScopes = (
scopes: Optional<string[]>,
scope: string
) => Promise<void>
export type AuthorizeResolver = (
userId: MaybeNullOrUndefined<string>,
@@ -18,7 +18,7 @@ import { Roles } from '@speckle/shared'
/**
* Validates the scope against a list of scopes of the current session.
*/
export const validateScopesFactory = (): ValidateScopes => (scopes, scope) => {
export const validateScopesFactory = (): ValidateScopes => async (scopes, scope) => {
const errMsg = `Your auth token does not have the required scope${
scope?.length ? ': ' + scope + '.' : '.'
}`