mirror of https://github.com/shred/acme4j
Add Registration ITs
parent
8782787343
commit
8d3d034103
|
@ -0,0 +1,156 @@
|
|||
/*
|
||||
* acme4j - Java ACME client
|
||||
*
|
||||
* Copyright (C) 2017 Richard "Shred" Körber
|
||||
* http://acme4j.shredzone.org
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
package org.shredzone.acme4j.it;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.KeyPair;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.shredzone.acme4j.Registration;
|
||||
import org.shredzone.acme4j.RegistrationBuilder;
|
||||
import org.shredzone.acme4j.Session;
|
||||
import org.shredzone.acme4j.Status;
|
||||
import org.shredzone.acme4j.exception.AcmeConflictException;
|
||||
import org.shredzone.acme4j.exception.AcmeException;
|
||||
import org.shredzone.acme4j.exception.AcmeUnauthorizedException;
|
||||
|
||||
/**
|
||||
* Registration related integration tests.
|
||||
*/
|
||||
public class RegistrationIT extends AbstractPebbleIT {
|
||||
|
||||
@Test
|
||||
public void testCreate() throws AcmeException {
|
||||
KeyPair keyPair = createKeyPair();
|
||||
Session session = new Session(pebbleURI(), keyPair);
|
||||
|
||||
// Register a new user
|
||||
RegistrationBuilder rb = new RegistrationBuilder();
|
||||
rb.addContact("mailto:acme@example.com");
|
||||
rb.agreeToTermsOfService();
|
||||
|
||||
Registration reg = rb.create(session);
|
||||
URI location = reg.getLocation();
|
||||
assertIsPebbleUri(location);
|
||||
|
||||
// TODO: Not yet supported by Pebble
|
||||
/*
|
||||
// Check registered data
|
||||
assertThat(reg.getContacts(), contains(URI.create("mailto:acme@example.com")));
|
||||
assertThat(reg.getStatus(), is(Status.GOOD));
|
||||
assertThat(reg.getTermsOfServiceAgreed(), is(true));
|
||||
*/
|
||||
|
||||
// TODO: Not yet supported by Pebble
|
||||
/*
|
||||
// Bind another Registration object
|
||||
Session session2 = new Session(pebbleURI(), keyPair);
|
||||
Registration reg2 = Registration.bind(session2, location);
|
||||
assertThat(reg2.getLocation(), is(location));
|
||||
assertThat(reg2.getContacts(), contains(URI.create("mailto:acme@example.com")));
|
||||
assertThat(reg2.getStatus(), is(Status.GOOD));
|
||||
assertThat(reg2.getTermsOfServiceAgreed(), is(true));
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO: Not yet supported by Pebble
|
||||
public void testModify() throws AcmeException {
|
||||
KeyPair keyPair = createKeyPair();
|
||||
Session session = new Session(pebbleURI(), keyPair);
|
||||
|
||||
RegistrationBuilder rb = new RegistrationBuilder();
|
||||
rb.addContact("mailto:acme@example.com");
|
||||
rb.agreeToTermsOfService();
|
||||
|
||||
Registration reg = rb.create(session);
|
||||
URI location = reg.getLocation();
|
||||
assertIsPebbleUri(location);
|
||||
|
||||
reg.modify().addContact("mailto:acme2@example.com").commit();
|
||||
|
||||
assertThat(reg.getContacts(), contains(
|
||||
URI.create("mailto:acme@example.com"),
|
||||
URI.create("mailto:acme2@example.com")));
|
||||
|
||||
// Still the same after updating
|
||||
reg.update();
|
||||
assertThat(reg.getContacts(), contains(
|
||||
URI.create("mailto:acme@example.com"),
|
||||
URI.create("mailto:acme2@example.com")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO: Not yet supported by Pebble
|
||||
public void testKeyChange() throws AcmeException {
|
||||
KeyPair keyPair = createKeyPair();
|
||||
Session session = new Session(pebbleURI(), keyPair);
|
||||
|
||||
Registration reg = new RegistrationBuilder().agreeToTermsOfService().create(session);
|
||||
URI location = reg.getLocation();
|
||||
|
||||
KeyPair newKeyPair = createKeyPair();
|
||||
reg.changeKey(newKeyPair);
|
||||
|
||||
try {
|
||||
Session sessionOldKey = new Session(pebbleURI(), keyPair);
|
||||
Registration oldRegistration = Registration.bind(sessionOldKey, location);
|
||||
oldRegistration.update();
|
||||
} catch (AcmeUnauthorizedException ex) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
Session sessionNewKey = new Session(pebbleURI(), newKeyPair);
|
||||
Registration newRegistration = Registration.bind(sessionNewKey, location);
|
||||
assertThat(newRegistration.getStatus(), is(Status.GOOD));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicate() throws AcmeException {
|
||||
KeyPair keyPair = createKeyPair();
|
||||
Session session = new Session(pebbleURI(), keyPair);
|
||||
|
||||
// First registration
|
||||
new RegistrationBuilder().agreeToTermsOfService().create(session);
|
||||
|
||||
try {
|
||||
new RegistrationBuilder().agreeToTermsOfService().create(session);
|
||||
fail("Successfully registered KeyPair a second time");
|
||||
} catch (AcmeConflictException ex) {
|
||||
// This exception is expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO: Not yet supported by Pebble
|
||||
public void testDeactivate() throws AcmeException {
|
||||
KeyPair keyPair = createKeyPair();
|
||||
Session session = new Session(pebbleURI(), keyPair);
|
||||
|
||||
Registration reg = new RegistrationBuilder().agreeToTermsOfService().create(session);
|
||||
URI location = reg.getLocation();
|
||||
|
||||
reg.deactivate();
|
||||
|
||||
Session session2 = new Session(pebbleURI(), keyPair);
|
||||
Registration reg2 = Registration.bind(session2, location);
|
||||
assertThat(reg2.getLocation(), is(location));
|
||||
assertThat(reg2.getStatus(), is(Status.DEACTIVATED));
|
||||
}
|
||||
|
||||
}
|
|
@ -51,6 +51,9 @@ public class SessionIT extends AbstractPebbleIT {
|
|||
public void testResources() throws AcmeException {
|
||||
Session session = new Session(pebbleURI(), keyPair);
|
||||
|
||||
// TODO: Not yet supported by Pebble
|
||||
// assertIsPebbleUri(session.resourceUri(Resource.KEY_CHANGE));
|
||||
|
||||
assertIsPebbleUri(session.resourceUri(Resource.NEW_NONCE));
|
||||
assertIsPebbleUri(session.resourceUri(Resource.NEW_REG));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue