Tweak the registrar-ote-setup web console

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=227736173
This commit is contained in:
guyben 2019-01-03 13:05:21 -08:00 committed by Ben McIlwain
parent 338f7343ba
commit 2af24c945c
5 changed files with 71 additions and 19 deletions

View file

@ -54,6 +54,11 @@ tr.subsection h3::first-letter {
width: 170px; width: 170px;
} }
.description ol {
list-style-type: decimal;
margin-left: 2em;
}
/* Setting groups and labels. */ /* Setting groups and labels. */

View file

@ -98,6 +98,7 @@ public final class ConsoleOteSetupAction implements Runnable {
@Inject @Config("base64StringGenerator") StringGenerator passwordGenerator; @Inject @Config("base64StringGenerator") StringGenerator passwordGenerator;
@Inject @Parameter("clientId") Optional<String> clientId; @Inject @Parameter("clientId") Optional<String> clientId;
@Inject @Parameter("email") Optional<String> email; @Inject @Parameter("email") Optional<String> email;
@Inject @Parameter("password") Optional<String> optionalPassword;
@Inject ConsoleOteSetupAction() {} @Inject ConsoleOteSetupAction() {}
@ -170,7 +171,7 @@ public final class ConsoleOteSetupAction implements Runnable {
data.put("contactEmail", email.get()); data.put("contactEmail", email.get());
try { try {
String password = passwordGenerator.createString(PASSWORD_LENGTH); String password = optionalPassword.orElse(passwordGenerator.createString(PASSWORD_LENGTH));
ImmutableMap<String, String> clientIdToTld = ImmutableMap<String, String> clientIdToTld =
OteAccountBuilder.forClientId(clientId.get()) OteAccountBuilder.forClientId(clientId.get())
.addContact(email.get()) .addContact(email.get())

View file

@ -53,4 +53,10 @@ public final class RegistrarConsoleModule {
static String provideEmail(HttpServletRequest req) { static String provideEmail(HttpServletRequest req) {
return extractRequiredParameter(req, "email"); return extractRequiredParameter(req, "email");
} }
@Provides
@Parameter("password")
static Optional<String> provideOptionalPassword(HttpServletRequest req) {
return extractOptionalParameter(req, "password");
}
} }

View file

@ -76,9 +76,9 @@
<td class="{css('setting')}"> <td class="{css('setting')}">
<textarea rows="7" cols="100" readonly> <textarea rows="7" cols="100" readonly>
{for $clientId in mapKeys($clientIdToTld)} {for $clientId in mapKeys($clientIdToTld)}
Login: {$clientId}{sp} Login: {$clientId}{sp}{sp}{sp}{sp}{sp}{sp}
Password: {$password}{sp} Password: {$password}{sp}{sp}{sp}{sp}{sp}{sp}
Tld: {$clientIdToTld[$clientId]}{\n} TLD: {$clientIdToTld[$clientId]}{sp}{sp}{sp}{sp}{sp}{sp}{\n}
{/for} {/for}
</textarea> </textarea>
</td> </td>
@ -102,22 +102,34 @@
{@param? contactEmail: string} /** If set - an initial value to fill for the email. */ {@param? contactEmail: string} /** If set - an initial value to fill for the email. */
<form name="item" class="{css('item')}" method="post" action="/registrar-ote-setup"> <form name="item" class="{css('item')}" method="post" action="/registrar-ote-setup">
<table> <table>
{call registry.soy.forms.inputFieldRowWithValue} <tr class="{css('kd-settings-pane-section')}">
{param label: 'Base clientId' /} <td>
{call registry.soy.forms.inputFieldLabel}
{param label: 'Base client ID' /}
{/call}
</td>
<td class="{css('setting')}">
{call registry.soy.forms.inputFieldValue }
{param name: 'clientId' /} {param name: 'clientId' /}
{param value: $baseClientId /} {param value: $baseClientId /}
{param placeholder: 'registrar\'s ID' /} {param placeholder: 'registrar\'s ID' /}
{param description kind="text"}
must 1) consist of only lowercase letters, numbers, or hyphens,
2) start with a letter, and 3) be between 3 and 14 characters (inclusive).
We require 1 and 2 since the registrar name will be used to create TLDs,
and we require 3 since we append \"-[1234]\" to the name to create client
IDs which are required by the EPP XML schema to be between 3-16 chars.
{/param}
{param readonly: false /} {param readonly: false /}
{/call} {/call}
<span class="{css('description')}">
Must:
<ol type="1">
<li>consist of only lowercase letters, numbers, or hyphens,</li>
<li>start with a letter, and</li>
<li>be between 3 and 14 characters (inclusive).</li>
</ol>
We require 1 and 2 since the registrar name will be used to create TLDs, and we
require 3 since we append "-[12345]" to the name to create client IDs which are
required by the EPP XML schema to be between 3-16 chars.
</span>
</td>
</tr>
{call registry.soy.forms.inputFieldRowWithValue} {call registry.soy.forms.inputFieldRowWithValue}
{param label: 'contact email' /} {param label: 'Contact email' /}
{param name: 'email' /} {param name: 'email' /}
{param value: $contactEmail /} {param value: $contactEmail /}
{param placeholder: 'registrar\'s assigned email' /} {param placeholder: 'registrar\'s assigned email' /}
@ -126,6 +138,15 @@
{/param} {/param}
{param readonly: false /} {param readonly: false /}
{/call} {/call}
{call registry.soy.forms.inputFieldRowWithValue}
{param label: 'Password (optional)' /}
{param name: 'password' /}
{param placeholder: 'Optional password' /}
{param description kind="text"}
The password used to for EPP login. Leave blank to auto-generate a password.
{/param}
{param readonly: false /}
{/call}
{call registry.soy.forms.submitRow} {call registry.soy.forms.submitRow}
{param label: 'create' /} {param label: 'create' /}
{/call} {/call}

View file

@ -97,6 +97,7 @@ public final class ConsoleOteSetupActionTest {
action.productName = "Nomulus"; action.productName = "Nomulus";
action.clientId = Optional.empty(); action.clientId = Optional.empty();
action.email = Optional.empty(); action.email = Optional.empty();
action.optionalPassword = Optional.empty();
action.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz"); action.passwordGenerator = new DeterministicStringGenerator("abcdefghijklmnopqrstuvwxyz");
message = new MimeMessage(Session.getDefaultInstance(new Properties(), null)); message = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
@ -160,6 +161,24 @@ public final class ConsoleOteSetupActionTest {
+ "Gave user contact@registry.example web access to these Registrars\n"); + "Gave user contact@registry.example web access to these Registrars\n");
} }
@Test
public void testPost_authorized_setPassword() throws Exception {
action.clientId = Optional.of("myclientid");
action.email = Optional.of("contact@registry.example");
action.optionalPassword = Optional.of("SomePassword");
action.method = Method.POST;
action.run();
// We just check some samples to make sure OteAccountBuilder was called successfully. We aren't
// checking that all the entities are there or that they have the correct values.
assertThat(loadByClientId("myclientid-4").get().testPassword("SomePassword"))
.isTrue();
assertThat(response.getPayload())
.contains("<h1>OT&E successfully created for registrar myclientid!</h1>");
assertThat(response.getPayload())
.contains("SomePassword");
}
@Test @Test
public void testPost_unauthorized() { public void testPost_unauthorized() {
action.registrarAccessor = action.registrarAccessor =