Skip to content

Commit

Permalink
Merge pull request cloudflare#732 from jakemalachowski/custom-origin-sni
Browse files Browse the repository at this point in the history
Add Custom Origin SNI field to Custom Hostname API Model
  • Loading branch information
jacobbednarz authored Oct 28, 2021
2 parents a8018d2 + e553ac7 commit ea24204
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
68 changes: 68 additions & 0 deletions custom_hostname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit ea24204

Please sign in to comment.