Compare commits
114 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0815a45c93 | |||
| 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 | |||
| 892d17f8dc | |||
| ccdace0951 | |||
| 87a6c63ac8 | |||
| 0fdd3c1558 | |||
| 0a92b7f4a0 | |||
| 430c418062 | |||
| aba23ad583 | |||
| c23ad4f6d3 | |||
| a1aadf130d | |||
| 47db928d3c | |||
| dd94920955 | |||
| 745c8b4e71 | |||
| 54a52d9ebe | |||
| 432d3d8840 | |||
| 500972ea6f | |||
| aa726dbd77 | |||
| 3da598485b | |||
| 22940982e7 | |||
| 62aaba7cae | |||
| d30db1d4cc | |||
| cc8c34868c | |||
| eb1aec157d | |||
| 2760503bfa | |||
| 9ade6ec23f | |||
| b7ba597b0a | |||
| a75556acd2 | |||
| 34eb81849b | |||
| 6adf9ea8b9 | |||
| 03b75c1da6 | |||
| 29816c44bb | |||
| 734e128696 | |||
| deb2605e08 | |||
| 0ba2cb3a1b | |||
| b8ae8e0a5b | |||
| 11399103e4 | |||
| 1b70908cad | |||
| a53b8e23e7 | |||
| 0689c0bc17 | |||
| 3a2685d5b6 | |||
| f9e6fd47a4 | |||
| cd5785c497 | |||
| 3967393895 | |||
| dbf0d7445c | |||
| 20d454d5c6 | |||
| 18ded6b7fc | |||
| bba5d7c581 | |||
| 70321152a7 | |||
| 25849c273c | |||
| 740b6386ef | |||
| 980005151f | |||
| c234771d28 | |||
| b71d73afe0 | |||
| 002f696161 | |||
| 1f8953ab41 | |||
| 9d8aaeb8f2 | |||
| 7ec0a5136d | |||
| 73f91a1261 | |||
| aacc679600 | |||
| 2a62d54f81 | |||
| eb99f05016 | |||
| 6fc1b22f7f |
+4
-3
@@ -1,5 +1,6 @@
|
|||||||
|
.git
|
||||||
|
.env
|
||||||
node_modules
|
node_modules
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
.env
|
*.md
|
||||||
.git
|
.vscode
|
||||||
.gitea
|
|
||||||
+74
-86
@@ -1,8 +1,4 @@
|
|||||||
name: "DevSecOps Enterprise Pipeline"
|
name: "DevSecOps Enterprise Pipeline"
|
||||||
|
|
||||||
# ==========================================
|
|
||||||
# PONTO 4: TRIGGERS (Push vs PR)
|
|
||||||
# ==========================================
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
@@ -13,128 +9,120 @@ jobs:
|
|||||||
security-gate-and-deploy:
|
security-gate-and-deploy:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout Code
|
- name: 0. Checkout Code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
# ==========================================
|
- name: 1. Build Application Image
|
||||||
# STAGE 1: STATIC SECURITY TESTING (SAST, SCA)
|
run: docker build -f backend/Dockerfile -t apex-solutions:latest .
|
||||||
# ==========================================
|
|
||||||
|
|
||||||
- name: Gitleaks Scan
|
- name: 1.5. Execute Unit Tests
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npm test
|
||||||
|
|
||||||
|
- name: 2. Secret Scanning (Gitleaks)
|
||||||
run: |
|
run: |
|
||||||
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz | tar -xz -C /tmp
|
curl -sL https://github.com/gitleaks/gitleaks/releases/download/v8.18.2/gitleaks_8.18.2_linux_x64.tar.gz | tar -xz -C /tmp
|
||||||
/tmp/gitleaks detect --source . --verbose --redact --log-opts="-1" --exit-code 1
|
/tmp/gitleaks detect --source . --no-git --verbose --redact --exit-code 1
|
||||||
|
|
||||||
# PONTO 3: Artefactos do Trivy adicionados
|
- name: 3. Software Composition Analysis (Trivy)
|
||||||
- name: Scan Docker Image Vulnerabilities (Trivy)
|
|
||||||
run: |
|
run: |
|
||||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
||||||
# 1. Guarda o output para um ficheiro de texto para o Artefato
|
trivy image --exit-code 1 --severity HIGH,CRITICAL apex-solutions:latest
|
||||||
trivy image --severity HIGH,CRITICAL --format table --output trivy-report.txt nginx:alpine
|
|
||||||
# 2. Corre novamente no terminal para forçar a quebra da pipeline se encontrar falhas (Exit-Code 1)
|
|
||||||
trivy image --severity HIGH,CRITICAL --exit-code 1 nginx:alpine
|
|
||||||
|
|
||||||
- name: Archive Trivy Report
|
- name: 4. Static Application Security Testing (SonarQube)
|
||||||
if: always()
|
|
||||||
uses: actions/upload-artifact@v3
|
|
||||||
with:
|
|
||||||
name: trivy-sca-report
|
|
||||||
path: trivy-report.txt
|
|
||||||
|
|
||||||
- name: SonarQube Analysis
|
|
||||||
run: |
|
run: |
|
||||||
curl -sL https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -o sonar-scanner.zip
|
curl -sL https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip -o sonar-scanner.zip
|
||||||
unzip -q sonar-scanner.zip
|
unzip -q sonar-scanner.zip
|
||||||
./sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
|
./sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
|
||||||
-Dsonar.projectKey=website-test \
|
-Dsonar.projectKey=website-apex \
|
||||||
-Dsonar.sources=. \
|
-Dsonar.sources=. \
|
||||||
|
-Dsonar.exclusions=**/node_modules/** \
|
||||||
-Dsonar.host.url=https://sonar.each-cs.com \
|
-Dsonar.host.url=https://sonar.each-cs.com \
|
||||||
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
||||||
-Dsonar.qualitygate.wait=true
|
-Dsonar.qualitygate.wait=true \
|
||||||
|
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
||||||
|
|
||||||
# ==========================================
|
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
||||||
# STAGE 2 & 3: DYNAMIC TESTING (ZAP)
|
|
||||||
# ==========================================
|
|
||||||
|
|
||||||
- name: Provision Ephemeral Sandbox
|
|
||||||
run: |
|
|
||||||
docker rm -f website-test-sandbox || true
|
|
||||||
docker run -d --name website-test-sandbox nginx:alpine
|
|
||||||
docker cp index.html website-test-sandbox:/usr/share/nginx/html/index.html
|
|
||||||
sleep 5
|
|
||||||
|
|
||||||
- name: OWASP ZAP Baseline Scan
|
|
||||||
run: |
|
run: |
|
||||||
|
echo ">>> 1. Limpeza profunda do ambiente..."
|
||||||
|
docker rm -f apex-sandbox zap-scanner || true
|
||||||
|
docker network rm zap-net || true
|
||||||
|
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
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
echo ">>> 3. Preparar Volume do ZAP e Diretório de Testes..."
|
||||||
mkdir -p qatests
|
mkdir -p qatests
|
||||||
docker rm -f zap-scanner || true
|
chmod 777 qatests
|
||||||
docker volume rm zap-reports || true
|
docker volume create zap-data
|
||||||
docker volume create zap-reports
|
|
||||||
|
echo ">>> 4. Executar OWASP ZAP (FULL SCAN + AJAX SPIDER)..."
|
||||||
|
set +e
|
||||||
|
|
||||||
docker run --user root --name zap-scanner \
|
docker run --user root --name zap-scanner \
|
||||||
--link website-test-sandbox:website-test-sandbox \
|
--network zap-net \
|
||||||
-v zap-reports:/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://website-test-sandbox \
|
-t http://apex-sandbox:3000 \
|
||||||
-r report.html \
|
-r report.html \
|
||||||
-I
|
-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.json qatests/report.json || true
|
||||||
|
|
||||||
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html
|
echo ">>> 6. Limpeza final dos contentores..."
|
||||||
docker rm -f zap-scanner || true
|
docker rm -f zap-scanner apex-sandbox || true
|
||||||
docker volume rm zap-reports || true
|
docker network rm zap-net || true
|
||||||
|
docker volume rm zap-data || true
|
||||||
|
|
||||||
- name: Teardown Ephemeral Sandbox
|
echo ">>> 7. Veredicto Final da Segurança (Gatekeeper Policy)..."
|
||||||
if: always()
|
if grep -qi 'Cross Site Scripting (Reflected)' qatests/report.html || grep -iE '"riskcode"\s*:\s*"3"|"risk"\s*:\s*"High"' qatests/report.json; then
|
||||||
run: |
|
echo "🚨 ALERTA CRÍTICO: O OWASP ZAP detetou uma vulnerabilidade de Injeção de Código (XSS)!"
|
||||||
docker rm -f website-test-sandbox || true
|
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)
|
||||||
# STAGE 4: PRODUCTION DEPLOYMENT (SSH)
|
if: github.event_name == 'push'
|
||||||
# ==========================================
|
uses: appleboy/ssh-action@master
|
||||||
|
|
||||||
# PONTO 6: Deploy Seguro Condicional
|
|
||||||
# Só executa se for um Push (não PR) e se for na branch main
|
|
||||||
- name: Hardened Production Deployment via SSH
|
|
||||||
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
|
|
||||||
uses: appleboy/ssh-action@v1.0.0
|
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.SSH_HOST }}
|
host: ${{ secrets.SSH_HOST }}
|
||||||
username: ${{ secrets.SSH_USER }}
|
username: ${{ secrets.SSH_USER }}
|
||||||
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||||
script: |
|
script: |
|
||||||
echo ">>> A iniciar Deploy Seguro no Servidor de Produção..."
|
set -e
|
||||||
|
|
||||||
# 1. Navegar para a pasta do projeto (Ajusta o caminho para o teu servidor real)
|
echo ">>> 1. A navegar para a pasta do projeto no servidor..."
|
||||||
cd /opt/website-test
|
cd /storage/docker/website-secure
|
||||||
|
|
||||||
# 2. Puxar as últimas alterações do repositório
|
echo ">>> 2. A transferir o código aprovado (git pull)..."
|
||||||
git pull origin main
|
git pull origin main
|
||||||
|
|
||||||
# 3. Tratamento do ficheiro .ENV dinâmico (Frente 2)
|
echo ">>> 3. A compilar a imagem Docker de Produção..."
|
||||||
# Isto injeta os Secrets do Gitea num ficheiro .env temporário no servidor
|
docker build -f backend/Dockerfile -t apex-solutions:prod .
|
||||||
echo "PORT=80" > .env
|
|
||||||
echo "API_SECRET=${{ secrets.API_SECRET_PROD }}" >> .env
|
|
||||||
|
|
||||||
# 4. Construir e iniciar o contentor de Produção
|
echo ">>> 4. A substituir o contentor em execução..."
|
||||||
docker build -t website-test-backend:latest .
|
docker rm -f portal-corporativo || true
|
||||||
docker rm -f website-test-backend || true
|
docker run -d -p 3000:3000 --name portal-corporativo --restart unless-stopped apex-solutions:prod
|
||||||
docker run -d -p 80:80 --env-file .env --name website-test-backend website-test-backend:latest
|
|
||||||
|
|
||||||
echo ">>> Deploy em Produção concluído com sucesso!"
|
echo "✅ Deploy concluído com sucesso! A aplicação está no ar."
|
||||||
|
|
||||||
# ==========================================
|
- name: 7. Archive ZAP Report
|
||||||
# STAGE 5: ARTIFACT MANAGEMENT & REPORTING
|
|
||||||
# ==========================================
|
|
||||||
|
|
||||||
- name: Archive ZAP Report (Raw HTML)
|
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: owasp-zap-report
|
name: owasp-zap-report
|
||||||
path: qatests/report.html
|
path: qatests/report.html
|
||||||
|
|
||||||
- name: Pipeline Status Notification
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
echo "Pipeline finished with status: ${{ job.status }}"
|
|
||||||
+27
-4
@@ -1,9 +1,32 @@
|
|||||||
FROM node:18-alpine
|
FROM node:22-alpine
|
||||||
WORKDIR /usr/src/app/backend
|
|
||||||
COPY backend/package*.json ./
|
# ==========================================
|
||||||
RUN npm install --omit=dev
|
# DEVSECOPS: HARDENING DA IMAGEM BASE
|
||||||
|
# ==========================================
|
||||||
|
# Agrupamos os comandos RUN num só para otimizar as camadas da imagem (Regra do SonarQube)
|
||||||
|
RUN apk update && apk upgrade --no-cache && \
|
||||||
|
npm install -g npm@latest && \
|
||||||
|
addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||||
|
|
||||||
|
# Define o diretório de trabalho
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# Ajusta as permissões da pasta para o novo utilizador
|
||||||
|
RUN chown -R appuser:appgroup /usr/src/app
|
||||||
|
|
||||||
|
# Copia os ficheiros e instala dependências
|
||||||
|
COPY package*.json ./
|
||||||
|
RUN npm install --omit=dev
|
||||||
|
|
||||||
|
# Copia o código fonte
|
||||||
COPY backend/ ./backend/
|
COPY backend/ ./backend/
|
||||||
COPY frontend/ ./frontend/
|
COPY frontend/ ./frontend/
|
||||||
|
|
||||||
|
# Altera a propriedade dos ficheiros copiados para o utilizador
|
||||||
|
RUN chown -R appuser:appgroup /usr/src/app
|
||||||
|
|
||||||
|
# Muda para o utilizador sem privilégios
|
||||||
|
USER appuser
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["node", "backend/server.js"]
|
CMD ["node", "backend/server.js"]
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "corporate-portal",
|
|
||||||
"version": "2.0.0",
|
|
||||||
"description": "Multi-page Corporate Portal for DevSecOps PoC",
|
|
||||||
"main": "server.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "node server.js"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"cors": "^2.8.5",
|
|
||||||
"express": "^4.18.2",
|
|
||||||
"nodemailer": "^6.9.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+48
-34
@@ -1,90 +1,104 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const cors = require('cors');
|
const cors = require('cors');
|
||||||
const path = require('path');
|
const path = require('node:path');
|
||||||
const nodemailer = require('nodemailer');
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
|
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')));
|
||||||
|
|
||||||
// Configuração do transporte de E-mail
|
// O eval() FOI REMOVIDO DAQUI PARA O SONARQUBE NÃO BLOQUEAR!
|
||||||
const transporter = nodemailer.createTransport({
|
|
||||||
host: 'mail.limpezascleanandcare.com',
|
|
||||||
port: 465,
|
|
||||||
secure: true,
|
|
||||||
auth: {
|
|
||||||
user: 'teste@limpezascleanandcare.com',
|
|
||||||
pass: 'HTC?D=}5&cHoTrH='
|
|
||||||
},
|
|
||||||
tls: {
|
|
||||||
rejectUnauthorized: false // Ignora avisos de certificado no servidor SMTP
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Endpoint do Formulário de Contacto (Com Recetor Dinâmico)
|
// Configuração do transporte de E-mail (Mocks de teste vs Produção)
|
||||||
|
let transporter;
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'test') {
|
||||||
|
transporter = { sendMail: jest.fn().mockResolvedValue({ messageId: 'test-id' }) };
|
||||||
|
} else {
|
||||||
|
transporter = nodemailer.createTransport({
|
||||||
|
host: 'mail.limpezascleanandcare.com',
|
||||||
|
port: 465,
|
||||||
|
secure: true,
|
||||||
|
auth: {
|
||||||
|
user: 'teste@limpezascleanandcare.com',
|
||||||
|
pass: 'HTC?D=}5&cHoTrH='
|
||||||
|
},
|
||||||
|
tls: { rejectUnauthorized: false }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Endpoint do Formulário de Contacto (Com a armadilha validada pelo Jest)
|
||||||
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.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(PORT, () => {
|
module.exports = { app, transporter };
|
||||||
console.log(`[Apex Server] Running on port ${PORT}`);
|
|
||||||
});
|
if (require.main === module) {
|
||||||
|
app.listen(PORT, () => {
|
||||||
|
console.log(`[Apex Server] Running on port ${PORT}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
+8
-3
@@ -33,10 +33,10 @@
|
|||||||
<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.
|
CI/CD TEST Works
|
||||||
</p>
|
</p>
|
||||||
<div class="mt-10 flex gap-4">
|
<div class="mt-10 flex gap-4">
|
||||||
<a href="#services" class="px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700">Explore Services</a>
|
<a href="#services" class="px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700">Explore Services</a>
|
||||||
@@ -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>
|
||||||
|
|||||||
+1
-1
@@ -79,7 +79,7 @@ body {
|
|||||||
/* Efeito ao passar o rato (Hover) */
|
/* Efeito ao passar o rato (Hover) */
|
||||||
.navbar a:hover {
|
.navbar a:hover {
|
||||||
color: white;
|
color: white;
|
||||||
background-color: rgba(255, 255, 255, 0.1); /* Fundo branco muito subtil */
|
background-color: rgba(255, 255, 255, 0.); /* Fundo branco muito subtil */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Estado da página atual (Active) */
|
/* Estado da página atual (Active) */
|
||||||
|
|||||||
Generated
+5521
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "website-secure",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest --coverage --coverageReporters=lcovonly"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://gitea.each-cs.com/pm/website-secure.git"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"type": "commonjs",
|
||||||
|
"dependencies": {
|
||||||
|
"cors": "^2.8.5",
|
||||||
|
"express": "^4.18.2",
|
||||||
|
"nodemailer": "^8.0.11"
|
||||||
|
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^30.4.2",
|
||||||
|
"supertest": "^7.2.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
const request = require('supertest');
|
||||||
|
process.env.NODE_ENV = 'test';
|
||||||
|
const { app, transporter } = require('../backend/server');
|
||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// MOCK EXTERNAL SERVICES
|
||||||
|
// ==========================================
|
||||||
|
jest.mock('nodemailer');
|
||||||
|
|
||||||
|
describe('Enterprise Application Flow & API Validation', () => {
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
// Configure the mock to simulate a successful SMTP response
|
||||||
|
nodemailer.createTransport.mockReturnValue({
|
||||||
|
sendMail: jest.fn().mockResolvedValue({ messageId: 'mock-id-enterprise-1234' })
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks(); // Clear tracking between tests
|
||||||
|
});
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// 1. STATIC ROUTING TESTS
|
||||||
|
// ==========================================
|
||||||
|
describe('1. Static Web Routing', () => {
|
||||||
|
it('Should return 200 OK and text/html for the Home Page (/)', async () => {
|
||||||
|
const response = await request(app).get('/');
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(response.headers['content-type']).toMatch(/text\/html/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Should return 404 Not Found for an unknown endpoint', async () => {
|
||||||
|
const response = await request(app).get('/invalid-admin-route');
|
||||||
|
expect(response.status).toBe(404);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// 2. API BUSINESS LOGIC & VALIDATION TESTS
|
||||||
|
// ==========================================
|
||||||
|
describe('2. Contact API Endpoint (/api/contact)', () => {
|
||||||
|
|
||||||
|
it('Should reject requests and return 400 Bad Request if email is missing', async () => {
|
||||||
|
const invalidPayload = {
|
||||||
|
firstName: 'John',
|
||||||
|
message: 'I need a security audit.'
|
||||||
|
// Missing 'email' deliberately
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await request(app).post('/api/contact').send(invalidPayload);
|
||||||
|
|
||||||
|
expect(response.status).toBe(400);
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// 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 () => {
|
||||||
|
const validPayload = {
|
||||||
|
firstName: 'Jane',
|
||||||
|
lastName: 'Doe',
|
||||||
|
email: 'jane.doe@example.com',
|
||||||
|
company: 'Apex Corporation',
|
||||||
|
message: 'Please send me the DevSecOps proposal.'
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await request(app).post('/api/contact').send(validPayload);
|
||||||
|
|
||||||
|
// Validate HTTP Response
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
// Validate Business Logic: Verifica o objeto 'transporter' que veio do server.js
|
||||||
|
expect(transporter.sendMail).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# Bloqueia a pipeline se encontrar algo grave
|
||||||
|
FAIL_ON_SEVERITY: HIGH
|
||||||
Reference in New Issue
Block a user