Add some protected methods for unit testing. Fix bug in URI resolving.

pull/17/merge
Richard Körber 2015-12-11 18:36:01 +01:00
parent bc8c1e822d
commit a59f31603d
1 changed files with 43 additions and 19 deletions

View File

@ -58,25 +58,7 @@ public class LetsEncryptAcmeClientProvider extends AbstractAcmeClientProvider {
@Override
public AcmeClient connect(URI serverUri) {
if (accepts(serverUri)) {
throw new IllegalArgumentException("Unknown URI " + serverUri);
}
String path = serverUri.getPath();
String directoryUri;
if (path == null || "v01".equals(path)) {
directoryUri = V01_DIRECTORY_URI;
} else if ("staging".equals(path)) {
directoryUri = STAGING_DIRECTORY_URI;
} else {
throw new IllegalArgumentException("Unknown URI " + serverUri);
}
try {
return new GenericAcmeClient(this, new URI(directoryUri));
} catch (URISyntaxException ex) {
throw new IllegalArgumentException(directoryUri, ex);
}
return createAcmeClient(resolve(serverUri));
}
@Override
@ -88,6 +70,48 @@ public class LetsEncryptAcmeClientProvider extends AbstractAcmeClientProvider {
return conn;
}
/**
* Creates an {@link AcmeClient} for the given directory URI.
*
* @param directoryUri
* Directory {@link URI}
* @return {@link AcmeClient}
*/
protected AcmeClient createAcmeClient(URI directoryUri) {
return new GenericAcmeClient(this, directoryUri);
}
/**
* Resolves the server URI and returns the matching directory URI.
*
* @param serverUri
* Server {@link URI} to resolve
* @return Directory {@link URI}
* @throws IllegalArgumentException
* if the server URI cannot be resolved
*/
protected URI resolve(URI serverUri) {
if (!accepts(serverUri)) {
throw new IllegalArgumentException("Unknown URI " + serverUri);
}
String path = serverUri.getPath();
String directoryUri;
if (path == null || "".equals(path) || "/".equals(path) || "/v01".equals(path)) {
directoryUri = V01_DIRECTORY_URI;
} else if ("/staging".equals(path)) {
directoryUri = STAGING_DIRECTORY_URI;
} else {
throw new IllegalArgumentException("Unknown URI " + serverUri);
}
try {
return new URI(directoryUri);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException(directoryUri, ex);
}
}
/**
* Lazily creates an {@link SSLSocketFactory} that exclusively accepts the Let's
* Encrypt certificate.