Skip to content

Commit

Permalink
Add failing test demonstrating need for DOTENV_KEY option
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Jun 16, 2023
1 parent 4f48954 commit 5861f6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ console.log(myObject) // values from .env or .env.vault live here now.
console.log(process.env) // this was not changed or written to
```

##### DOTENV_KEY

Default: `process.env.DOTENV_KEY`

Pass the `DOTENV_KEY` directly to config options. Defaults to looking for `process.env.DOTENV_KEY` environment variable. Note this only applies to decrypting `.env.vault` files. If passed as null or undefined, or not passed at all, dotenv falls back to its traditional job of parsing a `.env` file.

```js
require('dotenv').config({ DOTENV_KEY: 'dotenv://:key_1234…@dotenv.org/vault/.env.vault?environment=production' })
```

### Parse

The engine which parses the contents of your file containing environment
Expand Down
14 changes: 14 additions & 0 deletions tests/test-config-vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,20 @@ t.test('when DOTENV_KEY is empty string falls back to .env file', ct => {
ct.end()
})

t.test('when DOTENV_KEY is passed as an option it successfully decrypts and injects', ct => {
envStub.restore()
envStub = sinon.stub(process.env, 'DOTENV_KEY').value('')

ct.plan(1)

const result = dotenv.config({ path: testPath, DOTENV_KEY: dotenvKey })

ct.equal(result.parsed.ALPHA, 'zeta')
ct.equal(process.env.ALPHA, 'bar')

ct.end()
})

t.test('does not write over keys already in process.env by default', ct => {
ct.plan(2)

Expand Down

0 comments on commit 5861f6a

Please sign in to comment.