74 lines
3.7 KiB
JavaScript
74 lines
3.7 KiB
JavaScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { TemplateService } from '../../src/services/template.service.js';
|
|
|
|
describe('Unit Tests: Template Service (template.service.js)', () => {
|
|
const service = new TemplateService();
|
|
|
|
describe('Modo A — Proyecto Web Estático / PHP', () => {
|
|
it('debe generar el VirtualHost canónico exacto para Modo A', () => {
|
|
const template = service.renderStaticSiteTemplate({
|
|
subdomain: 'portfolio',
|
|
baseDomain: 'elingejose.com',
|
|
webRoot: '/var/www'
|
|
});
|
|
|
|
assert.ok(template.includes('<VirtualHost *:80>'), 'Debe abrir VirtualHost en puerto 80');
|
|
assert.ok(template.includes('</VirtualHost>'), 'Debe cerrar VirtualHost adecuadamente');
|
|
assert.ok(template.includes('ServerName portfolio.elingejose.com'), 'Debe declarar ServerName FQDN');
|
|
assert.ok(template.includes('DocumentRoot /var/www/portfolio'), 'Debe declarar DocumentRoot canónico');
|
|
assert.ok(template.includes('<Directory /var/www/portfolio>'), 'Debe abrir directiva Directory');
|
|
assert.ok(template.includes('Options -Indexes +FollowSymLinks'), 'Debe deshabilitar listar directorio');
|
|
assert.ok(template.includes('AllowOverride All'), 'Debe permitir .htaccess');
|
|
assert.ok(template.includes('Require all granted'), 'Debe conceder acceso a peticiones');
|
|
assert.ok(template.includes('ErrorLog ${APACHE_LOG_DIR}/portfolio_error.log'), 'Debe registrar logs de error');
|
|
assert.ok(template.includes('CustomLog ${APACHE_LOG_DIR}/portfolio_access.log combined'), 'Debe registrar logs de acceso');
|
|
});
|
|
});
|
|
|
|
describe('Modo B — Proxy Inverso por Puerto', () => {
|
|
it('debe generar el VirtualHost canónico exacto para Modo B', () => {
|
|
const template = service.renderProxySiteTemplate({
|
|
subdomain: 'api-service',
|
|
port: 8080,
|
|
baseDomain: 'elingejose.com'
|
|
});
|
|
|
|
assert.ok(template.includes('<VirtualHost *:80>'), 'Debe abrir VirtualHost en puerto 80');
|
|
assert.ok(template.includes('</VirtualHost>'), 'Debe cerrar VirtualHost');
|
|
assert.ok(template.includes('ServerName api-service.elingejose.com'), 'Debe declarar ServerName FQDN');
|
|
assert.ok(template.includes('ProxyPreserveHost On'), 'Debe incluir ProxyPreserveHost On');
|
|
assert.ok(template.includes('AllowEncodedSlashes NoDecode'), 'Debe incluir AllowEncodedSlashes NoDecode');
|
|
assert.ok(template.includes('ProxyPass / http://127.0.0.1:8080/ nocanon'), 'Debe usar 127.0.0.1 y nocanon');
|
|
assert.ok(template.includes('ProxyPassReverse / http://127.0.0.1:8080/'), 'Debe declarar ProxyPassReverse');
|
|
assert.ok(template.includes('ErrorLog ${APACHE_LOG_DIR}/api-service_error.log'), 'Debe declarar logs');
|
|
});
|
|
|
|
it('PROHIBICIÓN ESTRICTA: Debe usar siempre 127.0.0.1 y nunca localhost para evitar retrasos IPv6', () => {
|
|
const template = service.renderProxySiteTemplate({
|
|
subdomain: 'backend',
|
|
port: 5000,
|
|
baseDomain: 'elingejose.com'
|
|
});
|
|
|
|
assert.ok(!template.includes('localhost'), 'Prohibido usar localhost en directivas ProxyPass');
|
|
assert.ok(template.includes('127.0.0.1:5000'), 'Debe usar 127.0.0.1');
|
|
});
|
|
});
|
|
|
|
describe('Archivo inicial index.html', () => {
|
|
it('debe generar una página de bienvenida informativa y estructurada', () => {
|
|
const html = service.renderInitialIndexHtml({
|
|
subdomain: 'demo',
|
|
baseDomain: 'elingejose.com',
|
|
systemUser: 'ggc'
|
|
});
|
|
|
|
assert.ok(html.includes('demo.elingejose.com'));
|
|
assert.ok(html.includes('/var/www/demo'));
|
|
assert.ok(html.includes('2775 (ggc:www-data)'));
|
|
assert.ok(html.includes('Despliegue Git/SFTP'));
|
|
});
|
|
});
|
|
});
|