Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate audit through graphql-http #2359

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* text=auto

/.github export-ignore
/audit export-ignore
/benchmarks export-ignore
/docs export-ignore
/tests export-ignore
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ jobs:
- name: "Upload to Codecov"
uses: codecov/codecov-action@v2

audit:
runs-on: ubuntu-latest

defaults:
run:
working-directory: audit

steps:
- uses: actions/checkout@v3

- run: make setup

- run: make audit

benchmarks:
runs-on: ubuntu-latest

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ build: ## Build the local Docker containers

.PHONY: up
up: ## Bring up the docker-compose stack
docker-compose up -d
docker-compose up --detach

.PHONY: fix
fix: rector php-cs-fixer ## Automatic code fixes
Expand Down
24 changes: 24 additions & 0 deletions audit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dcclient=$$(echo "docker-compose exec -T client")

.PHONY: help
help: ## Displays this list of targets with descriptions
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: setup
setup: build ## Setup the local environment

.PHONY: build
build: ## Build the local Docker containers
docker-compose build --pull

.PHONY: up
up: ## Bring up the docker-compose stack
docker-compose up --detach

.PHONY: audit
audit: up ## Runs tests with PHPUnit
${dcclient} deno test --allow-net

.PHONY: fmt
fmt: up ## Runs tests with PHPUnit
${dcclient} deno fmt test.ts
18 changes: 18 additions & 0 deletions audit/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
server:
build:
context: ../
dockerfile: audit/server.dockerfile
entrypoint: 'php artisan serve --host=0.0.0.0'
healthcheck:
test: curl -f http://localhost:8000/graphql?query=%7B__typename%7D || exit 1
interval: 3s
timeout: 1s

client:
image: denoland/deno:1.31.3
working_dir: /workdir
volumes:
- ./:/workdir
entrypoint: /bin/bash
tty: true
20 changes: 20 additions & 0 deletions audit/server.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM php:8.1-cli

WORKDIR /app

COPY --from=composer /usr/bin/composer /usr/bin/composer

RUN apt-get update && \
apt-get install --yes \
git \
rsync \
libzip-dev \
zip \
&& docker-php-ext-install \
zip \
&& rm -rf /var/lib/apt/lists/*

RUN composer create-project --no-progress laravel/laravel /app
RUN composer require --no-progress nuwave/lighthouse:dev-master
COPY . /app/vendor/nuwave/lighthouse
RUN php artisan vendor:publish --tag=lighthouse-schema
27 changes: 27 additions & 0 deletions audit/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { serverAudits } from "npm:graphql-http";

for (
const audit of serverAudits({
url: "http://server:8000/graphql",
})
) {
// if (audit.name !== 'MUST accept application/json and match the content-type') continue;
Deno.test(
audit.name,
// { sanitizeResources: false },
async () => {
const result = await audit.fn();
// Clean up dangling resources
console.log(result);
// if ("response" in result) {
// await result.response.body?.cancel();
// }
if (result.status === "error") {
throw result.reason;
}
if (result.status === "warn") {
console.warn(result.reason); // or throw if you want full compliance (warnings are not requirements)
}
},
);
}