mirror of
https://github.com/google/nomulus.git
synced 2025-08-02 16:02:10 +02:00
Pay off technical debt with ConsoleUiServlet
1. Turn ConsoleUiServlet into an action 2. Remove AbstractUiServlet, which fixes its threading bug 3. Use type-safe soy template parameters when rendering console A follow-up change will add a new template parameter that renders the payment page link on the navigation bar. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117969638
This commit is contained in:
parent
79b2d5a990
commit
b6b13333dd
22 changed files with 265 additions and 365 deletions
|
@ -69,8 +69,7 @@ public final class RegistryTestServer {
|
|||
com.google.domain.registry.module.backend.BackendServlet.class),
|
||||
|
||||
// Registrar Console
|
||||
route("/registrar",
|
||||
com.google.domain.registry.ui.server.registrar.ConsoleUiServlet.class),
|
||||
route("/registrar", com.google.domain.registry.module.frontend.FrontendServlet.class),
|
||||
route("/registrar-settings",
|
||||
com.google.domain.registry.ui.server.registrar.RegistrarServlet.class),
|
||||
route("/registrar-payment",
|
||||
|
|
|
@ -46,11 +46,10 @@ function setUp() {
|
|||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
var testElt = goog.dom.getElement('test');
|
||||
goog.soy.renderElement(testElt, registry.soy.registrar.console.main, {
|
||||
user: {
|
||||
id: 'pmy@google.com',
|
||||
actionHref: 'blah'
|
||||
},
|
||||
xsrfToken: test.testXsrfToken,
|
||||
username: 'blah',
|
||||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
registry.registrar.ConsoleTestUtil.setup(test);
|
||||
|
|
|
@ -45,12 +45,10 @@ function setUp() {
|
|||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
testContact = createTestContact();
|
||||
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
|
||||
user: {
|
||||
id: 'test@acme.com',
|
||||
actionHref: 'blah',
|
||||
actionName: 'omg'
|
||||
},
|
||||
xsrfToken: test.testXsrfToken,
|
||||
username: 'blah',
|
||||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
|
|
|
@ -36,11 +36,10 @@ function setUp() {
|
|||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
|
||||
user: {
|
||||
id: 'test1.ui@example.com',
|
||||
actionHref: 'blah'
|
||||
},
|
||||
xsrfToken: 'test',
|
||||
username: 'blah',
|
||||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: 'daddy'
|
||||
});
|
||||
registry.registrar.ConsoleTestUtil.setup(test);
|
||||
|
|
|
@ -43,12 +43,10 @@ function setUp() {
|
|||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
|
||||
xsrfToken: 'ignore',
|
||||
clientId: 'ignore',
|
||||
user: {
|
||||
id: 'jart@google.com',
|
||||
actionHref: 'https://justinetunney.com',
|
||||
actionName: 'gtfo'
|
||||
}
|
||||
username: 'jart',
|
||||
logoutUrl: 'https://justinetunney.com',
|
||||
isAdmin: true,
|
||||
clientId: 'ignore'
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
|
||||
|
|
|
@ -43,12 +43,10 @@ function setUp() {
|
|||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
|
||||
xsrfToken: 'ignore',
|
||||
clientId: 'ignore',
|
||||
user: {
|
||||
id: 'test2.ui@example.com',
|
||||
actionHref: 'https://example.com',
|
||||
actionName: 'gtfo'
|
||||
}
|
||||
username: 'jart',
|
||||
logoutUrl: 'https://example.com',
|
||||
isAdmin: true,
|
||||
clientId: 'ignore'
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
|
||||
|
|
|
@ -50,11 +50,9 @@ function setUp() {
|
|||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
|
||||
user: {
|
||||
id: 'test@acme.com',
|
||||
actionHref: 'blah',
|
||||
actionName: 'omg'
|
||||
},
|
||||
username: 'jart',
|
||||
logoutUrl: 'https://example.com',
|
||||
isAdmin: true,
|
||||
xsrfToken: test.testXsrfToken,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
|
|
|
@ -44,12 +44,10 @@ function setUp() {
|
|||
registry.testing.addToDocument('<div id="test"/>');
|
||||
registry.testing.addToDocument('<div class="kd-butterbar"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.registrar.console.main, {
|
||||
user: {
|
||||
id: 'test1.ui@example.com',
|
||||
actionHref: 'blah',
|
||||
actionName: 'omg'
|
||||
},
|
||||
xsrfToken: test.testXsrfToken,
|
||||
username: 'blah',
|
||||
logoutUrl: 'omg',
|
||||
isAdmin: true,
|
||||
clientId: test.testClientId
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
|
|
|
@ -11,6 +11,7 @@ java_library(
|
|||
"//java/com/google/common/base",
|
||||
"//java/com/google/common/collect",
|
||||
"//java/com/google/common/io",
|
||||
"//java/com/google/common/net",
|
||||
"//java/com/google/common/testing",
|
||||
"//java/com/google/domain/registry/config",
|
||||
"//java/com/google/domain/registry/export/sheet",
|
||||
|
@ -31,8 +32,6 @@ java_library(
|
|||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
"//third_party/java/truth",
|
||||
|
||||
"//third_party/closure/templates",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
// Copyright 2016 Google Inc. 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 com.google.domain.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.appengine.api.users.UserServiceFactory;
|
||||
import com.google.common.net.MediaType;
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
import com.google.domain.registry.testing.FakeResponse;
|
||||
import com.google.domain.registry.testing.UserInfo;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/** Unit tests for {@link ConsoleUiAction}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConsoleUiActionTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngineRule = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withUserService(UserInfo.create("marla.singer@example.com", "12345"))
|
||||
.build();
|
||||
|
||||
@Mock
|
||||
private SessionUtils sessionUtils;
|
||||
|
||||
private final FakeResponse response = new FakeResponse();
|
||||
private final ConsoleUiAction action = new ConsoleUiAction();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
action.enabled = true;
|
||||
action.response = response;
|
||||
action.sessionUtils = sessionUtils;
|
||||
action.userService = UserServiceFactory.getUserService();
|
||||
when(sessionUtils.checkRegistrarConsoleLogin(any(HttpServletRequest.class))).thenReturn(true);
|
||||
when(sessionUtils.getRegistrarClientId(any(HttpServletRequest.class)))
|
||||
.thenReturn("TheRegistrar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webPage_disallowsIframe() throws Exception {
|
||||
action.run();
|
||||
assertThat(response.getHeaders()).containsEntry("X-Frame-Options", "SAMEORIGIN");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webPage_setsHtmlUtf8ContentType() throws Exception {
|
||||
action.run();
|
||||
assertThat(response.getContentType()).isEqualTo(MediaType.HTML_UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webPage_containsUserNickname() throws Exception {
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("marla.singer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userHasAccessAsTheRegistrar_showsRegistrarConsole() throws Exception {
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("Registrar Console");
|
||||
assertThat(response.getPayload()).contains("reg-content-and-footer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consoleDisabled_showsDisabledPage() throws Exception {
|
||||
action.enabled = false;
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("<h1>Console is disabled</h1>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userDoesntHaveAccessToAnyRegistrar_showsWhoAreYouPage() throws Exception {
|
||||
when(sessionUtils.checkRegistrarConsoleLogin(any(HttpServletRequest.class))).thenReturn(false);
|
||||
action.run();
|
||||
assertThat(response.getPayload()).contains("<h1>You need permission</h1>");
|
||||
}
|
||||
}
|
|
@ -1,99 +0,0 @@
|
|||
// Copyright 2016 Google Inc. 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 com.google.domain.registry.ui.server.registrar;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.domain.registry.config.TestRegistryConfig;
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
import com.google.domain.registry.testing.RegistryConfigRule;
|
||||
import com.google.domain.registry.testing.UserInfo;
|
||||
import com.google.domain.registry.ui.soy.registrar.ConsoleSoyInfo;
|
||||
import com.google.template.soy.data.SoyMapData;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/** Unit tests for {@link ConsoleUiServlet}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConsoleUiServletTest {
|
||||
|
||||
@Rule
|
||||
public AppEngineRule appEngineRule = AppEngineRule.builder()
|
||||
.withUserService(UserInfo.create("foo@bar.com", "12345"))
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final RegistryConfigRule configRule = new RegistryConfigRule();
|
||||
|
||||
@Mock
|
||||
HttpServletRequest req;
|
||||
|
||||
@Mock
|
||||
HttpServletResponse rsp;
|
||||
|
||||
final ConsoleUiServlet servlet = new ConsoleUiServlet();
|
||||
|
||||
final StringWriter stringWriter = new StringWriter();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
when(req.getMethod()).thenReturn("GET");
|
||||
when(rsp.getWriter()).thenReturn(new PrintWriter(stringWriter));
|
||||
when(req.getRequestURI()).thenReturn("/registrar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTofuCompilation() throws Exception {
|
||||
ConsoleUiServlet.TOFU_SUPPLIER.get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTofuRender() throws Exception {
|
||||
SoyMapData data = new SoyMapData();
|
||||
SoyMapData user = new SoyMapData();
|
||||
user.put("name", "lol");
|
||||
user.put("actionName", "lol");
|
||||
user.put("actionHref", "lol");
|
||||
data.put("user", user);
|
||||
ConsoleUiServlet.TOFU_SUPPLIER.get()
|
||||
.newRenderer(ConsoleSoyInfo.WHOAREYOU)
|
||||
.setCssRenamingMap(ConsoleUiServlet.CSS_RENAMING_MAP_SUPPLIER.get())
|
||||
.setData(data)
|
||||
.render();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGet_consoleDisabled() throws Exception {
|
||||
configRule.override(new TestRegistryConfig() {
|
||||
@Override
|
||||
public boolean isRegistrarConsoleEnabled() {
|
||||
return false;
|
||||
}});
|
||||
servlet.service(req, rsp);
|
||||
assertThat(stringWriter.toString()).contains("Console is disabled");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue