|
8 | 8 | * @brief Test for the ashSecurityHeaders plugin settings UI. |
9 | 9 | */ |
10 | 10 |
|
11 | | -const pluginRowId = 'component-grid-settings-plugins-settingsplugingrid-category-generic-row-ashsecurityheadersplugin'; |
12 | | - |
13 | | -function openSettingsModal() { |
14 | | - cy.get('nav a:contains("Website")').click(); |
15 | | - cy.get('button#plugins-button').click(); |
16 | | - |
17 | | - cy.get('#' + pluginRowId + ' .show_extras').click(); |
18 | | - cy.get('a[id^=' + pluginRowId + '-settings-button]').click(); |
19 | | - |
20 | | - cy.get('#ashSecurityHeadersSettings', { timeout: 10000 }).should('be.visible'); |
21 | | -} |
22 | | - |
23 | | -describe('Security Headers Plugin UI Tests', function() { |
24 | | - beforeEach(() => { |
25 | | - cy.setLocale('en_US'); |
26 | | - cy.login('admin', 'admin', 'publicknowledge'); |
27 | | - cy.get('nav a:contains("Settings")').click(); |
28 | | - }); |
29 | | - |
30 | | - it('Saves a custom header value and verifies it is stored', function() { |
31 | | - const customValue = 'DENY'; |
32 | | - const defaultValue = 'SAMEORIGIN'; |
33 | | - |
34 | | - openSettingsModal(); |
35 | | - |
36 | | - cy.get('input#headerXfo').clear().type(customValue); |
37 | | - cy.get('#ashSecurityHeadersSettings button:contains("Save")').click(); |
38 | | - |
39 | | - cy.get('.pkp_notification:contains("Changes saved")').should('be.visible'); |
40 | | - cy.get('.pkp_notification:contains("Changes saved")').should('not.exist'); |
41 | | - cy.get('div.pkp_modal_close').click(); |
42 | | - |
43 | | - openSettingsModal(); |
44 | | - cy.get('input#headerXfo').should('have.value', customValue); |
45 | | - |
46 | | - cy.get('input#headerXfo').clear().type(defaultValue); |
47 | | - cy.get('#ashSecurityHeadersSettings button:contains("Save")').click(); |
48 | | - cy.get('.pkp_notification:contains("Changes saved")').should('not.exist'); |
49 | | - }); |
50 | | - |
51 | | - it('Disables a header by saving an empty value', function() { |
52 | | - const defaultValue = 'SAMEORIGIN'; |
53 | | - |
54 | | - openSettingsModal(); |
55 | | - |
56 | | - cy.get('input#headerXfo').clear(); |
57 | | - cy.get('#ashSecurityHeadersSettings button:contains("Save")').click(); |
58 | | - |
59 | | - cy.get('.pkp_notification:contains("Changes saved")').should('be.visible'); |
60 | | - cy.get('.pkp_notification:contains("Changes saved")').should('not.exist'); |
61 | | - cy.get('div.pkp_modal_close').click(); |
62 | | - |
63 | | - openSettingsModal(); |
64 | | - cy.get('input#headerXfo').should('have.value', ''); |
65 | | - |
66 | | - cy.get('input#headerXfo').clear().type(defaultValue); |
67 | | - cy.get('#ashSecurityHeadersSettings button:contains("Save")').click(); |
68 | | - cy.get('.pkp_notification:contains("Changes saved")').should('not.exist'); |
69 | | - }); |
| 11 | +describe('Security Headers Plugin Tests', function() { |
| 12 | + const pluginDisplayName = 'Security Headers by AshVisual Theme'; |
| 13 | + |
| 14 | + it('Enables the plugin', function() { |
| 15 | + cy.login('admin', 'admin', 'publicknowledge'); |
| 16 | + |
| 17 | + cy.get('.app__nav a').contains('Website').click(); |
| 18 | + cy.get('button[id="plugins-button"]').click(); |
| 19 | + cy.get('div[id^="component-grid-settings-plugins-settingsplugingrid-"] td:contains("' + pluginDisplayName + '")') |
| 20 | + .parent() // Dapatkan <tr> parent |
| 21 | + .find('input[type="checkbox"].toggle-plugin') |
| 22 | + .check(); |
| 23 | + cy.get('div:contains("The plugin \\"Security Headers by AshVisual Theme\\" has been enabled.")'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('Configures and verifies a custom setting', function() { |
| 27 | + const customValue = 'DENY'; |
| 28 | + const defaultValue = 'SAMEORIGIN'; |
| 29 | + |
| 30 | + cy.login('admin', 'admin', 'publicknowledge'); |
| 31 | + |
| 32 | + cy.get('.app__nav a').contains('Website').click(); |
| 33 | + cy.get('button[id="plugins-button"]').click(); |
| 34 | + cy.get('div[id^="component-grid-settings-plugins-settingsplugingrid-"] td:contains("' + pluginDisplayName + '")') |
| 35 | + .parent() |
| 36 | + .find('a.show_extras') |
| 37 | + .click(); |
| 38 | + cy.get('a.settings').click(); |
| 39 | + cy.get('#ashSecurityHeadersSettings', { timeout: 20000 }).should('be.visible'); |
| 40 | + cy.get('input#headerXfo').clear().type(customValue, { delay: 0 }); |
| 41 | + cy.get('form[id="ashSecurityHeadersSettings"] button:contains("Save")').click(); |
| 42 | + cy.get('.pkp_notification:contains("Changes saved")').should('be.visible'); |
| 43 | + cy.get('input#headerXfo').clear().type(defaultValue, { delay: 0 }); |
| 44 | + cy.get('form[id="ashSecurityHeadersSettings"] button:contains("Save")').click(); |
| 45 | + cy.get('.pkp_notification:contains("Changes saved")').should('be.visible'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('Verifies the custom header is applied on the frontend', function() { |
| 49 | + const customValue = 'DENY'; |
| 50 | + const defaultValue = 'SAMEORIGIN'; |
| 51 | + |
| 52 | + cy.login('admin', 'admin', 'publicknowledge'); |
| 53 | + cy.get('.app__nav a').contains('Website').click(); |
| 54 | + cy.get('button[id="plugins-button"]').click(); |
| 55 | + cy.get('div[id^="component-grid-settings-plugins-settingsplugingrid-"] td:contains("' + pluginDisplayName + '")').parent().find('a.show_extras').click(); |
| 56 | + cy.get('a.settings').click(); |
| 57 | + cy.get('#ashSecurityHeadersSettings', { timeout: 20000 }).should('be.visible'); |
| 58 | + cy.get('input#headerXfo').clear().type(customValue, { delay: 0 }); |
| 59 | + cy.get('form[id="ashSecurityHeadersSettings"] button:contains("Save")').click(); |
| 60 | + cy.get('.pkp_notification:contains("Changes saved")').should('not.exist'); |
| 61 | + |
| 62 | + cy.request('/index.php/publicknowledge/index').its('headers').should('include', { |
| 63 | + 'x-frame-options': customValue |
| 64 | + }); |
| 65 | + |
| 66 | + cy.login('admin', 'admin', 'publicknowledge'); |
| 67 | + cy.get('.app__nav a').contains('Website').click(); |
| 68 | + cy.get('button[id="plugins-button"]').click(); |
| 69 | + cy.get('div[id^="component-grid-settings-plugins-settingsplugingrid-"] td:contains("' + pluginDisplayName + '")').parent().find('a.show_extras').click(); |
| 70 | + cy.get('a.settings').click(); |
| 71 | + cy.get('#ashSecurityHeadersSettings', { timeout: 20000 }).should('be.visible'); |
| 72 | + cy.get('input#headerXfo').clear().type(defaultValue, { delay: 0 }); |
| 73 | + cy.get('form[id="ashSecurityHeadersSettings"] button:contains("Save")').click(); |
| 74 | + }); |
70 | 75 | }); |
0 commit comments