@testcontainers/vault 11.3.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 - 2025 Cristian Greco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Testcontainers
2
+
3
+ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=116414510&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=EastUs)
4
+
5
+ [![Test](https://github.com/testcontainers/testcontainers-node/actions/workflows/checks.yml/badge.svg?branch=main)](https://github.com/testcontainers/testcontainers-node/actions/workflows/checks.yml)
6
+ [![npm version](https://badge.fury.io/js/testcontainers.svg)](https://www.npmjs.com/package/testcontainers)
7
+ [![npm version](https://img.shields.io/npm/dm/testcontainers.svg)](https://www.npmjs.com/package/testcontainers)
8
+
9
+ ![Testcontainers Banner](https://github.com/testcontainers/testcontainers-node/raw/main/docs/site/logo.png)
10
+
11
+ ## [📖 Documentation](https://node.testcontainers.org/)
12
+
13
+ ## License
14
+
15
+ See [LICENSE](https://github.com/testcontainers/testcontainers-node/blob/main/LICENSE).
16
+
17
+ ## Copyright
18
+
19
+ Copyright (c) 2018 - 2025 Cristian Greco and other authors.
20
+
21
+ ## Contributing
22
+
23
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute to this repo.
24
+
25
+ See [contributors](https://github.com/testcontainers/testcontainers-node/graphs/contributors/) for all contributors.
26
+
27
+ ---
28
+
29
+ Join our [Slack workspace](https://slack.testcontainers.org/) | [Testcontainers OSS](https://java.testcontainers.org/) | [Testcontainers Cloud](https://www.testcontainers.cloud/)
@@ -0,0 +1 @@
1
+ export { StartedVaultContainer, VaultContainer } from "./vault-container";
package/build/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VaultContainer = exports.StartedVaultContainer = void 0;
4
+ var vault_container_1 = require("./vault-container");
5
+ Object.defineProperty(exports, "StartedVaultContainer", { enumerable: true, get: function () { return vault_container_1.StartedVaultContainer; } });
6
+ Object.defineProperty(exports, "VaultContainer", { enumerable: true, get: function () { return vault_container_1.VaultContainer; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAA0E;AAAjE,wHAAA,qBAAqB,OAAA;AAAE,iHAAA,cAAc,OAAA"}
@@ -0,0 +1,80 @@
1
+ import { AbstractStartedContainer, GenericContainer } from "testcontainers";
2
+ /**
3
+ * Testcontainers module for HashiCorp Vault.
4
+ *
5
+ * This container exposes Vault on port 8200, sets up a wait strategy using the health check endpoint, and supports:
6
+ * - Supplying a root token
7
+ * - Executing post-start CLI init commands
8
+ */
9
+ export declare class VaultContainer extends GenericContainer {
10
+ private readonly initCommands;
11
+ private token?;
12
+ /**
13
+ * Constructs a VaultContainer with a default image and healthcheck strategy.
14
+ *
15
+ * - Sets VAULT_ADDR to internal container address
16
+ * - Adds IPC_LOCK capability (required by Vault)
17
+ * - Exposes Vault on port 8200
18
+ * - Waits for HTTP 200 response from /v1/sys/health
19
+ * @param image Docker image to use (e.g. `hashicorp/vault:1.13.0`)
20
+ */
21
+ constructor(image: string);
22
+ /**
23
+ * Sets a root token to be used with Vault, passed via environment variables.
24
+ *
25
+ * @param token Vault root token
26
+ * @returns this
27
+ */
28
+ withVaultToken(token: string): this;
29
+ /**
30
+ * Registers one or more Vault CLI init commands to be run after container starts.
31
+ *
32
+ * Example:
33
+ * .withInitCommands("secrets enable transit", "kv put secret/foo bar=baz")
34
+ *
35
+ * @param commands Vault CLI commands (without `vault` prefix)
36
+ * @returns this
37
+ */
38
+ withInitCommands(...commands: string[]): this;
39
+ /**
40
+ * Starts the Vault container and executes any registered init commands.
41
+ *
42
+ * Wraps the base container in a StartedVaultContainer with helper accessors.
43
+ */
44
+ start(): Promise<StartedVaultContainer>;
45
+ }
46
+ /**
47
+ * A running Vault container, with accessors for port, address, and exec helper.
48
+ */
49
+ export declare class StartedVaultContainer extends AbstractStartedContainer {
50
+ private readonly token?;
51
+ constructor(startedTestContainer: AbstractStartedContainer["startedTestContainer"], token?: string | undefined);
52
+ /**
53
+ * Returns the mapped host port for Vault (default: 8200).
54
+ */
55
+ getVaultPort(): number;
56
+ /**
57
+ * Returns the full Vault HTTP address (e.g., http://localhost:32768).
58
+ */
59
+ getAddress(): string;
60
+ /**
61
+ * Returns the root token set at container creation time, if any.
62
+ */
63
+ getRootToken(): string | undefined;
64
+ /**
65
+ * Executes Vault CLI commands inside the container after it has started.
66
+ *
67
+ * This is typically used to pre-configure secret engines or seed test data.
68
+ *
69
+ * @example
70
+ * await container.execVaultCommands([
71
+ * "secrets enable transit",
72
+ * "write -f transit/keys/my-key",
73
+ * "kv put secret/my-secret value=123",
74
+ * ]);
75
+ *
76
+ * @param commands Array of Vault CLI commands (without the `vault` prefix)
77
+ * @throws If the command fails (non-zero exit code)
78
+ */
79
+ execVaultCommands(commands: string[]): Promise<void>;
80
+ }
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StartedVaultContainer = exports.VaultContainer = void 0;
4
+ const testcontainers_1 = require("testcontainers");
5
+ const VAULT_PORT = 8200;
6
+ /**
7
+ * Testcontainers module for HashiCorp Vault.
8
+ *
9
+ * This container exposes Vault on port 8200, sets up a wait strategy using the health check endpoint, and supports:
10
+ * - Supplying a root token
11
+ * - Executing post-start CLI init commands
12
+ */
13
+ class VaultContainer extends testcontainers_1.GenericContainer {
14
+ initCommands = [];
15
+ token;
16
+ /**
17
+ * Constructs a VaultContainer with a default image and healthcheck strategy.
18
+ *
19
+ * - Sets VAULT_ADDR to internal container address
20
+ * - Adds IPC_LOCK capability (required by Vault)
21
+ * - Exposes Vault on port 8200
22
+ * - Waits for HTTP 200 response from /v1/sys/health
23
+ * @param image Docker image to use (e.g. `hashicorp/vault:1.13.0`)
24
+ */
25
+ constructor(image) {
26
+ super(image);
27
+ this.withExposedPorts(VAULT_PORT)
28
+ .withEnvironment({ VAULT_ADDR: `http://0.0.0.0:${VAULT_PORT}` })
29
+ .withAddedCapabilities("IPC_LOCK")
30
+ .withWaitStrategy(testcontainers_1.Wait.forHttp("/v1/sys/health", VAULT_PORT).forStatusCode(200));
31
+ }
32
+ /**
33
+ * Sets a root token to be used with Vault, passed via environment variables.
34
+ *
35
+ * @param token Vault root token
36
+ * @returns this
37
+ */
38
+ withVaultToken(token) {
39
+ this.token = token;
40
+ this.withEnvironment({
41
+ VAULT_DEV_ROOT_TOKEN_ID: token,
42
+ VAULT_TOKEN: token,
43
+ });
44
+ return this;
45
+ }
46
+ /**
47
+ * Registers one or more Vault CLI init commands to be run after container starts.
48
+ *
49
+ * Example:
50
+ * .withInitCommands("secrets enable transit", "kv put secret/foo bar=baz")
51
+ *
52
+ * @param commands Vault CLI commands (without `vault` prefix)
53
+ * @returns this
54
+ */
55
+ withInitCommands(...commands) {
56
+ this.initCommands.push(...commands);
57
+ return this;
58
+ }
59
+ /**
60
+ * Starts the Vault container and executes any registered init commands.
61
+ *
62
+ * Wraps the base container in a StartedVaultContainer with helper accessors.
63
+ */
64
+ async start() {
65
+ const started = await super.start();
66
+ const container = new StartedVaultContainer(started, this.token);
67
+ if (this.initCommands.length > 0) {
68
+ await container.execVaultCommands(this.initCommands);
69
+ }
70
+ return container;
71
+ }
72
+ }
73
+ exports.VaultContainer = VaultContainer;
74
+ /**
75
+ * A running Vault container, with accessors for port, address, and exec helper.
76
+ */
77
+ class StartedVaultContainer extends testcontainers_1.AbstractStartedContainer {
78
+ token;
79
+ constructor(startedTestContainer, token) {
80
+ super(startedTestContainer);
81
+ this.token = token;
82
+ }
83
+ /**
84
+ * Returns the mapped host port for Vault (default: 8200).
85
+ */
86
+ getVaultPort() {
87
+ return this.getMappedPort(VAULT_PORT);
88
+ }
89
+ /**
90
+ * Returns the full Vault HTTP address (e.g., http://localhost:32768).
91
+ */
92
+ getAddress() {
93
+ return `http://${this.getHost()}:${this.getVaultPort()}`;
94
+ }
95
+ /**
96
+ * Returns the root token set at container creation time, if any.
97
+ */
98
+ getRootToken() {
99
+ return this.token;
100
+ }
101
+ /**
102
+ * Executes Vault CLI commands inside the container after it has started.
103
+ *
104
+ * This is typically used to pre-configure secret engines or seed test data.
105
+ *
106
+ * @example
107
+ * await container.execVaultCommands([
108
+ * "secrets enable transit",
109
+ * "write -f transit/keys/my-key",
110
+ * "kv put secret/my-secret value=123",
111
+ * ]);
112
+ *
113
+ * @param commands Array of Vault CLI commands (without the `vault` prefix)
114
+ * @throws If the command fails (non-zero exit code)
115
+ */
116
+ async execVaultCommands(commands) {
117
+ const cmd = commands.map((c) => `vault ${c}`).join(" && ");
118
+ const result = await this.exec(["/bin/sh", "-c", cmd]);
119
+ if (result.exitCode !== 0) {
120
+ throw new Error(`execVaultCommands failed with exit code ${result.exitCode}: ${result.output}`);
121
+ }
122
+ }
123
+ }
124
+ exports.StartedVaultContainer = StartedVaultContainer;
125
+ //# sourceMappingURL=vault-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vault-container.js","sourceRoot":"","sources":["../src/vault-container.ts"],"names":[],"mappings":";;;AAAA,mDAAkF;AAElF,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;;;;;GAMG;AACH,MAAa,cAAe,SAAQ,iCAAgB;IACjC,YAAY,GAAa,EAAE,CAAC;IACrC,KAAK,CAAU;IAEvB;;;;;;;;OAQG;IACH,YAAY,KAAa;QACvB,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC;aAC9B,eAAe,CAAC,EAAE,UAAU,EAAE,kBAAkB,UAAU,EAAE,EAAE,CAAC;aAC/D,qBAAqB,CAAC,UAAU,CAAC;aACjC,gBAAgB,CAAC,qBAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;IACrF,CAAC;IAED;;;;;OAKG;IACI,cAAc,CAAC,KAAa;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,eAAe,CAAC;YACnB,uBAAuB,EAAE,KAAK;YAC9B,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACI,gBAAgB,CAAC,GAAG,QAAkB;QAC3C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACa,KAAK,CAAC,KAAK;QACzB,MAAM,OAAO,GAAG,MAAM,KAAK,C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;QAClG,CAAC;IACH,CAAC;CACF;AApDD,sDAoDC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@testcontainers/vault",
3
+ "version": "11.3.0",
4
+ "license": "MIT",
5
+ "keywords": [
6
+ "vault",
7
+ "hashicorp",
8
+ "testing",
9
+ "docker",
10
+ "testcontainers"
11
+ ],
12
+ "description": "HashiCorp Vault module for Testcontainers",
13
+ "homepage": "https://github.com/testcontainers/testcontainers-node#readme",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/testcontainers/testcontainers-node"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/testcontainers/testcontainers-node/issues"
20
+ },
21
+ "main": "build/index.js",
22
+ "files": [
23
+ "build"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "scripts": {
29
+ "prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
30
+ "build": "tsc --project tsconfig.build.json"
31
+ },
32
+ "devDependencies": {
33
+ "node-vault": "^0.10.5"
34
+ },
35
+ "dependencies": {
36
+ "testcontainers": "^11.3.0"
37
+ }
38
+ }