Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packager config mods #338

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions packager/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ import (
)

type Config struct {
LocalOnly bool
Port int
CertFile string // This must be the full certificate chain.
KeyFile string // Just for the first cert, obviously.
OCSPCache string
LocalOnly bool
Port int
CertFile string // This must be the full certificate chain.
KeyFile string // Just for the first cert, obviously.
NewCertFile string // The new full certificate chain replacing the expired one.
twifkak marked this conversation as resolved.
Show resolved Hide resolved
NewKeyFile string // For the first cert in NewCertFile.
twifkak marked this conversation as resolved.
Show resolved Hide resolved
AutoRenewCert bool // Should we auto-renew cert? Defaults to false.
twifkak marked this conversation as resolved.
Show resolved Hide resolved
OCSPCache string
ForwardedRequestHeaders []string
URLSet []URLSet
URLSet []URLSet
ACMEConfig *ACMEConfig
}

type URLSet struct {
Expand All @@ -50,6 +54,16 @@ type URLPattern struct {
SamePath *bool
}

type ACMEConfig struct {
Prod *ACMEServerConfig
Staging *ACMEServerConfig
twifkak marked this conversation as resolved.
Show resolved Hide resolved
}

type ACMEServerConfig struct {
DiscoURL string // ACME Production Directory Resource URL
AccountURL string // ACME Account URL
}

// TODO(twifkak): Extract default values into a function separate from the one
// that does the parsing and validation. This would make signer_test and
// validation_test less brittle.
Expand Down
75 changes: 75 additions & 0 deletions packager/util/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,81 @@ func TestInvalidQueryRE(t *testing.T) {
`))), "QueryRE must be a valid regexp")
}

func TestOptionalAutoRenewCertAndKey(t *testing.T) {
config, err := ReadConfig([]byte(`
CertFile = "cert.pem"
KeyFile = "key.pem"
NewCertFile = "newcert.pem"
NewKeyFile = "newkey.pem"
AutoRenewCert = false
OCSPCache = "/tmp/ocsp"
[[URLSet]]
[URLSet.Sign]
Domain = "example.com"
`))
require.NoError(t, err)
assert.Equal(t, Config{
Port: 8080,
CertFile: "cert.pem",
KeyFile: "key.pem",
NewCertFile: "newcert.pem",
AutoRenewCert: false,
NewKeyFile: "newkey.pem",
OCSPCache: "/tmp/ocsp",
URLSet: []URLSet{{
Sign: &URLPattern{
Domain: "example.com",
PathRE: stringPtr(".*"),
QueryRE: stringPtr(""),
MaxLength: 2000,
},
}},
}, *config)
}

func TestOptionalACMEConfig(t *testing.T) {
config, err := ReadConfig([]byte(`
CertFile = "cert.pem"
KeyFile = "key.pem"
OCSPCache = "/tmp/ocsp"
[[URLSet]]
[URLSet.Sign]
Domain = "example.com"
[ACMEConfig]
[ACMEConfig.Prod]
DiscoURL = "prod.disco.url"
AccountURL = "prod.account.url"
[ACMEConfig.Staging]
DiscoURL = "staging.disco.url"
AccountURL = "staging.account.url"
`))
require.NoError(t, err)
assert.Equal(t, Config{
Port: 8080,
CertFile: "cert.pem",
KeyFile: "key.pem",
OCSPCache: "/tmp/ocsp",
ACMEConfig: &ACMEConfig{
Prod: &ACMEServerConfig{
DiscoURL: "prod.disco.url",
AccountURL: "prod.account.url",
},
Staging: &ACMEServerConfig{
DiscoURL: "staging.disco.url",
AccountURL: "staging.account.url",
},
},
URLSet: []URLSet{{
Sign: &URLPattern{
Domain: "example.com",
PathRE: stringPtr(".*"),
QueryRE: stringPtr(""),
MaxLength: 2000,
},
}},
}, *config)
}

func TestSignMissing(t *testing.T) {
msg := errorFrom(ReadConfig([]byte(`
CertFile = "cert.pem"
Expand Down