FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScriptSolidServer/test/config.test.js at patchAppend · bourgeoa/JavaScriptSolidServer · GitHub
bourgeoa
JavaScriptSolidServer
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScriptSolidServer
/
test
/
config.test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
66 lines (58 loc) · 2.53 KB
Breadcrumbs
JavaScriptSolidServer
/
test
/
config.test.js
Copy path
File metadata and controls
66 lines (58 loc) · 2.53 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* Config / env-var parsing tests.
*
* Regression coverage for the env-coercion fix in #323: only known
* boolean keys may have their string values coerced to booleans.
* Otherwise an env var like JSS_SINGLE_USER_PASSWORD="true" would silently
* become a real boolean and break downstream code (bcrypt, etc.).
*/
import
{
describe
,
it
,
before
,
after
}
from
'node:test'
;
import
assert
from
'node:assert'
;
import
{
loadConfig
}
from
'../src/config.js'
;
describe
(
'config — env var boolean coercion'
,
(
)
=>
{
// Save/restore the env vars we touch so this test is hermetic.
const
KEYS
=
[
'JSS_SINGLE_USER_PASSWORD'
,
'JSS_IDP'
,
'JSS_BASE_DOMAIN'
,
'JSS_MULTIUSER'
]
;
const
original
=
{
}
;
before
(
(
)
=>
{
for
(
const
k
of
KEYS
)
original
[
k
]
=
process
.
env
[
k
]
;
}
)
;
after
(
(
)
=>
{
for
(
const
k
of
KEYS
)
{
if
(
original
[
k
]
===
undefined
)
delete
process
.
env
[
k
]
;
else
process
.
env
[
k
]
=
original
[
k
]
;
}
}
)
;
it
(
'preserves string-valued env vars when their value is "true"'
,
async
(
)
=>
{
process
.
env
.
JSS_SINGLE_USER_PASSWORD
=
'true'
;
const
cfg
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg
.
singleUserPassword
,
'true'
,
'password env var must remain a string, not be coerced to boolean true'
)
;
}
)
;
it
(
'preserves string-valued env vars when their value is "false"'
,
async
(
)
=>
{
process
.
env
.
JSS_SINGLE_USER_PASSWORD
=
'false'
;
const
cfg
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg
.
singleUserPassword
,
'false'
)
;
}
)
;
it
(
'preserves string-valued env vars when set to other strings'
,
async
(
)
=>
{
process
.
env
.
JSS_BASE_DOMAIN
=
'example.com'
;
const
cfg
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg
.
baseDomain
,
'example.com'
)
;
}
)
;
it
(
'still coerces known boolean keys'
,
async
(
)
=>
{
process
.
env
.
JSS_IDP
=
'true'
;
const
cfg
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg
.
idp
,
true
,
'idp env var should be coerced to boolean'
)
;
}
)
;
it
(
'still coerces known boolean keys when "false"'
,
async
(
)
=>
{
process
.
env
.
JSS_IDP
=
'false'
;
const
cfg
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg
.
idp
,
false
)
;
}
)
;
it
(
'coerces JSS_MULTIUSER to a boolean (regression for missed entry)'
,
async
(
)
=>
{
process
.
env
.
JSS_MULTIUSER
=
'false'
;
const
cfg
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg
.
multiuser
,
false
,
'multiuser must coerce to boolean false, not the string "false" (truthy)'
)
;
process
.
env
.
JSS_MULTIUSER
=
'true'
;
const
cfg2
=
await
loadConfig
(
{
}
,
null
)
;
assert
.
strictEqual
(
cfg2
.
multiuser
,
true
)
;
}
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL