-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: option to set CSR emails (#2423)
- Loading branch information
Showing
4 changed files
with
131 additions
and
42 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 |
---|---|---|
|
@@ -33,63 +33,83 @@ func TestGenerateCSR(t *testing.T) { | |
testCases := []struct { | ||
desc string | ||
privateKey crypto.PrivateKey | ||
domain string | ||
san []string | ||
mustStaple bool | ||
opts CSROptions | ||
expected expected | ||
}{ | ||
{ | ||
desc: "without SAN (nil)", | ||
privateKey: privateKey, | ||
domain: "lego.acme", | ||
mustStaple: true, | ||
expected: expected{len: 245}, | ||
opts: CSROptions{ | ||
Domain: "lego.acme", | ||
MustStaple: true, | ||
}, | ||
expected: expected{len: 245}, | ||
}, | ||
{ | ||
desc: "without SAN (empty)", | ||
privateKey: privateKey, | ||
domain: "lego.acme", | ||
san: []string{}, | ||
mustStaple: true, | ||
expected: expected{len: 245}, | ||
opts: CSROptions{ | ||
Domain: "lego.acme", | ||
SAN: []string{}, | ||
MustStaple: true, | ||
}, | ||
expected: expected{len: 245}, | ||
}, | ||
{ | ||
desc: "with SAN", | ||
privateKey: privateKey, | ||
domain: "lego.acme", | ||
san: []string{"a.lego.acme", "b.lego.acme", "c.lego.acme"}, | ||
mustStaple: true, | ||
expected: expected{len: 296}, | ||
opts: CSROptions{ | ||
Domain: "lego.acme", | ||
SAN: []string{"a.lego.acme", "b.lego.acme", "c.lego.acme"}, | ||
MustStaple: true, | ||
}, | ||
expected: expected{len: 296}, | ||
}, | ||
{ | ||
desc: "no domain", | ||
privateKey: privateKey, | ||
domain: "", | ||
mustStaple: true, | ||
expected: expected{len: 225}, | ||
opts: CSROptions{ | ||
Domain: "", | ||
MustStaple: true, | ||
}, | ||
expected: expected{len: 225}, | ||
}, | ||
{ | ||
desc: "no domain with SAN", | ||
privateKey: privateKey, | ||
domain: "", | ||
san: []string{"a.lego.acme", "b.lego.acme", "c.lego.acme"}, | ||
mustStaple: true, | ||
expected: expected{len: 276}, | ||
opts: CSROptions{ | ||
Domain: "", | ||
SAN: []string{"a.lego.acme", "b.lego.acme", "c.lego.acme"}, | ||
MustStaple: true, | ||
}, | ||
expected: expected{len: 276}, | ||
}, | ||
{ | ||
desc: "private key nil", | ||
privateKey: nil, | ||
domain: "fizz.buzz", | ||
mustStaple: true, | ||
expected: expected{error: true}, | ||
opts: CSROptions{ | ||
Domain: "fizz.buzz", | ||
MustStaple: true, | ||
}, | ||
expected: expected{error: true}, | ||
}, | ||
{ | ||
desc: "with email addresses", | ||
privateKey: privateKey, | ||
opts: CSROptions{ | ||
Domain: "example.com", | ||
SAN: []string{"example.org"}, | ||
EmailAddresses: []string{"[email protected]", "[email protected]"}, | ||
}, | ||
expected: expected{len: 287}, | ||
}, | ||
} | ||
|
||
for _, test := range testCases { | ||
t.Run(test.desc, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
csr, err := GenerateCSR(test.privateKey, test.domain, test.san, test.mustStaple) | ||
csr, err := CreateCSR(test.privateKey, test.opts) | ||
|
||
if test.expected.error { | ||
require.Error(t, err) | ||
|
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 |
---|---|---|
|
@@ -297,6 +297,45 @@ func TestChallengeHTTP_Client_Obtain_profile(t *testing.T) { | |
assert.Empty(t, resource.CSR) | ||
} | ||
|
||
func TestChallengeHTTP_Client_Obtain_emails_csr(t *testing.T) { | ||
err := os.Setenv("LEGO_CA_CERTIFICATES", "./fixtures/certs/pebble.minica.pem") | ||
require.NoError(t, err) | ||
defer func() { _ = os.Unsetenv("LEGO_CA_CERTIFICATES") }() | ||
|
||
privateKey, err := rsa.GenerateKey(rand.Reader, 2048) | ||
require.NoError(t, err, "Could not generate test key") | ||
|
||
user := &fakeUser{privateKey: privateKey} | ||
config := lego.NewConfig(user) | ||
config.CADirURL = load.PebbleOptions.HealthCheckURL | ||
|
||
client, err := lego.NewClient(config) | ||
require.NoError(t, err) | ||
|
||
err = client.Challenge.SetHTTP01Provider(http01.NewProviderServer("", "5002")) | ||
require.NoError(t, err) | ||
|
||
reg, err := client.Registration.Register(registration.RegisterOptions{TermsOfServiceAgreed: true}) | ||
require.NoError(t, err) | ||
user.registration = reg | ||
|
||
request := certificate.ObtainRequest{ | ||
Domains: []string{"acme.wtf"}, | ||
Bundle: true, | ||
EmailAddresses: []string{"[email protected]"}, | ||
} | ||
resource, err := client.Certificate.Obtain(request) | ||
require.NoError(t, err) | ||
|
||
require.NotNil(t, resource) | ||
assert.Equal(t, "acme.wtf", resource.Domain) | ||
assert.Regexp(t, `https://localhost:14000/certZ/[\w\d]{14,}`, resource.CertURL) | ||
assert.Regexp(t, `https://localhost:14000/certZ/[\w\d]{14,}`, resource.CertStableURL) | ||
assert.NotEmpty(t, resource.Certificate) | ||
assert.NotEmpty(t, resource.IssuerCertificate) | ||
assert.Empty(t, resource.CSR) | ||
} | ||
|
||
func TestChallengeHTTP_Client_Obtain_notBefore_notAfter(t *testing.T) { | ||
err := os.Setenv("LEGO_CA_CERTIFICATES", "./fixtures/certs/pebble.minica.pem") | ||
require.NoError(t, err) | ||
|