mirror of https://github.com/shred/acme4j
Session accepts a provider instance
parent
396ddd7c86
commit
9a22a74429
|
@ -99,6 +99,26 @@ public class Session {
|
||||||
.orElseThrow(() -> new IllegalArgumentException("No ACME provider found for " + localServerUri));
|
.orElseThrow(() -> new IllegalArgumentException("No ACME provider found for " + localServerUri));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link Session} using the given {@link AcmeProvider}.
|
||||||
|
* <p>
|
||||||
|
* This constructor should only be used for testing purposes.
|
||||||
|
*
|
||||||
|
* @param serverUri
|
||||||
|
* {@link URI} of the ACME server
|
||||||
|
* @param provider
|
||||||
|
* {@link AcmeProvider} to be used
|
||||||
|
* @since 2.8
|
||||||
|
*/
|
||||||
|
public Session(URI serverUri, AcmeProvider provider) {
|
||||||
|
this.serverUri = Objects.requireNonNull(serverUri, "serverUri");
|
||||||
|
this.provider = Objects.requireNonNull(provider, "provider");
|
||||||
|
|
||||||
|
if (!provider.accepts(serverUri)) {
|
||||||
|
throw new IllegalArgumentException("Provider does not accept " + serverUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs into an existing account.
|
* Logs into an existing account.
|
||||||
*
|
*
|
||||||
|
|
|
@ -34,6 +34,7 @@ import org.mockito.ArgumentMatchers;
|
||||||
import org.shredzone.acme4j.connector.Resource;
|
import org.shredzone.acme4j.connector.Resource;
|
||||||
import org.shredzone.acme4j.exception.AcmeException;
|
import org.shredzone.acme4j.exception.AcmeException;
|
||||||
import org.shredzone.acme4j.provider.AcmeProvider;
|
import org.shredzone.acme4j.provider.AcmeProvider;
|
||||||
|
import org.shredzone.acme4j.provider.GenericAcmeProvider;
|
||||||
import org.shredzone.acme4j.toolbox.TestUtils;
|
import org.shredzone.acme4j.toolbox.TestUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,12 +64,23 @@ public class SessionTest {
|
||||||
assertThat(session2, not(nullValue()));
|
assertThat(session2, not(nullValue()));
|
||||||
assertThat(session2.getServerUri(), is(serverUri));
|
assertThat(session2.getServerUri(), is(serverUri));
|
||||||
|
|
||||||
|
Session session3 = new Session(serverUri, new GenericAcmeProvider());
|
||||||
|
assertThat(session3, not(nullValue()));
|
||||||
|
assertThat(session3.getServerUri(), is(serverUri));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new Session("#*aBaDuRi*#");
|
new Session("#*aBaDuRi*#");
|
||||||
fail("accepted bad URI in constructor");
|
fail("accepted bad URI in constructor");
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new Session(URI.create("acme://invalid"), new GenericAcmeProvider());
|
||||||
|
fail("Provider accepted unsupported URI");
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,7 +201,7 @@ public class SessionTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the {@link Session} returns correct
|
* Asserts that the {@link Session} returns correct
|
||||||
* {@link Session#resourceUri(Resource)} and {@link Session#getMetadata()}.
|
* {@link Session#resourceUrl(Resource)} and {@link Session#getMetadata()}.
|
||||||
*
|
*
|
||||||
* @param session
|
* @param session
|
||||||
* {@link Session} to assert
|
* {@link Session} to assert
|
||||||
|
|
Loading…
Reference in New Issue