Skip to content

Commit be4a5da

Browse files
mitc-gjugeclaude
andcommitted
fix(dns): match apex records stored under any apex spelling
toSource always writes the apex as ".", but listRecords already accepted "" and "@" as apex spellings on read. The upsert lookup compared sources strictly, so a record stored under one of the other spellings would not have matched and the upsert would have created a duplicate apex record instead of updating it. Normalize the candidate's source before comparing, so read and match agree. Reported by Greptile on Dokploy#5257. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 2bc22c5 commit be4a5da

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎apps/dokploy/__test__/dns/infomaniak.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,29 @@ describe("infomaniakClient.upsertRecord", () => {
213213
expect(lastBody().source).toBe(".");
214214
});
215215

216+
it.each([".", "", "@"])(
217+
"matches an existing apex record stored with a %s source",
218+
async (source) => {
219+
mockFetch
220+
.mockResolvedValueOnce(
221+
ikSuccess([
222+
{ id: 8, type: "A", source, target: "1.1.1.1", ttl: 3600 },
223+
]),
224+
)
225+
.mockResolvedValueOnce(ikSuccess({ id: 8 }));
226+
227+
const result = await infomaniakClient.upsertRecord(config, {
228+
zoneId: "example.com",
229+
type: "A",
230+
name: "example.com",
231+
content: "1.2.3.4",
232+
});
233+
234+
expect(result).toEqual({ id: "8" });
235+
expect(lastCall()[1].method).toBe("PUT");
236+
},
237+
);
238+
216239
it("matches the existing apex record instead of creating a duplicate", async () => {
217240
mockFetch
218241
.mockResolvedValueOnce(

‎packages/server/src/utils/dns/infomaniak.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ const toSource = (name: string, zone: string) => {
7171
const toFqdn = (source: string, zone: string) =>
7272
APEX_SOURCES.has(source) ? zone : `${source}.${zone}`;
7373

74+
// toSource always writes the apex as ".", so an existing record stored under one
75+
// of the other apex spellings has to normalize to the same thing before it can
76+
// be matched.
77+
const normalizeSource = (source: string) =>
78+
APEX_SOURCES.has(source) ? "." : source;
79+
7480
// TXT targets are stored quoted; keep Dokploy's view of them unquoted so that
7581
// editing a record does not stack a new pair of quotes on every save.
7682
const unquoteTarget = (target: string) => {
@@ -146,7 +152,8 @@ export const infomaniakClient: DnsClient<InfomaniakConfig> = {
146152
const existing = await listZoneRecords(config, record.zoneId);
147153
const match = existing.find(
148154
(candidate) =>
149-
candidate.type === record.type && candidate.source === source,
155+
candidate.type === record.type &&
156+
normalizeSource(candidate.source) === source,
150157
);
151158

152159
const body = JSON.stringify(recordPayload(record, record.zoneId));

0 commit comments

Comments
 (0)