mirror of
https://github.com/google/nomulus.git
synced 2025-05-17 17:59:41 +02:00
Remove LoggedInFlow
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=137444791
This commit is contained in:
parent
8b068250d6
commit
b84d7f1fb5
50 changed files with 763 additions and 429 deletions
218
javatests/google/registry/flows/ExtensionManagerTest.java
Normal file
218
javatests/google/registry/flows/ExtensionManagerTest.java
Normal file
|
@ -0,0 +1,218 @@
|
|||
// Copyright 2016 The Nomulus Authors. All Rights Reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package google.registry.flows;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.testing.TestLogHandler;
|
||||
import google.registry.flows.EppException.UnimplementedExtensionException;
|
||||
import google.registry.flows.ExtensionManager.UndeclaredServiceExtensionException;
|
||||
import google.registry.flows.ExtensionManager.UnsupportedRepeatedExtensionException;
|
||||
import google.registry.flows.exceptions.OnlyToolCanPassMetadataException;
|
||||
import google.registry.flows.session.HelloFlow;
|
||||
import google.registry.model.domain.allocate.AllocateCreateExtension;
|
||||
import google.registry.model.domain.fee06.FeeInfoCommandExtensionV06;
|
||||
import google.registry.model.domain.launch.LaunchCreateExtension;
|
||||
import google.registry.model.domain.metadata.MetadataExtension;
|
||||
import google.registry.model.eppcommon.ProtocolDefinition.ServiceExtension;
|
||||
import google.registry.model.eppinput.EppInput;
|
||||
import google.registry.model.eppinput.EppInput.CommandExtension;
|
||||
import google.registry.testing.AppEngineRule;
|
||||
import google.registry.testing.ExceptionRule;
|
||||
import google.registry.util.TypeUtils;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link ExtensionManager}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class ExtensionManagerTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final ExceptionRule thrown = new ExceptionRule();
|
||||
|
||||
@Test
|
||||
public void testDuplicateExtensionsForbidden() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris()
|
||||
.setSuppliedExtensions(
|
||||
MetadataExtension.class,
|
||||
LaunchCreateExtension.class,
|
||||
MetadataExtension.class)
|
||||
.build();
|
||||
manager.register(MetadataExtension.class, LaunchCreateExtension.class);
|
||||
thrown.expect(UnsupportedRepeatedExtensionException.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleExtensionsFromSameGroupForbidden() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris(ServiceExtension.FEE_0_6.getUri())
|
||||
.setSuppliedExtensions(
|
||||
MetadataExtension.class,
|
||||
LaunchCreateExtension.class,
|
||||
AllocateCreateExtension.class)
|
||||
.build();
|
||||
manager.register(MetadataExtension.class);
|
||||
manager.registerAsGroup(
|
||||
ImmutableList.of(LaunchCreateExtension.class, AllocateCreateExtension.class));
|
||||
thrown.expect(UnsupportedRepeatedExtensionException.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUndeclaredExtensionsLogged() throws Exception {
|
||||
TestLogHandler handler = new TestLogHandler();
|
||||
Logger.getLogger(ExtensionManager.class.getCanonicalName()).addHandler(handler);
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris()
|
||||
.setSuppliedExtensions(MetadataExtension.class)
|
||||
.build();
|
||||
manager.register(MetadataExtension.class);
|
||||
manager.validate();
|
||||
ImmutableList.Builder<String> logMessages = new ImmutableList.Builder<>();
|
||||
for (LogRecord record : handler.getStoredLogRecords()) {
|
||||
logMessages.add(record.getMessage());
|
||||
}
|
||||
assertThat(logMessages.build()).contains(
|
||||
"Client clientId is attempting to run HelloFlow without declaring "
|
||||
+ "URIs [urn:google:params:xml:ns:metadata-1.0] on login");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlacklistedExtensions_forbiddenWhenUndeclared() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris()
|
||||
.setSuppliedExtensions(FeeInfoCommandExtensionV06.class)
|
||||
.build();
|
||||
manager.register(FeeInfoCommandExtensionV06.class);
|
||||
thrown.expect(UndeclaredServiceExtensionException.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBlacklistedExtensions_allowedWhenDeclared() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris(ServiceExtension.FEE_0_6.getUri())
|
||||
.setSuppliedExtensions(FeeInfoCommandExtensionV06.class)
|
||||
.build();
|
||||
manager.register(FeeInfoCommandExtensionV06.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetadataExtension_allowedForToolSource() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris()
|
||||
.setSuppliedExtensions(MetadataExtension.class)
|
||||
.build();
|
||||
manager.register(MetadataExtension.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetadataExtension_forbiddenWhenNotToolSource() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.CONSOLE)
|
||||
.setDeclaredUris()
|
||||
.setSuppliedExtensions(MetadataExtension.class)
|
||||
.build();
|
||||
manager.register(MetadataExtension.class);
|
||||
thrown.expect(OnlyToolCanPassMetadataException.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnimplementedExtensionsForbidden() throws Exception {
|
||||
ExtensionManager manager = new TestInstanceBuilder()
|
||||
.setEppRequestSource(EppRequestSource.TOOL)
|
||||
.setDeclaredUris()
|
||||
.setSuppliedExtensions(LaunchCreateExtension.class)
|
||||
.build();
|
||||
thrown.expect(UnimplementedExtensionException.class);
|
||||
manager.validate();
|
||||
}
|
||||
|
||||
/** A builder for a test-ready {@link ExtensionManager} instance. */
|
||||
private static class TestInstanceBuilder {
|
||||
|
||||
ExtensionManager manager = new ExtensionManager();
|
||||
|
||||
TestInstanceBuilder setEppRequestSource(EppRequestSource eppRequestSource) {
|
||||
manager.eppRequestSource = eppRequestSource;
|
||||
return this;
|
||||
}
|
||||
|
||||
TestInstanceBuilder setDeclaredUris(String... declaredUris) {
|
||||
manager.sessionMetadata =
|
||||
new StatelessRequestSessionMetadata("clientId", ImmutableSet.copyOf(declaredUris));
|
||||
return this;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
final TestInstanceBuilder setSuppliedExtensions(
|
||||
Class<? extends CommandExtension>... suppliedExtensionClasses) {
|
||||
manager.eppInput = new FakeEppInput(suppliedExtensionClasses);
|
||||
return this;
|
||||
}
|
||||
|
||||
ExtensionManager build() {
|
||||
manager.flowClass = HelloFlow.class;
|
||||
manager.clientId = manager.sessionMetadata.getClientId();
|
||||
return manager;
|
||||
}
|
||||
}
|
||||
|
||||
/** A minimal fake {@link EppInput} that presents the given extensions. */
|
||||
private static class FakeEppInput extends EppInput {
|
||||
|
||||
private final ImmutableList<CommandExtension> suppliedExtensions;
|
||||
|
||||
@SafeVarargs
|
||||
FakeEppInput(Class<? extends CommandExtension>... suppliedExtensionClasses) {
|
||||
ImmutableList.Builder<CommandExtension> instancesBuilder = new ImmutableList.Builder<>();
|
||||
for (Class<? extends CommandExtension> clazz : suppliedExtensionClasses) {
|
||||
instancesBuilder.add(TypeUtils.<CommandExtension>instantiate(clazz));
|
||||
}
|
||||
suppliedExtensions = instancesBuilder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandWrapper getCommandWrapper() {
|
||||
return new CommandWrapper() {
|
||||
@Override
|
||||
public ImmutableList<CommandExtension> getExtensions() {
|
||||
return suppliedExtensions;
|
||||
}};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue