File tree 2 files changed +14
-15
lines changed
2 files changed +14
-15
lines changed Original file line number Diff line number Diff line change @@ -505,17 +505,18 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
505
505
/**
506
506
* Helper function to return the default config file.
507
507
*
508
+ * @param {string } password - Password passed in (usually from generatePassword())
508
509
* @returns The default config file:
509
510
*
510
511
* - bind-addr: 127.0.0.1:8080
511
512
* - auth: password
512
- * - password: <generated- password>
513
+ * - password: <password>
513
514
* - cert: false
514
515
*/
515
- export async function defaultConfigFile ( ) : Promise < string > {
516
+ export function defaultConfigFile ( password : string ) : string {
516
517
return `bind-addr: 127.0.0.1:8080
517
518
auth: password
518
- password: ${ await generatePassword ( ) }
519
+ password: ${ password }
519
520
cert: false
520
521
`
521
522
}
@@ -540,7 +541,8 @@ export async function readConfigFile(configPath?: string): Promise<ConfigArgs> {
540
541
await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } )
541
542
542
543
try {
543
- await fs . writeFile ( configPath , await defaultConfigFile ( ) , {
544
+ const generatedPassword = await generatePassword ( )
545
+ await fs . writeFile ( configPath , defaultConfigFile ( generatedPassword ) , {
544
546
flag : "wx" , // wx means to fail if the path exists.
545
547
} )
546
548
logger . info ( `Wrote default config file to ${ humanPath ( configPath ) } ` )
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ import {
14
14
splitOnFirstEquals ,
15
15
} from "../../../src/node/cli"
16
16
import { tmpdir } from "../../../src/node/constants"
17
- import { paths } from "../../../src/node/util"
17
+ import { generatePassword , paths } from "../../../src/node/util"
18
18
import { useEnv } from "../../utils/helpers"
19
19
20
20
type Mutable < T > = {
@@ -646,15 +646,12 @@ describe("bindAddrFromArgs", () => {
646
646
647
647
describe ( "defaultConfigFile" , ( ) => {
648
648
it ( "should return the dfeault config file as a string" , async ( ) => {
649
- const actualDefaultConfigFile = await defaultConfigFile ( )
650
- // Since the password is autogenerated within the function
651
- // we can't assert it with .toMatch
652
- // but we can check that the config at least includes
653
- // these strings.
654
- const expectedStrings = [ `bind-addr: 127.0.0.1:8080` , `auth: password` , `password` , `cert: false` ]
655
-
656
- expectedStrings . forEach ( ( str ) => {
657
- expect ( actualDefaultConfigFile ) . toContain ( str )
658
- } )
649
+ const password = await generatePassword ( )
650
+ const actual = defaultConfigFile ( password )
651
+
652
+ expect ( actual ) . toMatch ( `bind-addr: 127.0.0.1:8080
653
+ auth: password
654
+ password: ${ password }
655
+ cert: false` )
659
656
} )
660
657
} )
You can’t perform that action at this time.
0 commit comments