// 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. 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.registrar.Console'); goog.require('registry.soy.registrar.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 registrarConsole; function setUp() { registry.testing.addToDocument('
'); registry.testing.addToDocument('
'); goog.soy.renderElement($('test'), registry.soy.registrar.console.main, { xsrfToken: 'ignore', username: 'jart', logoutUrl: 'https://justinetunney.com', isAdmin: true, clientId: 'ignore', showPaymentLink: false, logoFilename: 'logo.png', productName: 'Nomulus' }); 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(); registrarConsole = new registry.registrar.Console('☢', 'jartine'); mocks.$verifyAll(); } function tearDown() { goog.dispose(registrarConsole); stubs.reset(); mocks.$tearDown(); goog.testing.net.XhrIo.cleanup(); } /** Handles EPP login. */ function handleLogin() { var request = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' jartine' + ' undefined' + ' ' + ' 1.0' + ' en' + ' ' + ' ' + ' urn:ietf:params:xml:ns:host-1.0' + ' urn:ietf:params:xml:ns:domain-1.0' + ' urn:ietf:params:xml:ns:contact-1.0' + ' ' + ' ' + ' asdf-1235' + ' ' + ''); var response = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' Registrar is already logged in' + ' ' + ' ' + ' asdf-1235' + ' ytk1RO+8SmaDQxrTIdulnw==-3' + ' ' + ' ' + ''); var xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue(xhr.isActive()); assertEquals('/registrar-xhr', xhr.getLastUri()); assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token')); registry.testing.assertXmlEquals(request, xhr.getLastContent()); xhr.simulateResponse(200, response); } function testView() { historyMock.$reset(); historyMock.getToken().$returns('domain/justine.lol').$anyTimes(); mocks.$replayAll(); registrarConsole.handleHashChange(); handleLogin(); var request = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' ' + ' justine.lol' + ' ' + ' ' + ' abc-1234' + ' ' + ''); var response = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' Command completed successfully' + ' ' + ' ' + ' ' + ' justine.lol' + ' 6-roid' + ' ' + ' GK Chesterton' + ' <justine>' + ' candycrush' + ' krieger' + ' ' + ' ns1.justine.lol' + ' ns2.justine.lol' + ' ' + ' ns1.justine.lol' + ' justine' + ' justine' + ' 2014-07-10T02:17:02Z' + ' 2015-07-10T02:17:02Z' + ' ' + ' lolcat' + ' ' + ' ' + ' ' + ' ' + ' abc-1234' + ' ytk1RO+8SmaDQxrTIdulnw==-4' + ' ' + ' ' + ''); var xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue('XHR is inactive.', xhr.isActive()); assertEquals('/registrar-xhr', xhr.getLastUri()); assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token')); registry.testing.assertXmlEquals(request, xhr.getLastContent()); xhr.simulateResponse(200, response); assertEquals('We require more vespene gas.', 0, goog.testing.net.XhrIo.getSendInstances().length); mocks.$verifyAll(); assertTrue('Form should be read-only.', $('domain:exDate').readOnly); assertContains('justine.lol', $('reg-content').innerHTML); assertEquals('2015-07-10T02:17:02Z', $('domain:exDate').value); assertEquals('GK Chesterton', $('domain:registrant').value); assertEquals('', $('domain:contact[0].value').value); assertEquals('candycrush', $('domain:contact[1].value').value); assertEquals('krieger', $('domain:contact[2].value').value); assertEquals('lolcat', $('domain:authInfo.domain:pw').value); assertEquals('ns1.justine.lol', $('domain:ns.domain:hostObj[0].value').value); assertEquals('ns2.justine.lol', $('domain:ns.domain:hostObj[1].value').value); } function testEdit() { testView(); historyMock.$reset(); mocks.$replayAll(); registry.testing.click($('reg-app-btn-edit')); assertFalse('Form should be edible.', $('domain:exDate').readOnly); $('domain:registrant').value = 'Jonathan Swift'; $('domain:authInfo.domain:pw').value = '(✿◕‿◕)ノ'; registry.testing.click($('reg-app-btn-save')); var request = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' ' + ' justine.lol' + ' ' + ' Jonathan Swift' + ' ' + ' (✿◕‿◕)ノ' + ' ' + ' ' + ' ' + ' ' + ' abc-1234' + ' ' + ''); var response = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' This world is built from a million lies.' + ' ' + ' ' + ' abc-1234' + ' 214CjbYuTsijoP8sgyFUNg==-e' + ' ' + ' ' + ''); var xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue('XHR is inactive.', xhr.isActive()); assertEquals('/registrar-xhr', xhr.getLastUri()); assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token')); registry.testing.assertXmlEquals(request, xhr.getLastContent()); xhr.simulateResponse(200, response); request = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' ' + ' justine.lol' + ' ' + ' ' + ' abc-1234' + ' ' + ''); response = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' How can we live in the land of the dead?' + ' ' + ' ' + ' ' + ' justine.lol' + ' 6-roid' + ' ' + ' Jonathan Swift' + ' <justine>' + ' candycrush' + ' krieger' + ' ' + ' ns1.justine.lol' + ' ns2.justine.lol' + ' ' + ' ns1.justine.lol' + ' justine' + ' justine' + ' 2014-07-10T02:17:02Z' + ' 2015-07-10T02:17:02Z' + ' ' + ' (✿◕‿◕)ノ' + ' ' + ' ' + ' ' + ' ' + ' abc-1234' + ' ytk1RO+8SmaDQxrTIdulnw==-4' + ' ' + ' ' + ''); xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue('XHR is inactive.', xhr.isActive()); assertEquals('/registrar-xhr', xhr.getLastUri()); assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token')); registry.testing.assertXmlEquals(request, xhr.getLastContent()); xhr.simulateResponse(200, response); assertEquals('We require more vespene gas.', 0, goog.testing.net.XhrIo.getSendInstances().length); mocks.$verifyAll(); assertTrue($('domain:exDate').readOnly); assertContains('justine.lol', $('reg-content').innerHTML); assertEquals('2015-07-10T02:17:02Z', $('domain:exDate').value); assertEquals('Jonathan Swift', $('domain:registrant').value); assertEquals('', $('domain:contact[0].value').value); assertEquals('candycrush', $('domain:contact[1].value').value); assertEquals('krieger', $('domain:contact[2].value').value); assertEquals('(✿◕‿◕)ノ', $('domain:authInfo.domain:pw').value); assertEquals('ns1.justine.lol', $('domain:ns.domain:hostObj[0].value').value); assertEquals('ns2.justine.lol', $('domain:ns.domain:hostObj[1].value').value); } function testEdit_cancel_restoresOriginalValues() { testView(); registry.testing.click($('reg-app-btn-edit')); assertFalse('Form should be edible.', $('domain:exDate').readOnly); $('domain:registrant').value = 'Jonathan Swift'; $('domain:authInfo.domain:pw').value = '(✿◕‿◕)ノ'; registry.testing.click($('reg-app-btn-cancel')); assertTrue('Form should be read-only.', $('domain:exDate').readOnly); assertEquals('GK Chesterton', $('domain:registrant').value); assertEquals('lolcat', $('domain:authInfo.domain:pw').value); } function testCreate() { historyMock.$reset(); historyMock.getToken().$returns('domain').$anyTimes(); mocks.$replayAll(); registrarConsole.handleHashChange(); handleLogin(); mocks.$verifyAll(); assertFalse('Form should be edible.', $('domain:name').readOnly); $('domain:name').value = 'bog.lol'; $('domain:period').value = '1'; $('domain:authInfo.domain:pw').value = 'attorney at lawl'; $('domain:registrant').value = 'Chris Pohl'; registry.testing.click($('domain-contact-add-button')); $('domain:contact[0].value').value = 'BlutEngel'; $('domain:contact[0].@type').value = 'admin'; registry.testing.click($('domain-contact-add-button')); $('domain:contact[1].value').value = 'Ravenous'; $('domain:contact[1].@type').value = 'tech'; registry.testing.click($('domain-contact-add-button')); $('domain:contact[2].value').value = 'Dark Angels'; $('domain:contact[2].@type').value = 'billing'; historyMock.$reset(); mocks.$replayAll(); registry.testing.click($('reg-app-btn-save')); var request = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' ' + ' bog.lol' + ' 1' + ' Chris Pohl' + ' BlutEngel' + ' Ravenous' + ' Dark Angels' + ' ' + ' attorney at lawl' + ' ' + ' ' + ' ' + ' abc-1234' + ' ' + ''); var response = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' Command completed successfully' + ' ' + ' ' + ' ' + ' bog.lol' + ' 2014-07-17T08:19:24Z' + ' 2015-07-17T08:19:24Z' + ' ' + ' ' + ' ' + ' abc-1234' + ' OBPI6JvEQfOUaO8qGf+IKA==-7' + ' ' + ' ' + ''); var xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue('XHR is inactive.', xhr.isActive()); assertEquals('/registrar-xhr', xhr.getLastUri()); assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token')); registry.testing.assertXmlEquals(request, xhr.getLastContent()); xhr.simulateResponse(200, response); request = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' ' + ' bog.lol' + ' ' + ' ' + ' abc-1234' + ' ' + ''); response = registry.testing.loadXml( '' + '' + ' ' + ' ' + ' Command completed successfully' + ' ' + ' ' + ' ' + ' bog.lol' + ' 1f-roid' + ' ' + ' Chris Pohl' + ' BlutEngel' + ' Ravenous' + ' Dark Angels' + ' justine' + ' justine' + ' 2014-07-17T08:19:24Z' + ' 2015-07-17T08:19:24Z' + ' ' + ' attorney at lawl' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' abc-1234' + ' OBPI6JvEQfOUaO8qGf+IKA==-8' + ' ' + ' ' + ''); xhr = goog.testing.net.XhrIo.getSendInstances().pop(); assertTrue('XHR is inactive.', xhr.isActive()); assertEquals('/registrar-xhr', xhr.getLastUri()); assertEquals('☢', xhr.getLastRequestHeaders().get('X-CSRF-Token')); registry.testing.assertXmlEquals(request, xhr.getLastContent()); xhr.simulateResponse(200, response); assertEquals('We require more vespene gas.', 0, goog.testing.net.XhrIo.getSendInstances().length); mocks.$verifyAll(); assertTrue('Form should be read-only.', $('domain:exDate').readOnly); assertContains('bog.lol', $('reg-content').innerHTML); assertEquals('2015-07-17T08:19:24Z', $('domain:exDate').value); assertEquals('Chris Pohl', $('domain:registrant').value); assertEquals('BlutEngel', $('domain:contact[0].value').value); assertEquals('Ravenous', $('domain:contact[1].value').value); assertEquals('Dark Angels', $('domain:contact[2].value').value); assertEquals('attorney at lawl', $('domain:authInfo.domain:pw').value); assertNull(goog.dom.getElement('domain:ns.domain:hostObj[0].value')); }