[bitnami/joomla] Add Goss and Cypress tests (#10835)

* [bitnami/joomla] Add Goss and Cypress tests

Signed-off-by: FraPazGal <fdepaz@vmware.com>

* Redo API test

Signed-off-by: FraPazGal <fdepaz@vmware.com>

* Apply suggested changes

Signed-off-by: FraPazGal <fdepaz@vmware.com>

* Fix goss non-joomla typo

Signed-off-by: FraPazGal <fdepaz@vmware.com>

* Remove plugin folder

Signed-off-by: FraPazGal <fdepaz@vmware.com>

* Modify login check

Signed-off-by: FraPazGal <fdepaz@vmware.com>
This commit is contained in:
Francisco de Paz Galán
2022-06-28 13:56:26 +02:00
committed by GitHub
parent c1aaed2bac
commit 35369a16bb
11 changed files with 278 additions and 1 deletions

View File

@@ -0,0 +1,8 @@
{
"baseUrl": "http://localhost/",
"env": {
"username": "user",
"password": "ComplicatedPassword123!4"
},
"defaultCommandTimeout": 30000
}

View File

@@ -0,0 +1,5 @@
{
"newArticle": {
"title": "Super Article"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@@ -0,0 +1,8 @@
{
"newUser": {
"username": "NonTrivialUser",
"password": "N0ntR1Vi@lPaS$wOrD",
"email": "nontrivial@email.com",
"name": "Trivial Name"
}
}

View File

@@ -0,0 +1,92 @@
/// <reference types="cypress" />
import { random } from './utils';
it('allows user to log in and log out', () => {
cy.login();
cy.get('joomla-alert[type="warning"]').should('not.exist');
cy.contains('User Menu').click();
cy.contains('Log out').click();
cy.contains('Login Form');
});
it('allows creating a new user and login in', () => {
cy.login();
cy.visit('/administrator/index.php?option=com_users&view=users');
cy.get('.button-new').click();
cy.fixture('users').then((user) => {
cy.get('#jform_name').type(`${user.newUser.name}`, { force: true });
cy.get('#jform_username').type(`${random}.${user.newUser.username}`, {
force: true,
});
cy.get('#jform_password').type(`${user.newUser.password}`, { force: true });
cy.get('#jform_password2').type(`${user.newUser.password}`, {
force: true,
});
cy.get('#jform_email').type(`${random}.${user.newUser.email}`, {
force: true,
});
cy.contains('Save & Close').click();
cy.contains('User saved');
cy.contains('User Menu').click();
cy.contains('Log out').click();
cy.visit('/');
cy.get("[name='username']").type(`${random}.${user.newUser.username}`);
cy.get("[name='password']").type(`${user.newUser.password}`);
cy.contains('Log in').click();
cy.get('joomla-alert[type="warning"]').should('not.exist');
cy.contains(`Hi ${user.newUser.name}`);
});
});
it('allows creating an article and accessing it publicly', () => {
cy.login();
cy.visit('/administrator/index.php?option=com_content&view=articles');
cy.get('.button-new').click();
cy.fixture('articles').then((article) => {
cy.get('#jform_title')
.scrollIntoView()
.type(`${article.newArticle.title} ${random}`, {
force: true,
});
cy.contains('Content').click({ force: true });
cy.get('.switcher > [id="jform_featured1"]').click({ force: true });
cy.contains('Save').click();
cy.contains('Article saved');
cy.visit('/index.php');
cy.contains(`${article.newArticle.title} ${random}`);
});
});
it('allows updating an image', () => {
cy.login();
cy.visit('/administrator/index.php?option=com_media');
cy.contains('Upload').click();
cy.get('input[type="file"]').selectFile(
'cypress/fixtures/images/post_image.png',
{ force: true }
);
cy.contains('Item uploaded');
});
it('checks plugin management and API operabilty', () => {
cy.login();
cy.contains('User Menu').click();
cy.contains('Edit Account').click();
cy.contains('API Token').click({ force: true });
cy.get('#jform_joomlatoken_token')
.invoke('attr', 'value')
.then((APIToken) => {
cy.request({
method: 'GET',
url: '/api/index.php/v1/banners/categories',
form: true,
auth: {
bearer: APIToken,
},
}).then((response) => {
expect(response.status).to.eq(200);
expect(response.body).to.include.all.keys('links', 'data');
});
});
});

View File

@@ -0,0 +1,3 @@
/// <reference types="cypress" />
export let random = (Math.random() + 1).toString(36).substring(7);

View File

@@ -0,0 +1,23 @@
const CLICK_DELAY = 500;
for (const command of ['click']) {
Cypress.Commands.overwrite(command, (originalFn, ...args) => {
const origVal = originalFn(...args);
return new Promise((resolve) => {
setTimeout(() => {
resolve(origVal);
}, CLICK_DELAY);
});
});
}
Cypress.Commands.add(
'login',
(username = Cypress.env('username'), password = Cypress.env('password')) => {
cy.visit('/administrator');
cy.get("[name='username']").type(username);
cy.get("[name='passwd']").type(password);
cy.contains('Log in').click();
}
);

View File

@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
// Import commands.js using ES2015 syntax:
import './commands';
// Alternatively you can use CommonJS syntax:
// require('./commands')

View File

@@ -0,0 +1,26 @@
file:
/opt/bitnami/joomla:
filetype: symlink
linked-to: /bitnami/joomla
exists: true
/bitnami/joomla/logs:
exists: true
filetype: directory
mode: "0775"
/bitnami/joomla/configuration.php:
exists: true
filetype: file
mode: "0664"
contains:
- {{ printf "/db.*%s/" .Env.JOOMLA_DATABASE_NAME }}
command:
user-id-test:
exec: if [ "$(id -u)" -eq 0 ]; then exit 1; fi
exit-status: 0
stdout: []
stderr: []
joomla-version-ok:
exec: cat /opt/bitnami/joomla/administrator/language/en-GB/install.xml | grep --quiet $(echo $APP_VERSION | tr "-" ".")
exit-status: 0
stdout: []
stderr: []

View File

@@ -17,6 +17,19 @@
]
},
"verify": {
"context": {
"resources": {
"url": "{SHA_ARCHIVE}",
"path": "/bitnami/joomla"
},
"runtime_parameters": "am9vbWxhVXNlcm5hbWU6IHVzZXIKam9vbWxhUGFzc3dvcmQ6IENvbXBsaWNhdGVkUGFzc3dvcmQxMjMhNApzZXJ2aWNlOgogIHR5cGU6IExvYWRCYWxhbmNlcgogIHBvcnRzOgogICAgaHR0cDogODA=",
"target_platform": {
"target_platform_id": "{VIB_ENV_TARGET_PLATFORM}",
"size": {
"name": "S4"
}
}
},
"actions": [
{
"action_id": "trivy",
@@ -26,6 +39,38 @@
"OS"
]
}
},
{
"action_id": "health-check",
"params": {
"endpoint": "lb-joomla-http",
"app_protocol": "HTTP"
}
},
{
"action_id": "goss",
"params": {
"resources": {
"path": "/.vib/joomla/goss"
},
"remote": {
"workload": "deploy-joomla"
}
}
},
{
"action_id": "cypress",
"params": {
"resources": {
"path": "/.vib/joomla/cypress"
},
"endpoint": "lb-joomla-http",
"app_protocol": "HTTP",
"env": {
"username": "user",
"password": "ComplicatedPassword123!4"
}
}
}
]
},

View File

@@ -17,12 +17,59 @@
]
},
"verify": {
"context": {
"resources": {
"url": "{SHA_ARCHIVE}",
"path": "/bitnami/joomla"
},
"runtime_parameters": "am9vbWxhVXNlcm5hbWU6IHVzZXIKam9vbWxhUGFzc3dvcmQ6IENvbXBsaWNhdGVkUGFzc3dvcmQxMjMhNApzZXJ2aWNlOgogIHR5cGU6IExvYWRCYWxhbmNlcgogIHBvcnRzOgogICAgaHR0cDogODA=",
"target_platform": {
"target_platform_id": "{VIB_ENV_TARGET_PLATFORM}",
"size": {
"name": "S4"
}
}
},
"actions": [
{
"action_id": "trivy",
"params": {
"threshold": "CRITICAL",
"vuln_type": ["OS"]
"vuln_type": [
"OS"
]
}
},
{
"action_id": "health-check",
"params": {
"endpoint": "lb-joomla-http",
"app_protocol": "HTTP"
}
},
{
"action_id": "goss",
"params": {
"resources": {
"path": "/.vib/joomla/goss"
},
"remote": {
"workload": "deploy-joomla"
}
}
},
{
"action_id": "cypress",
"params": {
"resources": {
"path": "/.vib/joomla/cypress"
},
"endpoint": "lb-joomla-http",
"app_protocol": "HTTP",
"env": {
"username": "user",
"password": "ComplicatedPassword123!4"
}
}
}
]