mirror of
https://github.com/google/nomulus.git
synced 2025-06-02 02:28:40 +02:00
Delete admin console
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=116894352
This commit is contained in:
parent
6772b2ef80
commit
f2116093b1
33 changed files with 2 additions and 2912 deletions
|
@ -49,7 +49,6 @@ java_library(
|
|||
"//java/com/google/domain/registry/flows",
|
||||
"//java/com/google/domain/registry/module/backend",
|
||||
"//java/com/google/domain/registry/module/frontend",
|
||||
"//java/com/google/domain/registry/ui/server/admin",
|
||||
"//java/com/google/domain/registry/ui/server/api",
|
||||
"//java/com/google/domain/registry/ui/server/registrar",
|
||||
"//third_party/java/jsr305_annotations",
|
||||
|
|
|
@ -76,15 +76,7 @@ public final class RegistryTestServer {
|
|||
route("/registrar-payment",
|
||||
com.google.domain.registry.module.frontend.FrontendServlet.class),
|
||||
route("/registrar-payment-setup",
|
||||
com.google.domain.registry.module.frontend.FrontendServlet.class),
|
||||
|
||||
// Admin Console
|
||||
route("/_dr/admin",
|
||||
com.google.domain.registry.ui.server.admin.AdminUiServlet.class),
|
||||
route("/_dr/admin/registry/*",
|
||||
com.google.domain.registry.ui.server.admin.RegistryServlet.class),
|
||||
route("/_dr/admin/registrar/*",
|
||||
com.google.domain.registry.ui.server.admin.RegistrarServlet.class));
|
||||
com.google.domain.registry.module.frontend.FrontendServlet.class));
|
||||
|
||||
private final TestServer server;
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
|
||||
|
||||
load("//third_party/closure/testing:closure_js_test.bzl", "closure_js_test")
|
||||
|
||||
|
||||
closure_js_test(
|
||||
name = "test",
|
||||
size = "medium",
|
||||
timeout = "short",
|
||||
srcs = glob(["*_test.js"]),
|
||||
deps = [
|
||||
"//java/com/google/domain/registry/ui/js/admin",
|
||||
"//java/com/google/domain/registry/ui/soy/admin:Console",
|
||||
"//javascript/closure",
|
||||
"//javatests/com/google/domain/registry/ui/js:testing",
|
||||
],
|
||||
)
|
|
@ -1,306 +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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.History');
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.soy');
|
||||
goog.require('goog.string');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.asserts');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.testing.mockmatchers');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.admin.Console');
|
||||
goog.require('registry.soy.admin.console');
|
||||
goog.require('registry.testing');
|
||||
|
||||
|
||||
var $ = goog.dom.getRequiredElement;
|
||||
var _ = goog.testing.mockmatchers.ignoreArgument;
|
||||
var stubs = new goog.testing.PropertyReplacer();
|
||||
var mocks = new goog.testing.MockControl();
|
||||
|
||||
var historyMock;
|
||||
var adminConsole;
|
||||
|
||||
|
||||
function setUp() {
|
||||
registry.testing.addToDocument('<div id="test"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.admin.console.main, {
|
||||
xsrfToken: 'ignore',
|
||||
clientIdentifier: 'ignore',
|
||||
user: {
|
||||
'id': 'go@daddy.tld',
|
||||
'actionHref': 'http://godaddy.com',
|
||||
'actionName': 'ignore'
|
||||
}
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
|
||||
historyMock = mocks.createStrictMock(goog.History);
|
||||
mocks.createConstructorMock(goog, 'History')().$returns(historyMock);
|
||||
historyMock.addEventListener(_, _, _);
|
||||
historyMock.setEnabled(true);
|
||||
|
||||
mocks.$replayAll();
|
||||
adminConsole = new registry.admin.Console('༼༎෴ ༎༽');
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
function tearDown() {
|
||||
goog.dispose(adminConsole);
|
||||
stubs.reset();
|
||||
mocks.$tearDown();
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
}
|
||||
|
||||
|
||||
function testCollectionView() {
|
||||
historyMock.$reset();
|
||||
historyMock.getToken().$returns('registrar');
|
||||
mocks.$replayAll();
|
||||
adminConsole.handleHashChange();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar',
|
||||
{op: 'read', args: {}},
|
||||
{set: []});
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
assertNotNull($('clientIdentifier'));
|
||||
}
|
||||
|
||||
|
||||
function testCreate() {
|
||||
testCollectionView();
|
||||
var testRegistrar = createTestRegistrar();
|
||||
$('clientIdentifier').value = testRegistrar.clientIdentifier;
|
||||
$('registrarName').value = testRegistrar.registrarName;
|
||||
$('icannReferralEmail').value = testRegistrar.icannReferralEmail;
|
||||
$('emailAddress').value = testRegistrar.emailAddress;
|
||||
$('localizedAddress.street[0]').value =
|
||||
testRegistrar.localizedAddress.street[0];
|
||||
$('localizedAddress.city').value = testRegistrar.localizedAddress.city;
|
||||
$('localizedAddress.countryCode').value =
|
||||
testRegistrar.localizedAddress.countryCode;
|
||||
registry.testing.click($('create-button'));
|
||||
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar/daddy', {
|
||||
op: 'create',
|
||||
args: testRegistrar
|
||||
},
|
||||
{results: ['daddy: ok']});
|
||||
|
||||
testRegistrar.state = 'PENDING';
|
||||
testRegistrar.lastUpdateTime = '2014-08-11T21:57:58.801Z';
|
||||
testRegistrar.creationTime = '2014-08-11T21:57:58.801Z';
|
||||
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar/daddy',
|
||||
{op: 'read', args: {}},
|
||||
{item: testRegistrar });
|
||||
mocks.$verifyAll();
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
assertEquals('daddy',
|
||||
goog.dom.getElementsByTagNameAndClass('h1')[0].innerHTML);
|
||||
assertEquals('PENDING', $('state').value);
|
||||
|
||||
historyMock.$reset();
|
||||
historyMock.getToken().$returns('registrar');
|
||||
mocks.$replayAll();
|
||||
adminConsole.handleHashChange();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar',
|
||||
{op: 'read', args: {}},
|
||||
{set: [testRegistrar]});
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
function testItemViewEditSave() {
|
||||
testCreate();
|
||||
historyMock.$reset();
|
||||
historyMock.getToken().$returns('registrar/daddy');
|
||||
mocks.$replayAll();
|
||||
|
||||
adminConsole.handleHashChange();
|
||||
var testRegistrar = createTestRegistrar();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar/daddy',
|
||||
{op: 'read', args: {}},
|
||||
{item: testRegistrar });
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
|
||||
assertTrue('Form should be read-only.', $('registrarName').readOnly);
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
assertFalse('Form should be edible.', $('registrarName').readOnly);
|
||||
|
||||
testRegistrar.registrarName = 'GoDaddy';
|
||||
testRegistrar.emailAddress = 'new@email.com';
|
||||
testRegistrar.icannReferralEmail = 'new@referral.com';
|
||||
testRegistrar.state = 'ACTIVE';
|
||||
testRegistrar.allowedTlds = 'foo,bar,baz';
|
||||
testRegistrar.driveFolderId = 'driveFolderId';
|
||||
testRegistrar.phoneNumber = '+1.2345678900';
|
||||
testRegistrar.faxNumber = '+1.2345678900';
|
||||
testRegistrar.whoisServer = 'blah.blee.foo';
|
||||
testRegistrar.blockPremiumNames = true;
|
||||
testRegistrar.localizedAddress = {
|
||||
street: ['mean', '', ''],
|
||||
city: 'NYC',
|
||||
state: 'AZ',
|
||||
zip: '5555',
|
||||
countryCode: 'NZ'
|
||||
};
|
||||
testRegistrar.clientCertificate = '-----BEGIN CERTIFICATE-----' +
|
||||
'MIIDvTCCAqWgAwIBAgIJAK/PgPT0jTwRMA0GCSqGSIb3DQEBCwUAMHUxCzAJBgNV' +
|
||||
'BAYTAlVTMREwDwYDVQQIDAhOZXcgWW9yazERMA8GA1UEBwwITmV3IFlvcmsxDzAN' +
|
||||
'BgNVBAoMBkdvb2dsZTEdMBsGA1UECwwUZG9tYWluLXJlZ2lzdHJ5LXRlc3QxEDAO' +
|
||||
'BgNVBAMMB2NsaWVudDEwHhcNMTUwODI2MTkxODA4WhcNNDMwMTExMTkxODA4WjB1' +
|
||||
'MQswCQYDVQQGEwJVUzERMA8GA1UECAwITmV3IFlvcmsxETAPBgNVBAcMCE5ldyBZ' +
|
||||
'b3JrMQ8wDQYDVQQKDAZHb29nbGUxHTAbBgNVBAsMFGRvbWFpbi1yZWdpc3RyeS10' +
|
||||
'ZXN0MRAwDgYDVQQDDAdjbGllbnQxMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB' +
|
||||
'CgKCAQEAvoE/IoFJyzb0dU4NFhL8FYgy+B/GnUd5aA66CMx5xKRMbEAtIgxU8TTO' +
|
||||
'W+9jdTsE00Grk3Ct4KdY73CYW+6IFXL4O0K/m5S+uajh+I2UMVZJV38RAIqNxue0' +
|
||||
'Egv9M4haSsCVIPcX9b+6McywfYSF1bzPb2Gb2FAQO7Jb0BjlPhPMIROCrbG40qPg' +
|
||||
'LWrl33dz+O52kO+DyZEzHqI55xH6au77sMITsJe+X23lzQcMFUUm8moiOw0EKrj/' +
|
||||
'GaMTZLHP46BCRoJDAPTNx55seIwgAHbKA2VVtqrvmA2XYJQA6ipdhfKRoJFy8Z8H' +
|
||||
'DYsorGtazQL2HhF/5uJD25z1m5eQHQIDAQABo1AwTjAdBgNVHQ4EFgQUParEmiSR' +
|
||||
'U/Oqy8hr7k+MBKhZwVkwHwYDVR0jBBgwFoAUParEmiSRU/Oqy8hr7k+MBKhZwVkw' +
|
||||
'DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAojsUhF6PtZrStnHBFWNR' +
|
||||
'ryzvANB8krZlYeX9Hkqn8zIVfAkpbVmL8aZQ7yj17jSpw47PQh3x5gwA9yc/SS0G' +
|
||||
'E1rGuxYH02UGbua8G0+vviSQfLtskPQzK7EIR63WNhHEo/Q9umLJkZ0LguWEBf3L' +
|
||||
'q8CoXv2i/RNvqVPcTNp/zCKXJZAa8wAjNRJs834AZj4k5xwyYZ3F8D5PGz+YMOmV' +
|
||||
'M9Qd+NdXSC/Qn7HQzFhE8p5elBV35P8oX5dXEfn0S7zOXDenp5JvvLoggOWOcKsq' +
|
||||
'KiWDQrsT+TMKmHL94/h4t7FghtQLMzY5SGYJsYTv/LG8tewrz6KRb/Wj3JNojyEw' +
|
||||
'Ug==' +
|
||||
'-----END CERTIFICATE-----';
|
||||
testRegistrar.phonePasscode = '01234';
|
||||
testRegistrar.ipAddressWhitelist = '1.1.1.1,2.2.2.2';
|
||||
testRegistrar.password = 'yoyoSheep';
|
||||
testRegistrar.billingIdentifier = '12345';
|
||||
testRegistrar.ianaIdentifier = '11111';
|
||||
testRegistrar.url = 'http://yoyo.com';
|
||||
testRegistrar.referralUrl = 'http://other.com';
|
||||
testRegistrar.contacts = [{
|
||||
name: 'Joe',
|
||||
emailAddress: 'joe@go.com',
|
||||
phoneNumber: '',
|
||||
faxNumber: '',
|
||||
types: 'ADMIN,TECH',
|
||||
gaeUserId: '1234'
|
||||
}, {
|
||||
name: 'Jane',
|
||||
emailAddress: 'joe@go.com',
|
||||
phoneNumber: '',
|
||||
faxNumber: '',
|
||||
types: '',
|
||||
gaeUserId: '5432'
|
||||
}];
|
||||
|
||||
for (var i in testRegistrar) {
|
||||
// Not all keys are present as inputs with id,
|
||||
// e.g. clientIdentifier.
|
||||
var inputElt = goog.dom.getElement(i);
|
||||
if (inputElt) {
|
||||
inputElt.value = testRegistrar[i];
|
||||
}
|
||||
if (i == 'contacts' ||
|
||||
i == 'localizedAddress' ||
|
||||
i == 'blockPremiumNames') {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (testRegistrar.blockPremiumNames) {
|
||||
$('blockPremiumNames').setAttribute('checked', true);
|
||||
}
|
||||
|
||||
var addr = testRegistrar['localizedAddress'];
|
||||
$('localizedAddress.street[0]').value = addr.street[0];
|
||||
$('localizedAddress.street[1]').value = addr.street[1];
|
||||
$('localizedAddress.street[2]').value = addr.street[2];
|
||||
$('localizedAddress.city').value = addr.city;
|
||||
$('localizedAddress.state').value = addr.state;
|
||||
$('localizedAddress.zip').value = addr.zip;
|
||||
$('localizedAddress.countryCode').value = addr.countryCode;
|
||||
|
||||
var contacts = testRegistrar['contacts'];
|
||||
for (var c = 0; c < contacts.length; c++) {
|
||||
registry.testing.click($('add-contact-button'));
|
||||
var contact = contacts[c];
|
||||
for (var ci in contact) {
|
||||
// Form IDs are the full path ref.
|
||||
$('contacts[' + c + '].' + ci).value = contact[ci];
|
||||
}
|
||||
}
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
|
||||
// Convert string to wire vals for assert comparison.
|
||||
testRegistrar.billingIdentifier =
|
||||
goog.string.parseInt(testRegistrar.billingIdentifier);
|
||||
testRegistrar.ianaIdentifier =
|
||||
goog.string.parseInt(testRegistrar.ianaIdentifier);
|
||||
testRegistrar.allowedTlds = testRegistrar.allowedTlds.split(',');
|
||||
testRegistrar.ipAddressWhitelist =
|
||||
testRegistrar.ipAddressWhitelist.split(',');
|
||||
// And the readonly field the client adds.
|
||||
testRegistrar.readonly = false;
|
||||
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar/daddy',
|
||||
{op: 'update', args: testRegistrar},
|
||||
{results: ['daddy: ok']});
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registrar/daddy',
|
||||
{op: 'read', args: {}},
|
||||
{item: testRegistrar});
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
/** @return {!Object.<string, ?>} */
|
||||
function createTestRegistrar() {
|
||||
return {
|
||||
clientIdentifier: 'daddy',
|
||||
registrarName: 'The Daddy',
|
||||
icannReferralEmail: 'lol@sloth.test',
|
||||
emailAddress: 'foo@bar.com',
|
||||
localizedAddress: {
|
||||
street: ['111 8th Ave.'],
|
||||
city: 'NYC',
|
||||
countryCode: 'NZ'
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,207 +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.
|
||||
|
||||
goog.setTestOnly();
|
||||
|
||||
goog.require('goog.History');
|
||||
goog.require('goog.dispose');
|
||||
goog.require('goog.dom');
|
||||
goog.require('goog.soy');
|
||||
goog.require('goog.testing.MockControl');
|
||||
goog.require('goog.testing.PropertyReplacer');
|
||||
goog.require('goog.testing.asserts');
|
||||
goog.require('goog.testing.jsunit');
|
||||
goog.require('goog.testing.mockmatchers');
|
||||
goog.require('goog.testing.net.XhrIo');
|
||||
goog.require('registry.admin.Console');
|
||||
goog.require('registry.soy.admin.console');
|
||||
goog.require('registry.testing');
|
||||
|
||||
|
||||
var $ = goog.dom.getRequiredElement;
|
||||
var _ = goog.testing.mockmatchers.ignoreArgument;
|
||||
var stubs = new goog.testing.PropertyReplacer();
|
||||
var mocks = new goog.testing.MockControl();
|
||||
|
||||
var historyMock;
|
||||
var adminConsole;
|
||||
|
||||
|
||||
function setUp() {
|
||||
registry.testing.addToDocument('<div id="test"/>');
|
||||
goog.soy.renderElement($('test'), registry.soy.admin.console.main, {
|
||||
xsrfToken: 'ignore',
|
||||
clientId: 'ignore',
|
||||
user: {
|
||||
'id': 'go@daddy.tld',
|
||||
'actionHref': 'http://godaddy.com',
|
||||
'actionName': 'ignore'
|
||||
}
|
||||
});
|
||||
stubs.setPath('goog.net.XhrIo', goog.testing.net.XhrIo);
|
||||
|
||||
historyMock = mocks.createStrictMock(goog.History);
|
||||
mocks.createConstructorMock(goog, 'History')().$returns(historyMock);
|
||||
historyMock.addEventListener(_, _, _);
|
||||
historyMock.setEnabled(true);
|
||||
|
||||
mocks.$replayAll();
|
||||
adminConsole = new registry.admin.Console('༼༎෴ ༎༽');
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
function tearDown() {
|
||||
goog.dispose(adminConsole);
|
||||
stubs.reset();
|
||||
mocks.$tearDown();
|
||||
goog.testing.net.XhrIo.cleanup();
|
||||
}
|
||||
|
||||
|
||||
function testCollectionView() {
|
||||
historyMock.$reset();
|
||||
historyMock.getToken().$returns('registry');
|
||||
mocks.$replayAll();
|
||||
adminConsole.handleHashChange();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry',
|
||||
{op: 'read', args: {}},
|
||||
{set: []});
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
assertNotNull($('newTldName'));
|
||||
}
|
||||
|
||||
|
||||
/** Creates test registry. */
|
||||
function createTestRegistry() {
|
||||
return {
|
||||
addGracePeriod: 'PT432000S',
|
||||
autoRenewGracePeriod: 'PT3888000S',
|
||||
automaticTransferLength: 'PT432000S',
|
||||
name: 'foo',
|
||||
pendingDeleteLength: 'PT432000S',
|
||||
redemptionGracePeriod: 'PT2592000S',
|
||||
renewGracePeriod: 'PT432000S',
|
||||
state: 'PREDELEGATION',
|
||||
tldStateTransitions: '{1970-01-01T00:00:00.000Z=PREDELEGATION}',
|
||||
transferGracePeriod: 'PT432000S'
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function testCreate() {
|
||||
testCollectionView();
|
||||
$('newTldName').value = 'foo';
|
||||
registry.testing.click($('create-button'));
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry/foo', {
|
||||
op: 'create',
|
||||
args: {
|
||||
newTldName: 'foo'
|
||||
}
|
||||
},
|
||||
{results: ['foo: ok']});
|
||||
var testReg = createTestRegistry();
|
||||
testReg.creationTime = '2014-08-07T20:35:39.142Z';
|
||||
testReg.lastUpdateTime = '2014-08-07T20:35:39.142Z';
|
||||
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry/foo',
|
||||
{op: 'read', args: {}},
|
||||
{item: testReg });
|
||||
mocks.$verifyAll();
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
assertEquals('foo', goog.dom.getElementsByTagNameAndClass('h1')[0].innerHTML);
|
||||
|
||||
historyMock.$reset();
|
||||
historyMock.getToken().$returns('registry');
|
||||
mocks.$replayAll();
|
||||
adminConsole.handleHashChange();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry',
|
||||
{op: 'read', args: {}},
|
||||
{set: [testReg]});
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
}
|
||||
|
||||
|
||||
function testItemViewEditSave() {
|
||||
testCreate();
|
||||
historyMock.$reset();
|
||||
historyMock.getToken().$returns('registry/foo');
|
||||
mocks.$replayAll();
|
||||
|
||||
adminConsole.handleHashChange();
|
||||
var testReg = createTestRegistry();
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry/foo',
|
||||
{op: 'read', args: {}},
|
||||
{item: testReg });
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
|
||||
assertTrue('Form should be read-only.', $('addGracePeriod').readOnly);
|
||||
registry.testing.click($('reg-app-btn-edit'));
|
||||
assertFalse('Form should be editable.', $('addGracePeriod').readOnly);
|
||||
|
||||
// Edit state
|
||||
testReg.tldStateTransitions = 'GENERAL_AVAILABILITY,1970-01-01T00:00:00.000Z';
|
||||
for (var i in testReg) {
|
||||
// Not all keys are present as inputs with id,
|
||||
// e.g. name.
|
||||
var inputElt = goog.dom.getElement(i);
|
||||
if (inputElt) {
|
||||
inputElt.value = testReg[i];
|
||||
}
|
||||
}
|
||||
registry.testing.click($('reg-app-btn-save'));
|
||||
|
||||
// Convert string to wire vals.
|
||||
var tldStateTransitionStr = testReg.tldStateTransitions;
|
||||
testReg.tldStateTransitions = [{
|
||||
tldState: 'GENERAL_AVAILABILITY',
|
||||
transitionTime: '1970-01-01T00:00:00.000Z'
|
||||
}];
|
||||
// And the readonly field the client adds.
|
||||
testReg.readonly = false;
|
||||
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry/foo',
|
||||
{op: 'update', args: testReg},
|
||||
{results: ['foo: ok']});
|
||||
|
||||
// Restore the stringified version.
|
||||
testReg.tldStateTransitions = tldStateTransitionStr;
|
||||
registry.testing.assertReqMockRsp(
|
||||
'༼༎෴ ༎༽',
|
||||
'/_dr/admin/registry/foo',
|
||||
{op: 'read', args: {}},
|
||||
{item: testReg});
|
||||
assertEquals('We require more vespene gas.',
|
||||
0, goog.testing.net.XhrIo.getSendInstances().length);
|
||||
mocks.$verifyAll();
|
||||
}
|
|
@ -1,29 +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.admin;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Unit tests for {@link AdminUiServlet}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class AdminUiServletTest {
|
||||
|
||||
@Test
|
||||
public void testTofuCompilation() throws Exception {
|
||||
AdminUiServlet.TOFU_SUPPLIER.get();
|
||||
}
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
package(default_visibility = ["//java/com/google/domain/registry:registry_project"])
|
||||
|
||||
load("//java/com/google/testing/builddefs:GenTestRules.bzl", "GenTestRules")
|
||||
|
||||
|
||||
java_library(
|
||||
name = "admin",
|
||||
srcs = glob(["*.java"]),
|
||||
deps = [
|
||||
"//java/com/google/common/base",
|
||||
"//java/com/google/common/collect",
|
||||
"//java/com/google/domain/registry/config",
|
||||
"//java/com/google/domain/registry/export/sheet",
|
||||
"//java/com/google/domain/registry/model",
|
||||
"//java/com/google/domain/registry/ui/server/admin",
|
||||
"//java/com/google/domain/registry/util",
|
||||
"//javatests/com/google/domain/registry/testing",
|
||||
"//third_party/java/appengine:appengine-api-testonly",
|
||||
"//third_party/java/joda_time",
|
||||
"//third_party/java/junit",
|
||||
"//third_party/java/mockito",
|
||||
"//third_party/java/objectify:objectify-v4_1",
|
||||
"//third_party/java/servlet/servlet_api",
|
||||
"//third_party/java/truth",
|
||||
],
|
||||
)
|
||||
|
||||
GenTestRules(
|
||||
name = "GeneratedTestRules",
|
||||
test_files = glob(["*Test.java"]),
|
||||
deps = [":admin"],
|
||||
)
|
|
@ -1,340 +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.admin;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.domain.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static com.google.domain.registry.testing.DatastoreHelper.createTld;
|
||||
import static com.google.domain.registry.testing.TaskQueueHelper.assertNoTasksEnqueued;
|
||||
import static com.google.domain.registry.testing.TaskQueueHelper.assertTasksEnqueued;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.appengine.api.modules.ModulesService;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.domain.registry.config.RegistryEnvironment;
|
||||
import com.google.domain.registry.export.sheet.SyncRegistrarsSheetTask;
|
||||
import com.google.domain.registry.model.common.EntityGroupRoot;
|
||||
import com.google.domain.registry.model.ofy.Ofy;
|
||||
import com.google.domain.registry.model.registrar.Registrar;
|
||||
import com.google.domain.registry.model.registrar.Registrar.State;
|
||||
import com.google.domain.registry.model.registrar.RegistrarAddress;
|
||||
import com.google.domain.registry.model.registrar.RegistrarContact;
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
import com.google.domain.registry.testing.CertificateSamples;
|
||||
import com.google.domain.registry.testing.FakeClock;
|
||||
import com.google.domain.registry.testing.InjectRule;
|
||||
import com.google.domain.registry.testing.TaskQueueHelper.TaskMatcher;
|
||||
import com.google.domain.registry.util.CidrAddressBlock;
|
||||
import com.google.domain.registry.util.DateTimeUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/** Tests for {@link RegistrarServlet}. */
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RegistrarServletTest {
|
||||
|
||||
//TODO(pmy): remove this duplicate of the registrar console test.
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.withTaskQueue()
|
||||
.build();
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
@Mock
|
||||
private ModulesService modulesService;
|
||||
|
||||
final String clientId = "NewDaddy";
|
||||
final String tld = "xn--q9jyb4c";
|
||||
|
||||
FakeClock clock = new FakeClock(DateTimeUtils.START_OF_TIME.plusMillis(1));
|
||||
HttpServletRequest req;
|
||||
Registrar registrar;
|
||||
Map<String, Object> regMap;
|
||||
RegistrarServlet servlet;
|
||||
|
||||
/**
|
||||
* Empty whoisServer and referralUrl fields should be set to
|
||||
* defaults by server.
|
||||
*/
|
||||
static Registrar simulateDefaultsForEmptyFields(Registrar registrar) {
|
||||
return registrar.asBuilder()
|
||||
.setWhoisServer(RegistryEnvironment.get().config().getRegistrarDefaultWhoisServer())
|
||||
.setReferralUrl(
|
||||
RegistryEnvironment.get().config().getRegistrarDefaultReferralUrl().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
inject.setStaticField(
|
||||
Registrar.class, "saltSupplier", Suppliers.ofInstance(new byte[]{1, 2, 3, 4}));
|
||||
inject.setStaticField(SyncRegistrarsSheetTask.class, "modulesService", modulesService);
|
||||
req = Mockito.mock(HttpServletRequest.class);
|
||||
when(req.getContextPath()).thenReturn("/_dr/admin");
|
||||
when(req.getRequestURI()).thenReturn("/_dr/admin/registrar/" + clientId);
|
||||
when(modulesService.getVersionHostname("backend", null)).thenReturn("backend.hostname");
|
||||
createTld(tld);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateRegistrar() {
|
||||
registrar = loadRegistrar(clientId);
|
||||
assertThat(registrar).isNull();
|
||||
|
||||
// A minimal registrar.
|
||||
registrar = new Registrar.Builder()
|
||||
.setClientIdentifier(clientId)
|
||||
.setRegistrarName("TheRegistrar")
|
||||
.setEmailAddress("admin@registrar.com")
|
||||
.setIcannReferralEmail("lol@sloth.test")
|
||||
.setState(State.ACTIVE)
|
||||
.setType(Registrar.Type.TEST)
|
||||
.build();
|
||||
regMap = registrar.toJsonMap();
|
||||
servlet = new RegistrarServlet();
|
||||
Map<String, ?> result = servlet.doJsonPost(req, ImmutableMap.of(
|
||||
"op", "create",
|
||||
"args", regMap));
|
||||
assertThat(result).containsEntry("results", ImmutableList.of(clientId + ": ok"));
|
||||
|
||||
registrar = simulateDefaultsForEmptyFields(registrar);
|
||||
Registrar createdRegistrar = loadRegistrar(clientId);
|
||||
assertThat(createdRegistrar).isEqualTo(registrar);
|
||||
registrar = createdRegistrar;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFullRegistrarUpdate() throws Exception {
|
||||
testCreateRegistrar();
|
||||
registrar = makeFullRegistrarObject();
|
||||
regMap = registrar.toJsonMap();
|
||||
regMap.put("password", "password");
|
||||
sendUpdate();
|
||||
registrar = registrar.asBuilder()
|
||||
.build();
|
||||
assertThat(loadRegistrar(clientId)).isEqualTo(registrar);
|
||||
assertTasksEnqueued("sheet", new TaskMatcher()
|
||||
.url(SyncRegistrarsSheetTask.PATH)
|
||||
.method("GET")
|
||||
.header("Host", "backend.hostname"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMoreUpdates() throws Exception {
|
||||
testFullRegistrarUpdate();
|
||||
|
||||
// Toggle the block premium names flag.
|
||||
regMap.put("blockPremiumNames", true);
|
||||
sendUpdate();
|
||||
registrar = registrar.asBuilder()
|
||||
.setBlockPremiumNames(true)
|
||||
.build();
|
||||
assertThat(loadRegistrar(clientId)).isEqualTo(registrar);
|
||||
|
||||
testSetAndNull("whoisServer", "foo.bar.com");
|
||||
testSetAndNull("url", "http://acme.com/");
|
||||
testSetAndNull("referralUrl", "http://acme.com/");
|
||||
testSetAndNull("phoneNumber", "+1.5551234444");
|
||||
testSetAndNull("faxNumber", "+1.5551234444");
|
||||
|
||||
regMap.put("clientCertificate", CertificateSamples.SAMPLE_CERT);
|
||||
sendUpdate();
|
||||
registrar = registrar.asBuilder()
|
||||
.setClientCertificate((String) regMap.get("clientCertificate"), clock.nowUtc())
|
||||
.build();
|
||||
assertThat(loadRegistrar(clientId)).isEqualTo(registrar);
|
||||
regMap.put("clientCertificate", CertificateSamples.SAMPLE_CERT2);
|
||||
sendUpdate();
|
||||
registrar = registrar.asBuilder()
|
||||
.setClientCertificate(CertificateSamples.SAMPLE_CERT2, clock.nowUtc())
|
||||
.build();
|
||||
assertThat(loadRegistrar(clientId)).isEqualTo(registrar);
|
||||
|
||||
// Update the password.
|
||||
regMap.put("password", "newPassword");
|
||||
sendUpdate();
|
||||
registrar = registrar.asBuilder().setPassword("newPassword").build();
|
||||
assertThat(loadRegistrar(clientId).testPassword("newPassword")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContactCreate() throws Exception {
|
||||
testFullRegistrarUpdate();
|
||||
|
||||
Map<String, /* @Nullable */ Object> contact = new HashMap<>();
|
||||
contact.put("name", "foo");
|
||||
contact.put("emailAddress", "foo@lol.com");
|
||||
contact.put("types", "ADMIN,LEGAL");
|
||||
contact.put("gaeUserId", "1234");
|
||||
|
||||
regMap.put("contacts", ImmutableList.of(contact));
|
||||
sendUpdate();
|
||||
|
||||
assertThat(registrar.getContacts()).containsExactly(
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("foo")
|
||||
.setEmailAddress("foo@lol.com")
|
||||
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN, RegistrarContact.Type.LEGAL))
|
||||
.setGaeUserId("1234")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdate_badState_returnsFormFieldError() throws Exception {
|
||||
testCreateRegistrar();
|
||||
Map<String, ?> result = new RegistrarServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"emailAddress", registrar.getEmailAddress(),
|
||||
"icannReferralEmail", registrar.getIcannReferralEmail(),
|
||||
"registrarName", registrar.getRegistrarName(),
|
||||
"state", "boo!")));
|
||||
assertThat(result).containsEntry("status", "ERROR");
|
||||
assertThat(result).containsEntry("field", "state");
|
||||
assertThat(result).containsEntry("message", "Enum State does not contain 'boo!'");
|
||||
assertNoTasksEnqueued("sheet");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContactUpdates() throws Exception {
|
||||
testFullRegistrarUpdate();
|
||||
|
||||
Map<String, /* @Nullable */ Object> adminContact1 = new HashMap<>();
|
||||
adminContact1.put("name", "contact1");
|
||||
adminContact1.put("emailAddress", "contact1@email.com");
|
||||
adminContact1.put("phoneNumber", "+1.2125650666");
|
||||
adminContact1.put("faxNumber", null);
|
||||
adminContact1.put("types", "ADMIN");
|
||||
|
||||
Map<String, /* @Nullable */ Object> adminContact2 = new HashMap<>();
|
||||
adminContact2.put("name", "foo");
|
||||
adminContact2.put("emailAddress", "foo@lol.com");
|
||||
adminContact2.put("types", "ADMIN");
|
||||
adminContact2.put("gaeUserId", "1234");
|
||||
|
||||
regMap.put("contacts", ImmutableList.of(adminContact1, adminContact2));
|
||||
sendUpdate();
|
||||
|
||||
assertThat(loadRegistrar(clientId).getContacts()).containsExactly(
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("contact1")
|
||||
.setEmailAddress("contact1@email.com")
|
||||
.setPhoneNumber("+1.2125650666")
|
||||
.setFaxNumber(null)
|
||||
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN))
|
||||
.build(),
|
||||
new RegistrarContact.Builder()
|
||||
.setParent(registrar)
|
||||
.setName("foo")
|
||||
.setEmailAddress("foo@lol.com")
|
||||
.setPhoneNumber(null)
|
||||
.setFaxNumber(null)
|
||||
.setTypes(ImmutableSet.of(RegistrarContact.Type.ADMIN))
|
||||
.setGaeUserId("1234")
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCertificateUpdate() throws Exception {
|
||||
testFullRegistrarUpdate();
|
||||
regMap.put("clientCertificate", CertificateSamples.SAMPLE_CERT2);
|
||||
sendUpdate();
|
||||
assertThat(loadRegistrar(clientId).getClientCertificate())
|
||||
.isEqualTo(CertificateSamples.SAMPLE_CERT2);
|
||||
assertThat(loadRegistrar(clientId).getClientCertificateHash())
|
||||
.isEqualTo(CertificateSamples.SAMPLE_CERT2_HASH);
|
||||
}
|
||||
|
||||
private Registrar makeFullRegistrarObject() {
|
||||
return registrar.asBuilder()
|
||||
.setRegistrarName("TRO LLC")
|
||||
.setAllowedTlds(ImmutableSet.of(tld))
|
||||
.setBillingIdentifier(12345L)
|
||||
.setBlockPremiumNames(false)
|
||||
.setEmailAddress("email@foo.bar")
|
||||
.setPhoneNumber("+1.2125551212")
|
||||
.setFaxNumber("+1.2125551212")
|
||||
.setLocalizedAddress(new RegistrarAddress.Builder()
|
||||
.setCity("loc city")
|
||||
.setCountryCode("CC")
|
||||
.setState("loc state")
|
||||
.setStreet(ImmutableList.of("loc street1", "loc street2"))
|
||||
.setZip("loc zip")
|
||||
.build())
|
||||
.setIpAddressWhitelist(ImmutableList.of(CidrAddressBlock.create("192.168.0.1/32")))
|
||||
.setPassword("password")
|
||||
.setReferralUrl("referral url")
|
||||
.setWhoisServer("whois.server")
|
||||
.setUrl("url")
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Registrar loadRegistrar(String id) {
|
||||
return ofy().load().type(Registrar.class)
|
||||
.parent(EntityGroupRoot.getCrossTldKey()).id(id).now();
|
||||
}
|
||||
|
||||
private void testSetAndNull(String field, String val) throws Exception {
|
||||
// Test null first and then restore value second to not affect
|
||||
// full registrar state in later tests.
|
||||
regMap.put(field, null);
|
||||
sendUpdate();
|
||||
registrar = setBuilderField(registrar.asBuilder(), field, null, val.getClass()).build();
|
||||
assertThat(loadRegistrar(clientId)).isEqualTo(registrar);
|
||||
|
||||
regMap.put(field, val);
|
||||
sendUpdate();
|
||||
registrar = setBuilderField(registrar.asBuilder(), field, val).build();
|
||||
assertThat(loadRegistrar(clientId)).isEqualTo(registrar);
|
||||
}
|
||||
|
||||
private Registrar.Builder setBuilderField(
|
||||
Registrar.Builder builder, String field, Object val, Class<?>... nullClass) throws Exception {
|
||||
java.lang.reflect.Method setter = Registrar.Builder.class.getMethod(
|
||||
"set" + field.substring(0, 1).toUpperCase() + field.substring(1),
|
||||
val == null ? nullClass[0] : val.getClass());
|
||||
setter.invoke(builder, val);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private void sendUpdate() {
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
Map<String, ?> result = servlet.doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", regMap));
|
||||
assertThat(result).doesNotContainEntry("status", "ERROR");
|
||||
}
|
||||
}
|
|
@ -1,304 +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.admin;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.domain.registry.model.registry.Registries.getTlds;
|
||||
import static com.google.domain.registry.util.DateTimeUtils.START_OF_TIME;
|
||||
import static org.joda.time.DateTimeZone.UTC;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSortedMap;
|
||||
import com.google.domain.registry.model.ofy.Ofy;
|
||||
import com.google.domain.registry.model.registry.Registry;
|
||||
import com.google.domain.registry.model.registry.Registry.TldState;
|
||||
import com.google.domain.registry.testing.AppEngineRule;
|
||||
import com.google.domain.registry.testing.FakeClock;
|
||||
import com.google.domain.registry.testing.InjectRule;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.Duration;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/** Tests for {@link RegistryServlet}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class RegistryServletTest {
|
||||
|
||||
@Rule
|
||||
public final AppEngineRule appEngine = AppEngineRule.builder()
|
||||
.withDatastore()
|
||||
.build();
|
||||
|
||||
HttpServletRequest req;
|
||||
|
||||
@Rule
|
||||
public final InjectRule inject = new InjectRule();
|
||||
|
||||
FakeClock clock = new FakeClock();
|
||||
|
||||
DateTime now = DateTime.now(UTC);
|
||||
|
||||
DateTime creationTime;
|
||||
|
||||
private static final Map<String, ?> SUCCESS = ImmutableMap.of("results", "OK");
|
||||
|
||||
private Registry createRegistry(String tld, TldState tldState) {
|
||||
return createRegistry(tld, ImmutableSortedMap.of(START_OF_TIME, tldState));
|
||||
}
|
||||
|
||||
private Registry createRegistry(
|
||||
String tld, ImmutableSortedMap<DateTime, TldState> tldStateTransitions) {
|
||||
return new Registry.Builder()
|
||||
.setTldStr(tld)
|
||||
.setTldStateTransitions(tldStateTransitions)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
inject.setStaticField(Ofy.class, "clock", clock);
|
||||
req = Mockito.mock(HttpServletRequest.class);
|
||||
Mockito.when(req.getContextPath()).thenReturn("/_dr/admin");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsePath() {
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/foo");
|
||||
assertThat(new RegistryServlet().parsePath(req)).isEqualTo("registry/foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseId() {
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/foo");
|
||||
assertThat(new RegistryServlet().parseId(req)).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost() {
|
||||
String tld = "xn--q9jyb4c";
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/" + tld);
|
||||
|
||||
assertThat(getTlds()).doesNotContain(tld);
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
new RegistryServlet().doJsonPost(req, ImmutableMap.of("op", "create"));
|
||||
creationTime = clock.nowUtc();
|
||||
|
||||
assertThat(Registry.get(tld)).isEqualTo(
|
||||
createRegistry(tld, TldState.PREDELEGATION));
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
Map<String, ?> result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRUSH")))));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
assertThat(Registry.get(tld)).isEqualTo(
|
||||
createRegistry(tld,
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME, TldState.PREDELEGATION,
|
||||
now, TldState.SUNRUSH)));
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of()));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
assertThat(Registry.get(tld)).isEqualTo(
|
||||
createRegistry(tld,
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME, TldState.PREDELEGATION,
|
||||
now, TldState.SUNRUSH)));
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRISE"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(1).toString(), "tldState", "SUNRUSH")))));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
assertThat(Registry.get(tld)).isEqualTo(
|
||||
createRegistry(tld,
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME, TldState.PREDELEGATION,
|
||||
now, TldState.SUNRISE,
|
||||
now.plusMonths(1), TldState.SUNRUSH)));
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRISE"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(1).toString(), "tldState", "SUNRUSH"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(2).toString(), "tldState", "QUIET_PERIOD"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(3).toString(),
|
||||
"tldState", "GENERAL_AVAILABILITY")))));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
assertThat(Registry.get(tld)).isEqualTo(
|
||||
createRegistry(tld,
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME, TldState.PREDELEGATION,
|
||||
now, TldState.SUNRISE,
|
||||
now.plusMonths(1), TldState.SUNRUSH,
|
||||
now.plusMonths(2), TldState.QUIET_PERIOD,
|
||||
now.plusMonths(3), TldState.GENERAL_AVAILABILITY)));
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRUSH"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(1).toString(),
|
||||
"tldState", "GENERAL_AVAILABILITY")))));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
assertThat(Registry.get(tld)).isEqualTo(
|
||||
createRegistry(tld,
|
||||
ImmutableSortedMap.of(
|
||||
START_OF_TIME, TldState.PREDELEGATION,
|
||||
now, TldState.SUNRUSH,
|
||||
now.plusMonths(1), TldState.GENERAL_AVAILABILITY)));
|
||||
|
||||
Registry tldRegistry = Registry.get(tld);
|
||||
|
||||
// Switch to foobar.
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/foobar");
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "create"));
|
||||
creationTime = clock.nowUtc();
|
||||
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "QUIET_PERIOD")))));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
assertThat(Registry.get("foobar")).isEqualTo(
|
||||
createRegistry("foobar", ImmutableSortedMap.of(START_OF_TIME, TldState.QUIET_PERIOD)));
|
||||
|
||||
// Make sure updating this new TLD "foobar" didn't modify the tld we are using.
|
||||
assertThat(Registry.get(tld)).isEqualTo(tldRegistry);
|
||||
|
||||
// This should fail since the states are out of order (SUNRISE comes before SUNRUSH).
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/" + tld);
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"id", tld,
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRUSH"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(1).toString(), "tldState", "SUNRISE")))));
|
||||
assertThat(result).isNotEqualTo(SUCCESS);
|
||||
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/xn--q9jyb4c");
|
||||
|
||||
// This should fail since the same state appears twice.
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRISE"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(1).toString(), "tldState", "SUNRISE")))));
|
||||
assertThat(result).isNotEqualTo(SUCCESS);
|
||||
|
||||
// This is the same as the case above, but with a different ordering. It should still fail
|
||||
// regardless.
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", ImmutableMap.of(
|
||||
"tldStateTransitions", ImmutableList.of(
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.plusMonths(1).toString(), "tldState", "SUNRISE"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", now.toString(), "tldState", "SUNRUSH"),
|
||||
ImmutableMap.of(
|
||||
"transitionTime", START_OF_TIME.toString(), "tldState", "PREDELEGATION")))));
|
||||
assertThat(result).isNotEqualTo(SUCCESS);
|
||||
|
||||
// To foobar.
|
||||
Mockito.when(req.getRequestURI()).thenReturn("/_dr/admin/registry/foobar");
|
||||
|
||||
// Test that all grace periods and other various status periods can be configured.
|
||||
clock.setTo(clock.nowUtc().plusMinutes(1));
|
||||
result = new RegistryServlet().doJsonPost(req, ImmutableMap.of(
|
||||
"op", "update",
|
||||
"args", new ImmutableMap.Builder<String, String>()
|
||||
.put("addGracePeriod", Duration.standardSeconds(1).toString())
|
||||
.put("autoRenewGracePeriod", Duration.standardSeconds(2).toString())
|
||||
.put("redemptionGracePeriod", Duration.standardSeconds(3).toString())
|
||||
.put("renewGracePeriod", Duration.standardSeconds(4).toString())
|
||||
.put("transferGracePeriod", Duration.standardSeconds(5).toString())
|
||||
.put("automaticTransferLength", Duration.standardSeconds(6).toString())
|
||||
.put("pendingDeleteLength", Duration.standardSeconds(7).toString()).build()));
|
||||
assertThat(result).isEqualTo(SUCCESS);
|
||||
|
||||
Registry loadedRegistry = Registry.get("foobar");
|
||||
assertThat(loadedRegistry.getAddGracePeriodLength()).isEqualTo(Duration.standardSeconds(1));
|
||||
assertThat(loadedRegistry.getAutoRenewGracePeriodLength())
|
||||
.isEqualTo(Duration.standardSeconds(2));
|
||||
assertThat(loadedRegistry.getRedemptionGracePeriodLength())
|
||||
.isEqualTo(Duration.standardSeconds(3));
|
||||
assertThat(loadedRegistry.getRenewGracePeriodLength()).isEqualTo(Duration.standardSeconds(4));
|
||||
assertThat(loadedRegistry.getTransferGracePeriodLength())
|
||||
.isEqualTo(Duration.standardSeconds(5));
|
||||
assertThat(loadedRegistry.getAutomaticTransferLength()).isEqualTo(Duration.standardSeconds(6));
|
||||
assertThat(loadedRegistry.getPendingDeleteLength()).isEqualTo(Duration.standardSeconds(7));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue