@digitraffic/common 2022.10.31-3 → 2022.11.1-1
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/dist/aws/infra/api/integration.d.ts +21 -0
- package/dist/aws/infra/api/integration.js.map +1 -0
- package/dist/aws/infra/api/response.d.ts +22 -0
- package/dist/aws/infra/api/response.js.map +1 -0
- package/dist/aws/infra/api/responses.d.ts +39 -0
- package/dist/aws/infra/api/responses.js.map +1 -0
- package/dist/aws/infra/api/static-integration.d.ts +15 -0
- package/dist/aws/infra/api/static-integration.js.map +1 -0
- package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
- package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
- package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
- package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
- package/dist/aws/infra/canaries/canary-role.js.map +1 -0
- package/dist/aws/infra/canaries/canary.d.ts +8 -0
- package/dist/aws/infra/canaries/canary.js.map +1 -0
- package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
- package/dist/aws/infra/canaries/database-canary.js.map +1 -0
- package/dist/aws/infra/canaries/database-checker.d.ts +21 -0
- package/dist/aws/infra/canaries/database-checker.js.map +1 -0
- package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
- package/dist/aws/infra/canaries/url-canary.js.map +1 -0
- package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
- package/dist/aws/infra/canaries/url-checker.js.map +1 -0
- package/dist/aws/infra/documentation.d.ts +56 -0
- package/dist/aws/infra/documentation.js.map +1 -0
- package/dist/aws/infra/scheduler.d.ts +12 -0
- package/dist/aws/infra/scheduler.js.map +1 -0
- package/dist/aws/infra/security-rule.d.ts +12 -0
- package/dist/aws/infra/security-rule.js.map +1 -0
- package/dist/aws/infra/sqs-integration.d.ts +7 -0
- package/dist/aws/infra/sqs-integration.js.map +1 -0
- package/dist/aws/infra/sqs-queue.d.ts +16 -0
- package/dist/aws/infra/sqs-queue.js.map +1 -0
- package/dist/aws/infra/stack/lambda-configs.d.ts +72 -0
- package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
- package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
- package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
- package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
- package/dist/aws/infra/stack/rest_apis.js +27 -31
- package/dist/aws/infra/stack/rest_apis.js.map +1 -0
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +3 -2
- package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
- package/dist/aws/infra/stack/stack.d.ts +45 -0
- package/dist/aws/infra/stack/stack.js.map +1 -0
- package/dist/aws/infra/stack/subscription.d.ts +17 -0
- package/dist/aws/infra/stack/subscription.js.map +1 -0
- package/dist/aws/infra/usage-plans.d.ts +15 -0
- package/dist/aws/infra/usage-plans.js.map +1 -0
- package/dist/aws/runtime/apikey.d.ts +2 -0
- package/dist/aws/runtime/apikey.js.map +1 -0
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
- package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
- package/dist/aws/runtime/environment.d.ts +1 -0
- package/dist/aws/runtime/environment.js +4 -1
- package/dist/aws/runtime/environment.js.map +1 -0
- package/dist/aws/runtime/messaging.d.ts +10 -0
- package/dist/aws/runtime/messaging.js.map +1 -0
- package/dist/aws/runtime/s3.d.ts +2 -0
- package/dist/aws/runtime/s3.js.map +1 -0
- package/dist/aws/runtime/secrets/dbsecret.d.ts +54 -0
- package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
- package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
- package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
- package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
- package/dist/aws/runtime/secrets/secret-holder.d.ts +26 -0
- package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
- package/dist/aws/runtime/secrets/secret.d.ts +8 -0
- package/dist/aws/runtime/secrets/secret.js.map +1 -0
- package/dist/aws/types/errors.d.ts +8 -0
- package/dist/aws/types/errors.js.map +1 -0
- package/dist/aws/types/lambda-response.d.ts +13 -0
- package/dist/aws/types/lambda-response.js.map +1 -0
- package/dist/aws/types/mediatypes.d.ts +11 -0
- package/dist/aws/types/mediatypes.js +2 -1
- package/dist/aws/types/mediatypes.js.map +1 -0
- package/dist/aws/types/model-with-reference.d.ts +7 -0
- package/dist/aws/types/model-with-reference.js.map +1 -0
- package/dist/aws/types/proxytypes.d.ts +26 -0
- package/dist/aws/types/proxytypes.js.map +1 -0
- package/dist/aws/types/tags.d.ts +2 -0
- package/dist/aws/types/tags.js.map +1 -0
- package/dist/database/cached.d.ts +7 -0
- package/dist/database/cached.js.map +1 -0
- package/dist/database/database.d.ts +19 -0
- package/dist/database/database.js +6 -8
- package/dist/database/database.js.map +1 -0
- package/dist/database/last-updated.d.ts +16 -0
- package/dist/database/last-updated.js.map +1 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/database/models.js.map +1 -0
- package/dist/marine/id_utils.d.ts +3 -0
- package/dist/marine/id_utils.js.map +1 -0
- package/dist/marine/rtz.d.ts +48 -0
- package/dist/marine/rtz.js.map +1 -0
- package/dist/test/asserter.d.ts +11 -0
- package/dist/test/asserter.js.map +1 -0
- package/dist/test/db-testutils.d.ts +3 -0
- package/dist/test/db-testutils.js +5 -1
- package/dist/test/db-testutils.js.map +1 -0
- package/dist/test/httpserver.d.ts +19 -0
- package/dist/test/httpserver.js.map +1 -0
- package/dist/test/secret.d.ts +3 -0
- package/dist/test/secret.js.map +1 -0
- package/dist/test/secrets-manager.d.ts +9 -0
- package/dist/test/secrets-manager.js.map +1 -0
- package/dist/test/testutils.d.ts +12 -0
- package/dist/test/testutils.js.map +1 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js.map +1 -0
- package/dist/types/input-error.d.ts +2 -0
- package/dist/types/input-error.js.map +1 -0
- package/dist/types/language.d.ts +5 -0
- package/dist/types/language.js.map +1 -0
- package/dist/types/traffictype.d.ts +8 -0
- package/dist/types/traffictype.js.map +1 -0
- package/dist/types/validator.d.ts +4 -0
- package/dist/types/validator.js.map +1 -0
- package/dist/utils/api-model.d.ts +87 -0
- package/dist/utils/api-model.js.map +1 -0
- package/dist/utils/base64.d.ts +12 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/date-utils.d.ts +17 -0
- package/dist/utils/date-utils.js.map +1 -0
- package/dist/utils/geojson-types.d.ts +14 -0
- package/dist/utils/geojson-types.js.map +1 -0
- package/dist/utils/geometry.d.ts +36 -0
- package/dist/utils/geometry.js.map +1 -0
- package/dist/utils/retry.d.ts +13 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/slack.d.ts +5 -0
- package/dist/utils/slack.js.map +1 -0
- package/dist/utils/utils.d.ts +46 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/aws/infra/stack/rest_apis.ts +144 -91
- package/src/aws/infra/stack/stack-checking-aspect.ts +5 -2
- package/src/aws/runtime/environment.ts +5 -1
- package/src/aws/types/mediatypes.ts +2 -1
- package/src/database/database.ts +9 -10
- package/src/test/db-testutils.ts +5 -0
- package/.editorconfig +0 -9
- package/.eslintignore +0 -4
- package/.eslintrc.json +0 -27
- package/.github/CODEOWNERS +0 -2
- package/.github/workflows/build.yml +0 -36
- package/.github/workflows/eslint.yml +0 -38
- package/.github/workflows/mirror.yml +0 -15
- package/.gitignore +0 -29
- package/.husky/pre-commit +0 -4
- package/.prettierrc.json +0 -10
- package/jest.config.js +0 -15
- package/test/marine/id_utils.test.ts +0 -57
- package/test/promise/promise.test.ts +0 -143
- package/test/secrets/dbsecret.test.ts +0 -59
- package/test/secrets/secret-holder.test.ts +0 -143
- package/test/secrets/secret.test.ts +0 -49
- package/test/test/httpserver.test.ts +0 -128
- package/test/utils/date-utils.test.ts +0 -28
- package/test/utils/geometry.test.ts +0 -29
- package/test/utils/utils.test.ts +0 -64
- package/tsconfig.eslint.json +0 -4
- package/tsconfig.json +0 -22
- package/yarn.lock +0 -4060
package/.eslintrc.json
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"env": {
|
3
|
-
"browser": false,
|
4
|
-
"commonjs": true,
|
5
|
-
"es2021": true
|
6
|
-
},
|
7
|
-
"parser": "@typescript-eslint/parser",
|
8
|
-
"parserOptions": {
|
9
|
-
"project": ["./tsconfig.eslint.json"]
|
10
|
-
},
|
11
|
-
"plugins": ["@typescript-eslint"],
|
12
|
-
"extends": [
|
13
|
-
"eslint:recommended",
|
14
|
-
"plugin:@typescript-eslint/eslint-recommended",
|
15
|
-
"plugin:@typescript-eslint/recommended",
|
16
|
-
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
|
17
|
-
// "plugin:@typescript-eslint/strict",
|
18
|
-
"prettier"
|
19
|
-
],
|
20
|
-
"rules": {
|
21
|
-
"@typescript-eslint/no-extraneous-class": "off",
|
22
|
-
"@typescript-eslint/no-non-null-assertion": "error",
|
23
|
-
"@typescript-eslint/non-nullable-type-assertion-style": "error",
|
24
|
-
"@typescript-eslint/no-throw-literal": "error",
|
25
|
-
"@typescript-eslint/no-explicit-any": "error"
|
26
|
-
}
|
27
|
-
}
|
package/.github/CODEOWNERS
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
name: Build
|
2
|
-
on: [push]
|
3
|
-
jobs:
|
4
|
-
build:
|
5
|
-
if: github.event.repo.name != 'tmfg/digitraffic-common'
|
6
|
-
runs-on: ubuntu-20.04
|
7
|
-
steps:
|
8
|
-
- name: Checkout
|
9
|
-
uses: actions/checkout@v3
|
10
|
-
- name: Setup Node.js
|
11
|
-
uses: actions/setup-node@v2
|
12
|
-
with:
|
13
|
-
node-version: '14'
|
14
|
-
- name: Compile
|
15
|
-
run: |
|
16
|
-
yarn
|
17
|
-
yarn build
|
18
|
-
- name: Run tests
|
19
|
-
run: |
|
20
|
-
yarn test >> $GITHUB_STEP_SUMMARY
|
21
|
-
- name: Test Report
|
22
|
-
uses: dorny/test-reporter@v1
|
23
|
-
if: success() || failure()
|
24
|
-
with:
|
25
|
-
name: Jest test report
|
26
|
-
reporter: jest-junit
|
27
|
-
path: junit.xml
|
28
|
-
- name: Notify Slack
|
29
|
-
if: failure()
|
30
|
-
uses: 8398a7/action-slack@v3
|
31
|
-
with:
|
32
|
-
status: failure
|
33
|
-
text: FAILED digitraffic-common build
|
34
|
-
fields: repo, job, took
|
35
|
-
env:
|
36
|
-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
|
@@ -1,38 +0,0 @@
|
|
1
|
-
name: ESLint
|
2
|
-
|
3
|
-
on: [push]
|
4
|
-
|
5
|
-
jobs:
|
6
|
-
lint:
|
7
|
-
runs-on: ubuntu-22.04
|
8
|
-
steps:
|
9
|
-
- name: Checkout
|
10
|
-
uses: actions/checkout@v3
|
11
|
-
with:
|
12
|
-
fetch-depth: 0
|
13
|
-
|
14
|
-
- name: Setup Node.js
|
15
|
-
uses: actions/setup-node@v3
|
16
|
-
with:
|
17
|
-
node-version: "14"
|
18
|
-
|
19
|
-
- name: Install packages
|
20
|
-
run: yarn install --frozen-lock
|
21
|
-
|
22
|
-
- name: Create ESLint reports for affected projects
|
23
|
-
id: report
|
24
|
-
run: yarn eslint-report -- -o ${{ github.ref_name }}/report.html
|
25
|
-
continue-on-error: true
|
26
|
-
|
27
|
-
- name: Publish report
|
28
|
-
id: publish-reports
|
29
|
-
uses: tmfg/digitraffic-actions@gh-pages-publish/v1
|
30
|
-
with:
|
31
|
-
GH_PAGES_BRANCH: gh-pages
|
32
|
-
FILE_PATH: ${{ github.ref_name }}/report.html
|
33
|
-
COMMIT_MESSAGE: ESLint report in branch $CURRENT_BRANCH
|
34
|
-
LINK_TEXT: ESLint report
|
35
|
-
|
36
|
-
- name: Fail on ESLint errors
|
37
|
-
run: |
|
38
|
-
if [[ "${{ steps.report.outcome }}" == "failure" || "${{ steps.report-affected.outcome }}" == "failure" ]]; then exit 1; else exit 0; fi
|
@@ -1,15 +0,0 @@
|
|
1
|
-
name: 'Mirror repo to public'
|
2
|
-
on:
|
3
|
-
push:
|
4
|
-
branches:
|
5
|
-
- master
|
6
|
-
jobs:
|
7
|
-
Mirror-action:
|
8
|
-
if: github.repository != 'tmfg/digitraffic-common'
|
9
|
-
runs-on: ubuntu-latest
|
10
|
-
steps:
|
11
|
-
- name: Mirror
|
12
|
-
uses: tmfg/digitraffic-actions@mirror/v1
|
13
|
-
with:
|
14
|
-
mirror-repo: git@github.com:tmfg/digitraffic-common.git
|
15
|
-
ssh-private-key: ${{ secrets.SSH_MIRROR_KEY }}
|
package/.gitignore
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
*
|
2
|
-
|
3
|
-
!.husky/
|
4
|
-
!.husky/pre-commit
|
5
|
-
!/.editorconfig
|
6
|
-
!/.eslintignore
|
7
|
-
!/.eslintrc.json
|
8
|
-
!/.gitignore
|
9
|
-
!/.prettierrc.json
|
10
|
-
!/jest.config.js
|
11
|
-
!/LICENSE
|
12
|
-
!/package.json
|
13
|
-
!/README.md
|
14
|
-
!/tsconfig.json
|
15
|
-
!/tsconfig.eslint.json
|
16
|
-
!/yarn.lock
|
17
|
-
|
18
|
-
!src/
|
19
|
-
!src/**/
|
20
|
-
!src/**/*.ts
|
21
|
-
|
22
|
-
!test/
|
23
|
-
!test/**/
|
24
|
-
!test/**/*.ts
|
25
|
-
|
26
|
-
!.github/
|
27
|
-
!.github/**/
|
28
|
-
!.github/workflows/**/**.yml
|
29
|
-
!.github/CODEOWNERS
|
package/.husky/pre-commit
DELETED
package/.prettierrc.json
DELETED
package/jest.config.js
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
import * as IdUtils from '../../src/marine/id_utils';
|
2
|
-
import {getRandomNumber} from "../../src/test/testutils";
|
3
|
-
|
4
|
-
describe('IdUtils tests', () => {
|
5
|
-
|
6
|
-
test('isValidLOCODE - success', () => {
|
7
|
-
expect(IdUtils.isValidLOCODE('FILOL')).toBe(true);
|
8
|
-
});
|
9
|
-
|
10
|
-
test('isValidLOCODE - fail with non-finnish prefix', () => {
|
11
|
-
expect(IdUtils.isValidLOCODE('SEABS')).toBe(false);
|
12
|
-
});
|
13
|
-
|
14
|
-
test('isValidLOCODE - fail with numbers', () => {
|
15
|
-
expect(IdUtils.isValidLOCODE('FIAA1')).toBe(false);
|
16
|
-
});
|
17
|
-
|
18
|
-
test('isValidIMO - successful checksum - ship TRANSMAR', () => {
|
19
|
-
expect(IdUtils.isValidIMO(9167332)).toBe(true);
|
20
|
-
});
|
21
|
-
|
22
|
-
test('isValidIMO - successful checksum - ship ANNIKA B', () => {
|
23
|
-
expect(IdUtils.isValidIMO(9213715)).toBe(true);
|
24
|
-
});
|
25
|
-
|
26
|
-
test('isValidIMO - successful checksum - ship X PRESS ELBE', () => {
|
27
|
-
expect(IdUtils.isValidIMO(9483669)).toBe(true);
|
28
|
-
});
|
29
|
-
|
30
|
-
test('isValidIMO - successful checksum - ship SILVERFORS', () => {
|
31
|
-
expect(IdUtils.isValidIMO(8322765)).toBe(true);
|
32
|
-
});
|
33
|
-
|
34
|
-
test('isValidIMO - invalid checksum', () => {
|
35
|
-
expect(IdUtils.isValidIMO(8322766)).toBe(false);
|
36
|
-
});
|
37
|
-
|
38
|
-
test('isValidIMO - fail with number smaller than 1000000', () => {
|
39
|
-
expect(IdUtils.isValidIMO(getRandomNumber(0, 1000000 - 1))).toBe(false);
|
40
|
-
});
|
41
|
-
|
42
|
-
test('isValidIMO - fail with number larger than 9999999', () => {
|
43
|
-
expect(IdUtils.isValidIMO(getRandomNumber(9999999 + 1, 99999999))).toBe(false);
|
44
|
-
});
|
45
|
-
|
46
|
-
test('isValidMMSI - success', () => {
|
47
|
-
expect(IdUtils.isValidMMSI(230927000)).toBe(true);
|
48
|
-
});
|
49
|
-
|
50
|
-
test('isValidMMSI - fail with number smaller than 100000000', () => {
|
51
|
-
expect(IdUtils.isValidMMSI(getRandomNumber(0, 100000000 - 1))).toBe(false);
|
52
|
-
});
|
53
|
-
|
54
|
-
test('isValidMMSI - fail with number larger than 999999999', () => {
|
55
|
-
expect(IdUtils.isValidMMSI(getRandomNumber(999999999 + 1, 9999999999))).toBe(false);
|
56
|
-
});
|
57
|
-
});
|
@@ -1,143 +0,0 @@
|
|
1
|
-
import {getRandomInteger} from "../../src/test/testutils";
|
2
|
-
import {retry, RetryLogError} from "../../src/utils/retry";
|
3
|
-
|
4
|
-
describe('Promise utils tests', () => {
|
5
|
-
|
6
|
-
test('retry - no retries', async () => {
|
7
|
-
const fn = jest.fn().mockResolvedValue(1);
|
8
|
-
|
9
|
-
const ret = await retry(fn, 0, RetryLogError.NO_LOGGING);
|
10
|
-
|
11
|
-
expect(ret).toBe(1);
|
12
|
-
expect(fn.mock.calls.length).toBe(1);
|
13
|
-
});
|
14
|
-
|
15
|
-
test('retry - error with n+1 retries', async () => {
|
16
|
-
const fn = jest.fn().mockRejectedValue('error');
|
17
|
-
const retries = getRandomInteger(1, 10);
|
18
|
-
|
19
|
-
try {
|
20
|
-
await retry(fn, retries, RetryLogError.NO_LOGGING);
|
21
|
-
} catch {
|
22
|
-
// ignore
|
23
|
-
} finally {
|
24
|
-
expect(fn.mock.calls.length).toBe(retries + 1);
|
25
|
-
}
|
26
|
-
});
|
27
|
-
|
28
|
-
test('retry - no error with n+1 retries', async () => {
|
29
|
-
const fn = jest.fn().mockResolvedValue(1);
|
30
|
-
const retries = getRandomInteger(1, 10);
|
31
|
-
|
32
|
-
const ret = await retry(fn, retries, RetryLogError.NO_LOGGING);
|
33
|
-
|
34
|
-
expect(ret).toBe(1);
|
35
|
-
expect(fn.mock.calls.length).toBe(1);
|
36
|
-
});
|
37
|
-
|
38
|
-
test('retry - errors with no error logging', async () => {
|
39
|
-
const fn = jest.fn().mockRejectedValue('error');
|
40
|
-
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
41
|
-
|
42
|
-
try {
|
43
|
-
await retry(fn, getRandomInteger(0, 10), RetryLogError.NO_LOGGING);
|
44
|
-
} catch {
|
45
|
-
// ignore
|
46
|
-
} finally {
|
47
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(0);
|
48
|
-
consoleErrorSpy.mockRestore();
|
49
|
-
}
|
50
|
-
});
|
51
|
-
|
52
|
-
test('retry - no retries with error logging', async () => {
|
53
|
-
const fn = jest.fn().mockRejectedValue('error');
|
54
|
-
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
55
|
-
|
56
|
-
try {
|
57
|
-
await retry(fn, 0, RetryLogError.LOG_ALL_AS_ERRORS);
|
58
|
-
} catch {
|
59
|
-
// ignore
|
60
|
-
} finally {
|
61
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(1);
|
62
|
-
consoleErrorSpy.mockRestore();
|
63
|
-
}
|
64
|
-
});
|
65
|
-
|
66
|
-
test('retry - retries with error logging', async () => {
|
67
|
-
const fn = jest.fn().mockRejectedValue('error');
|
68
|
-
const retries = getRandomInteger(1, 10);
|
69
|
-
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
70
|
-
|
71
|
-
try {
|
72
|
-
await retry(fn, retries, RetryLogError.LOG_ALL_AS_ERRORS);
|
73
|
-
} catch {
|
74
|
-
// ignore
|
75
|
-
} finally {
|
76
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(retries + 1);
|
77
|
-
consoleErrorSpy.mockRestore();
|
78
|
-
}
|
79
|
-
});
|
80
|
-
|
81
|
-
test('retry - exceeded retry count throws error', async () => {
|
82
|
-
const fn = jest.fn().mockRejectedValue('error');
|
83
|
-
|
84
|
-
await expect(() => retry(fn, 3, RetryLogError.LOG_ALL_AS_ERRORS)).rejects.toThrow();
|
85
|
-
});
|
86
|
-
|
87
|
-
test('retry - defaults', async () => {
|
88
|
-
const fn = jest.fn().mockRejectedValue('error');
|
89
|
-
const consoleErrorSpy = jest.spyOn(global.console, 'error').mockImplementation();
|
90
|
-
|
91
|
-
try {
|
92
|
-
await retry(fn);
|
93
|
-
} catch {
|
94
|
-
// ignore
|
95
|
-
} finally {
|
96
|
-
expect(fn.mock.calls.length).toBe(3 + 1);
|
97
|
-
expect(consoleErrorSpy).toHaveBeenCalledTimes(1); // last retry
|
98
|
-
}
|
99
|
-
});
|
100
|
-
|
101
|
-
test('retry - NaN throws error', async () => {
|
102
|
-
const fn = jest.fn();
|
103
|
-
|
104
|
-
await expect(() => retry(fn, NaN, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
105
|
-
});
|
106
|
-
|
107
|
-
test('retry - Infinity throws error', async () => {
|
108
|
-
const fn = jest.fn();
|
109
|
-
|
110
|
-
await expect(() => retry(fn, Infinity, RetryLogError.NO_LOGGING)).rejects.toThrow();
|
111
|
-
});
|
112
|
-
|
113
|
-
test('retry - exceeded maximum retry count throws error', async () => {
|
114
|
-
const fn = jest.fn();
|
115
|
-
|
116
|
-
await expect(() => retry(fn, getRandomInteger(101, 1000000), RetryLogError.NO_LOGGING)).rejects.toThrow();
|
117
|
-
});
|
118
|
-
|
119
|
-
test('retry - use without mocks without retry', async () => {
|
120
|
-
const val = 1;
|
121
|
-
const fn = () => Promise.resolve(val);
|
122
|
-
|
123
|
-
const ret = await retry(fn);
|
124
|
-
|
125
|
-
expect(ret).toBe(val);
|
126
|
-
});
|
127
|
-
|
128
|
-
test('retry - use without mocks with retry', async () => {
|
129
|
-
let i = 0;
|
130
|
-
const val = 1;
|
131
|
-
const fn = () => {
|
132
|
-
if (i < 3) {
|
133
|
-
i++;
|
134
|
-
throw new Error('not yet');
|
135
|
-
}
|
136
|
-
return Promise.resolve(val);
|
137
|
-
};
|
138
|
-
|
139
|
-
const ret = await retry(fn);
|
140
|
-
|
141
|
-
expect(ret).toBe(val);
|
142
|
-
});
|
143
|
-
});
|
@@ -1,59 +0,0 @@
|
|
1
|
-
import {mockSecret, stubSecretsManager} from "../../src/test/secrets-manager";
|
2
|
-
|
3
|
-
import * as sinon from 'sinon';
|
4
|
-
|
5
|
-
const SECRET_ID = "test_secret";
|
6
|
-
const SECRET_WITH_PREFIX = {
|
7
|
-
"prefix.value" : "value",
|
8
|
-
"prefix.name" : "name",
|
9
|
-
"wrong.value" : "value",
|
10
|
-
};
|
11
|
-
const SECRET_EMPTY = {};
|
12
|
-
|
13
|
-
stubSecretsManager();
|
14
|
-
|
15
|
-
import {GenericSecret, withSecret, withSecretAndPrefix} from "../../src/aws/runtime/secrets/secret";
|
16
|
-
|
17
|
-
describe('secret - test', () => {
|
18
|
-
afterEach(() => {
|
19
|
-
sinon.restore();
|
20
|
-
});
|
21
|
-
|
22
|
-
test('getSecret - no secret', async () => {
|
23
|
-
mockSecret(null);
|
24
|
-
|
25
|
-
await expect(async () => {
|
26
|
-
await withSecret(SECRET_ID, () => {
|
27
|
-
// do nothing
|
28
|
-
});
|
29
|
-
}).rejects.toThrowError("No secret found!");
|
30
|
-
});
|
31
|
-
|
32
|
-
test('getSecret - empty secret', async () => {
|
33
|
-
mockSecret(SECRET_EMPTY);
|
34
|
-
|
35
|
-
await withSecret(SECRET_ID, (secret: GenericSecret) => {
|
36
|
-
expect(secret).toEqual(SECRET_EMPTY);
|
37
|
-
});
|
38
|
-
});
|
39
|
-
|
40
|
-
test('getSecret - no prefix', async () => {
|
41
|
-
mockSecret(SECRET_WITH_PREFIX);
|
42
|
-
|
43
|
-
await withSecret(SECRET_ID, (secret: GenericSecret) => {
|
44
|
-
expect(secret).toEqual(SECRET_WITH_PREFIX);
|
45
|
-
});
|
46
|
-
});
|
47
|
-
|
48
|
-
test('getSecret - with prefix', async () => {
|
49
|
-
mockSecret(SECRET_WITH_PREFIX);
|
50
|
-
|
51
|
-
await withSecretAndPrefix(SECRET_ID, 'prefix', (secret: GenericSecret) => {
|
52
|
-
expect(secret).toEqual({
|
53
|
-
value: "value",
|
54
|
-
name: "name",
|
55
|
-
});
|
56
|
-
});
|
57
|
-
|
58
|
-
});
|
59
|
-
});
|
@@ -1,143 +0,0 @@
|
|
1
|
-
import { mockSecret, stubSecretsManager } from "../../src/test/secrets-manager";
|
2
|
-
|
3
|
-
import * as sinon from "sinon";
|
4
|
-
|
5
|
-
const SECRET_WITH_PREFIX = {
|
6
|
-
"prefix.value": "value",
|
7
|
-
"prefix.name": "name",
|
8
|
-
"wrong.value": "value",
|
9
|
-
username: "DB_USER",
|
10
|
-
};
|
11
|
-
const SECRET_EMPTY = {};
|
12
|
-
|
13
|
-
const stubSM = stubSecretsManager();
|
14
|
-
|
15
|
-
import { SecretHolder } from "../../src/aws/runtime/secrets/secret-holder";
|
16
|
-
import { DatabaseEnvironmentKeys } from "../../src/aws/runtime/secrets/dbsecret";
|
17
|
-
|
18
|
-
describe("SecretHolder - tests", () => {
|
19
|
-
beforeEach(() => {
|
20
|
-
process.env["SECRET_ID"] = "test-id";
|
21
|
-
});
|
22
|
-
|
23
|
-
afterEach(() => {
|
24
|
-
sinon.restore();
|
25
|
-
sinon.reset();
|
26
|
-
delete process.env[DatabaseEnvironmentKeys.DB_USER];
|
27
|
-
});
|
28
|
-
|
29
|
-
test("get - no secret", async () => {
|
30
|
-
mockSecret(null);
|
31
|
-
|
32
|
-
const holder = SecretHolder.create();
|
33
|
-
await expect(async () => {
|
34
|
-
await holder.get();
|
35
|
-
}).rejects.toThrowError("No secret found!");
|
36
|
-
});
|
37
|
-
|
38
|
-
test("get - empty secret", async () => {
|
39
|
-
mockSecret(SECRET_EMPTY);
|
40
|
-
|
41
|
-
const holder = SecretHolder.create();
|
42
|
-
const secret = await holder.get();
|
43
|
-
|
44
|
-
expect(secret).toEqual(SECRET_EMPTY);
|
45
|
-
});
|
46
|
-
|
47
|
-
test("get - no prefix", async () => {
|
48
|
-
mockSecret(SECRET_WITH_PREFIX);
|
49
|
-
|
50
|
-
const holder = SecretHolder.create();
|
51
|
-
const secret = await holder.get();
|
52
|
-
|
53
|
-
expect(secret).toEqual(SECRET_WITH_PREFIX);
|
54
|
-
});
|
55
|
-
|
56
|
-
test("get - check keys - not found", async () => {
|
57
|
-
mockSecret(SECRET_WITH_PREFIX);
|
58
|
-
|
59
|
-
const holder = SecretHolder.create("", ["not_found"]);
|
60
|
-
await expect(async () => {
|
61
|
-
await holder.get();
|
62
|
-
}).rejects.toThrow();
|
63
|
-
});
|
64
|
-
|
65
|
-
test("get - check keys - found", async () => {
|
66
|
-
mockSecret(SECRET_WITH_PREFIX);
|
67
|
-
|
68
|
-
const holder = SecretHolder.create("", ["prefix.value", "username"]);
|
69
|
-
|
70
|
-
await holder.get();
|
71
|
-
});
|
72
|
-
|
73
|
-
test("setDatabaseCredentials - no prefix", async () => {
|
74
|
-
mockSecret(SECRET_WITH_PREFIX);
|
75
|
-
|
76
|
-
const holder = SecretHolder.create();
|
77
|
-
expect(process.env[DatabaseEnvironmentKeys.DB_USER]).toBeUndefined();
|
78
|
-
|
79
|
-
await holder.setDatabaseCredentials();
|
80
|
-
expect(process.env[DatabaseEnvironmentKeys.DB_USER]).toEqual(
|
81
|
-
SECRET_WITH_PREFIX.username
|
82
|
-
);
|
83
|
-
});
|
84
|
-
|
85
|
-
test("setDatabaseCredentials - with prefix", async () => {
|
86
|
-
mockSecret(SECRET_WITH_PREFIX);
|
87
|
-
|
88
|
-
const holder = SecretHolder.create("prefix");
|
89
|
-
expect(process.env[DatabaseEnvironmentKeys.DB_USER]).toBeUndefined();
|
90
|
-
|
91
|
-
await holder.setDatabaseCredentials();
|
92
|
-
expect(process.env[DatabaseEnvironmentKeys.DB_USER]).toEqual(
|
93
|
-
SECRET_WITH_PREFIX.username
|
94
|
-
);
|
95
|
-
});
|
96
|
-
|
97
|
-
test("getSecret - with prefix", async () => {
|
98
|
-
mockSecret(SECRET_WITH_PREFIX);
|
99
|
-
|
100
|
-
const holder = SecretHolder.create("prefix");
|
101
|
-
const secret = await holder.get();
|
102
|
-
|
103
|
-
expect(secret).toEqual({
|
104
|
-
value: "value",
|
105
|
-
name: "name",
|
106
|
-
});
|
107
|
-
});
|
108
|
-
|
109
|
-
test("get - ttl - do not fetch", async () => {
|
110
|
-
mockSecret(SECRET_WITH_PREFIX);
|
111
|
-
|
112
|
-
const holder = SecretHolder.create();
|
113
|
-
|
114
|
-
const callCount = stubSM.callCount;
|
115
|
-
|
116
|
-
await holder.get();
|
117
|
-
expect(stubSM.callCount).toEqual(callCount + 1);
|
118
|
-
|
119
|
-
// gets cached secret
|
120
|
-
await holder.get();
|
121
|
-
expect(stubSM.callCount).toEqual(callCount + 1);
|
122
|
-
});
|
123
|
-
|
124
|
-
test("get - ttl - fetch", async () => {
|
125
|
-
mockSecret(SECRET_WITH_PREFIX);
|
126
|
-
|
127
|
-
const holder = new SecretHolder("", "", [], {
|
128
|
-
ttl: 1,
|
129
|
-
});
|
130
|
-
|
131
|
-
const callCount = stubSM.callCount;
|
132
|
-
|
133
|
-
await holder.get();
|
134
|
-
expect(stubSM.callCount).toEqual(callCount + 1);
|
135
|
-
|
136
|
-
// cache expires, fetches secret again
|
137
|
-
const start = Date.now();
|
138
|
-
while (Date.now() < start + 2000);
|
139
|
-
|
140
|
-
await holder.get();
|
141
|
-
expect(stubSM.callCount).toEqual(callCount + 2);
|
142
|
-
});
|
143
|
-
});
|
@@ -1,49 +0,0 @@
|
|
1
|
-
import {mockSecret, stubSecretsManager} from "../../src/test/secrets-manager";
|
2
|
-
|
3
|
-
import * as sinon from 'sinon';
|
4
|
-
|
5
|
-
const SECRET_ID = "test_secret";
|
6
|
-
const SECRET_WITH_PREFIX = {
|
7
|
-
"prefix.value" : "value",
|
8
|
-
"prefix.name" : "name",
|
9
|
-
"wrong.value" : "value",
|
10
|
-
};
|
11
|
-
const SECRET_EMPTY = {};
|
12
|
-
|
13
|
-
stubSecretsManager();
|
14
|
-
|
15
|
-
import {getSecret} from "../../src/aws/runtime/secrets/secret";
|
16
|
-
|
17
|
-
describe('secret - test', () => {
|
18
|
-
afterEach(() => {
|
19
|
-
sinon.restore();
|
20
|
-
});
|
21
|
-
|
22
|
-
test('getSecret - no secret', async () => {
|
23
|
-
mockSecret(null);
|
24
|
-
await expect(async () => {
|
25
|
-
await getSecret(SECRET_ID, '');
|
26
|
-
}).rejects.toThrowError("No secret found!");
|
27
|
-
});
|
28
|
-
|
29
|
-
test('getSecret - empty secret', async () => {
|
30
|
-
mockSecret(SECRET_EMPTY);
|
31
|
-
const secret = await getSecret(SECRET_ID, '');
|
32
|
-
expect(secret).toEqual(SECRET_EMPTY);
|
33
|
-
});
|
34
|
-
|
35
|
-
test('getSecret - no prefix', async () => {
|
36
|
-
mockSecret(SECRET_WITH_PREFIX);
|
37
|
-
const secret = await getSecret(SECRET_ID, '');
|
38
|
-
expect(secret).toEqual(SECRET_WITH_PREFIX);
|
39
|
-
});
|
40
|
-
|
41
|
-
test('getSecret - with prefix', async () => {
|
42
|
-
mockSecret(SECRET_WITH_PREFIX);
|
43
|
-
const secret = await getSecret(SECRET_ID, 'prefix');
|
44
|
-
expect(secret).toEqual({
|
45
|
-
value: "value",
|
46
|
-
name: "name",
|
47
|
-
});
|
48
|
-
});
|
49
|
-
});
|