@backstage/backend-test-utils 0.3.3 → 0.3.4-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -15
- package/dist/index.cjs.js +526 -56
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +171 -2
- package/package.json +36 -35
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="jest" />
|
|
3
3
|
import { Knex } from 'knex';
|
|
4
4
|
import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
|
|
5
|
-
import { ServiceFactory, ServiceRef, ExtensionPoint, BackendFeature, RootConfigService, LoggerService, TokenManagerService, IdentityService } from '@backstage/backend-plugin-api';
|
|
5
|
+
import { ServiceFactory, ServiceRef, ExtensionPoint, BackendFeature, RootConfigService, LoggerService, TokenManagerService, IdentityService, AuthService, DiscoveryService, BackstageCredentials, HttpAuthService, BackstageUserInfo, UserInfoService, BackstageNonePrincipal, BackstageUserPrincipal, BackstageServicePrincipal } from '@backstage/backend-plugin-api';
|
|
6
6
|
import * as _backstage_backend_app_api from '@backstage/backend-app-api';
|
|
7
7
|
import { Backend, ExtendedHttpServer } from '@backstage/backend-app-api';
|
|
8
8
|
import { JsonObject } from '@backstage/types';
|
|
@@ -374,6 +374,68 @@ declare namespace mockServices {
|
|
|
374
374
|
const factory: () => ServiceFactory<IdentityService, "plugin">;
|
|
375
375
|
const mock: (partialImpl?: Partial<IdentityService> | undefined) => ServiceMock<IdentityService>;
|
|
376
376
|
}
|
|
377
|
+
function auth(options?: {
|
|
378
|
+
pluginId?: string;
|
|
379
|
+
disableDefaultAuthPolicy?: boolean;
|
|
380
|
+
}): AuthService;
|
|
381
|
+
namespace auth {
|
|
382
|
+
const factory: () => ServiceFactory<AuthService, "plugin">;
|
|
383
|
+
const mock: (partialImpl?: Partial<AuthService> | undefined) => ServiceMock<AuthService>;
|
|
384
|
+
}
|
|
385
|
+
function discovery(): DiscoveryService;
|
|
386
|
+
namespace discovery {
|
|
387
|
+
const factory: () => ServiceFactory<DiscoveryService, "plugin">;
|
|
388
|
+
const mock: (partialImpl?: Partial<DiscoveryService> | undefined) => ServiceMock<DiscoveryService>;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Creates a mock implementation of the `HttpAuthService`.
|
|
392
|
+
*
|
|
393
|
+
* By default all requests without credentials are treated as requests from
|
|
394
|
+
* the default mock user principal. This behavior can be configured with the
|
|
395
|
+
* `defaultCredentials` option.
|
|
396
|
+
*/
|
|
397
|
+
function httpAuth(options?: {
|
|
398
|
+
pluginId?: string;
|
|
399
|
+
/**
|
|
400
|
+
* The default credentials to use if there are no credentials present in the
|
|
401
|
+
* incoming request.
|
|
402
|
+
*
|
|
403
|
+
* By default all requests without credentials are treated as authenticated
|
|
404
|
+
* as the default mock user as returned from `mockCredentials.user()`.
|
|
405
|
+
*/
|
|
406
|
+
defaultCredentials?: BackstageCredentials;
|
|
407
|
+
}): HttpAuthService;
|
|
408
|
+
namespace httpAuth {
|
|
409
|
+
/**
|
|
410
|
+
* Creates a mock service factory for the `HttpAuthService`.
|
|
411
|
+
*
|
|
412
|
+
* By default all requests without credentials are treated as requests from
|
|
413
|
+
* the default mock user principal. This behavior can be configured with the
|
|
414
|
+
* `defaultCredentials` option.
|
|
415
|
+
*/
|
|
416
|
+
const factory: (options?: {
|
|
417
|
+
defaultCredentials?: BackstageCredentials | undefined;
|
|
418
|
+
} | undefined) => ServiceFactory<HttpAuthService, "plugin">;
|
|
419
|
+
const mock: (partialImpl?: Partial<HttpAuthService> | undefined) => ServiceMock<HttpAuthService>;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Creates a mock implementation of the `UserInfoService`.
|
|
423
|
+
*
|
|
424
|
+
* By default it extracts the user's entity ref from a user principal and
|
|
425
|
+
* returns that as the only ownership entity ref, but this can be overridden
|
|
426
|
+
* by passing in a custom set of user info.
|
|
427
|
+
*/
|
|
428
|
+
function userInfo(customInfo?: Partial<BackstageUserInfo>): UserInfoService;
|
|
429
|
+
namespace userInfo {
|
|
430
|
+
/**
|
|
431
|
+
* Creates a mock service factory for the `UserInfoService`.
|
|
432
|
+
*
|
|
433
|
+
* By default it extracts the user's entity ref from a user principal and
|
|
434
|
+
* returns that as the only ownership entity ref.
|
|
435
|
+
*/
|
|
436
|
+
const factory: () => ServiceFactory<UserInfoService, "plugin">;
|
|
437
|
+
const mock: (partialImpl?: Partial<UserInfoService> | undefined) => ServiceMock<UserInfoService>;
|
|
438
|
+
}
|
|
377
439
|
namespace cache {
|
|
378
440
|
const factory: () => ServiceFactory<_backstage_backend_plugin_api.CacheService, "plugin">;
|
|
379
441
|
const mock: (partialImpl?: Partial<_backstage_backend_plugin_api.CacheService> | undefined) => ServiceMock<_backstage_backend_plugin_api.CacheService>;
|
|
@@ -416,4 +478,111 @@ declare namespace mockServices {
|
|
|
416
478
|
}
|
|
417
479
|
}
|
|
418
480
|
|
|
419
|
-
|
|
481
|
+
/**
|
|
482
|
+
* @public
|
|
483
|
+
*/
|
|
484
|
+
declare namespace mockCredentials {
|
|
485
|
+
/**
|
|
486
|
+
* Creates a mocked credentials object for a unauthenticated principal.
|
|
487
|
+
*/
|
|
488
|
+
function none(): BackstageCredentials<BackstageNonePrincipal>;
|
|
489
|
+
/**
|
|
490
|
+
* Utilities related to none credentials.
|
|
491
|
+
*/
|
|
492
|
+
namespace none {
|
|
493
|
+
/**
|
|
494
|
+
* Returns an authorization header that translates to unauthenticated
|
|
495
|
+
* credentials.
|
|
496
|
+
*
|
|
497
|
+
* This is useful when one wants to explicitly test unauthenticated requests
|
|
498
|
+
* while still using the default behavior of the mock HttpAuthService where
|
|
499
|
+
* it defaults to user credentials.
|
|
500
|
+
*/
|
|
501
|
+
function header(): string;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Creates a mocked credentials object for a user principal.
|
|
505
|
+
*
|
|
506
|
+
* The default user entity reference is 'user:default/mock'.
|
|
507
|
+
*/
|
|
508
|
+
function user(userEntityRef?: string): BackstageCredentials<BackstageUserPrincipal>;
|
|
509
|
+
/**
|
|
510
|
+
* Utilities related to user credentials.
|
|
511
|
+
*/
|
|
512
|
+
namespace user {
|
|
513
|
+
/**
|
|
514
|
+
* Creates a mocked user token. If a payload is provided it will be encoded
|
|
515
|
+
* into the token and forwarded to the credentials object when authenticated
|
|
516
|
+
* by the mock auth service.
|
|
517
|
+
*/
|
|
518
|
+
function token(userEntityRef?: string): string;
|
|
519
|
+
/**
|
|
520
|
+
* Returns an authorization header with a mocked user token. If a payload is
|
|
521
|
+
* provided it will be encoded into the token and forwarded to the
|
|
522
|
+
* credentials object when authenticated by the mock auth service.
|
|
523
|
+
*/
|
|
524
|
+
function header(userEntityRef?: string): string;
|
|
525
|
+
function invalidToken(): string;
|
|
526
|
+
function invalidHeader(): string;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Creates a mocked credentials object for a user principal with limited
|
|
530
|
+
* access.
|
|
531
|
+
*
|
|
532
|
+
* The default user entity reference is 'user:default/mock'.
|
|
533
|
+
*/
|
|
534
|
+
function limitedUser(userEntityRef?: string): BackstageCredentials<BackstageUserPrincipal>;
|
|
535
|
+
/**
|
|
536
|
+
* Utilities related to limited user credentials.
|
|
537
|
+
*/
|
|
538
|
+
namespace limitedUser {
|
|
539
|
+
/**
|
|
540
|
+
* Creates a mocked limited user token. If a payload is provided it will be
|
|
541
|
+
* encoded into the token and forwarded to the credentials object when
|
|
542
|
+
* authenticated by the mock auth service.
|
|
543
|
+
*/
|
|
544
|
+
function token(userEntityRef?: string): string;
|
|
545
|
+
/**
|
|
546
|
+
* Returns an authorization header with a mocked limited user token. If a
|
|
547
|
+
* payload is provided it will be encoded into the token and forwarded to
|
|
548
|
+
* the credentials object when authenticated by the mock auth service.
|
|
549
|
+
*/
|
|
550
|
+
function cookie(userEntityRef?: string): string;
|
|
551
|
+
function invalidToken(): string;
|
|
552
|
+
function invalidCookie(): string;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Creates a mocked credentials object for a service principal.
|
|
556
|
+
*
|
|
557
|
+
* The default subject is 'external:test-service'.
|
|
558
|
+
*/
|
|
559
|
+
function service(subject?: string): BackstageCredentials<BackstageServicePrincipal>;
|
|
560
|
+
/**
|
|
561
|
+
* Utilities related to service credentials.
|
|
562
|
+
*/
|
|
563
|
+
namespace service {
|
|
564
|
+
/**
|
|
565
|
+
* Options for the creation of mock service tokens.
|
|
566
|
+
*/
|
|
567
|
+
type TokenOptions = {
|
|
568
|
+
onBehalfOf: BackstageCredentials;
|
|
569
|
+
targetPluginId: string;
|
|
570
|
+
};
|
|
571
|
+
/**
|
|
572
|
+
* Creates a mocked service token. The provided options will be encoded into
|
|
573
|
+
* the token and forwarded to the credentials object when authenticated by
|
|
574
|
+
* the mock auth service.
|
|
575
|
+
*/
|
|
576
|
+
function token(options?: TokenOptions): string;
|
|
577
|
+
/**
|
|
578
|
+
* Returns an authorization header with a mocked service token. The provided
|
|
579
|
+
* options will be encoded into the token and forwarded to the credentials
|
|
580
|
+
* object when authenticated by the mock auth service.
|
|
581
|
+
*/
|
|
582
|
+
function header(options?: TokenOptions): string;
|
|
583
|
+
function invalidToken(): string;
|
|
584
|
+
function invalidHeader(): string;
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
export { MockDirectory, MockDirectoryContent, MockDirectoryContentCallback, MockDirectoryContentCallbackContext, MockDirectoryContentOptions, MockDirectoryOptions, ServiceFactoryTester, ServiceFactoryTesterOptions, ServiceMock, TestBackend, TestBackendOptions, TestDatabaseId, TestDatabases, createMockDirectory, isDockerDisabledForTests, mockCredentials, mockServices, setupRequestMockHandlers, startTestBackend };
|
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/backend-test-utils",
|
|
3
|
+
"version": "0.3.4-next.2",
|
|
3
4
|
"description": "Test helpers library for Backstage backends",
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
"backstage": {
|
|
6
|
+
"role": "node-library"
|
|
7
|
+
},
|
|
7
8
|
"publishConfig": {
|
|
8
9
|
"access": "public"
|
|
9
10
|
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"backstage",
|
|
13
|
+
"test"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://backstage.io",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/backstage/backstage",
|
|
19
|
+
"directory": "packages/backend-test-utils"
|
|
20
|
+
},
|
|
21
|
+
"license": "Apache-2.0",
|
|
10
22
|
"exports": {
|
|
11
23
|
".": {
|
|
12
24
|
"require": "./dist/index.cjs.js",
|
|
@@ -15,57 +27,46 @@
|
|
|
15
27
|
},
|
|
16
28
|
"./package.json": "./package.json"
|
|
17
29
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "https://github.com/backstage/backstage",
|
|
25
|
-
"directory": "packages/backend-test-utils"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"backstage",
|
|
29
|
-
"test"
|
|
30
|
+
"main": "./dist/index.cjs.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist"
|
|
30
34
|
],
|
|
31
|
-
"license": "Apache-2.0",
|
|
32
35
|
"scripts": {
|
|
33
36
|
"build": "backstage-cli package build",
|
|
37
|
+
"clean": "backstage-cli package clean",
|
|
34
38
|
"lint": "backstage-cli package lint",
|
|
35
|
-
"test": "backstage-cli package test",
|
|
36
39
|
"prepack": "backstage-cli package prepack",
|
|
37
40
|
"postpack": "backstage-cli package postpack",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
41
|
+
"start": "backstage-cli package start",
|
|
42
|
+
"test": "backstage-cli package test"
|
|
40
43
|
},
|
|
41
44
|
"dependencies": {
|
|
42
|
-
"@backstage/backend-app-api": "^0.
|
|
43
|
-
"@backstage/backend-common": "^0.21.
|
|
44
|
-
"@backstage/backend-plugin-api": "^0.6.
|
|
45
|
-
"@backstage/config": "^1.
|
|
46
|
-
"@backstage/errors": "^1.2.
|
|
47
|
-
"@backstage/plugin-auth-node": "^0.4.
|
|
45
|
+
"@backstage/backend-app-api": "^0.6.0-next.2",
|
|
46
|
+
"@backstage/backend-common": "^0.21.4-next.2",
|
|
47
|
+
"@backstage/backend-plugin-api": "^0.6.14-next.2",
|
|
48
|
+
"@backstage/config": "^1.2.0-next.1",
|
|
49
|
+
"@backstage/errors": "^1.2.4-next.0",
|
|
50
|
+
"@backstage/plugin-auth-node": "^0.4.9-next.2",
|
|
48
51
|
"@backstage/types": "^1.1.1",
|
|
49
52
|
"better-sqlite3": "^9.0.0",
|
|
53
|
+
"cookie": "^0.6.0",
|
|
50
54
|
"express": "^4.17.1",
|
|
51
55
|
"fs-extra": "^11.0.0",
|
|
52
56
|
"knex": "^3.0.0",
|
|
53
57
|
"msw": "^1.0.0",
|
|
54
|
-
"mysql2": "^
|
|
58
|
+
"mysql2": "^3.0.0",
|
|
55
59
|
"pg": "^8.11.3",
|
|
56
|
-
"testcontainers": "^
|
|
60
|
+
"testcontainers": "^10.0.0",
|
|
57
61
|
"textextensions": "^5.16.0",
|
|
58
|
-
"uuid": "^
|
|
59
|
-
},
|
|
60
|
-
"peerDependencies": {
|
|
61
|
-
"@types/jest": "*"
|
|
62
|
+
"uuid": "^9.0.0"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
|
-
"@backstage/cli": "^0.25.2",
|
|
65
|
+
"@backstage/cli": "^0.25.3-next.2",
|
|
65
66
|
"@types/supertest": "^2.0.8",
|
|
66
67
|
"supertest": "^6.1.3"
|
|
67
68
|
},
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@types/jest": "*"
|
|
71
|
+
}
|
|
71
72
|
}
|