From e553ac7395e6a643a903fedb9cc2c7137be39367 Mon Sep 17 00:00:00 2001 From: Jake Malachowski Date: Thu, 28 Oct 2021 16:19:28 -0700 Subject: [PATCH] add custom origin sni field to custom hostname struct --- custom_hostname.go | 1 + custom_hostname_test.go | 68 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/custom_hostname.go b/custom_hostname.go index bb5112acb1..80ae218645 100644 --- a/custom_hostname.go +++ b/custom_hostname.go @@ -76,6 +76,7 @@ type CustomHostname struct { ID string `json:"id,omitempty"` Hostname string `json:"hostname,omitempty"` CustomOriginServer string `json:"custom_origin_server,omitempty"` + CustomOriginSNI string `json:"custom_origin_sni,omitempty"` SSL *CustomHostnameSSL `json:"ssl,omitempty"` CustomMetadata CustomMetadata `json:"custom_metadata,omitempty"` Status CustomHostnameStatus `json:"status,omitempty"` diff --git a/custom_hostname_test.go b/custom_hostname_test.go index 51da7476e1..d62d6783d7 100644 --- a/custom_hostname_test.go +++ b/custom_hostname_test.go @@ -326,6 +326,74 @@ func TestCustomHostname_CreateCustomHostname_No_SSL(t *testing.T) { } } +func TestCustomHostname_CreateCustomHostname_CustomOriginSNI(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/zones/foo/custom_hostnames", func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method) + + w.Header().Set("content-type", "application/json") + w.WriteHeader(http.StatusCreated) + fmt.Fprintf(w, ` +{ + "success": true, + "errors": [], + "messages": [], + "result": { + "id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9", + "hostname": "app.example.com", + "custom_origin_server": "example.app.com", + "custom_origin_sni": "app.example.com", + "status": "pending", + "verification_errors": [ + "None of the A or AAAA records are owned by this account and the pre-generated ownership verification token was not found." + ], + "ownership_verification": { + "type": "txt", + "name": "_cf-custom-hostname.app.example.com", + "value": "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0" + }, + "ownership_verification_http": { + "http_url": "http://app.example.com/.well-known/cf-custom-hostname-challenge/37c82d20-99fb-490e-ba0a-489fa483b776", + "http_body": "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0" + }, + "created_at": "2020-02-06T18:11:23.531995Z" + } +}`) + }) + + response, err := client.CreateCustomHostname(context.Background(), "foo", CustomHostname{Hostname: "app.example.com", CustomOriginSNI: "app.example.com"}) + + createdAt, _ := time.Parse(time.RFC3339, "2020-02-06T18:11:23.531995Z") + + want := &CustomHostnameResponse{ + Result: CustomHostname{ + ID: "0d89c70d-ad9f-4843-b99f-6cc0252067e9", + Hostname: "app.example.com", + CustomOriginServer: "example.app.com", + CustomOriginSNI: "app.example.com", + Status: "pending", + VerificationErrors: []string{"None of the A or AAAA records are owned by this account and the pre-generated ownership verification token was not found."}, + OwnershipVerification: CustomHostnameOwnershipVerification{ + Type: "txt", + Name: "_cf-custom-hostname.app.example.com", + Value: "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0", + }, + OwnershipVerificationHTTP: CustomHostnameOwnershipVerificationHTTP{ + HTTPUrl: "http://app.example.com/.well-known/cf-custom-hostname-challenge/37c82d20-99fb-490e-ba0a-489fa483b776", + HTTPBody: "38ddbedc-6cc3-4a4c-af67-9c5b02344ce0", + }, + CreatedAt: &createdAt, + }, + Response: Response{Success: true, Errors: []ResponseInfo{}, Messages: []ResponseInfo{}}, + } + + if assert.NoError(t, err) { + assert.Equal(t, want, response) + } +} + func TestCustomHostname_CustomHostnames(t *testing.T) { setup() defer teardown()