From 59e278a648065fd4cf12ff3e86da1b87870b8cb7 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Sat, 24 Feb 2018 20:08:51 -0500 Subject: [PATCH] ensure correct url is built for inventory hosts page --- awx/ui/test/e2e/fixtures.js | 42 +++++++++++++++---------------- awx/ui/test/e2e/tests/test-xss.js | 12 +++++++-- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/awx/ui/test/e2e/fixtures.js b/awx/ui/test/e2e/fixtures.js index ecb45db9dc..ddc705cdf7 100644 --- a/awx/ui/test/e2e/fixtures.js +++ b/awx/ui/test/e2e/fixtures.js @@ -10,24 +10,17 @@ import { const session = `e2e-${uuid().substr(0, 8)}`; const store = {}; -const getOrCreate = (endpoint, data, unique = ['name', 'username', 'id']) => { - const identifier = Object.keys(data).find(key => unique.includes(key)); +const getOrCreate = (endpoint, data, unique = ['name']) => { + const identifiers = Object.keys(data).filter(key => unique.indexOf(key) > -1); - if (identifier === undefined) { + if (identifiers.length < 1) { throw new Error('A unique key value must be provided.'); } - const identity = data[identifier]; + const lookup = `${endpoint}/${identifiers.map(key => data[key]).join('-')}`; + const params = Object.assign(...identifiers.map(key => ({ [key]: data[key] }))); - store[endpoint] = store[endpoint] || {}; - - if (store[endpoint][identity]) { - return store[endpoint][identity].then(created => created.data); - } - - const query = { params: { [identifier]: identity } }; - - store[endpoint][identity] = get(endpoint, query) + store[lookup] = store[lookup] || get(endpoint, { params }) .then(res => { if (res.data.results.length > 1) { return Promise.reject(new Error('More than one matching result.')); @@ -44,7 +37,7 @@ const getOrCreate = (endpoint, data, unique = ['name', 'username', 'id']) => { return Promise.reject(new Error(`unexpected response: ${res}`)); }); - return store[endpoint][identity].then(created => created.data); + return store[lookup].then(created => created.data); }; const getOrganization = (namespace = session) => getOrCreate('/organizations/', { @@ -57,7 +50,12 @@ const getInventory = (namespace = session) => getOrganization(namespace) name: `${namespace}-inventory`, description: namespace, organization: organization.id - })); + }).then(inventory => getOrCreate('/hosts/', { + name: `${namespace}-host`, + description: namespace, + inventory: inventory.id, + variables: JSON.stringify({ ansible_connection: 'local' }), + }, ['name', 'inventory']).then(() => inventory))); const getHost = (namespace = session) => getInventory(namespace) .then(inventory => getOrCreate('/hosts/', { @@ -65,7 +63,7 @@ const getHost = (namespace = session) => getInventory(namespace) description: namespace, inventory: inventory.id, variables: JSON.stringify({ ansible_connection: 'local' }), - })); + }, ['name', 'inventory'])); const getInventoryScript = (namespace = session) => getOrganization(namespace) .then(organization => getOrCreate('/inventory_scripts/', { @@ -265,8 +263,8 @@ const getWorkflowTemplate = (namespace = session) => { ]; const createSuccessNodes = ([projectNode, jobNode, sourceNode]) => Promise.all([ - getOrCreate(projectNode.related.success_nodes, { id: jobNode.id }), - getOrCreate(jobNode.related.success_nodes, { id: sourceNode.id }), + getOrCreate(projectNode.related.success_nodes, { id: jobNode.id }, ['id']), + getOrCreate(jobNode.related.success_nodes, { id: sourceNode.id }, ['id']), ]); return Promise.all(nodes) @@ -287,7 +285,7 @@ const getAuditor = (namespace = session) => getOrganization(namespace) is_superuser: false, is_system_auditor: true, password: AWX_E2E_PASSWORD - })); + }, ['username'])); const getUser = (namespace = session) => getOrganization(namespace) .then(organization => getOrCreate('/users/', { @@ -299,7 +297,7 @@ const getUser = (namespace = session) => getOrganization(namespace) is_superuser: false, is_system_auditor: false, password: AWX_E2E_PASSWORD - })); + }, ['username'])); const getJobTemplateAdmin = (namespace = session) => { const rolePromise = getJobTemplate(namespace) @@ -315,7 +313,7 @@ const getJobTemplateAdmin = (namespace = session) => { is_superuser: false, is_system_auditor: false, password: AWX_E2E_PASSWORD - })); + }, ['username'])); const assignRolePromise = Promise.all([userPromise, rolePromise]) .then(([user, role]) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id })); @@ -338,7 +336,7 @@ const getProjectAdmin = (namespace = session) => { is_superuser: false, is_system_auditor: false, password: AWX_E2E_PASSWORD - })); + }, ['username'])); const assignRolePromise = Promise.all([userPromise, rolePromise]) .then(([user, role]) => post(`/api/v2/roles/${role.id}/users/`, { id: user.id })); diff --git a/awx/ui/test/e2e/tests/test-xss.js b/awx/ui/test/e2e/tests/test-xss.js index 5d15bdfc99..b8ac4dba2f 100644 --- a/awx/ui/test/e2e/tests/test-xss.js +++ b/awx/ui/test/e2e/tests/test-xss.js @@ -40,7 +40,7 @@ module.exports = { getTeam(namespace).then(obj => { data.team = obj; }), getProjectAdmin(namespace).then(obj => { data.user = obj; }), getNotificationTemplate(namespace).then(obj => { data.notification = obj; }), - getJob(namespaceShort).then(obj => { data.job = obj; }), + getJob(namespace).then(obj => { data.job = obj; }), ]; Promise.all(resources) @@ -58,7 +58,6 @@ module.exports = { urls.organization = `${pages.organizations.url()}/${data.organization.id}`; urls.inventory = `${pages.inventories.url()}/inventory/${data.inventory.id}`; - urls.inventoryHosts = `${urls.inventory}/hosts`; urls.inventoryScript = `${pages.inventoryScripts.url()}/${data.inventoryScript.id}`; urls.inventorySource = `${urls.inventory}/inventory_sources/edit/${data.inventorySource.id}`; urls.sourceSchedule = `${urls.inventorySource}/schedules/${data.sourceSchedule.id}`; @@ -72,6 +71,7 @@ module.exports = { urls.notification = `${pages.notificationTemplates.url()}/${data.notification.id}`; urls.jobs = `${pages.jobs.url()}`; urls.jobsSchedules = `${pages.jobs.url()}/schedules`; + urls.inventoryHosts = `${pages.inventories.url()}/inventory/${data.host.summary_fields.inventory.id}/hosts`; client.useCss(); client.login(); @@ -691,6 +691,14 @@ module.exports = { const popOver = `${itemRow} td[class*="active_failures-"] div[class*="popover"]`; client.navigateTo(urls.inventoryHosts); + client.expect.element('div[class^="Panel"] smart-search').visible; + client.expect.element('div[class^="Panel"] smart-search input').enabled; + + client.sendKeys('div[class^="Panel"] smart-search input', `id:>${data.host.id - 1} id:<${data.host.id + 1}`); + client.sendKeys('div[class^="Panel"] smart-search input', client.Keys.ENTER); + + client.expect.element('div.spinny').visible; + client.expect.element('div.spinny').not.visible; client.click(itemName); client.expect.element(popOver).present;