issue #11 - Refactor CfDnsClient with a simplified CfDnsClientBuilder for authentication and configuration. Update tests and README for new builder. Added authtification with apiToken
This commit is contained in:
1 parent
b593ca7311
commit
607b634b35
11 files changed
+228
-175
No files matched your search
@@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import codes.thischwa.cf.auth.CfAuthBuilder;
|
||||
import codes.thischwa.cf.model.RecordType;
|
||||
import codes.thischwa.cf.model.ZoneEntity;
|
||||
import java.util.List;
|
||||
@@ -31,14 +30,14 @@ public class CfClientPenTest {
|
||||
}
|
||||
|
||||
private CfDnsClient newClient() {
|
||||
return new CfDnsClient(true, CfAuthBuilder.build(API_TOKEN));
|
||||
return new CfDnsClientBuilder().withEmptyResultThrowsException(true).withApiTokenAuth(API_TOKEN).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Invalid credentials should not authenticate and must throw CloudflareApiException")
|
||||
void testInvalidCredentialsShouldFail() {
|
||||
// Use syntactically valid but wrong credentials
|
||||
CfDnsClient badClient = new CfDnsClient(CfAuthBuilder.build("invalid@example.com", UUID.randomUUID().toString()));
|
||||
CfDnsClient badClient = new CfDnsClientBuilder().withEmailKeyAuth("invalid@example.com", UUID.randomUUID().toString()).build();
|
||||
assertThrows(CloudflareApiException.class, badClient::zoneList);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import codes.thischwa.cf.auth.ApiTokenAuth;
|
||||
import codes.thischwa.cf.auth.CfAuthBuilder;
|
||||
import codes.thischwa.cf.auth.EmailKeyAuth;
|
||||
import codes.thischwa.cf.model.BatchEntry;
|
||||
import codes.thischwa.cf.model.RecordEntity;
|
||||
import codes.thischwa.cf.model.RecordType;
|
||||
@@ -33,7 +30,7 @@ public class CfClientTest {
|
||||
|
||||
private static final String API_TOKEN = System.getenv("API_TOKEN");
|
||||
|
||||
private final CfDnsClient client = new CfDnsClient(true, CfAuthBuilder.build(API_TOKEN));
|
||||
private final CfDnsClient client = new CfDnsClientBuilder().withEmptyResultThrowsException(true).withApiTokenAuth(API_TOKEN).build();
|
||||
|
||||
@BeforeAll
|
||||
static void checkEnv() {
|
||||
@@ -225,16 +222,6 @@ public class CfClientTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testException() {
|
||||
// Test EmailKeyAuth validation
|
||||
assertThrows(IllegalArgumentException.class, () -> new EmailKeyAuth("email", ""));
|
||||
assertThrows(IllegalArgumentException.class, () -> new EmailKeyAuth("", "key"));
|
||||
|
||||
// Test ApiTokenAuth validation;
|
||||
assertThrows(IllegalArgumentException.class, () -> new ApiTokenAuth(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRecordEntityInvalidType() {
|
||||
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
|
||||
|
||||
Reference in new issue
Block a user