@tsed/testcontainers-vault 8.29.0

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 (2) hide show
  1. package/package.json +36 -0
  2. package/readme.md +204 -0
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@tsed/testcontainers-vault",
3
+ "description": "A module to test Ts.ED code that use Vault as a secrets manager using Test Containers",
4
+ "type": "module",
5
+ "version": "8.29.0",
6
+ "source": "./src/index.ts",
7
+ "main": "./lib/esm/index.js",
8
+ "module": "./lib/esm/index.js",
9
+ "typings": "./lib/types/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "tsed-source": "./src/index.ts",
13
+ "types": "./lib/types/index.d.ts",
14
+ "import": "./lib/esm/index.js",
15
+ "default": "./lib/esm/index.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "build": "yarn build:ts",
20
+ "build:ts": "tsc --build tsconfig.esm.json"
21
+ },
22
+ "dependencies": {
23
+ "tslib": "2.8.1"
24
+ },
25
+ "devDependencies": {
26
+ "typescript": "6.0.2"
27
+ },
28
+ "peerDependencies": {},
29
+ "repository": "https://github.com/tsedio/tsed",
30
+ "bugs": {
31
+ "url": "https://github.com/tsedio/tsed/issues"
32
+ },
33
+ "homepage": "https://github.com/tsedio/tsed/tree/production/packages/testcontainers/vault",
34
+ "author": "Romain Lenzotti",
35
+ "license": "MIT"
36
+ }
package/readme.md ADDED
@@ -0,0 +1,204 @@
1
+ <p style="text-align: center" align="center">
2
+ <a href="https://tsed.dev" target="_blank"><img src="https://tsed.dev/tsed-og.png" width="200" alt="Ts.ED logo"/></a>
3
+ </p>
4
+
5
+ <div align="center">
6
+ <h1>TestContainers Vault</h1>
7
+
8
+ [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
9
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
10
+ [![github](https://img.shields.io/static/v1?label=Github%20sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/romakita)
11
+ [![opencollective](https://img.shields.io/static/v1?label=OpenCollective%20sponsor&message=%E2%9D%A4&logo=OpenCollective&color=%23fe8e86)](https://opencollective.com/tsed)
12
+
13
+ </div>
14
+
15
+ <div align="center">
16
+ <a href="https://tsed.dev/">Website</a>
17
+ <span>&nbsp;&nbsp;โ€ข&nbsp;&nbsp;</span>
18
+ <a href="https://tsed.dev/getting-started/">Getting started</a>
19
+ <span>&nbsp;&nbsp;โ€ข&nbsp;&nbsp;</span>
20
+ <a href="https://slack.tsed.dev">Slack</a>
21
+ <span>&nbsp;&nbsp;โ€ข&nbsp;&nbsp;</span>
22
+ <a href="https://twitter.com/TsED_io">Twitter</a>
23
+ </div>
24
+
25
+ <hr />
26
+
27
+ A [Ts.ED](https://tsed.dev/) package to help you easily test your code using the power
28
+ of [TestContainers](https://node.testcontainers.org/) with HashiCorp Vault.
29
+
30
+ > **Note:** This package does **not** depend on `@tsed/platform-http` and can be used with any test framework.
31
+
32
+ ---
33
+
34
+ ## โœจ Features
35
+
36
+ - ๐Ÿš€ Easily spin up a Vault server in a Docker container for your tests
37
+ - ๐Ÿ›‘ Automatically stop the Vault server after your tests
38
+ - ๐Ÿ”„ Reset the Vault server state between tests
39
+ - ๐Ÿ” Pre-configured with dev mode and root token for easy testing
40
+
41
+ ---
42
+
43
+ ## ๐Ÿ“ฆ Installation
44
+
45
+ Install the package with your favorite package manager:
46
+
47
+ ```sh npm
48
+ npm install --save-dev @tsedio/testcontainers-vault
49
+ ```
50
+
51
+ ```sh yarn
52
+ yarn add --dev @tsedio/testcontainers-vault
53
+ ```
54
+
55
+ ```sh pnpm
56
+ pnpm add --dev @tsedio/testcontainers-vault
57
+ ```
58
+
59
+ ```sh bun
60
+ bun add --dev @tsedio/testcontainers-vault
61
+ ```
62
+
63
+ ---
64
+
65
+ ## โš™๏ธ Configuration
66
+
67
+ Set up a global test lifecycle to manage your Vault container.
68
+
69
+ ### ๐Ÿงช Vitest
70
+
71
+ Add a global setup in your `vitest.config.ts`:
72
+
73
+ ```ts
74
+ import {defineConfig} from "vitest/config";
75
+
76
+ export default defineConfig({
77
+ test: {
78
+ globalSetup: [import.meta.resolve("@tsed/testcontainers-vault/vitest/setup")]
79
+ }
80
+ });
81
+ ```
82
+
83
+ ---
84
+
85
+ ### ๐Ÿงช Jest
86
+
87
+ Add `globalSetup` and `globalTeardown` to your Jest config:
88
+
89
+ ```ts
90
+ // jest.config.js
91
+ module.exports = {
92
+ globalSetup: ["jest.setup.js"],
93
+ globalTeardown: ["jest.teardown.js"]
94
+ };
95
+ ```
96
+
97
+ Create the following files:
98
+
99
+ ```ts
100
+ // jest.setup.js
101
+ import {TestContainersVault} from "@tsedio/testcontainers-vault";
102
+
103
+ module.exports = async () => {
104
+ await TestContainersVault.startContainer();
105
+ };
106
+
107
+ // jest.teardown.js
108
+ import {TestContainersVault} from "@tsedio/testcontainers-vault";
109
+
110
+ module.exports = async () => {
111
+ await TestContainersVault.stopContainer();
112
+ };
113
+ ```
114
+
115
+ ---
116
+
117
+ ## ๐Ÿ› ๏ธ Usage
118
+
119
+ Set up a Vault connection in your project like this:
120
+
121
+ ```ts
122
+ import {withOptions} from "@tsed/config";
123
+ import {VaultConfigSource} from "@tsedio/config-vault";
124
+ import {TestContainersVault} from "@tsedio/testcontainers-vault";
125
+
126
+ describe("Integration test", () => {
127
+ beforeEach(async () => {
128
+ return DITest.create({
129
+ extends: [
130
+ withOptions(VaultConfigSource, {
131
+ name: "vault",
132
+ ...TestContainersVault.getVaultOptions(),
133
+ secretPath: "secret/data/tsed-test"
134
+ })
135
+ ]
136
+ });
137
+ });
138
+
139
+ afterEach(() => DITest.reset());
140
+
141
+ it("should store and retrieve secrets", async () => {
142
+ const configs = inject<CONFIG_SOURCES>(CONFIG_SOURCES);
143
+ const instance = configs.vault as VaultConfigSource;
144
+
145
+ await instance.set("hello", "world");
146
+ const result = await instance.getAll();
147
+
148
+ expect(result).toEqual({
149
+ hello: "world"
150
+ });
151
+ });
152
+ });
153
+ ```
154
+
155
+ ---
156
+
157
+ ## ๐Ÿ’ก Tips
158
+
159
+ - ๐Ÿงน Use `TestContainersVault.reset()` to clear all secrets in the Vault server between tests.
160
+ - ๐Ÿ” The default root token is `dev-token` and the server runs in dev mode.
161
+ - ๐ŸŒ You can use `TestContainersVault.getClient()` to get a pre-configured node-vault client.
162
+
163
+ ---
164
+
165
+ ## ๐Ÿ“š Resources
166
+
167
+ - [Ts.ED Documentation](https://tsed.dev/) ๐Ÿ“–
168
+ - [TestContainers Node.js](https://node.testcontainers.org/) ๐Ÿณ
169
+ - [HashiCorp Vault](https://www.vaultproject.io/) ๐Ÿ”
170
+ - [node-vault](https://github.com/kr1sp1n/node-vault) ๐Ÿ—๏ธ
171
+
172
+ ## Contributors
173
+
174
+ <a href="https://github.com/tsedio/tsed/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
175
+
176
+ ## Backers
177
+
178
+ Thank you to all our backers! ๐Ÿ™ [[Become a backer](https://opencollective.com/tsed#backer)]
179
+
180
+ <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a>
181
+
182
+ ## Sponsors
183
+
184
+ Support this project by becoming a sponsor. Your logo will show up here with a link to your
185
+ website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
186
+
187
+ ## License
188
+
189
+ The MIT License (MIT)
190
+
191
+ Copyright (c) 2016 - Today Ts.ED
192
+
193
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
194
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
195
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
196
+ persons to whom the Software is furnished to do so, subject to the following conditions:
197
+
198
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
199
+ Software.
200
+
201
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
202
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
203
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
204
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.