Apply suggestions from code review

Co-authored-by: Julien Neuhart <j.neuhart@thecodingmachine.com>
This commit is contained in:
tomjvdberg
2020-06-08 08:31:57 +02:00
committed by GitHub
parent 1e6926ee2d
commit 4d46b98e7f
6 changed files with 39 additions and 39 deletions

View File

@@ -40,8 +40,9 @@ const (
// DefaultGoogleChromeRpccBufferSizeEnvVar contains the name
// of the environment variable "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE".
DefaultGoogleChromeRpccBufferSizeEnvVar string = "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE"
// Allow self signed certificates when using a remote url
URLIgnoreCertificateErrorsEnvVar string = "URL_IGNORE_CERTIFICATE_ERRORS"
// GoogleChromeIgnoreCertificateErrorsEnvVar contains the name
// of the environment variable "GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS".
GoogleChromeIgnoreCertificateErrorsEnvVar string = "GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS"
)
// Config contains the application
@@ -55,7 +56,7 @@ type Config struct {
defaultListenPort int64
disableGoogleChrome bool
disableUnoconv bool
urlIgnoreCertificateErrors bool
googleChromeIgnoreCertificateErrors bool
logLevel xlog.Level
rootPath string
maximumGoogleChromeRpccBufferSize int64
@@ -78,7 +79,7 @@ func DefaultConfig() Config {
rootPath: "/",
maximumGoogleChromeRpccBufferSize: 104857600, // ~100 MB
defaultGoogleChromeRpccBufferSize: 1048576, // 1 MB
urlIgnoreCertificateErrors: false,
googleChromeIgnoreCertificateErrors: false,
}
}
@@ -192,11 +193,11 @@ func FromEnv() (Config, error) {
if err != nil {
return c, err
}
urlIgnoreCertificateErrors, err := xassert.BoolFromEnv(
URLIgnoreCertificateErrorsEnvVar,
c.urlIgnoreCertificateErrors,
googleChromeIgnoreCertificateErrors, err := xassert.BoolFromEnv(
GoogleChromeIgnoreCertificateErrorsEnvVar,
c.googleChromeIgnoreCertificateErrors,
)
c.urlIgnoreCertificateErrors = urlIgnoreCertificateErrors
c.googleChromeIgnoreCertificateErrors = googleChromeIgnoreCertificateErrors
if err != nil {
return c, err
}
@@ -287,9 +288,6 @@ func (c Config) DefaultGoogleChromeRpccBufferSize() int64 {
return c.defaultGoogleChromeRpccBufferSize
}
// IgnoreCertificateErrors returns true if
// Google Chrome should ignore certificate errors
// in case of self signed certificates for example.
func (c Config) IgnoreCertificateErrors() bool {
func (c Config) GoogleChromeIgnoreCertificateErrors() bool {
return c.urlIgnoreCertificateErrors
}

View File

@@ -380,38 +380,38 @@ func TestDefaultGoogleChromeRpccBufferSizeFromEnv(t *testing.T) {
os.Unsetenv(DefaultGoogleChromeRpccBufferSizeEnvVar)
}
func TestIgnoreCertificateErrorsFromEnv(t *testing.T) {
func TestGoogleChromeIgnoreCertificateErrorsFromEnv(t *testing.T) {
var (
expected Config
result Config
err error
)
// URL_IGNORE_CERTIFICATE_ERRORS correctly set to true.
os.Setenv(URLIgnoreCertificateErrorsEnvVar, "1")
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS correctly set to true.
os.Setenv(GoogleChromeIgnoreCertificateErrorsEnvVar, "1")
expected = DefaultConfig()
expected.urlIgnoreCertificateErrors = true
expected.googleChromeIgnoreCertificateErrors = true
result, err = FromEnv()
assert.Nil(t, err)
assert.Equal(t, expected, result)
os.Unsetenv(URLIgnoreCertificateErrorsEnvVar)
// URL_IGNORE_CERTIFICATE_ERRORS correctly set to false.
os.Setenv(URLIgnoreCertificateErrorsEnvVar, "0")
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS correctly set to false.
os.Setenv(GooleChromeIgnoreCertificateErrorsEnvVar, "0")
expected = DefaultConfig()
expected.urlIgnoreCertificateErrors = false
expected.googleChromeIgnoreCertificateErrors = false
result, err = FromEnv()
assert.Nil(t, err)
assert.Equal(t, expected, result)
os.Unsetenv(URLIgnoreCertificateErrorsEnvVar)
// URL_IGNORE_CERTIFICATE_ERRORS wrongly set.
os.Setenv(URLIgnoreCertificateErrorsEnvVar, "foo")
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS wrongly set.
os.Setenv(GoogleChromeIgnoreCertificateErrorsEnvVar, "foo")
expected = DefaultConfig()
result, err = FromEnv()
test.AssertError(t, err)
assert.Equal(t, expected, result)
os.Unsetenv(URLIgnoreCertificateErrorsEnvVar)
// URL_IGNORE_CERTIFICATE_ERRORS not set at all.
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS not set at all.
expected = DefaultConfig()
expected.urlIgnoreCertificateErrors = false
expected.googleChromeIgnoreCertificateErrors = false
result, err = FromEnv()
assert.Nil(t, err)
assert.Equal(t, expected, result)
@@ -431,5 +431,5 @@ func TestGetters(t *testing.T) {
assert.Equal(t, result.rootPath, result.RootPath())
assert.Equal(t, result.maximumGoogleChromeRpccBufferSize, result.MaximumGoogleChromeRpccBufferSize())
assert.Equal(t, result.defaultGoogleChromeRpccBufferSize, result.DefaultGoogleChromeRpccBufferSize())
assert.Equal(t, result.urlIgnoreCertificateErrors, result.IgnoreCertificateErrors())
assert.Equal(t, result.googleChromeIgnoreCertificateErrors, result.GoogleChromeIgnoreCertificateErrors())
}