permission-backend: extract AllowAllPermissionPolicy from standaloneServer in permission-backend

Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
This commit is contained in:
Mike Lewis
2021-11-22 11:22:24 +00:00
parent 806778d58e
commit be1f89d383
3 changed files with 71 additions and 4 deletions
@@ -0,0 +1,35 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
AuthorizeResult,
Permission,
} from '@backstage/plugin-permission-common';
import { AllowAllPermissionPolicy } from './AllowAllPermissionPolicy';
describe('AllowAllPermissionPolicy', () => {
const policy = new AllowAllPermissionPolicy();
it('returns ALLOW when no identity is passed', async () => {
await expect(
policy.handle({
permission: {
name: 'any.permission',
} as Permission,
}),
).resolves.toEqual({ result: AuthorizeResult.ALLOW });
});
});
@@ -0,0 +1,34 @@
/*
* Copyright 2021 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { BackstageIdentity } from '@backstage/plugin-auth-backend';
import { AuthorizeResult } from '@backstage/plugin-permission-common';
import {
PermissionPolicy,
PolicyAuthorizeRequest,
PolicyResult,
} from '@backstage/plugin-permission-node';
export class AllowAllPermissionPolicy implements PermissionPolicy {
async handle(
_request: PolicyAuthorizeRequest,
_user?: BackstageIdentity,
): Promise<PolicyResult> {
return {
result: AuthorizeResult.ALLOW,
};
}
}
@@ -20,8 +20,8 @@ import {
} from '@backstage/backend-common';
import { Server } from 'http';
import { Logger } from 'winston';
import { AllowAllPermissionPolicy } from './AllowAllPermissionPolicy';
import { createRouter } from './router';
import { AuthorizeResult } from '@backstage/plugin-permission-common';
export interface ServerOptions {
port: number;
@@ -38,9 +38,7 @@ export async function startStandaloneServer(
const router = await createRouter({
logger,
config,
policy: {
handle: () => Promise.resolve({ result: AuthorizeResult.ALLOW }),
},
policy: new AllowAllPermissionPolicy(),
});
let service = createServiceBuilder(module)