diff --git a/packages/backend-test-utils/package.json b/packages/backend-test-utils/package.json index 725be0d905..385d79fca3 100644 --- a/packages/backend-test-utils/package.json +++ b/packages/backend-test-utils/package.json @@ -39,10 +39,10 @@ "@backstage/backend-plugin-api": "workspace:^", "@backstage/cli": "workspace:^", "@backstage/config": "workspace:^", + "@backstage/plugin-auth-node": "workspace:^", "@backstage/types": "workspace:^", "better-sqlite3": "^8.0.0", "express": "^4.17.1", - "express-promise-router": "^4.1.0", "knex": "^2.0.0", "msw": "^0.49.0", "mysql2": "^2.2.5", diff --git a/packages/backend-test-utils/src/next/implementations/mockIdentityService.ts b/packages/backend-test-utils/src/next/implementations/mockIdentityService.ts new file mode 100644 index 0000000000..30a464d877 --- /dev/null +++ b/packages/backend-test-utils/src/next/implementations/mockIdentityService.ts @@ -0,0 +1,50 @@ +/* + * Copyright 2023 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 { + coreServices, + createServiceFactory, + IdentityService, +} from '@backstage/backend-plugin-api'; +import { + IdentityApiGetIdentityRequest, + BackstageIdentityResponse, +} from '@backstage/plugin-auth-node'; + +class MockIdentityServiceImpl implements IdentityService { + getIdentity( + _options: IdentityApiGetIdentityRequest, + ): Promise { + return Promise.resolve({ + token: 'mock-token', + identity: { + type: 'user', + userEntityRef: 'user:default/mock-user', + ownershipEntityRefs: [], + }, + }); + } +} + +export const mockIdentityFactory = createServiceFactory({ + service: coreServices.identity, + deps: {}, + async factory() { + const service = new MockIdentityServiceImpl(); + return async () => { + return service; + }; + }, +}); diff --git a/packages/backend-test-utils/src/next/wiring/TestBackend.ts b/packages/backend-test-utils/src/next/wiring/TestBackend.ts index 31bb7f025d..78c2f78e5e 100644 --- a/packages/backend-test-utils/src/next/wiring/TestBackend.ts +++ b/packages/backend-test-utils/src/next/wiring/TestBackend.ts @@ -46,6 +46,7 @@ import { mockRootLoggerService } from '../implementations/mockRootLoggerService' import { mockTokenManagerFactory } from '../implementations/mockTokenManagerService'; import { ConfigReader } from '@backstage/config'; import express from 'express'; +import { mockIdentityFactory } from '../implementations/mockIdentityService'; /** @alpha */ export interface TestBackendOptions< @@ -90,6 +91,7 @@ const defaultServiceFactories = [ loggerFactory(), mockConfigFactory(), mockRootLoggerService(), + mockIdentityFactory(), mockTokenManagerFactory(), permissionsFactory(), rootLifecycleFactory(), diff --git a/yarn.lock b/yarn.lock index d6822cad9d..e8f1a31b99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3567,11 +3567,11 @@ __metadata: "@backstage/backend-plugin-api": "workspace:^" "@backstage/cli": "workspace:^" "@backstage/config": "workspace:^" + "@backstage/plugin-auth-node": "workspace:^" "@backstage/types": "workspace:^" "@types/supertest": ^2.0.8 better-sqlite3: ^8.0.0 express: ^4.17.1 - express-promise-router: ^4.1.0 knex: ^2.0.0 msw: ^0.49.0 mysql2: ^2.2.5