-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpcserver: Adds ability to allow alternative dns names for TLS.
- rpcserver: Adds ability to allow alternative dns names for TLS. - Adds AltDNSNames config for passing additional hostnames to the TLS certificate generate method. Without this change there is no way to pass in alternative dns names for the rpc server. - Additionally this commit allows the user to set 'DCRD_ALT_DNSNAMES' as an environment variable when starting dcrd. This is useful for docker and other app runtimes that require apps to be 12 factor.
- Loading branch information
1 parent
8c588a6
commit ea54d03
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2018 The Decred developers | ||
// Use of this source code is governed by an ISC | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// in order to test command line arguments and environment variables | ||
// you will need to append the flags to the os.Args variable like so | ||
// os.Args = append(os.Args, "--altdnsnames=\"hostname1,hostname2\"") | ||
// For environment variables you can use the | ||
// os.Setenv("DCRD_ALT_DNSNAMES", "hostname1,hostname2") to set the variable | ||
// before loadConfig() is called | ||
// These args and env variables will then get parsed by loadConfig() | ||
|
||
func setup() { | ||
// Temp config file is used to ensure there are no external influences | ||
// from previously set env variables or default config files. | ||
file, _ := ioutil.TempFile("", "dcrd_test_file.cfg") | ||
defer os.Remove(file.Name()) | ||
|
||
// Parse the -test.* flags before removing them from the command line | ||
// arguments list, which we do to allow go-flags to succeed. | ||
flag.Parse() | ||
os.Args = os.Args[:1] | ||
} | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
_, _, err := loadConfig() | ||
if err != nil { | ||
t.Errorf("Failed to load dcrd config: %s\n", err.Error()) | ||
} | ||
} | ||
|
||
func TestDefaultAltDNSNames(t *testing.T) { | ||
cfg, _, _ := loadConfig() | ||
if len(cfg.AltDNSNames) != 0 { | ||
t.Errorf("Invalid default value for altdnsnames: %s\n", cfg.AltDNSNames) | ||
} | ||
} | ||
|
||
func TestAltDNSNamesWithEnv(t *testing.T) { | ||
os.Setenv("DCRD_ALT_DNSNAMES", "hostname1,hostname2") | ||
cfg, _, _ := loadConfig() | ||
hostnames := strings.Join(cfg.AltDNSNames, ",") | ||
if hostnames != "hostname1,hostname2" { | ||
t.Errorf("altDNSNames should be %s but was %s", "hostname1,hostname2", hostnames) | ||
} | ||
} | ||
|
||
func TestAltDNSNamesWithArg(t *testing.T) { | ||
setup() | ||
old := os.Args | ||
os.Args = append(os.Args, "--altdnsnames=\"hostname1,hostname2\"") | ||
cfg, _, _ := loadConfig() | ||
hostnames := strings.Join(cfg.AltDNSNames, ",") | ||
if hostnames != "hostname1,hostname2" { | ||
t.Errorf("altDNSNames should be %s but was %s", "hostname1,hostname2", hostnames) | ||
} | ||
os.Args = old | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters