Compare commits
26
Commits
cb3303dab0
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e06aa67c24 | ||
|
|
2031aa93e6 | ||
|
|
3f28774944 | ||
|
|
0ddc6b29ce | ||
|
|
b95d9bc5a0 | ||
|
|
980942fac5 | ||
|
|
6dd9a477e5 | ||
|
|
50d8d385f7 | ||
|
|
9de0eaf850 | ||
|
|
d09b5cb98b | ||
|
|
02dee0f720 | ||
|
|
b35517afa7 | ||
|
|
8e4d8ef427 | ||
|
|
1ddc1ce832 | ||
|
|
5488a92c2d | ||
|
|
330f665b97 | ||
|
|
c02ce68df5 | ||
|
|
1a37d308e3 | ||
|
|
a7292153e2 | ||
|
|
848453c04e | ||
|
|
0d78e39a70 | ||
|
|
d802edf6ee | ||
|
|
ff4adb5c4d | ||
|
|
4a3859e17c | ||
|
|
ad641c1573 | ||
|
|
37321c6f9a |
No files matched your search
@@ -7,6 +7,7 @@ on:
|
|||||||
- 'feature/**'
|
- 'feature/**'
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [ opened, synchronize, reopened ]
|
types: [ opened, synchronize, reopened ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ CfDnsClient cfDnsClient = new CfDnsClientBuilder()
|
|||||||
```java
|
```java
|
||||||
CfDnsClient cfDnsClient = new CfDnsClientBuilder()
|
CfDnsClient cfDnsClient = new CfDnsClientBuilder()
|
||||||
.withApiTokenAuth("your-api-token")
|
.withApiTokenAuth("your-api-token")
|
||||||
.withBaseUrl("https://custom-api.example.com/client/v4") // must use HTTPS
|
.withBaseUrl("https://api.cloudflare.com/client/v4") // HTTPS required;
|
||||||
.withConnectTimeout(Duration.ofSeconds(5)) // default: 10 s
|
.withConnectTimeout(Duration.ofSeconds(5)) // default: 10 s
|
||||||
.withResponseTimeout(Duration.ofSeconds(15)) // default: 30 s
|
.withResponseTimeout(Duration.ofSeconds(15)) // default: 30 s
|
||||||
.withEmptyResultThrowsException(true) // default: false
|
.withEmptyResultThrowsException(true) // default: false
|
||||||
|
|||||||
+3
-2
@@ -1,6 +1,6 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
- 0.6.0-SNAPSHOT:
|
- 1.0.0:
|
||||||
- **Breaking Changes**:
|
- **Breaking Changes**:
|
||||||
- `recordList` overloads replaced, because they were ambiguous (e.g. `recordList(zone, null)` didn't compile):
|
- `recordList` overloads replaced, because they were ambiguous (e.g. `recordList(zone, null)` didn't compile):
|
||||||
- `recordList(zone, String subdomain, RecordType... types)` and `recordList(zone, String subdomain)` → `recordListBySubdomain(zone, subdomain, types...)`
|
- `recordList(zone, String subdomain, RecordType... types)` and `recordList(zone, String subdomain)` → `recordListBySubdomain(zone, subdomain, types...)`
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
- `CfDnsClient#recordCreateSld(...)` was removed; use `recordCreateSubdomain(...)`
|
- `CfDnsClient#recordCreateSld(...)` was removed; use `recordCreateSubdomain(...)`
|
||||||
- `PagingRequest` is now an immutable record with `page()` and `perPage()` accessors. The setters and `getPagingParams()` were removed; use `forRecords(...)`, `forZones(...)`, `next()` and `withPage(...)` instead.
|
- `PagingRequest` is now an immutable record with `page()` and `perPage()` accessors. The setters and `getPagingParams()` were removed; use `forRecords(...)`, `forZones(...)`, `next()` and `withPage(...)` instead.
|
||||||
- `PagingRequest.defaultPaging()` now requests 50 items instead of 1,000. Page numbers and page sizes are validated; zone requests accept 5–50 items per page, while DNS record requests accept 1–5,000,000.
|
- `PagingRequest.defaultPaging()` now requests 50 items instead of 1,000. Page numbers and page sizes are validated; zone requests accept 5–50 items per page, while DNS record requests accept 1–5,000,000.
|
||||||
- `withBaseUrl` only accepts HTTPS URLs (plain HTTP only for loopback hosts like `localhost`), otherwise an `IllegalArgumentException` is thrown
|
- `withBaseUrl` only accepts HTTPS URLs, otherwise an `IllegalArgumentException` is thrown
|
||||||
- `build()` throws an `IllegalStateException` if no authentication was configured, `null` credentials throw an `IllegalArgumentException`
|
- `build()` throws an `IllegalStateException` if no authentication was configured, `null` credentials throw an `IllegalArgumentException`
|
||||||
- zone names and subdomains with whitespace, control characters or `\ ? # & ; | < > " ' `` ` `` are rejected with an `IllegalArgumentException`, zone and record IDs must be alphanumeric
|
- zone names and subdomains with whitespace, control characters or `\ ? # & ; | < > " ' `` ` `` are rejected with an `IllegalArgumentException`, zone and record IDs must be alphanumeric
|
||||||
- timestamps of `RecordEntity` and `ZoneEntity` (`createdOn`, `modifiedOn`, `activatedOn`) are of type `java.time.Instant` instead of `LocalDateTime`, so the time zone (UTC) isn't lost anymore
|
- timestamps of `RecordEntity` and `ZoneEntity` (`createdOn`, `modifiedOn`, `activatedOn`) are of type `java.time.Instant` instead of `LocalDateTime`, so the time zone (UTC) isn't lost anymore
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
- unexpected runtime exceptions aren't wrapped into a `CloudflareApiException("Unexpected error!")` anymore
|
- unexpected runtime exceptions aren't wrapped into a `CloudflareApiException("Unexpected error!")` anymore
|
||||||
- batch DELETE sends only the record IDs, batch PATCH sends all writable attributes which aren't `null` (before: only the content)
|
- batch DELETE sends only the record IDs, batch PATCH sends all writable attributes which aren't `null` (before: only the content)
|
||||||
- security: query values (zone names, subdomains) are URL-encoded and IDs are validated, which prevents query parameter injection and path traversal
|
- security: query values (zone names, subdomains) are URL-encoded and IDs are validated, which prevents query parameter injection and path traversal
|
||||||
|
- Unicode subdomains are converted to Punycode before requests are sent
|
||||||
- connect and response timeouts (defaults: 10 s / 30 s), configurable via `withConnectTimeout` / `withResponseTimeout`
|
- connect and response timeouts (defaults: 10 s / 30 s), configurable via `withConnectTimeout` / `withResponseTimeout`
|
||||||
- `CfDnsClient` uses one shared HTTP client with connection pooling instead of a new one per request and implements `AutoCloseable`, call `close()` to release the connections
|
- `CfDnsClient` uses one shared HTTP client with connection pooling instead of a new one per request and implements `AutoCloseable`, call `close()` to release the connections
|
||||||
- `CloudflareApiException` provides the HTTP status code (`getStatusCode()`) and the errors reported by Cloudflare (`getErrors()`)
|
- `CloudflareApiException` provides the HTTP status code (`getStatusCode()`) and the errors reported by Cloudflare (`getErrors()`)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>codes.thischwa</groupId>
|
<groupId>codes.thischwa</groupId>
|
||||||
<artifactId>cloudflaredns</artifactId>
|
<artifactId>cloudflaredns</artifactId>
|
||||||
<version>0.6.0-SNAPSHOT</version>
|
<version>1.0.0</version>
|
||||||
<name>CloudflareDNS-java</name>
|
<name>CloudflareDNS-java</name>
|
||||||
<inceptionYear>2025</inceptionYear>
|
<inceptionYear>2025</inceptionYear>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@@ -51,7 +51,7 @@
|
|||||||
<developerConnection>scm:git:https://git.mein-gateway.de/thischwa/CloudflareDNS-java.git</developerConnection>
|
<developerConnection>scm:git:https://git.mein-gateway.de/thischwa/CloudflareDNS-java.git</developerConnection>
|
||||||
<connection>scm:git:https://git.mein-gateway.de/thischwa/CloudflareDNS-java.git</connection>
|
<connection>scm:git:https://git.mein-gateway.de/thischwa/CloudflareDNS-java.git</connection>
|
||||||
<url>https://git.mein-gateway.de/thischwa/CloudflareDNS-java</url>
|
<url>https://git.mein-gateway.de/thischwa/CloudflareDNS-java</url>
|
||||||
<tag>HEAD</tag>
|
<tag>v1.0.0</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|||||||
+13
-7
@@ -1,25 +1,25 @@
|
|||||||
# Test Report
|
# Test Report
|
||||||
|
|
||||||
_Generated on 2026-11-07 13:00:45 UTC_
|
_Generated on 2026-11-16 18:29:19 UTC_
|
||||||
|
|
||||||
**❌ Some tests failed**
|
**✅ All tests passed**
|
||||||
|
|
||||||
## Test Results
|
## Test Results
|
||||||
|
|
||||||
| | Tests | Passed | Failed | Skipped |
|
| | Tests | Passed | Failed | Skipped |
|
||||||
|---|---|---|---|---|
|
|---|---|---|---|---|
|
||||||
| **Total** | 164 | 162 | 2 | 0 |
|
| **Total** | 165 | 165 | 0 | 0 |
|
||||||
|
|
||||||
### Details
|
### Details
|
||||||
|
|
||||||
| Status | Suite | Tests | Passed | Failed | Skipped |
|
| Status | Suite | Tests | Passed | Failed | Skipped |
|
||||||
|---|---|---|---|---|---|
|
|---|---|---|---|---|---|
|
||||||
| ✅ | codes.thischwa.cf.CfBasicHttpClientErrorTest | 7 | 7 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.CfBasicHttpClientErrorTest | 6 | 6 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.CfBasicHttpClientTest | 9 | 9 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.CfBasicHttpClientTest | 9 | 9 | 0 | 0 |
|
||||||
|
| ✅ | codes.thischwa.cf.CfClientIntegrationTest | 19 | 19 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.CfClientPenTest | 4 | 4 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.CfClientPenTest | 4 | 4 | 0 | 0 |
|
||||||
| ❌ | codes.thischwa.cf.CfClientTest | 18 | 16 | 2 | 0 |
|
|
||||||
| ✅ | codes.thischwa.cf.CfDnsClientBuilderTest | 21 | 21 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.CfDnsClientBuilderTest | 21 | 21 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.CfDnsClientMockTest | 41 | 41 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.CfDnsClientMockTest | 42 | 42 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.CfRequestTest | 10 | 10 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.CfRequestTest | 10 | 10 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.ObjectMapperTest | 4 | 4 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.ObjectMapperTest | 4 | 4 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.ResponseValidatorTest | 11 | 11 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.ResponseValidatorTest | 11 | 11 | 0 | 0 |
|
||||||
@@ -30,4 +30,10 @@ _Generated on 2026-11-07 13:00:45 UTC_
|
|||||||
| ✅ | codes.thischwa.cf.model.RecordTypeTest | 3 | 3 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.model.RecordTypeTest | 3 | 3 | 0 | 0 |
|
||||||
| ✅ | codes.thischwa.cf.model.ZoneEntityTest | 1 | 1 | 0 | 0 |
|
| ✅ | codes.thischwa.cf.model.ZoneEntityTest | 1 | 1 | 0 | 0 |
|
||||||
|
|
||||||
_No JaCoCo report found._
|
## Coverage
|
||||||
|
|
||||||
|
| Package | Line Coverage | Branch Coverage |
|
||||||
|
|---|---|---|
|
||||||
|
| codes.thischwa.cf.fluent | 100% (23/23) | 100% (4/4) |
|
||||||
|
| codes.thischwa.cf.model | 100% (102/102) | 96% (23/24) |
|
||||||
|
| codes.thischwa.cf | 97% (441/454) | 88% (189/214) |
|
||||||
@@ -15,6 +15,7 @@ import codes.thischwa.cf.model.ResponseEntity;
|
|||||||
import codes.thischwa.cf.model.ResultInfo;
|
import codes.thischwa.cf.model.ResultInfo;
|
||||||
import codes.thischwa.cf.model.ZoneEntity;
|
import codes.thischwa.cf.model.ZoneEntity;
|
||||||
import codes.thischwa.cf.model.ZoneMultipleResponse;
|
import codes.thischwa.cf.model.ZoneMultipleResponse;
|
||||||
|
import java.net.IDN;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -76,11 +77,11 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* .build();
|
* .build();
|
||||||
* </code></pre>
|
* </code></pre>
|
||||||
*
|
*
|
||||||
* <p>Example with custom base URL:
|
* <p>Example specifying the Cloudflare API base URL:
|
||||||
* <pre><code>
|
* <pre><code>
|
||||||
* CfDnsClient cfDnsClient = new CfDnsClientBuilder()
|
* CfDnsClient cfDnsClient = new CfDnsClientBuilder()
|
||||||
* .withApiTokenAuth("your-api-token")
|
* .withApiTokenAuth("your-api-token")
|
||||||
* .withBaseUrl("https://custom-api.example.com")
|
* .withBaseUrl(CfDnsClientBuilder.DEFAULT_BASEURL)
|
||||||
* .build();
|
* .build();
|
||||||
* </code></pre>
|
* </code></pre>
|
||||||
*/
|
*/
|
||||||
@@ -176,7 +177,17 @@ public class CfDnsClient extends CfBasicHttpClient {
|
|||||||
if (APEX.equals(subdomain)) {
|
if (APEX.equals(subdomain)) {
|
||||||
return zone.getName();
|
return zone.getName();
|
||||||
}
|
}
|
||||||
return subdomain + "." + zone.getName();
|
String asciiSubdomain = subdomain;
|
||||||
|
if (!subdomain.chars().allMatch(character -> character <= 0x7f)) {
|
||||||
|
try {
|
||||||
|
// IDN implements IDNA2003 (Unicode 3.2), newer code points (e.g. emojis) must be allowed
|
||||||
|
asciiSubdomain = IDN.toASCII(subdomain, IDN.ALLOW_UNASSIGNED);
|
||||||
|
} catch (IllegalArgumentException exception) {
|
||||||
|
throw new IllegalArgumentException("Invalid internationalized subdomain: " + subdomain,
|
||||||
|
exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return asciiSubdomain + "." + zone.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -318,15 +329,17 @@ public class CfDnsClient extends CfBasicHttpClient {
|
|||||||
* Optionally, filters by one or more DNS record types.
|
* Optionally, filters by one or more DNS record types.
|
||||||
*
|
*
|
||||||
* @param zone The zone entity containing information about the domain zone.
|
* @param zone The zone entity containing information about the domain zone.
|
||||||
* @param subdomain The subdomain relative to the zone (e.g. "www" for "www.example.com"),
|
* @param subdomain The subdomain relative to the zone (e.g. "www" for "www.example.com");
|
||||||
* or {@link #APEX} for the zone apex.
|
* Unicode subdomains are converted to Punycode. {@link #APEX} indicates the
|
||||||
|
* zone apex.
|
||||||
* @param types Optional DNS record types to filter the results. If none are given, records of
|
* @param types Optional DNS record types to filter the results. If none are given, records of
|
||||||
* all types are returned.
|
* all types are returned.
|
||||||
* @return A list of {@code RecordEntity} objects representing the DNS records for the specified domain.
|
* @return A list of {@code RecordEntity} objects representing the DNS records for the specified domain.
|
||||||
* @throws CloudflareNotFoundException if no records were found and 'emptyResultThrowsException'
|
* @throws CloudflareNotFoundException if no records were found and 'emptyResultThrowsException'
|
||||||
* is enabled
|
* is enabled
|
||||||
* @throws CloudflareApiException if an error occurs while interacting with the Cloudflare API
|
* @throws CloudflareApiException if an error occurs while interacting with the Cloudflare API
|
||||||
* @throws IllegalArgumentException if the subdomain is blank or contains invalid characters
|
* @throws IllegalArgumentException if the subdomain is blank, contains invalid characters or
|
||||||
|
* cannot be converted to Punycode
|
||||||
*/
|
*/
|
||||||
public List<RecordEntity> recordListBySubdomain(ZoneEntity zone, String subdomain,
|
public List<RecordEntity> recordListBySubdomain(ZoneEntity zone, String subdomain,
|
||||||
@Nullable RecordType... types)
|
@Nullable RecordType... types)
|
||||||
@@ -361,8 +374,9 @@ public class CfDnsClient extends CfBasicHttpClient {
|
|||||||
* Creates a new DNS record for a given subdomain within the specified zone.
|
* Creates a new DNS record for a given subdomain within the specified zone.
|
||||||
*
|
*
|
||||||
* @param zone The ZoneEntity representing the DNS zone where the record is to be created.
|
* @param zone The ZoneEntity representing the DNS zone where the record is to be created.
|
||||||
* @param subdomain The subdomain relative to the zone (e.g. "api" for "api.example.com"),
|
* @param subdomain The subdomain relative to the zone (e.g. "api" for "api.example.com");
|
||||||
* or {@link #APEX} for the zone apex.
|
* Unicode subdomains are converted to Punycode. {@link #APEX} indicates the
|
||||||
|
* zone apex.
|
||||||
* @param ttl The time-to-live (TTL) value for the DNS record in seconds.
|
* @param ttl The time-to-live (TTL) value for the DNS record in seconds.
|
||||||
* @param type The RecordType specifying the type of the DNS record (e.g., A, AAAA, CNAME).
|
* @param type The RecordType specifying the type of the DNS record (e.g., A, AAAA, CNAME).
|
||||||
* @param content The content of the DNS record (e.g., IP address for A/AAAA records, target
|
* @param content The content of the DNS record (e.g., IP address for A/AAAA records, target
|
||||||
@@ -370,7 +384,8 @@ public class CfDnsClient extends CfBasicHttpClient {
|
|||||||
* @return The created RecordEntity object containing details of the newly created DNS record.
|
* @return The created RecordEntity object containing details of the newly created DNS record.
|
||||||
* @throws CloudflareApiException If an error occurs while communicating with the Cloudflare API
|
* @throws CloudflareApiException If an error occurs while communicating with the Cloudflare API
|
||||||
* or creating the record.
|
* or creating the record.
|
||||||
* @throws IllegalArgumentException if the subdomain is blank or contains invalid characters
|
* @throws IllegalArgumentException if the subdomain is blank, contains invalid characters or
|
||||||
|
* cannot be converted to Punycode
|
||||||
*/
|
*/
|
||||||
public RecordEntity recordCreateSubdomain(ZoneEntity zone, String subdomain, int ttl, RecordType type,
|
public RecordEntity recordCreateSubdomain(ZoneEntity zone, String subdomain, int ttl, RecordType type,
|
||||||
String content) throws CloudflareApiException {
|
String content) throws CloudflareApiException {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package codes.thischwa.cf;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
|
||||||
import org.apache.hc.core5.http.ClassicHttpRequest;
|
import org.apache.hc.core5.http.ClassicHttpRequest;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@@ -29,11 +28,6 @@ public class CfDnsClientBuilder {
|
|||||||
*/
|
*/
|
||||||
public static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofSeconds(30);
|
public static final Duration DEFAULT_RESPONSE_TIMEOUT = Duration.ofSeconds(30);
|
||||||
|
|
||||||
/**
|
|
||||||
* Hosts for which plain HTTP is allowed (e.g. for local tests).
|
|
||||||
*/
|
|
||||||
private static final Set<String> LOOPBACK_HOSTS = Set.of("localhost", "127.0.0.1", "[::1]", "::1");
|
|
||||||
|
|
||||||
private boolean emptyResultThrowsException;
|
private boolean emptyResultThrowsException;
|
||||||
private CfAuth auth;
|
private CfAuth auth;
|
||||||
private Duration connectTimeout = DEFAULT_CONNECT_TIMEOUT;
|
private Duration connectTimeout = DEFAULT_CONNECT_TIMEOUT;
|
||||||
@@ -62,13 +56,14 @@ public class CfDnsClientBuilder {
|
|||||||
* Sets the base URL to be used by the {@code CfDnsClient}.
|
* Sets the base URL to be used by the {@code CfDnsClient}.
|
||||||
* This method allows configuring the base URL for API requests, overriding any default value.
|
* This method allows configuring the base URL for API requests, overriding any default value.
|
||||||
*
|
*
|
||||||
* <p>To protect the credentials, the URL must use HTTPS. Plain HTTP is only allowed for
|
* <p>Only HTTPS URLs with a host are accepted. User information, query parameters and fragments
|
||||||
* loopback hosts (e.g. {@code localhost}) for testing purposes.
|
* are not permitted. Credentials are sent to the configured host, so only use trusted URLs.
|
||||||
*
|
*
|
||||||
* @param baseUrl the base URL to be used for API requests, {@code null} resets it to
|
* @param baseUrl the base URL to be used for API requests, {@code null} resets it to
|
||||||
* {@link #DEFAULT_BASEURL}
|
* {@link #DEFAULT_BASEURL}
|
||||||
* @return the current instance of {@code CfDnsClientBuilder}, enabling method chaining
|
* @return the current instance of {@code CfDnsClientBuilder}, enabling method chaining
|
||||||
* @throws IllegalArgumentException if the URL is invalid or doesn't use HTTPS
|
* @throws IllegalArgumentException if the URL is invalid, doesn't use HTTPS, has no host or
|
||||||
|
* contains user information, a query or a fragment
|
||||||
*/
|
*/
|
||||||
public CfDnsClientBuilder withBaseUrl(@Nullable String baseUrl) {
|
public CfDnsClientBuilder withBaseUrl(@Nullable String baseUrl) {
|
||||||
this.baseUrl = baseUrl == null ? null : validateBaseUrl(baseUrl);
|
this.baseUrl = baseUrl == null ? null : validateBaseUrl(baseUrl);
|
||||||
@@ -124,7 +119,6 @@ public class CfDnsClientBuilder {
|
|||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
throw new IllegalArgumentException("Invalid base URL: " + baseUrl, e);
|
throw new IllegalArgumentException("Invalid base URL: " + baseUrl, e);
|
||||||
}
|
}
|
||||||
String scheme = uri.getScheme() == null ? "" : uri.getScheme().toLowerCase(Locale.ROOT);
|
|
||||||
String host = uri.getHost();
|
String host = uri.getHost();
|
||||||
if (host == null || host.isBlank()) {
|
if (host == null || host.isBlank()) {
|
||||||
throw new IllegalArgumentException("Base URL must contain a host: " + baseUrl);
|
throw new IllegalArgumentException("Base URL must contain a host: " + baseUrl);
|
||||||
@@ -132,9 +126,11 @@ public class CfDnsClientBuilder {
|
|||||||
if (uri.getRawQuery() != null || uri.getRawFragment() != null) {
|
if (uri.getRawQuery() != null || uri.getRawFragment() != null) {
|
||||||
throw new IllegalArgumentException("Base URL must not contain a query or fragment: " + baseUrl);
|
throw new IllegalArgumentException("Base URL must not contain a query or fragment: " + baseUrl);
|
||||||
}
|
}
|
||||||
boolean https = "https".equals(scheme);
|
if (uri.getRawUserInfo() != null) {
|
||||||
boolean loopbackHttp = "http".equals(scheme) && LOOPBACK_HOSTS.contains(host.toLowerCase(Locale.ROOT));
|
throw new IllegalArgumentException("Base URL must not contain user information: " + baseUrl);
|
||||||
if (!https && !loopbackHttp) {
|
}
|
||||||
|
String scheme = uri.getScheme() == null ? "" : uri.getScheme().toLowerCase(Locale.ROOT);
|
||||||
|
if (!"https".equals(scheme)) {
|
||||||
throw new IllegalArgumentException("Base URL must use HTTPS: " + baseUrl);
|
throw new IllegalArgumentException("Base URL must use HTTPS: " + baseUrl);
|
||||||
}
|
}
|
||||||
String normalized = uri.toString();
|
String normalized = uri.toString();
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ public interface ZoneOperations {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Selects a record with specific types within the zone for further operations.
|
* Selects a record with specific types within the zone for further operations.
|
||||||
* <p>
|
* <p>The type filter does not restrict a subsequent {@link RecordOperations#delete(RecordType...)} call;
|
||||||
* The type filter does not restrict a subsequent {@link RecordOperations#delete(RecordType...)} call;
|
|
||||||
* that method uses its own type arguments, and calling it without arguments deletes all record types
|
* that method uses its own type arguments, and calling it without arguments deletes all record types
|
||||||
* for the selected subdomain. A {@link CloudflareApiException} from an individual deletion is
|
* for the selected subdomain. A {@link CloudflareApiException} from an individual deletion is
|
||||||
* logged and does not stop later attempts; see {@link RecordOperations#delete(RecordType...)}.
|
* logged and does not stop later attempts; see {@link RecordOperations#delete(RecordType...)}.
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ class CfBasicHttpClientErrorTest {
|
|||||||
private final AtomicInteger requestCount = new AtomicInteger();
|
private final AtomicInteger requestCount = new AtomicInteger();
|
||||||
private volatile int status;
|
private volatile int status;
|
||||||
private volatile String body;
|
private volatile String body;
|
||||||
private volatile String lastPath;
|
|
||||||
private volatile long delayMillis;
|
private volatile long delayMillis;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
@@ -43,7 +42,6 @@ class CfBasicHttpClientErrorTest {
|
|||||||
server = HttpServer.create(new InetSocketAddress("localhost", 0), 0);
|
server = HttpServer.create(new InetSocketAddress("localhost", 0), 0);
|
||||||
server.createContext("/", exchange -> {
|
server.createContext("/", exchange -> {
|
||||||
requestCount.incrementAndGet();
|
requestCount.incrementAndGet();
|
||||||
lastPath = exchange.getRequestURI().getRawPath();
|
|
||||||
if (delayMillis > 0) {
|
if (delayMillis > 0) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(delayMillis);
|
Thread.sleep(delayMillis);
|
||||||
@@ -58,10 +56,8 @@ class CfBasicHttpClientErrorTest {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
server.start();
|
server.start();
|
||||||
client = new CfDnsClientBuilder()
|
client = new CfDnsClient(false, "http://localhost:" + server.getAddress().getPort(),
|
||||||
.withApiTokenAuth("test-token")
|
new CfDnsClientBuilder.ApiTokenAuth("test-token"));
|
||||||
.withBaseUrl("http://localhost:" + server.getAddress().getPort())
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
@@ -138,27 +134,14 @@ class CfBasicHttpClientErrorTest {
|
|||||||
assertTrue(e.getErrors().isEmpty());
|
assertTrue(e.getErrors().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void trailingSlashOfBaseUrlIsRemoved() throws Exception {
|
|
||||||
respond(200, ZONE_JSON);
|
|
||||||
try (CfDnsClient slashClient = new CfDnsClientBuilder()
|
|
||||||
.withApiTokenAuth("test-token")
|
|
||||||
.withBaseUrl("http://localhost:" + server.getAddress().getPort() + "/client/v4/")
|
|
||||||
.build()) {
|
|
||||||
slashClient.zoneList();
|
|
||||||
}
|
|
||||||
assertEquals("/client/v4/zones", lastPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void responseTimeoutIsApplied() throws Exception {
|
void responseTimeoutIsApplied() throws Exception {
|
||||||
respond(200, ZONE_JSON);
|
respond(200, ZONE_JSON);
|
||||||
delayMillis = 2000;
|
delayMillis = 2000;
|
||||||
try (CfDnsClient timeoutClient = new CfDnsClientBuilder()
|
try (CfDnsClient timeoutClient = new CfDnsClient(false,
|
||||||
.withApiTokenAuth("test-token")
|
"http://localhost:" + server.getAddress().getPort(),
|
||||||
.withBaseUrl("http://localhost:" + server.getAddress().getPort())
|
new CfDnsClientBuilder.ApiTokenAuth("test-token"), CfDnsClient.RECORDS_PER_PAGE,
|
||||||
.withResponseTimeout(Duration.ofMillis(200))
|
CfDnsClientBuilder.DEFAULT_CONNECT_TIMEOUT, Duration.ofMillis(200))) {
|
||||||
.build()) {
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
CloudflareApiException e = assertThrows(CloudflareApiException.class, timeoutClient::zoneList);
|
CloudflareApiException e = assertThrows(CloudflareApiException.class, timeoutClient::zoneList);
|
||||||
long elapsedMillis = (System.nanoTime() - start) / 1_000_000;
|
long elapsedMillis = (System.nanoTime() - start) / 1_000_000;
|
||||||
|
|||||||
+125
-49
@@ -16,6 +16,7 @@ import codes.thischwa.cf.model.PagingRequest;
|
|||||||
import codes.thischwa.cf.model.RecordEntity;
|
import codes.thischwa.cf.model.RecordEntity;
|
||||||
import codes.thischwa.cf.model.RecordType;
|
import codes.thischwa.cf.model.RecordType;
|
||||||
import codes.thischwa.cf.model.ZoneEntity;
|
import codes.thischwa.cf.model.ZoneEntity;
|
||||||
|
import java.net.IDN;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -30,7 +31,7 @@ import org.junit.jupiter.api.BeforeAll;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CfClientTest {
|
public class CfClientIntegrationTest {
|
||||||
|
|
||||||
private static final String ZONE_STR = "mein-d-ns.de";
|
private static final String ZONE_STR = "mein-d-ns.de";
|
||||||
private static final String SLD_STR = "devsld";
|
private static final String SLD_STR = "devsld";
|
||||||
@@ -43,6 +44,9 @@ public class CfClientTest {
|
|||||||
private static final String IP_PREFIX = "130.0.0.";
|
private static final String IP_PREFIX = "130.0.0.";
|
||||||
private static final String UPDATED_IP_PREFIX = "130.1.0.";
|
private static final String UPDATED_IP_PREFIX = "130.1.0.";
|
||||||
|
|
||||||
|
private record PagedResult(int total, Set<String> allIds, List<List<RecordEntity>> pages) {
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void checkEnv() {
|
static void checkEnv() {
|
||||||
assumeTrue(API_TOKEN != null && !API_TOKEN.isBlank(), "API_TOKEN not set; skipping client tests");
|
assumeTrue(API_TOKEN != null && !API_TOKEN.isBlank(), "API_TOKEN not set; skipping client tests");
|
||||||
@@ -470,78 +474,73 @@ public class CfClientTest {
|
|||||||
assertEquals(2, groupedRecords.get("example.com.").size(), "The key 'example.com.' should have 2 records.");
|
assertEquals(2, groupedRecords.get("example.com.").size(), "The key 'example.com.' should have 2 records.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPaging() throws Exception {
|
void testPaging() throws Exception {
|
||||||
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
||||||
String pagingSld = "paging-" + System.currentTimeMillis();
|
String pagingSld = "paging-" + System.currentTimeMillis();
|
||||||
List<RecordEntity> createdRecords = new ArrayList<>();
|
List<RecordEntity> createdRecords = new ArrayList<>();
|
||||||
|
Set<String> createdIds = new HashSet<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int existingCount = 0;
|
List<RecordEntity> staleRecords = List.of();
|
||||||
try {
|
try {
|
||||||
List<RecordEntity> allRecords = client.recordList(zone);
|
staleRecords = client.recordList(zone).stream()
|
||||||
existingCount = allRecords.size();
|
.filter(record -> record.getName() != null && record.getName().startsWith("paging-"))
|
||||||
} catch (CloudflareApiException e) {
|
.toList();
|
||||||
// ignore
|
} catch (CloudflareNotFoundException ignored) {
|
||||||
|
// The zone is empty.
|
||||||
}
|
}
|
||||||
|
deleteQuietly(zone, staleRecords);
|
||||||
|
|
||||||
// Calculate how many records we need to create to reach at least 12 total A records
|
// Each record gets its own name, so the order by name is unambiguous.
|
||||||
// (to test paging with pageSize 5: page 1 = 5, page 2 = 5, page 3 = 2+)
|
for (int i = 1; i <= 12; i++) {
|
||||||
int targetCount = 12;
|
|
||||||
int recordsToCreate = Math.max(0, targetCount - existingCount);
|
|
||||||
|
|
||||||
// Create additional A records if needed. Each record gets its own name, so the order by name
|
|
||||||
// is unambiguous (Cloudflare doesn't guarantee a stable order of records with the same name).
|
|
||||||
for (int i = 1; i <= recordsToCreate; i++) {
|
|
||||||
String name = String.format("%s-%02d.%s", pagingSld, i, ZONE_STR);
|
String name = String.format("%s-%02d.%s", pagingSld, i, ZONE_STR);
|
||||||
RecordEntity record = RecordEntity.build(name, RecordType.A, TTL, "127.0.0." + i);
|
RecordEntity record = RecordEntity.build(name, RecordType.A, TTL, "127.0.0." + i);
|
||||||
RecordEntity created = client.recordCreate(zone, record);
|
RecordEntity created = client.recordCreate(zone, record);
|
||||||
createdRecords.add(created);
|
createdRecords.add(created);
|
||||||
assertNotNull(created.getId());
|
assertNotNull(created.getId());
|
||||||
|
createdIds.add(created.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test paging with page size of 5
|
PagedResult pagedResult = pageThrough(zone, createdIds, 5);
|
||||||
PagingRequest page1Request = PagingRequest.forRecords(1, 5);
|
List<String> pagedIds = pagedResult.pages().stream()
|
||||||
List<RecordEntity> page1Records = client.recordList(zone, page1Request);
|
.flatMap(List::stream)
|
||||||
assertEquals(5, page1Records.size(), "First page should contain 5 records");
|
.map(RecordEntity::getId)
|
||||||
|
.toList();
|
||||||
|
Set<String> pagedIdSet = new HashSet<>(pagedIds);
|
||||||
|
|
||||||
// 2nd page should also contain 5 records (if we have at least 12 total)
|
for (int page = 1; page <= pagedResult.pages().size(); page++) {
|
||||||
PagingRequest page2Request = PagingRequest.forRecords(2, 5);
|
int expected = Math.max(0, Math.min(5,
|
||||||
List<RecordEntity> page2Records = client.recordList(zone, page2Request);
|
pagedResult.total() - 5 * (page - 1)));
|
||||||
assertEquals(5, page2Records.size(), "Second page should contain at least 5 records");
|
assertEquals(expected, pagedResult.pages().get(page - 1).size(),
|
||||||
|
"Page " + page + " should contain " + expected + " records");
|
||||||
|
}
|
||||||
|
assertTrue(pagedResult.pages().get(pagedResult.pages().size() - 1).isEmpty(),
|
||||||
|
"The page after the last result page should be empty");
|
||||||
|
assertEquals(pagedIds.size(), pagedIdSet.size(), "Pages should not overlap");
|
||||||
|
assertEquals(pagedResult.allIds(), pagedIdSet,
|
||||||
|
"Pages should contain every record in the zone");
|
||||||
|
assertTrue(pagedResult.allIds().containsAll(createdIds),
|
||||||
|
"The paged records should contain all records created by this test");
|
||||||
|
|
||||||
// 3rd page should contain 2 records
|
List<String> createdNamesInPageOrder = pagedResult.pages().stream()
|
||||||
PagingRequest page3Request = PagingRequest.forRecords(3, 5);
|
.flatMap(List::stream)
|
||||||
List<RecordEntity> page3Records = client.recordList(zone, page3Request);
|
.filter(record -> createdIds.contains(record.getId()))
|
||||||
assertEquals(2, page3Records.size(), "Third page should contain 2 records");
|
.map(RecordEntity::getName)
|
||||||
|
.toList();
|
||||||
// Verify no overlap between pages
|
assertEquals(createdRecords.stream().map(RecordEntity::getName).toList(),
|
||||||
List<String> page1Ids = page1Records.stream().map(RecordEntity::getId).toList();
|
createdNamesInPageOrder, "The test records should be sorted by name");
|
||||||
List<String> page2Ids = page2Records.stream().map(RecordEntity::getId).toList();
|
|
||||||
List<String> page3Ids = page3Records.stream().map(RecordEntity::getId).toList();
|
|
||||||
Set<String> generatedRecordIds = new HashSet<>(page1Ids);
|
|
||||||
generatedRecordIds.addAll(page2Ids);
|
|
||||||
generatedRecordIds.addAll(page3Ids);
|
|
||||||
assertEquals(createdRecords.size(), generatedRecordIds.size());
|
|
||||||
|
|
||||||
// Verify our created records are in the zone
|
|
||||||
List<RecordEntity> allRecords = client.recordList(zone);
|
|
||||||
Set<String> allRecordIds = allRecords.stream().map(RecordEntity::getId).collect(Collectors.toSet());
|
|
||||||
assertEquals(createdRecords.size(), allRecordIds.size());
|
|
||||||
assertTrue(allRecordIds.containsAll(generatedRecordIds));
|
|
||||||
|
|
||||||
// Without PagingRequest all pages must be fetched, also if the page size is small
|
// Without PagingRequest all pages must be fetched, also if the page size is small
|
||||||
try (CfDnsClient smallPageClient = new CfDnsClient(true, CfDnsClientBuilder.DEFAULT_BASEURL,
|
try (CfDnsClient smallPageClient = new CfDnsClient(true, CfDnsClientBuilder.DEFAULT_BASEURL,
|
||||||
new CfDnsClientBuilder.ApiTokenAuth(API_TOKEN), 5)) {
|
new CfDnsClientBuilder.ApiTokenAuth(API_TOKEN), 5)) {
|
||||||
// a new client (connection) may see a lagging state of the record list for a short time
|
List<RecordEntity> allRecords = awaitRecords(() -> smallPageClient.recordList(zone),
|
||||||
Set<String> smallPageIds = awaitRecords(() -> smallPageClient.recordList(zone),
|
recs -> ids(recs).containsAll(createdIds));
|
||||||
recs -> recs.size() >= allRecordIds.size()).stream()
|
assertTrue(ids(allRecords).containsAll(createdIds));
|
||||||
.map(RecordEntity::getId).collect(Collectors.toSet());
|
List<RecordEntity> aRecords = awaitRecords(
|
||||||
assertEquals(allRecordIds, smallPageIds);
|
|
||||||
assertEquals(createdRecords.size(), awaitRecords(
|
|
||||||
() -> smallPageClient.recordListByType(zone, RecordType.A),
|
() -> smallPageClient.recordListByType(zone, RecordType.A),
|
||||||
recs -> recs.size() >= createdRecords.size()).size());
|
recs -> ids(recs).containsAll(createdIds));
|
||||||
|
assertTrue(ids(aRecords).containsAll(createdIds));
|
||||||
assertEquals(1, smallPageClient.recordListBySubdomain(zone, pagingSld + "-01").size());
|
assertEquals(1, smallPageClient.recordListBySubdomain(zone, pagingSld + "-01").size());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -549,6 +548,47 @@ public class CfClientTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Set<String> ids(List<RecordEntity> records) {
|
||||||
|
return records.stream().map(RecordEntity::getId).collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
|
private PagedResult pageThrough(ZoneEntity zone, Set<String> createdIds, int pageSize)
|
||||||
|
throws CloudflareApiException, InterruptedException {
|
||||||
|
PagedResult result = null;
|
||||||
|
for (int attempt = 1; attempt <= 3; attempt++) {
|
||||||
|
List<RecordEntity> allRecords = awaitRecords(() -> client.recordList(zone),
|
||||||
|
records -> ids(records).containsAll(createdIds));
|
||||||
|
int total = allRecords.size();
|
||||||
|
Set<String> allIds = ids(allRecords);
|
||||||
|
List<List<RecordEntity>> pages = new ArrayList<>();
|
||||||
|
List<String> pagedIds = new ArrayList<>();
|
||||||
|
int pageCount = (total + pageSize - 1) / pageSize + 1;
|
||||||
|
boolean pageSizesMatch = true;
|
||||||
|
|
||||||
|
for (int page = 1; page <= pageCount; page++) {
|
||||||
|
int currentPage = page;
|
||||||
|
int expected = Math.max(0, Math.min(pageSize, total - pageSize * (page - 1)));
|
||||||
|
List<RecordEntity> pageRecords = awaitRecords(
|
||||||
|
() -> client.recordList(zone, PagingRequest.forRecords(currentPage, pageSize)),
|
||||||
|
records -> records.size() == expected);
|
||||||
|
pages.add(pageRecords);
|
||||||
|
pagedIds.addAll(pageRecords.stream().map(RecordEntity::getId).toList());
|
||||||
|
if (pageRecords.size() != expected) {
|
||||||
|
pageSizesMatch = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result = new PagedResult(total, allIds, pages);
|
||||||
|
if (pageSizesMatch && new HashSet<>(pagedIds).equals(allIds)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (attempt < 3) {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testApiErrorDetails() throws Exception {
|
void testApiErrorDetails() throws Exception {
|
||||||
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
||||||
@@ -642,6 +682,39 @@ public class CfClientTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIdnSubdomain() throws Exception {
|
||||||
|
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
||||||
|
String idnSub = "bücher-" + System.currentTimeMillis();
|
||||||
|
String punycodeSub = IDN.toASCII(idnSub);
|
||||||
|
assertTrue(punycodeSub.startsWith("xn--"), punycodeSub);
|
||||||
|
try {
|
||||||
|
// the Unicode subdomain is sent as Punycode, Cloudflare returns the Punycode name
|
||||||
|
RecordEntity rec = client.recordCreateSubdomain(zone, idnSub, TTL, RecordType.A, "130.0.0.30");
|
||||||
|
assertNotNull(rec.getId());
|
||||||
|
assertEquals(punycodeSub + "." + ZONE_STR, rec.getName());
|
||||||
|
assertEquals(punycodeSub, rec.getSubdomain());
|
||||||
|
|
||||||
|
// the record is found by the Unicode and by the Punycode subdomain
|
||||||
|
List<RecordEntity> byUnicode = client.recordListBySubdomain(zone, idnSub, RecordType.A);
|
||||||
|
assertEquals(1, byUnicode.size());
|
||||||
|
assertEquals(rec.getId(), byUnicode.get(0).getId());
|
||||||
|
assertEquals("130.0.0.30", byUnicode.get(0).getContent());
|
||||||
|
List<RecordEntity> byPunycode = client.recordListBySubdomain(zone, punycodeSub, RecordType.A);
|
||||||
|
assertEquals(1, byPunycode.size());
|
||||||
|
assertEquals(rec.getId(), byPunycode.get(0).getId());
|
||||||
|
|
||||||
|
// delete by the Unicode subdomain
|
||||||
|
client.recordDeleteTypeIfExists(zone, idnSub, RecordType.A);
|
||||||
|
assertThrows(CloudflareNotFoundException.class,
|
||||||
|
() -> client.recordListBySubdomain(zone, idnSub, RecordType.A));
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
client.recordDeleteTypeIfExists(zone, punycodeSub, RecordType.A);
|
||||||
|
} catch (Exception e) { /* ignore */ }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testTypeFilter() throws Exception {
|
void testTypeFilter() throws Exception {
|
||||||
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
ZoneEntity zone = client.zoneGet(ZONE_STR);
|
||||||
@@ -753,6 +826,9 @@ public class CfClientTest {
|
|||||||
}
|
}
|
||||||
} catch (CloudflareNotFoundException e) {
|
} catch (CloudflareNotFoundException e) {
|
||||||
recs = List.of();
|
recs = List.of();
|
||||||
|
if (condition.test(recs)) {
|
||||||
|
return recs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("Records not yet listed (attempt {}), waiting ...", attempt);
|
log.info("Records not yet listed (attempt {}), waiting ...", attempt);
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
@@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@@ -125,18 +126,6 @@ class CfDnsClientBuilderTest {
|
|||||||
assertNotNull(client);
|
assertNotNull(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void testBuilderWithMultipleBaseUrls() {
|
|
||||||
// Test setting base URL multiple times (last one wins)
|
|
||||||
CfDnsClient client = new CfDnsClientBuilder()
|
|
||||||
.withApiTokenAuth("test-token")
|
|
||||||
.withBaseUrl("https://old-api.example.com")
|
|
||||||
.withBaseUrl("https://new-api.example.com") // This should override
|
|
||||||
.build();
|
|
||||||
|
|
||||||
assertNotNull(client);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEmptyResultThrowsExceptionToggle() {
|
void testEmptyResultThrowsExceptionToggle() {
|
||||||
// Test toggling the flag multiple times (last one wins)
|
// Test toggling the flag multiple times (last one wins)
|
||||||
@@ -162,13 +151,21 @@ class CfDnsClientBuilderTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBaseUrlAllowsHttpForLoopbackOnly() {
|
void testBaseUrlAllowsOnlyCloudflareHttps() {
|
||||||
assertNotNull(new CfDnsClientBuilder().withApiTokenAuth("t").withBaseUrl("http://localhost:8080").build());
|
assertNotNull(new CfDnsClientBuilder().withApiTokenAuth("t")
|
||||||
assertNotNull(new CfDnsClientBuilder().withApiTokenAuth("t").withBaseUrl("http://127.0.0.1:8080/v4").build());
|
.withBaseUrl("HTTPS://API.CLOUDFLARE.COM/client/v4/").build());
|
||||||
assertNotNull(new CfDnsClientBuilder().withApiTokenAuth("t").withBaseUrl("HTTPS://API.example.com/").build());
|
|
||||||
assertNotNull(new CfDnsClientBuilder().withApiTokenAuth("t").withBaseUrl(null).build());
|
assertNotNull(new CfDnsClientBuilder().withApiTokenAuth("t").withBaseUrl(null).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testBaseUrlTrailingSlashIsRemoved() throws ReflectiveOperationException {
|
||||||
|
Method validateBaseUrl = CfDnsClientBuilder.class.getDeclaredMethod("validateBaseUrl", String.class);
|
||||||
|
validateBaseUrl.setAccessible(true);
|
||||||
|
|
||||||
|
assertEquals("HTTPS://API.CLOUDFLARE.COM/client/v4",
|
||||||
|
validateBaseUrl.invoke(null, "HTTPS://API.CLOUDFLARE.COM/client/v4/"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testInvalidTimeoutsAreRejected() {
|
void testInvalidTimeoutsAreRejected() {
|
||||||
CfDnsClientBuilder builder = new CfDnsClientBuilder();
|
CfDnsClientBuilder builder = new CfDnsClientBuilder();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.IDN;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -787,6 +788,12 @@ class CfDnsClientMockTest {
|
|||||||
() -> spyClient.recordCreateSubdomain(zone, sub, 60, RecordType.A, "1.2.3.4"), sub);
|
() -> spyClient.recordCreateSubdomain(zone, sub, 60, RecordType.A, "1.2.3.4"), sub);
|
||||||
}
|
}
|
||||||
assertThrows(IllegalArgumentException.class, () -> spyClient.recordListBySubdomain(zone, null));
|
assertThrows(IllegalArgumentException.class, () -> spyClient.recordListBySubdomain(zone, null));
|
||||||
|
String tooLongIdnLabel = "ä".repeat(64);
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> spyClient.recordListBySubdomain(zone, tooLongIdnLabel));
|
||||||
|
assertThrows(IllegalArgumentException.class,
|
||||||
|
() -> spyClient.recordCreateSubdomain(zone, tooLongIdnLabel, 60, RecordType.A,
|
||||||
|
"1.2.3.4"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> spyClient.zoneGet("example.com&account.id=1"));
|
assertThrows(IllegalArgumentException.class, () -> spyClient.zoneGet("example.com&account.id=1"));
|
||||||
assertThrows(IllegalArgumentException.class, () -> spyClient.zoneGet(" "));
|
assertThrows(IllegalArgumentException.class, () -> spyClient.zoneGet(" "));
|
||||||
verify(spyClient, never()).getRequest(anyString(), any());
|
verify(spyClient, never()).getRequest(anyString(), any());
|
||||||
@@ -810,6 +817,40 @@ class CfDnsClientMockTest {
|
|||||||
eq(RecordMultipleResponse.class));
|
eq(RecordMultipleResponse.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testIdnSubdomainIsConvertedToPunycode() throws Exception {
|
||||||
|
CfDnsClient spyClient = spy(client);
|
||||||
|
ZoneEntity zone = createTestZone();
|
||||||
|
doReturn(recordResponse(List.of(), new ResultInfo(0)))
|
||||||
|
.when(spyClient).getRequest(anyString(), eq(RecordMultipleResponse.class));
|
||||||
|
doReturn(singleResponse(RecordEntity.build(
|
||||||
|
"xn--bcher-kva.example.com", RecordType.A, 60, "1.2.3.4")))
|
||||||
|
.when(spyClient).postRequest(anyString(), any(), eq(RecordSingleResponse.class));
|
||||||
|
|
||||||
|
spyClient.recordListBySubdomain(zone, "bücher");
|
||||||
|
spyClient.recordListBySubdomain(zone, "shop.bücher");
|
||||||
|
spyClient.recordListBySubdomain(zone, "xn--bcher-kva");
|
||||||
|
// code points newer than IDNA2003 (Unicode 3.2) like emojis must not be rejected
|
||||||
|
spyClient.recordListBySubdomain(zone, "emoji-🥷-忍者");
|
||||||
|
spyClient.recordCreateSubdomain(zone, "bücher", 60, RecordType.A, "1.2.3.4");
|
||||||
|
|
||||||
|
String base = "/zones/" + TEST_ZONE_ID + "/dns_records?name=";
|
||||||
|
String suffix = "&order=name&direction=asc&page=1&per_page=" + CfDnsClient.RECORDS_PER_PAGE;
|
||||||
|
verify(spyClient, times(2)).getRequest(eq(base + "xn--bcher-kva.example.com" + suffix),
|
||||||
|
eq(RecordMultipleResponse.class));
|
||||||
|
verify(spyClient).getRequest(eq(base + "shop.xn--bcher-kva.example.com" + suffix),
|
||||||
|
eq(RecordMultipleResponse.class));
|
||||||
|
String emojiPunycode = IDN.toASCII("emoji-🥷-忍者", IDN.ALLOW_UNASSIGNED);
|
||||||
|
assertTrue(emojiPunycode.startsWith("xn--"), emojiPunycode);
|
||||||
|
verify(spyClient).getRequest(eq(base + emojiPunycode + ".example.com" + suffix),
|
||||||
|
eq(RecordMultipleResponse.class));
|
||||||
|
|
||||||
|
ArgumentCaptor<Object> payload = ArgumentCaptor.forClass(Object.class);
|
||||||
|
verify(spyClient).postRequest(eq("/zones/" + TEST_ZONE_ID + "/dns_records"),
|
||||||
|
payload.capture(), eq(RecordSingleResponse.class));
|
||||||
|
assertEquals("xn--bcher-kva.example.com", ((RecordEntity) payload.getValue()).getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRecordIdPathTraversalIsRejected() throws Exception {
|
void testRecordIdPathTraversalIsRejected() throws Exception {
|
||||||
CfDnsClient spyClient = spy(client);
|
CfDnsClient spyClient = spy(client);
|
||||||
|
|||||||
Reference in new issue
Block a user