From 83d6f38ec745d1ead5ee11b9eb635cc1ec2f02e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Sat, 18 Jan 2025 11:47:16 +0100 Subject: [PATCH] Add method to return profile description --- .../java/org/shredzone/acme4j/Metadata.java | 17 +++++++++++++++++ .../java/org/shredzone/acme4j/SessionTest.java | 5 +++++ 2 files changed, 22 insertions(+) diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Metadata.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Metadata.java index e81edbf4..6cf47738 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Metadata.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Metadata.java @@ -155,6 +155,23 @@ public class Metadata { .isPresent(); } + /** + * Returns a description of the requested profile. This can be a human-readable string + * or a URL linking to a documentation. + *

+ * Empty if the profile is not allowed. + * + * @since 3.5.0 + */ + public Optional getProfileDescription(String profile) { + return meta.get("profiles").optional() + .map(Value::asObject) + .orElseGet(JSON::empty) + .get(profile) + .optional() + .map(Value::asString); + } + /** * Returns whether the CA supports subdomain auth according to RFC9444. * diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java index cc74ba19..9af96608 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/SessionTest.java @@ -185,7 +185,11 @@ public class SessionTest { softly.assertThat(meta.isAutoRenewalGetAllowed()).isTrue(); softly.assertThat(meta.isProfileAllowed()).isTrue(); softly.assertThat(meta.isProfileAllowed("classic")).isTrue(); + softly.assertThat(meta.isProfileAllowed("custom")).isTrue(); softly.assertThat(meta.isProfileAllowed("invalid")).isFalse(); + softly.assertThat(meta.getProfileDescription("classic")).contains("The profile you're accustomed to"); + softly.assertThat(meta.getProfileDescription("custom")).contains("Some other profile"); + softly.assertThat(meta.getProfileDescription("invalid")).isEmpty(); softly.assertThat(meta.isExternalAccountRequired()).isTrue(); softly.assertThat(meta.isSubdomainAuthAllowed()).isTrue(); softly.assertThat(meta.getJSON()).isNotNull(); @@ -240,6 +244,7 @@ public class SessionTest { .isThrownBy(meta::isAutoRenewalGetAllowed); softly.assertThat(meta.isProfileAllowed()).isFalse(); softly.assertThat(meta.isProfileAllowed("classic")).isFalse(); + softly.assertThat(meta.getProfileDescription("classic")).isEmpty(); } }