Compare commits
30 Commits
pm-patch-2
...
deb2605e08
| Author | SHA1 | Date | |
|---|---|---|---|
| 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
|
||||
npm-debug.log
|
||||
.env
|
||||
.git
|
||||
.gitea
|
||||
*.md
|
||||
.vscode
|
||||
+36
-15
@@ -1,7 +1,9 @@
|
||||
name: "DevSecOps Pipeline"
|
||||
name: "DevSecOps Enterprise Pipeline"
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
security-gate-and-deploy:
|
||||
@@ -15,43 +17,54 @@ jobs:
|
||||
- name: 1. Build Application Image
|
||||
run: docker build -f backend/Dockerfile -t apex-solutions:latest .
|
||||
|
||||
- name: 1.5. Execute Unit Tests (Business Logic)
|
||||
run: |
|
||||
echo ">>> Syncing dependencies and executing test suite..."
|
||||
# O 'npm install' vai atualizar automaticamente o package-lock.json
|
||||
# caso exista alguma divergência com o package.json
|
||||
npm install
|
||||
npm test
|
||||
|
||||
# ==========================================
|
||||
# ETAPAS ESTÁTICAS DE SEGURANÇA SEPARADAS
|
||||
# STATIC SECURITY ANALYSIS STAGES
|
||||
# ==========================================
|
||||
|
||||
- name: 2. Secret Scanning (Gitleaks)
|
||||
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
|
||||
/tmp/gitleaks detect --source . --verbose --redact --exit-code 1 || echo "[ALERTA] Credenciais detetadas! Ignorado temporariamente."
|
||||
/tmp/gitleaks detect --source . --verbose --redact --exit-code 1
|
||||
|
||||
- name: 3. Software Composition Analysis (Trivy)
|
||||
run: |
|
||||
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
|
||||
trivy image --severity HIGH,CRITICAL apex-solutions:latest || echo "[ALERTA] Vulnerabilidades de infraestrutura encontradas!"
|
||||
trivy image --severity HIGH,CRITICAL apex-solutions:latest
|
||||
|
||||
- name: 4. Static Application Security Testing (SonarQube)
|
||||
run: |
|
||||
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
|
||||
./sonar-scanner-5.0.1.3006-linux/bin/sonar-scanner \
|
||||
-Dsonar.projectKey=apex-solutions \
|
||||
-Dsonar.projectKey=website-apex \
|
||||
-Dsonar.sources=. \
|
||||
-Dsonar.exclusions=**/node_modules/** \
|
||||
-Dsonar.host.url=https://sonar.each-cs.com \
|
||||
-Dsonar.token=${{ secrets.SONAR_TOKEN }} \
|
||||
-Dsonar.qualitygate.wait=true || echo "[ALERTA] SonarQube falhou no Quality Gate."
|
||||
-Dsonar.qualitygate.wait=true \
|
||||
-Dsonar.javascript.lcov.reportPaths=coverage/lcov.info
|
||||
|
||||
# ==========================================
|
||||
# ETAPAS DINÂMICAS E DEPLOY
|
||||
# DYNAMIC SECURITY ANALYSIS & DEPLOYMENT
|
||||
# ==========================================
|
||||
|
||||
- name: 5. Dynamic Security Scan (OWASP ZAP)
|
||||
if: github.event_name == 'push'
|
||||
run: |
|
||||
echo ">>> Lançando Sandbox Efêmero..."
|
||||
echo ">>> Provisioning ephemeral sandbox environment..."
|
||||
docker rm -f apex-sandbox || true
|
||||
docker run -d --name apex-sandbox apex-solutions:latest
|
||||
sleep 5
|
||||
|
||||
echo ">>> Executando OWASP ZAP Baseline Scan..."
|
||||
echo ">>> Initiating OWASP ZAP Baseline Scan..."
|
||||
mkdir -p qatests
|
||||
docker rm -f zap-scanner || true
|
||||
docker volume rm zap-reports || true
|
||||
@@ -67,24 +80,32 @@ jobs:
|
||||
|
||||
docker cp zap-scanner:/zap/wrk/report.html qatests/report.html || true
|
||||
|
||||
echo ">>> Destruindo Sandbox..."
|
||||
echo ">>> Decommissioning ephemeral sandbox..."
|
||||
docker rm -f zap-scanner || true
|
||||
docker volume rm zap-reports || true
|
||||
docker rm -f apex-sandbox || true
|
||||
|
||||
- name: 6. Production Deployment & Local Reports
|
||||
if: github.event_name == 'push'
|
||||
run: |
|
||||
echo ">>> Atualizando Produção..."
|
||||
echo ">>> Deploying application to production environment..."
|
||||
docker rm -f portal-corporativo || true
|
||||
docker run -d -p 3000:3000 --name portal-corporativo apex-solutions:latest
|
||||
sleep 3
|
||||
curl --silent --show-error --fail http://localhost:3000 || exit 1
|
||||
|
||||
echo ">>> Publicando Relatório ZAP no servidor Web..."
|
||||
echo ">>> Awaiting Node.js service initialization..."
|
||||
sleep 5
|
||||
|
||||
echo ">>> Container logs (for diagnostic purposes):"
|
||||
docker logs portal-corporativo
|
||||
|
||||
echo ">>> Performing internal health check (via wget)..."
|
||||
docker exec portal-corporativo wget --spider -S http://localhost:3000
|
||||
|
||||
echo ">>> Publishing OWASP ZAP security report to web server..."
|
||||
docker cp qatests/report.html portal-corporativo:/usr/src/app/frontend/zap-report.html || true
|
||||
|
||||
- name: 7. Archive ZAP Report (Gitea Artifacts)
|
||||
if: always()
|
||||
if: always() && github.event_name == 'push'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: owasp-zap-report
|
||||
|
||||
+21
-3
@@ -1,9 +1,27 @@
|
||||
FROM node:18-alpine
|
||||
WORKDIR /usr/src/app/backend
|
||||
COPY backend/package*.json ./
|
||||
RUN npm install --omit=dev
|
||||
|
||||
# Cria um grupo e um utilizador sem privilégios
|
||||
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
||||
|
||||
# Define o diretório de trabalho
|
||||
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 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
|
||||
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"
|
||||
}
|
||||
}
|
||||
+24
-9
@@ -1,9 +1,14 @@
|
||||
const express = require('express');
|
||||
const cors = require('cors');
|
||||
const path = require('path');
|
||||
const path = require('node:path');
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
const app = express();
|
||||
|
||||
|
||||
app.disable('x-powered-by');
|
||||
|
||||
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
app.use(cors());
|
||||
@@ -20,7 +25,14 @@ app.get('/careers', (req, res) => res.sendFile(path.join(__dirname, '../frontend
|
||||
app.get('/contact', (req, res) => res.sendFile(path.join(__dirname, '../frontend/contact.html')));
|
||||
|
||||
// Configuração do transporte de E-mail
|
||||
const transporter = nodemailer.createTransport({
|
||||
let transporter;
|
||||
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
// Em teste, criamos um mock vazio para evitar erros
|
||||
transporter = { sendMail: jest.fn().mockResolvedValue({ messageId: 'test-id' }) };
|
||||
} else {
|
||||
// Em produção, usamos o transporter real
|
||||
transporter = nodemailer.createTransport({
|
||||
host: 'mail.limpezascleanandcare.com',
|
||||
port: 465,
|
||||
secure: true,
|
||||
@@ -28,10 +40,10 @@ const transporter = nodemailer.createTransport({
|
||||
user: 'teste@limpezascleanandcare.com',
|
||||
pass: 'HTC?D=}5&cHoTrH='
|
||||
},
|
||||
tls: {
|
||||
rejectUnauthorized: false // Ignora avisos de certificado no servidor SMTP
|
||||
}
|
||||
});
|
||||
tls: { rejectUnauthorized: false }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Endpoint do Formulário de Contacto (Com Recetor Dinâmico)
|
||||
app.post('/api/contact', async (req, res) => {
|
||||
@@ -84,7 +96,10 @@ app.post('/api/contact', async (req, res) => {
|
||||
res.status(500).json({ error: 'Internal server error. Could not send confirmation email.' });
|
||||
}
|
||||
});
|
||||
|
||||
app.listen(PORT, () => {
|
||||
module.exports = { app, transporter };
|
||||
// Export the app for testing, but only listen if run directly
|
||||
if (require.main === module) {
|
||||
app.listen(PORT, () => {
|
||||
console.log(`[Apex Server] Running on port ${PORT}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Home | Apex Solutions</title>
|
||||
<title>Home | Apex Solutions branch sec</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<style>
|
||||
html { scroll-behavior: smooth; } /* Animação suave ao clicar no link de serviços */
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ body {
|
||||
/* Efeito ao passar o rato (Hover) */
|
||||
.navbar a:hover {
|
||||
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) */
|
||||
|
||||
Generated
+4983
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"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",
|
||||
"devDependencies": {
|
||||
"jest": "^30.4.2",
|
||||
"supertest": "^7.2.2",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.18.2",
|
||||
"nodemailer": "^6.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
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);
|
||||
expect(response.body).toHaveProperty('error', 'Email and message are required.');
|
||||
});
|
||||
|
||||
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
|
||||
// Como este objeto é o que injetámos no server, ele já é o mock!
|
||||
expect(transporter.sendMail).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user