@digitraffic/common 2022.10.31-4 → 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.
Files changed (168) hide show
  1. package/dist/aws/infra/api/integration.d.ts +21 -0
  2. package/dist/aws/infra/api/integration.js.map +1 -0
  3. package/dist/aws/infra/api/response.d.ts +22 -0
  4. package/dist/aws/infra/api/response.js.map +1 -0
  5. package/dist/aws/infra/api/responses.d.ts +39 -0
  6. package/dist/aws/infra/api/responses.js.map +1 -0
  7. package/dist/aws/infra/api/static-integration.d.ts +15 -0
  8. package/dist/aws/infra/api/static-integration.js.map +1 -0
  9. package/dist/aws/infra/canaries/canary-alarm.d.ts +6 -0
  10. package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
  11. package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
  12. package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
  13. package/dist/aws/infra/canaries/canary-parameters.d.ts +18 -0
  14. package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
  15. package/dist/aws/infra/canaries/canary-role.d.ts +6 -0
  16. package/dist/aws/infra/canaries/canary-role.js.map +1 -0
  17. package/dist/aws/infra/canaries/canary.d.ts +8 -0
  18. package/dist/aws/infra/canaries/canary.js.map +1 -0
  19. package/dist/aws/infra/canaries/database-canary.d.ts +18 -0
  20. package/dist/aws/infra/canaries/database-canary.js.map +1 -0
  21. package/dist/aws/infra/canaries/database-checker.d.ts +21 -0
  22. package/dist/aws/infra/canaries/database-checker.js.map +1 -0
  23. package/dist/aws/infra/canaries/url-canary.d.ts +16 -0
  24. package/dist/aws/infra/canaries/url-canary.js.map +1 -0
  25. package/dist/aws/infra/canaries/url-checker.d.ts +46 -0
  26. package/dist/aws/infra/canaries/url-checker.js.map +1 -0
  27. package/dist/aws/infra/documentation.d.ts +56 -0
  28. package/dist/aws/infra/documentation.js.map +1 -0
  29. package/dist/aws/infra/scheduler.d.ts +12 -0
  30. package/dist/aws/infra/scheduler.js.map +1 -0
  31. package/dist/aws/infra/security-rule.d.ts +12 -0
  32. package/dist/aws/infra/security-rule.js.map +1 -0
  33. package/dist/aws/infra/sqs-integration.d.ts +7 -0
  34. package/dist/aws/infra/sqs-integration.js.map +1 -0
  35. package/dist/aws/infra/sqs-queue.d.ts +16 -0
  36. package/dist/aws/infra/sqs-queue.js.map +1 -0
  37. package/dist/aws/infra/stack/lambda-configs.d.ts +72 -0
  38. package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
  39. package/dist/aws/infra/stack/monitoredfunction.d.ts +84 -0
  40. package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
  41. package/dist/aws/infra/stack/rest_apis.d.ts +41 -0
  42. package/dist/aws/infra/stack/rest_apis.js +27 -31
  43. package/dist/aws/infra/stack/rest_apis.js.map +1 -0
  44. package/dist/aws/infra/stack/stack-checking-aspect.d.ts +21 -0
  45. package/dist/aws/infra/stack/stack-checking-aspect.js +3 -2
  46. package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
  47. package/dist/aws/infra/stack/stack.d.ts +45 -0
  48. package/dist/aws/infra/stack/stack.js.map +1 -0
  49. package/dist/aws/infra/stack/subscription.d.ts +17 -0
  50. package/dist/aws/infra/stack/subscription.js.map +1 -0
  51. package/dist/aws/infra/usage-plans.d.ts +15 -0
  52. package/dist/aws/infra/usage-plans.js.map +1 -0
  53. package/dist/aws/runtime/apikey.d.ts +2 -0
  54. package/dist/aws/runtime/apikey.js.map +1 -0
  55. package/dist/aws/runtime/digitraffic-integration-response.d.ts +8 -0
  56. package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
  57. package/dist/aws/runtime/environment.d.ts +1 -0
  58. package/dist/aws/runtime/environment.js +4 -1
  59. package/dist/aws/runtime/environment.js.map +1 -0
  60. package/dist/aws/runtime/messaging.d.ts +10 -0
  61. package/dist/aws/runtime/messaging.js.map +1 -0
  62. package/dist/aws/runtime/s3.d.ts +2 -0
  63. package/dist/aws/runtime/s3.js.map +1 -0
  64. package/dist/aws/runtime/secrets/dbsecret.d.ts +54 -0
  65. package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
  66. package/dist/aws/runtime/secrets/proxy-holder.d.ts +9 -0
  67. package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
  68. package/dist/aws/runtime/secrets/rds-holder.d.ts +9 -0
  69. package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
  70. package/dist/aws/runtime/secrets/secret-holder.d.ts +26 -0
  71. package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
  72. package/dist/aws/runtime/secrets/secret.d.ts +8 -0
  73. package/dist/aws/runtime/secrets/secret.js.map +1 -0
  74. package/dist/aws/types/errors.d.ts +8 -0
  75. package/dist/aws/types/errors.js.map +1 -0
  76. package/dist/aws/types/lambda-response.d.ts +13 -0
  77. package/dist/aws/types/lambda-response.js.map +1 -0
  78. package/dist/aws/types/mediatypes.d.ts +11 -0
  79. package/dist/aws/types/mediatypes.js +2 -1
  80. package/dist/aws/types/mediatypes.js.map +1 -0
  81. package/dist/aws/types/model-with-reference.d.ts +7 -0
  82. package/dist/aws/types/model-with-reference.js.map +1 -0
  83. package/dist/aws/types/proxytypes.d.ts +26 -0
  84. package/dist/aws/types/proxytypes.js.map +1 -0
  85. package/dist/aws/types/tags.d.ts +2 -0
  86. package/dist/aws/types/tags.js.map +1 -0
  87. package/dist/database/cached.d.ts +7 -0
  88. package/dist/database/cached.js.map +1 -0
  89. package/dist/database/database.d.ts +19 -0
  90. package/dist/database/database.js +6 -8
  91. package/dist/database/database.js.map +1 -0
  92. package/dist/database/last-updated.d.ts +16 -0
  93. package/dist/database/last-updated.js.map +1 -0
  94. package/dist/database/models.d.ts +6 -0
  95. package/dist/database/models.js.map +1 -0
  96. package/dist/marine/id_utils.d.ts +3 -0
  97. package/dist/marine/id_utils.js.map +1 -0
  98. package/dist/marine/rtz.d.ts +48 -0
  99. package/dist/marine/rtz.js.map +1 -0
  100. package/dist/test/asserter.d.ts +11 -0
  101. package/dist/test/asserter.js.map +1 -0
  102. package/dist/test/db-testutils.d.ts +3 -0
  103. package/dist/test/db-testutils.js +5 -1
  104. package/dist/test/db-testutils.js.map +1 -0
  105. package/dist/test/httpserver.d.ts +19 -0
  106. package/dist/test/httpserver.js.map +1 -0
  107. package/dist/test/secret.d.ts +3 -0
  108. package/dist/test/secret.js.map +1 -0
  109. package/dist/test/secrets-manager.d.ts +9 -0
  110. package/dist/test/secrets-manager.js.map +1 -0
  111. package/dist/test/testutils.d.ts +12 -0
  112. package/dist/test/testutils.js.map +1 -0
  113. package/dist/types/either.d.ts +9 -0
  114. package/dist/types/either.js.map +1 -0
  115. package/dist/types/input-error.d.ts +2 -0
  116. package/dist/types/input-error.js.map +1 -0
  117. package/dist/types/language.d.ts +5 -0
  118. package/dist/types/language.js.map +1 -0
  119. package/dist/types/traffictype.d.ts +8 -0
  120. package/dist/types/traffictype.js.map +1 -0
  121. package/dist/types/validator.d.ts +4 -0
  122. package/dist/types/validator.js.map +1 -0
  123. package/dist/utils/api-model.d.ts +87 -0
  124. package/dist/utils/api-model.js.map +1 -0
  125. package/dist/utils/base64.d.ts +12 -0
  126. package/dist/utils/base64.js.map +1 -0
  127. package/dist/utils/date-utils.d.ts +17 -0
  128. package/dist/utils/date-utils.js.map +1 -0
  129. package/dist/utils/geojson-types.d.ts +14 -0
  130. package/dist/utils/geojson-types.js.map +1 -0
  131. package/dist/utils/geometry.d.ts +36 -0
  132. package/dist/utils/geometry.js.map +1 -0
  133. package/dist/utils/retry.d.ts +13 -0
  134. package/dist/utils/retry.js.map +1 -0
  135. package/dist/utils/slack.d.ts +5 -0
  136. package/dist/utils/slack.js.map +1 -0
  137. package/dist/utils/utils.d.ts +46 -0
  138. package/dist/utils/utils.js.map +1 -0
  139. package/package.json +1 -1
  140. package/src/aws/infra/stack/rest_apis.ts +144 -91
  141. package/src/aws/infra/stack/stack-checking-aspect.ts +5 -2
  142. package/src/aws/runtime/environment.ts +5 -1
  143. package/src/aws/types/mediatypes.ts +2 -1
  144. package/src/database/database.ts +9 -10
  145. package/src/test/db-testutils.ts +5 -0
  146. package/.editorconfig +0 -9
  147. package/.eslintignore +0 -4
  148. package/.eslintrc.json +0 -27
  149. package/.github/CODEOWNERS +0 -2
  150. package/.github/workflows/build.yml +0 -36
  151. package/.github/workflows/eslint.yml +0 -38
  152. package/.github/workflows/mirror.yml +0 -15
  153. package/.gitignore +0 -29
  154. package/.husky/pre-commit +0 -4
  155. package/.prettierrc.json +0 -10
  156. package/jest.config.js +0 -15
  157. package/test/marine/id_utils.test.ts +0 -57
  158. package/test/promise/promise.test.ts +0 -143
  159. package/test/secrets/dbsecret.test.ts +0 -59
  160. package/test/secrets/secret-holder.test.ts +0 -143
  161. package/test/secrets/secret.test.ts +0 -49
  162. package/test/test/httpserver.test.ts +0 -128
  163. package/test/utils/date-utils.test.ts +0 -28
  164. package/test/utils/geometry.test.ts +0 -29
  165. package/test/utils/utils.test.ts +0 -64
  166. package/tsconfig.eslint.json +0 -4
  167. package/tsconfig.json +0 -22
  168. 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
- }
@@ -1,2 +0,0 @@
1
- # These owners will be the default owners for everything in the repo.
2
- * @teijosol @jouniso @teemu-solita @jkhaak-solita @solita-ijunnone @mattihe
@@ -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
@@ -1,4 +0,0 @@
1
- #!/bin/sh
2
- . "$(dirname "$0")/_/husky.sh"
3
-
4
- yarn lint-staged
package/.prettierrc.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "overrides": [
3
- {
4
- "files": ["*.json", "*.yml", "*.yaml"],
5
- "options": {
6
- "tabWidth": 2
7
- }
8
- }
9
- ]
10
- }
package/jest.config.js DELETED
@@ -1,15 +0,0 @@
1
- module.exports = {
2
- roots: [
3
- '<rootDir>/test',
4
- ],
5
- testMatch: [
6
- '**/*.test.ts',
7
- ],
8
- testResultsProcessor: 'jest-junit',
9
- preset: 'ts-jest',
10
- coverageThreshold: {
11
- global: {
12
- lines: 70,
13
- },
14
- },
15
- }
@@ -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
- });