Skip to content

Commit

Permalink
Properly implement Vultr DNS record deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed May 31, 2024
1 parent ed40eec commit c766b04
Show file tree
Hide file tree
Showing 14 changed files with 706 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ target
.jqwik-database
dependency-reduced-pom.xml
pom.xml.versionsBackup
.run
5 changes: 3 additions & 2 deletions README-CHANGES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</c:change>
</c:changes>
</c:release>
<c:release date="2024-05-28T20:38:37+00:00" is-open="true" ticket-system="com.github.io7m.certusine" version="3.1.0">
<c:release date="2024-05-31T09:18:06+00:00" is-open="true" ticket-system="com.github.io7m.certusine" version="3.1.0">
<c:changes>
<c:change date="2024-04-20T00:00:00+00:00" summary="Upgrade io.opentelemetry:opentelemetry-bom 1.36.0 → 1.37.0"/>
<c:change date="2024-04-20T00:00:00+00:00" summary="Upgrade io.opentelemetry:opentelemetry-sdk-logs 1.36.0 → 1.37.0"/>
Expand Down Expand Up @@ -101,11 +101,12 @@
<c:ticket id="50"/>
</c:tickets>
</c:change>
<c:change compatible="false" date="2024-05-28T20:38:37+00:00" summary="Gandi.net now requires Personal Access Tokens instead of API keys.">
<c:change compatible="false" date="2024-05-28T00:00:00+00:00" summary="Gandi.net now requires Personal Access Tokens instead of API keys.">
<c:tickets>
<c:ticket id="55"/>
</c:tickets>
</c:change>
<c:change date="2024-05-31T09:18:06+00:00" summary="Properly implement Vultr DNS record deletion."/>
</c:changes>
</c:release>
</c:releases>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,29 @@
import com.io7m.certusine.api.CSDNSRecordNameType.CSDNSRecordNameRelative;
import com.io7m.certusine.vultr.CSVultrDNSConfigurators;
import com.io7m.jlexing.core.LexicalPositions;
import com.io7m.quixote.core.QWebServerType;
import com.io7m.quixote.core.QWebServers;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Map;

import static com.io7m.certusine.api.CSTelemetryNoOp.noop;
import static java.util.Map.entry;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

public final class CSVultrDNSTests
{
private CSFakeVultrServer fakeServer;
private CSVultrDNSConfigurators provider;
private Path directory;
private QWebServers servers;
private QWebServerType server;

@BeforeEach
public void setup()
Expand All @@ -49,6 +55,10 @@ public void setup()
CSFakeVultrServer.create(20000);
this.provider =
new CSVultrDNSConfigurators();
this.servers =
new QWebServers();
this.server =
this.servers.create(20001);
}

@AfterEach
Expand All @@ -58,6 +68,7 @@ public void tearDown()
CSTestDirectories.deleteDirectory(this.directory);

this.fakeServer.close();
this.server.close();
}

/**
Expand Down Expand Up @@ -169,4 +180,207 @@ public void testVultrMissingRequired1()
);
});
}

/**
* If the server returns all the right responses, the execution succeeds.
*
* @throws Exception On errors
*/

@Test
public void testVultrCreateDelete()
throws Exception
{
final var v =
this.provider.create(
new CSConfigurationParameters(
this.directory,
LexicalPositions.zero(),
Map.ofEntries(
entry("api-key", "abcd"),
entry("api-base", "http://localhost:20001/"),
entry("domain", "example.com")
)
)
);

this.server.addResponse()
.forPath("/domains/.*")
.withFixedText(text("vultr-dns-records-0.json"));

this.server.addResponse()
.forPath("/domains/.*")
.withFixedText(text("vultr-dns-records-1.json"));

this.server.addResponse()
.forPath("/domains/.*")
.forMethod("DELETE")
.withStatus(204)
.withFixedText("");

this.server.addResponse()
.forPath("/domains/.*")
.forMethod("DELETE")
.withStatus(204)
.withFixedText("");

v.deleteTXTRecord(
noop(),
new CSDNSRecordNameRelative("z"), "200.200.200.201"
);

{
final var r =
this.server.requestsReceived().get(0);
assertEquals("/domains/example.com/records", r.path());
}

{
final var r =
this.server.requestsReceived().get(1);
assertEquals("/domains/example.com/records", r.path());
}

{
final var r =
this.server.requestsReceived().get(2);
assertEquals("/domains/example.com/records/ff690447-7b0d-408b-a408-fd2410281a60", r.path());
}

{
final var r =
this.server.requestsReceived().get(3);
assertEquals("/domains/example.com/records/68440bec-b17f-4532-a58b-d2b6a7e3b69c", r.path());
}
}

/**
* If the server returns errors, the execution fails.
*
* @throws Exception On errors
*/

@Test
public void testVultrCreateDeleteFails0()
throws Exception
{
final var v =
this.provider.create(
new CSConfigurationParameters(
this.directory,
LexicalPositions.zero(),
Map.ofEntries(
entry("api-key", "abcd"),
entry("api-base", "http://localhost:20001/"),
entry("domain", "example.com")
)
)
);

this.server.addResponse()
.forPath("/domains/.*")
.withFixedText(text("vultr-dns-records-0.json"));

this.server.addResponse()
.forPath("/domains/.*")
.withFixedText(text("vultr-dns-records-1.json"));

this.server.addResponse()
.forPath("/domains/.*")
.forMethod("DELETE")
.withStatus(500)
.withFixedText("");

assertThrows(IOException.class, () -> {
v.deleteTXTRecord(
noop(),
new CSDNSRecordNameRelative("z"), "200.200.200.201"
);
});

{
final var r =
this.server.requestsReceived().get(0);
assertEquals("/domains/example.com/records", r.path());
}

{
final var r =
this.server.requestsReceived().get(1);
assertEquals("/domains/example.com/records", r.path());
}

{
final var r =
this.server.requestsReceived().get(2);
assertEquals("/domains/example.com/records/ff690447-7b0d-408b-a408-fd2410281a60", r.path());
}
}

/**
* If the server returns errors, the execution fails.
*
* @throws Exception On errors
*/

@Test
public void testVultrCreateDeleteFails1()
throws Exception
{
final var v =
this.provider.create(
new CSConfigurationParameters(
this.directory,
LexicalPositions.zero(),
Map.ofEntries(
entry("api-key", "abcd"),
entry("api-base", "http://localhost:20001/"),
entry("domain", "example.com")
)
)
);

this.server.addResponse()
.forPath("/domains/.*")
.withFixedText(text("vultr-dns-records-0.json"));

this.server.addResponse()
.forPath("/domains/.*")
.withStatus(500)
.withFixedText(text("vultr-dns-records-1.json"));

assertThrows(IOException.class, () -> {
v.deleteTXTRecord(
noop(),
new CSDNSRecordNameRelative("z"), "200.200.200.201"
);
});

{
final var r =
this.server.requestsReceived().get(0);
assertEquals("/domains/example.com/records", r.path());
}

{
final var r =
this.server.requestsReceived().get(1);
assertEquals("/domains/example.com/records", r.path());
}
}

private static String text(
final String name)
throws IOException
{
try (var stream =
CSVultrDNSTests.class.getResourceAsStream(
"/com/io7m/certusine/tests/%s".formatted(name)
)) {
return new String(
stream.readAllBytes(),
StandardCharsets.UTF_8
);
}
}
}
1 change: 1 addition & 0 deletions com.io7m.certusine.tests/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
requires org.mockito;
requires org.shredzone.acme4j;
requires org.slf4j;
requires org.dnsjava;

exports com.io7m.certusine.tests;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"records": [
{
"id": "e9358824-b050-4514-a1ec-39afcff829de",
"type": "A",
"name": "x",
"data": "200.200.200.200",
"priority": 0,
"ttl": 300
},
{
"id": "b542b76c-b3c3-483b-8f34-842b854b55d7",
"type": "TXT",
"name": "y",
"data": "\"200.200.200.200\"",
"priority": 0,
"ttl": 300
},
{
"id": "c473afb8-6d68-4205-a8ca-2ca81a525c04",
"type": "TXT",
"name": "y",
"data": "\"200.200.200.201\"",
"priority": 0,
"ttl": 300
},
{
"id": "0a818032-c985-482c-b62b-ece6f622b956",
"type": "TXT",
"name": "z",
"data": "\"200.200.200.200\"",
"priority": 0,
"ttl": 300
},
{
"id": "ff690447-7b0d-408b-a408-fd2410281a60",
"type": "TXT",
"name": "z",
"data": "\"200.200.200.201\"",
"priority": 0,
"ttl": 300
}
],
"meta": {
"total": 1000,
"links": {
"next": "Token",
"prev": ""
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"records": [
{
"id": "34389b43-b8b9-4d9d-a380-449f05c501d9",
"type": "A",
"name": "x",
"data": "200.200.200.200",
"priority": 0,
"ttl": 300
},
{
"id": "68440bec-b17f-4532-a58b-d2b6a7e3b69c",
"type": "TXT",
"name": "z",
"data": "\"200.200.200.201\"",
"priority": 0,
"ttl": 300
}
],
"meta": {
"total": 1000,
"links": {
"next": "",
"prev": ""
}
}
}
13 changes: 13 additions & 0 deletions com.io7m.certusine.vultr/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.io7m.dixmont</groupId>
<artifactId>com.io7m.dixmont.core</artifactId>
</dependency>

<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.bundle</artifactId>
Expand Down
Loading

0 comments on commit c766b04

Please sign in to comment.