Skip to content

Commit 1bd96cb

Browse files
committed
fix(core): send complete Cloudflare validation payload
1 parent cd98471 commit 1bd96cb

2 files changed

Lines changed: 35 additions & 13 deletions

File tree

be/apps/core/src/modules/infrastructure/cloudflare/cloudflare-custom-hostname.service.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,32 @@ describe('cloudflareCustomHostnameService', () => {
5858
expect(request.headers).toMatchObject({ authorization: 'Bearer test-token' })
5959
expect(JSON.parse(String(request.body))).toEqual({
6060
hostname: 'photos.example.com',
61-
ssl: { method: 'http', settings: { min_tls_version: '1.2' } },
61+
ssl: { method: 'http', type: 'dv', settings: { min_tls_version: '1.2' } },
62+
})
63+
})
64+
65+
it('retries domain validation with a complete domain-validation SSL payload', async () => {
66+
fetchMock.mockResolvedValueOnce(
67+
cloudflareResponse(
68+
{
69+
id: 'hostname-id',
70+
hostname: 'photos.example.com',
71+
status: 'active',
72+
ssl: { method: 'http', status: 'active' },
73+
},
74+
{ status: 202 },
75+
),
76+
)
77+
78+
await service.retryValidation('hostname-id')
79+
80+
const [url, request] = fetchMock.mock.calls[0] as [string, RequestInit]
81+
expect(url).toBe(
82+
'https://api.cloudflare.com/client/v4/zones/0123456789abcdef0123456789abcdef/custom_hostnames/hostname-id',
83+
)
84+
expect(request.method).toBe('PATCH')
85+
expect(JSON.parse(String(request.body))).toEqual({
86+
ssl: { method: 'http', type: 'dv', settings: { min_tls_version: '1.2' } },
6287
})
6388
})
6489

be/apps/core/src/modules/infrastructure/cloudflare/cloudflare-custom-hostname.service.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import { injectable } from 'tsyringe'
66
const CLOUDFLARE_API_BASE_URL = 'https://api.cloudflare.com/client/v4'
77
const HTTP_PROTOCOL_PATTERN = /^https?:\/\//
88
const TRAILING_DOT_PATTERN = /\.$/
9+
const CUSTOM_HOSTNAME_SSL_CONFIG = {
10+
method: 'http',
11+
type: 'dv',
12+
settings: {
13+
min_tls_version: '1.2',
14+
},
15+
} as const
916

1017
interface CloudflareApiError {
1118
code?: number
@@ -48,12 +55,7 @@ export class CloudflareCustomHostnameService {
4855
method: 'POST',
4956
body: {
5057
hostname,
51-
ssl: {
52-
method: 'http',
53-
settings: {
54-
min_tls_version: '1.2',
55-
},
56-
},
58+
ssl: CUSTOM_HOSTNAME_SSL_CONFIG,
5759
},
5860
})
5961
}
@@ -87,12 +89,7 @@ export class CloudflareCustomHostnameService {
8789
return await this.request<CloudflareCustomHostname>(`/custom_hostnames/${customHostnameId}`, {
8890
method: 'PATCH',
8991
body: {
90-
ssl: {
91-
method: 'http',
92-
settings: {
93-
min_tls_version: '1.2',
94-
},
95-
},
92+
ssl: CUSTOM_HOSTNAME_SSL_CONFIG,
9693
},
9794
})
9895
}

0 commit comments

Comments
 (0)