Compare commits
53 Commits
892d17f8dc
...
teste
| Author | SHA1 | Date | |
|---|---|---|---|
| 560e5ea94a | |||
| 211d03189a | |||
| 48c768ef00 | |||
| c897cd4858 | |||
| 5e09e812c3 | |||
| 0133159c0f | |||
| 9e582170dc | |||
| 09f3c5c97b | |||
| f8a53f0d2f | |||
| 9cf7b1b4d1 | |||
| f386e25432 | |||
| a213cc9482 | |||
| c63239e7ee | |||
| 35260c3717 | |||
| a6a7f3b0b5 | |||
| 0d221313e9 | |||
| 5929b935c1 | |||
| 414ebd29ad | |||
| 2ddbf37ca2 | |||
| e9e243ee42 | |||
| fd94417c8d | |||
| 6fc77e5569 | |||
| c7e505765a | |||
| 4fc7cb055f | |||
| fb337cfe01 | |||
| 021e844a4a | |||
| 1b301f879c | |||
| f354755871 | |||
| 3f46bbebf7 | |||
| 139ef63129 | |||
| 21123e6149 | |||
| 6e36250d69 | |||
| ad08cda20e | |||
| f7f382965c | |||
| 3bfccdeca6 | |||
| 8ed247f3c3 | |||
| 85e6d4b66a | |||
| 76f95077ce | |||
| 007678a44d | |||
| b3294390a5 | |||
| 1c27802143 | |||
| d921ecae04 | |||
| e7629428df | |||
| f8a3643ab9 | |||
| c78f05a818 | |||
| 869da6930b | |||
| a74380b072 | |||
| 30aca3e8da | |||
| b6691b241b | |||
| 7c7a2efd61 | |||
| 5805011296 | |||
| 313f93a05d | |||
| 5afbb57dcc |
+56
-14
@@ -46,40 +46,82 @@ jobs:
|
|||||||
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
||||||
|
|
||||||
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
||||||
if: github.event_name == 'push'
|
|
||||||
run: |
|
run: |
|
||||||
|
echo ">>> 1. Limpeza profunda do ambiente..."
|
||||||
docker rm -f apex-sandbox zap-scanner || true
|
docker rm -f apex-sandbox zap-scanner || true
|
||||||
docker network rm zap-net || true
|
docker network rm zap-net || true
|
||||||
docker network create zap-net
|
docker volume rm zap-data || true
|
||||||
|
|
||||||
|
echo ">>> 2. Criar rede e iniciar Sandbox..."
|
||||||
|
docker network create zap-net
|
||||||
docker run -d --name apex-sandbox --network zap-net apex-solutions:latest
|
docker run -d --name apex-sandbox --network zap-net apex-solutions:latest
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
|
echo ">>> 3. Preparar Volume do ZAP e Diretório de Testes..."
|
||||||
mkdir -p qatests
|
mkdir -p qatests
|
||||||
|
chmod 777 qatests
|
||||||
|
docker volume create zap-data
|
||||||
|
|
||||||
|
echo ">>> 4. Executar OWASP ZAP (FULL SCAN + AJAX SPIDER)..."
|
||||||
|
set +e
|
||||||
|
|
||||||
# Mapeamos o diretório atual do runner para /zap/wrk/
|
|
||||||
docker run --user root --name zap-scanner \
|
docker run --user root --name zap-scanner \
|
||||||
--network zap-net \
|
--network zap-net \
|
||||||
-v "$(pwd):/zap/wrk/:rw" \
|
-v zap-data:/zap/wrk/:rw \
|
||||||
-t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py \
|
-t ghcr.io/zaproxy/zaproxy:stable zap-full-scan.py \
|
||||||
-t http://apex-sandbox:3000 \
|
-t http://apex-sandbox:3000 \
|
||||||
-r report.html \
|
-r report.html \
|
||||||
-I -c zap-baseline.conf
|
-J report.json \
|
||||||
|
-j
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo ">>> 5. Recolher os relatórios..."
|
||||||
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
|
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
|
||||||
|
docker cp zap-scanner:/zap/wrk/report.json qatests/report.json || true
|
||||||
|
|
||||||
|
echo ">>> 6. Limpeza final dos contentores..."
|
||||||
docker rm -f zap-scanner apex-sandbox || true
|
docker rm -f zap-scanner apex-sandbox || true
|
||||||
docker network rm zap-net || true
|
docker network rm zap-net || true
|
||||||
|
docker volume rm zap-data || true
|
||||||
|
|
||||||
- name: 6. Production Deployment
|
echo ">>> 7. Veredicto Final da Segurança (Gatekeeper Policy)..."
|
||||||
|
if grep -qi 'Cross Site Scripting (Reflected)' qatests/report.html || grep -iE '"riskcode"\s*:\s*"3"|"risk"\s*:\s*"High"' qatests/report.json; then
|
||||||
|
echo "🚨 ALERTA CRÍTICO: O OWASP ZAP detetou uma vulnerabilidade de Injeção de Código (XSS)!"
|
||||||
|
echo "🛑 Pipeline BLOQUEADA para proteger a Branch Principal e a Produção."
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "✅ ZAP Scan concluído. Nenhuma falha Crítica ou Alta encontrada."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: 6. Deploy em Produção (SSH)
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
run: |
|
uses: appleboy/ssh-action@master
|
||||||
docker rm -f portal-corporativo || true
|
with:
|
||||||
docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest
|
host: ${{ secrets.SSH_HOST }}
|
||||||
sleep 5
|
username: ${{ secrets.SSH_USER }}
|
||||||
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
|
script: |
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo ">>> 1. A navegar para a pasta do projeto no servidor..."
|
||||||
|
cd /storage/docker/website-secure
|
||||||
|
|
||||||
|
echo ">>> 2. A transferir o código aprovado (git pull)..."
|
||||||
|
git pull origin main
|
||||||
|
|
||||||
|
echo ">>> 3. A compilar a imagem Docker de Produção..."
|
||||||
|
docker build -f backend/Dockerfile -t apex-solutions:prod .
|
||||||
|
|
||||||
|
echo ">>> 4. A substituir o contentor em execução..."
|
||||||
|
docker rm -f portal-corporativo || true
|
||||||
|
docker run -d -p 3000:3000 --name portal-corporativo --restart unless-stopped apex-solutions:prod
|
||||||
|
|
||||||
|
echo "✅ Deploy concluído com sucesso! A aplicação está no ar."
|
||||||
|
|
||||||
- name: 7. Archive ZAP Report
|
- name: 7. Archive ZAP Report
|
||||||
if: always() && github.event_name == 'push'
|
if: always()
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: owasp-zap-report
|
name: owasp-zap-report
|
||||||
|
|||||||
+23
-37
@@ -7,44 +7,31 @@ const app = express();
|
|||||||
|
|
||||||
app.disable('x-powered-by');
|
app.disable('x-powered-by');
|
||||||
|
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = process.env.PORT || 3000;
|
||||||
|
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Serve a pasta frontend
|
// Serve a pasta frontend
|
||||||
app.use(express.static(path.join(__dirname, '../frontend'), { extensions: ['html'] }));
|
app.use(express.static(path.join(__dirname, '../frontend'), { extensions: ['html'] }));
|
||||||
|
|
||||||
// Rotas das 4 páginas
|
// Rotas das páginas estáticas (A rota '/' original foi comentada para não dar conflito com a do ZAP)
|
||||||
app.get('/', (req, res) => res.sendFile(path.join(__dirname, '../frontend/index.html')));
|
// app.get('/', (req, res) => res.sendFile(path.join(__dirname, '../frontend/index.html')));
|
||||||
app.get('/about', (req, res) => res.sendFile(path.join(__dirname, '../frontend/about.html')));
|
app.get('/about', (req, res) => res.sendFile(path.join(__dirname, '../frontend/about.html')));
|
||||||
app.get('/careers', (req, res) => res.sendFile(path.join(__dirname, '../frontend/careers.html')));
|
app.get('/careers', (req, res) => res.sendFile(path.join(__dirname, '../frontend/careers.html')));
|
||||||
app.get('/contact', (req, res) => res.sendFile(path.join(__dirname, '../frontend/contact.html')));
|
app.get('/contact', (req, res) => res.sendFile(path.join(__dirname, '../frontend/contact.html')));
|
||||||
|
|
||||||
// Rota de Pesquisa Vulnerável a Reflected XSS (Armadilha para o OWASP ZAP)
|
// O eval() FOI REMOVIDO DAQUI PARA O SONARQUBE NÃO BLOQUEAR!
|
||||||
app.get('/api/search', (req, res) => {
|
|
||||||
const termoPesquisa = req.query.q || '';
|
|
||||||
// A vulnerabilidade: devolver o input diretamente para o navegador como HTML
|
|
||||||
res.send(`
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<h2>Resultados da pesquisa para: ${termoPesquisa}</h2>
|
|
||||||
<p>Nenhum resultado encontrado.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
`);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Configuração do transporte de E-mail
|
// Configuração do transporte de E-mail (Mocks de teste vs Produção)
|
||||||
let transporter;
|
let transporter;
|
||||||
|
|
||||||
if (process.env.NODE_ENV === 'test') {
|
if (process.env.NODE_ENV === 'test') {
|
||||||
// Em teste, criamos um mock vazio para evitar erros
|
|
||||||
transporter = { sendMail: jest.fn().mockResolvedValue({ messageId: 'test-id' }) };
|
transporter = { sendMail: jest.fn().mockResolvedValue({ messageId: 'test-id' }) };
|
||||||
} else {
|
} else {
|
||||||
// Em produção, usamos o transporter real
|
|
||||||
transporter = nodemailer.createTransport({
|
transporter = nodemailer.createTransport({
|
||||||
host: 'mail.limpezascleanandcare.com',
|
host: 'mail.limpezascleanandcare.com',
|
||||||
port: 465,
|
port: 465,
|
||||||
@@ -57,62 +44,61 @@ if (process.env.NODE_ENV === 'test') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Endpoint do Formulário de Contacto (Com a armadilha validada pelo Jest)
|
||||||
// Endpoint do Formulário de Contacto (Com Recetor Dinâmico)
|
|
||||||
app.post('/api/contact', async (req, res) => {
|
app.post('/api/contact', async (req, res) => {
|
||||||
const { firstName, lastName, email, company, message } = req.body;
|
const { firstName, lastName, email, company, message } = req.body;
|
||||||
|
|
||||||
|
// Se faltarem dados, devolvemos HTML para simular XSS e bater com o teste unitário
|
||||||
if (!email || !message) {
|
if (!email || !message) {
|
||||||
return res.status(400).json({ error: 'Email and message are required.' });
|
res.setHeader('Content-Type', 'text/html');
|
||||||
|
return res.status(400).send(`
|
||||||
|
<h2>Erro de Validação</h2>
|
||||||
|
<p>Os campos Email e Mensagem são obrigatórios.</p>
|
||||||
|
<p>Nome recebido: ${firstName}</p>
|
||||||
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Construção do Email - Agora enviado para o e-mail inserido no formulário
|
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
from: '"Apex Solutions" <teste@limpezascleanandcare.com>', // Remetente fixo válido
|
from: '"Apex Solutions" <teste@limpezascleanandcare.com>',
|
||||||
to: email, // RECETOR DINÂMICO (Vem diretamente do campo Email Address)
|
to: email,
|
||||||
subject: `Confirmation: We received your request, ${firstName}!`,
|
subject: `Confirmation: We received your request, ${firstName}!`,
|
||||||
html: `
|
html: `
|
||||||
<div style="font-family: Arial, sans-serif; padding: 20px; color: #333; max-width: 600px; margin: 0 auto; border: 1px solid #e2e8f0; border-radius: 8px;">
|
<div style="font-family: Arial, sans-serif; padding: 20px; color: #333; max-width: 600px; margin: 0 auto; border: 1px solid #e2e8f0; border-radius: 8px;">
|
||||||
<h2 style="color: #2563eb;">Hello ${firstName} ${lastName},</h2>
|
<h2 style="color: #2563eb;">Hello ${firstName} ${lastName},</h2>
|
||||||
<p style="font-size: 15px; line-height: 1.5; color: #475569;">
|
<p style="font-size: 15px; line-height: 1.5; color: #475569;">
|
||||||
Thank you for reaching out to <strong>Apex Solutions</strong>. This is an automated confirmation to let you know that we have successfully received your inquiry.
|
Thank you for reaching out to <strong>Apex Solutions</strong>. This is an automated confirmation.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div style="margin: 20px 0; background: #f8fafc; padding: 15px; border-left: 4px solid #2563eb; border-radius: 4px;">
|
<div style="margin: 20px 0; background: #f8fafc; padding: 15px; border-left: 4px solid #2563eb; border-radius: 4px;">
|
||||||
<h4 style="margin: 0 0 10px 0; color: #1e293b;">Summary of your submission:</h4>
|
<h4 style="margin: 0 0 10px 0; color: #1e293b;">Summary of your submission:</h4>
|
||||||
<p style="margin: 5px 0; font-size: 14px;"><strong>Subject/Company:</strong> ${company || 'Not specified'}</p>
|
<p style="margin: 5px 0; font-size: 14px;"><strong>Subject/Company:</strong> ${company || 'Not specified'}</p>
|
||||||
<p style="margin: 10px 0 0 0; font-size: 14px; font-style: italic; color: #64748b;">"${message}"</p>
|
<p style="margin: 10px 0 0 0; font-size: 14px; font-style: italic; color: #64748b;">"${message}"</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p style="font-size: 15px; line-height: 1.5; color: #475569;">
|
<p style="font-size: 15px; line-height: 1.5; color: #475569;">
|
||||||
Our advisory team will review your details and get back to you within 24 business hours.
|
Our team will get back to you within 24 business hours.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<hr style="border: 0; border-top: 1px solid #e2e8f0; margin: 20px 0;" />
|
<hr style="border: 0; border-top: 1px solid #e2e8f0; margin: 20px 0;" />
|
||||||
|
|
||||||
<p style="font-size: 12px; color: #94a3b8; text-align: center; margin: 0;">
|
<p style="font-size: 12px; color: #94a3b8; text-align: center; margin: 0;">
|
||||||
Best regards,<br>
|
Best regards,<br><strong>Apex Solutions Corporate Team</strong>
|
||||||
<strong>Apex Solutions Corporate Team</strong>
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
};
|
};
|
||||||
|
|
||||||
// Envia o e-mail real
|
|
||||||
const info = await transporter.sendMail(mailOptions);
|
const info = await transporter.sendMail(mailOptions);
|
||||||
console.log(`[Email Sent Automatically to ${email}] Message ID: ${info.messageId}`);
|
console.log(`[Email Sent Automatically to ${email}] Message ID: ${info.messageId}`);
|
||||||
|
|
||||||
res.status(200).json({ success: true, message: 'Thank you! A confirmation email has been dispatched to your address.' });
|
res.status(200).json({ success: true, message: 'Thank you! A confirmation email has been dispatched.' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[Email Error]:`, error);
|
console.error(`[Email Error]:`, error);
|
||||||
res.status(500).json({ error: 'Internal server error. Could not send confirmation email.' });
|
res.status(500).json({ error: 'Internal server error. Could not send confirmation email.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = { app, transporter };
|
module.exports = { app, transporter };
|
||||||
// Export the app for testing, but only listen if run directly
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
app.listen(PORT, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`[Apex Server] Running on port ${PORT}`);
|
console.log(`[Apex Server] Running on port ${PORT}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
+8
-3
@@ -3,7 +3,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Home | Apex Solutions branch sec</title>
|
<title>Home | Apex Solutions</title>
|
||||||
<script src="https://cdn.tailwindcss.com"></script>
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
<style>
|
<style>
|
||||||
html { scroll-behavior: smooth; } /* Animação suave ao clicar no link de serviços */
|
html { scroll-behavior: smooth; } /* Animação suave ao clicar no link de serviços */
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-24 lg:py-32">
|
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-24 lg:py-32">
|
||||||
<h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:text-6xl">
|
<h1 class="text-4xl tracking-tight font-extrabold text-gray-900 sm:text-5xl md:text-6xl">
|
||||||
<span class="block">Innovative Solutions for</span>
|
<span class="block">Innovative Solutions for</span>
|
||||||
<span class="block text-blue-600">Modern Businesses</span>
|
<span class="block text-blue-600">Modern website-secure</span>
|
||||||
</h1>
|
</h1>
|
||||||
<p class="mt-6 max-w-2xl text-lg text-gray-500 leading-relaxed">
|
<p class="mt-6 max-w-2xl text-lg text-gray-500 leading-relaxed">
|
||||||
At Apex Solutions, we deliver high-quality business consulting, technology services, and strategic insights. We help organizations across the globe achieve their goals through operational excellence and digital transformation.
|
At Apex Solutions, we deliver high-quality business consulting, technology services, and strategic insights. We help organizations across the globe achieve their goals through operational excellence and digital transformation.
|
||||||
@@ -93,7 +93,12 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
<!--<div style="display: none;">
|
||||||
|
<form action="/api/search" method="GET">
|
||||||
|
<input type="text" name="q" value="teste">
|
||||||
|
<button type="submit">Pesquisar</button>
|
||||||
|
</form>
|
||||||
|
</div>-->
|
||||||
<footer class="bg-slate-900 text-slate-400 py-12 text-center">
|
<footer class="bg-slate-900 text-slate-400 py-12 text-center">
|
||||||
<p>© 2026 Apex Solutions. All rights reserved.</p>
|
<p>© 2026 Apex Solutions. All rights reserved.</p>
|
||||||
</footer>
|
</footer>
|
||||||
|
|||||||
Generated
-37
@@ -11,7 +11,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"lodash": "4.17.15",
|
|
||||||
"nodemailer": "^8.0.11"
|
"nodemailer": "^8.0.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -1308,9 +1307,6 @@
|
|||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1325,9 +1321,6 @@
|
|||||||
"arm64"
|
"arm64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1342,9 +1335,6 @@
|
|||||||
"loong64"
|
"loong64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1359,9 +1349,6 @@
|
|||||||
"loong64"
|
"loong64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1376,9 +1363,6 @@
|
|||||||
"ppc64"
|
"ppc64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1393,9 +1377,6 @@
|
|||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1410,9 +1391,6 @@
|
|||||||
"riscv64"
|
"riscv64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1427,9 +1405,6 @@
|
|||||||
"s390x"
|
"s390x"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1444,9 +1419,6 @@
|
|||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"glibc"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -1461,9 +1433,6 @@
|
|||||||
"x64"
|
"x64"
|
||||||
],
|
],
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"libc": [
|
|
||||||
"musl"
|
|
||||||
],
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
@@ -3900,12 +3869,6 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/lodash": {
|
|
||||||
"version": "4.17.15",
|
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
|
||||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/lru-cache": {
|
"node_modules/lru-cache": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"nodemailer": "^8.0.11"
|
"nodemailer": "^8.0.11"
|
||||||
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^30.4.2",
|
"jest": "^30.4.2",
|
||||||
|
|||||||
+9
-3
@@ -35,6 +35,7 @@ describe('Enterprise Application Flow & API Validation', () => {
|
|||||||
const response = await request(app).get('/invalid-admin-route');
|
const response = await request(app).get('/invalid-admin-route');
|
||||||
expect(response.status).toBe(404);
|
expect(response.status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
@@ -52,10 +53,16 @@ describe('Enterprise Application Flow & API Validation', () => {
|
|||||||
const response = await request(app).post('/api/contact').send(invalidPayload);
|
const response = await request(app).post('/api/contact').send(invalidPayload);
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
expect(response.body).toHaveProperty('error', 'Email and message are required.');
|
|
||||||
|
// ==========================================
|
||||||
|
// CORREÇÃO DEVSECOPS: O servidor agora devolve HTML para a armadilha XSS!
|
||||||
|
// Lemos o response.text (HTML) em vez do response.body (JSON)
|
||||||
|
// ==========================================
|
||||||
|
expect(response.text).toContain('Erro de Validação');
|
||||||
|
expect(response.text).toContain('John'); // Garante que o input foi refletido na página
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should process request, return 200 OK, and invoke SMTP transporter with valid data', async () => {
|
it('Should process request, return 200 OK, and invoke SMTP transporter with valid data', async () => {
|
||||||
const validPayload = {
|
const validPayload = {
|
||||||
firstName: 'Jane',
|
firstName: 'Jane',
|
||||||
lastName: 'Doe',
|
lastName: 'Doe',
|
||||||
@@ -70,7 +77,6 @@ it('Should process request, return 200 OK, and invoke SMTP transporter with vali
|
|||||||
expect(response.status).toBe(200);
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
// Validate Business Logic: Verifica o objeto 'transporter' que veio do server.js
|
// Validate Business Logic: Verifica o objeto 'transporter' que veio do server.js
|
||||||
// Como este objeto é o que injetámos no server, ele já é o mock!
|
|
||||||
expect(transporter.sendMail).toHaveBeenCalledTimes(1);
|
expect(transporter.sendMail).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user