mirror of https://github.com/shred/acme4j
Fix unit tests
parent
c0fede3b1a
commit
43b6a7c7c6
|
@ -134,25 +134,24 @@ public class Metadata {
|
||||||
/**
|
/**
|
||||||
* Returns whether the CA supports the profile feature.
|
* Returns whether the CA supports the profile feature.
|
||||||
*
|
*
|
||||||
* @since 3.5
|
* @since 3.5.0
|
||||||
* @throws AcmeNotSupportedException if the server does not support the profile feature.
|
|
||||||
*/
|
*/
|
||||||
public boolean isProfileAllowed() {
|
public boolean isProfileAllowed() {
|
||||||
return meta.getFeature("profile").optional().isPresent();
|
return meta.get("profiles").isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the CA supports the requested profile.
|
* Returns whether the CA supports the requested profile.
|
||||||
|
* <p>
|
||||||
|
* Also returns {@code false} if profiles are not allowed in general.
|
||||||
*
|
*
|
||||||
* @since 3.5
|
* @since 3.5.0
|
||||||
* @throws AcmeNotSupportedException if the server does not support the requested profile.
|
|
||||||
*/
|
*/
|
||||||
public boolean isProfileAllowed(String profile) {
|
public boolean isProfileAllowed(String profile) {
|
||||||
return meta.getFeature("profile").optional()
|
return meta.get("profiles").optional()
|
||||||
.map(Value::asObject)
|
.map(Value::asObject)
|
||||||
.orElseGet(JSON::empty)
|
.orElseGet(JSON::empty)
|
||||||
.get(profile)
|
.get(profile)
|
||||||
.optional()
|
|
||||||
.isPresent();
|
.isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -440,11 +440,11 @@ public class Order extends AcmeJsonResource implements PollableResource {
|
||||||
/**
|
/**
|
||||||
* Returns the selected profile.
|
* Returns the selected profile.
|
||||||
*
|
*
|
||||||
* @since 3.5
|
* @since 3.5.0
|
||||||
* @throws AcmeNotSupportedException if profile is not supported
|
* @throws AcmeNotSupportedException if profile is not supported
|
||||||
*/
|
*/
|
||||||
public String getProfile() {
|
public String getProfile() {
|
||||||
return getJSON().getFeature("profile").toString();
|
return getJSON().getFeature("profile").asString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -273,15 +273,15 @@ public class OrderBuilder {
|
||||||
/**
|
/**
|
||||||
* Notifies the CA of the desired profile of the ordered certificate.
|
* Notifies the CA of the desired profile of the ordered certificate.
|
||||||
* <p>
|
* <p>
|
||||||
* Optional, only supported if the CA supports profiles. However, in this
|
* Optional, only supported if the CA supports profiles. However, in this case the
|
||||||
* case the client <em>may</em> include this field.
|
* client <em>may</em> include this field.
|
||||||
*
|
*
|
||||||
* @param profile
|
* @param profile
|
||||||
* Identifier of the desired profile
|
* Identifier of the desired profile
|
||||||
* @return itself
|
* @return itself
|
||||||
* @draft This method is currently based on RFC draft draft-aaron-acme-profiles. It may be changed or removed
|
* @draft This method is currently based on RFC draft draft-aaron-acme-profiles. It
|
||||||
* without notice to reflect future changes to the draft. SemVer rules do not apply
|
* may be changed or removed without notice to reflect future changes to the draft.
|
||||||
* here.
|
* SemVer rules do not apply here.
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
public OrderBuilder profile(String profile) {
|
public OrderBuilder profile(String profile) {
|
||||||
|
@ -376,7 +376,7 @@ public class OrderBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (profile != null && !session.getMetadata().isProfileAllowed(profile)) {
|
if (profile != null && !session.getMetadata().isProfileAllowed(profile)) {
|
||||||
throw new AcmeNotSupportedException("profile with value " + profile);
|
throw new AcmeNotSupportedException("profile: " + profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasAncestorDomain = identifierSet.stream()
|
var hasAncestorDomain = identifierSet.stream()
|
||||||
|
@ -421,7 +421,7 @@ public class OrderBuilder {
|
||||||
claims.put("replaces", replaces);
|
claims.put("replaces", replaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(profile != null) {
|
if (profile != null) {
|
||||||
claims.put("profile", profile);
|
claims.put("profile", profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import static org.shredzone.acme4j.toolbox.AcmeUtils.parseTimestamp;
|
||||||
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
import static org.shredzone.acme4j.toolbox.TestUtils.getJSON;
|
||||||
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
import static org.shredzone.acme4j.toolbox.TestUtils.url;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -342,7 +343,6 @@ public class OrderBuilderTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testProfileOrderCertificate() throws Exception {
|
public void testProfileOrderCertificate() throws Exception {
|
||||||
|
|
||||||
var provider = new TestableConnectionProvider() {
|
var provider = new TestableConnectionProvider() {
|
||||||
@Override
|
@Override
|
||||||
public int sendSignedRequest(URL url, JSONBuilder claims, Login login) {
|
public int sendSignedRequest(URL url, JSONBuilder claims, Login login) {
|
||||||
|
@ -354,7 +354,7 @@ public class OrderBuilderTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSON readJsonResponse() {
|
public JSON readJsonResponse() {
|
||||||
return getJSON("requestAutoRenewOrderResponse");
|
return getJSON("requestProfileOrderResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -365,8 +365,8 @@ public class OrderBuilderTest {
|
||||||
|
|
||||||
var login = provider.createLogin();
|
var login = provider.createLogin();
|
||||||
|
|
||||||
provider.putMetadata("profile",JSON.parse(
|
provider.putMetadata("profiles",JSON.parse(
|
||||||
"{\"classic\": true}"
|
"{\"classic\": \"The same profile you're accustomed to\"}"
|
||||||
).toMap());
|
).toMap());
|
||||||
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
||||||
|
|
||||||
|
@ -381,72 +381,54 @@ public class OrderBuilderTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.close();
|
provider.close();
|
||||||
provider.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that a profile {@link Order} cannot be created if the profile is unsupported by the CA.
|
* Test that a profile {@link Order} cannot be created if the profile is unsupported
|
||||||
|
* by the CA.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUnsupportedProfileOrderCertificateFails() throws Exception {
|
public void testUnsupportedProfileOrderCertificateFails() throws Exception {
|
||||||
|
var provider = new TestableConnectionProvider();
|
||||||
|
provider.putMetadata("profiles",JSON.parse(
|
||||||
|
"{\"classic\": \"The same profile you're accustomed to\"}"
|
||||||
|
).toMap());
|
||||||
|
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
||||||
|
|
||||||
var provider = new TestableConnectionProvider() {
|
var login = provider.createLogin();
|
||||||
@Override
|
|
||||||
public int sendSignedRequest(URL url, JSONBuilder claims, Login login) {
|
|
||||||
assertThat(url).isEqualTo(resourceUrl);
|
|
||||||
assertThatJson(claims.toString()).isEqualTo(getJSON("requestProfileOrderRequest").toString());
|
|
||||||
assertThat(login).isNotNull();
|
|
||||||
return HttpURLConnection.HTTP_CREATED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
var account = new Account(login);
|
||||||
public JSON readJsonResponse() {
|
assertThatExceptionOfType(AcmeNotSupportedException.class).isThrownBy(() -> {
|
||||||
return getJSON("requestAutoRenewOrderResponse");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public URL getLocation() {
|
|
||||||
return locationUrl;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
assertThrows(AcmeNotSupportedException.class, () -> {
|
|
||||||
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
|
||||||
|
|
||||||
var login = provider.createLogin();
|
|
||||||
|
|
||||||
var account = new Account(login);
|
|
||||||
account.newOrder()
|
account.newOrder()
|
||||||
.domain("example.org")
|
.domain("example.org")
|
||||||
.profile("invalid")
|
.profile("invalid")
|
||||||
.create();
|
.create();
|
||||||
|
}).withMessage("Server does not support profile: invalid");
|
||||||
provider.close();
|
provider.close();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that a profile {@link Order} cannot be created if the feature is unsupported by the CA.
|
* Test that a profile {@link Order} cannot be created if the feature is unsupported
|
||||||
|
* by the CA.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testProfileOrderCertificateFails() {
|
public void testProfileOrderCertificateFails() throws IOException {
|
||||||
assertThrows(AcmeNotSupportedException.class, () -> {
|
var provider = new TestableConnectionProvider();
|
||||||
var provider = new TestableConnectionProvider();
|
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
||||||
provider.putTestResource(Resource.NEW_ORDER, resourceUrl);
|
|
||||||
|
|
||||||
var login = provider.createLogin();
|
var login = provider.createLogin();
|
||||||
|
|
||||||
var account = new Account(login);
|
var account = new Account(login);
|
||||||
|
assertThatExceptionOfType(AcmeNotSupportedException.class).isThrownBy(() -> {
|
||||||
account.newOrder()
|
account.newOrder()
|
||||||
.domain("example.org")
|
.domain("example.org")
|
||||||
.profile("classic")
|
.profile("classic")
|
||||||
.create();
|
.create();
|
||||||
|
}).withMessage("Server does not support profile");
|
||||||
|
|
||||||
provider.close();
|
provider.close();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the ARI replaces field is set.
|
* Test that the ARI replaces field is set.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue