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

fix(tls/subscription): Add support for Certainly CA. #1315

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions pkg/commands/tls/subscription/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const emptyString = ""

var certAuth = []string{"lets-encrypt", "globalsign"}
var certAuth = []string{"certainly", "lets-encrypt", "globalsign"}

// NewCreateCommand returns a usable command registered under the parent.
func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateCommand {
Expand All @@ -24,7 +24,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
c.CmdClause.Flag("domain", "Domain(s) to add to the TLS certificates generated for the subscription (set flag once per domain)").Required().StringsVar(&c.domains)

// Optional.
c.CmdClause.Flag("cert-auth", "The entity that issues and certifies the TLS certificates for your subscription. Valid values are lets-encrypt or globalsign").HintOptions(certAuth...).EnumVar(&c.certAuth, certAuth...)
c.CmdClause.Flag("cert-auth", "The entity that issues and certifies the TLS certificates for your subscription. Valid values are certainly, lets-encrypt, and globalsign").HintOptions(certAuth...).EnumVar(&c.certAuth, certAuth...)
c.CmdClause.Flag("common-name", "The domain name associated with the subscription. Default to the first domain specified by --domain").StringVar(&c.commonName)
c.CmdClause.Flag("config", "Alphanumeric string identifying a TLS configuration").StringVar(&c.config)

Expand Down
56 changes: 56 additions & 0 deletions pkg/commands/tls/subscription/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,62 @@ func TestTLSSubscriptionCreate(t *testing.T) {
Args: "--domain example.com",
WantOutput: fmt.Sprintf("Created TLS Subscription '%s' (Authority: %s, Common Name: example.com)", mockResponseID, certificateAuthority),
},
{
Name: "validate cert-auth == certainly",
API: mock.API{
CreateTLSSubscriptionFn: func(i *fastly.CreateTLSSubscriptionInput) (*fastly.TLSSubscription, error) {
return &fastly.TLSSubscription{
ID: mockResponseID,
CertificateAuthority: i.CertificateAuthority,
CommonName: i.Domains[0],
}, nil
},
},
Args: "--domain example.com --cert-auth certainly",
WantOutput: fmt.Sprintf("Created TLS Subscription '%s' (Authority: certainly, Common Name: example.com)", mockResponseID),
},
{
Name: "validate cert-auth == lets-encrypt",
API: mock.API{
CreateTLSSubscriptionFn: func(i *fastly.CreateTLSSubscriptionInput) (*fastly.TLSSubscription, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be refactored into a function, but I'll leave that for our future team members who will be working on improving the test suite.

return &fastly.TLSSubscription{
ID: mockResponseID,
CertificateAuthority: i.CertificateAuthority,
CommonName: i.Domains[0],
}, nil
},
},
Args: "--domain example.com --cert-auth lets-encrypt",
WantOutput: fmt.Sprintf("Created TLS Subscription '%s' (Authority: lets-encrypt, Common Name: example.com)", mockResponseID),
},
{
Name: "validate cert-auth == globalsign",
API: mock.API{
CreateTLSSubscriptionFn: func(i *fastly.CreateTLSSubscriptionInput) (*fastly.TLSSubscription, error) {
return &fastly.TLSSubscription{
ID: mockResponseID,
CertificateAuthority: i.CertificateAuthority,
CommonName: i.Domains[0],
}, nil
},
},
Args: "--domain example.com --cert-auth globalsign",
WantOutput: fmt.Sprintf("Created TLS Subscription '%s' (Authority: globalsign, Common Name: example.com)", mockResponseID),
},
{
Name: "validate cert-auth is invalid",
API: mock.API{
CreateTLSSubscriptionFn: func(i *fastly.CreateTLSSubscriptionInput) (*fastly.TLSSubscription, error) {
return &fastly.TLSSubscription{
ID: mockResponseID,
CertificateAuthority: i.CertificateAuthority,
CommonName: i.Domains[0],
}, nil
},
},
Args: "--domain example.com --cert-auth not-valid",
WantError: "enum value must be one of certainly,lets-encrypt,globalsign",
},
}

testutil.RunCLIScenarios(t, []string{root.CommandName, "create"}, scenarios)
Expand Down