Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

contoso-api

The lab application for AZ-400 Challenge 19–24 (03c-pipeline-fundamentals) and the deployment, testing and security challenges that follow.

The contoso-api repo referenced in those challenges is fictional — it does not exist on GitHub. The starter repo the site tells you to fork (azurecertprep/az400-lab-starter) returns 404. So this is that repo, built to match the structure in the challenge scenario exactly.

What it is

A small Express.js REST API, containerized, ready to deploy to Azure App Service or Container Apps.

contoso-api/
  src/
    index.js              Express app + server (exports app for tests)
    routes/
      health.js           GET /health, GET /health/ready
      orders.js           GET/POST/DELETE /api/orders
    middleware/
      requestLogger.js    structured JSON request log
      errorHandler.js     central error handler
      validate.js         pure validation function (easy to unit test)
  tests/
    unit/                 validate + errorHandler (no HTTP)
    integration/          supertest against the whole app
  Dockerfile              multi-stage, non-root, HEALTHCHECK
  jest.config.js          coverage thresholds already set to 80%
  eslint.config.js
  package.json
  .github/
    workflows/            EMPTY - you fill this in during the challenges
    actions/              EMPTY - you build the composite action in Challenge 23

.github/workflows/ and .github/actions/ are deliberately empty. Writing them is the lab.

Verified working

Run these locally before you start:

npm install
npm run lint            # clean
npm test                # 13 tests pass
npm run test:coverage   # ~96% statements, above the 80% gate
npm start               # http://localhost:3000/health

Confirmed on Node v24.8.0 / npm 11.6.0 on 2026-08-20.

Try the API

curl http://localhost:3000/health
curl -X POST http://localhost:3000/api/orders \
  -H "Content-Type: application/json" \
  -d '{"customer":"Fabrikam","amount":99.99}'
curl http://localhost:3000/api/orders

Scripts

Script What it does Used by
npm run lint ESLint Challenge 19 build job
npm run test:unit Unit tests only Challenge 16
npm run test:integration Integration tests only Challenge 16
npm run test:coverage Coverage + cobertura + lcov reports Challenge 18
npm test Everything, plus JUnit XML in test-results/ Publishing test results

jest-junit writes test-results/junit.xml, which is what PublishTestResults@2 in Azure Pipelines and the test-summary actions in GitHub expect. cobertura-coverage.xml under coverage/ is what PublishCodeCoverageResults@2 expects.

Push it to your own GitHub

cd "d:/02_CI_Projects/Azure devops/contoso-api"
git init -b main
git add .
git commit -m "chore: initial contoso-api lab application"

# with GitHub CLI (install from https://cli.github.com/)
gh repo create contoso-api --public --source=. --push

# or manually: create an empty repo on github.com first, then
git remote add origin https://github.com/<your-username>/contoso-api.git
git push -u origin main

Make it public if you want to use GitHub Advanced Security (CodeQL, Dependabot, secret scanning) for free in Challenge 44 — GHAS is free on public repos only.

Deliberate weak spots (for later challenges)

These are left in on purpose, so the scanning labs have something to find:

  • Orders are stored in memory, not a database — Challenge 29 adds real DB migrations.
  • No authentication on /api/orders — a finding for Challenge 44.
  • npm audit will report transitive advisories in dev dependencies — Dependabot practice.
  • No SECURITY.md, no CODEOWNERS — you add those in Challenges 08 and 44.

Do not fix these before the challenges ask you to.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages