3010: Apollo 4 major update and complete security overhaul to prepare for public api support

* 2919: rewrite for update to apollo 4 (#131)

* rewrite for update to apollo 4

* removed container tests, edited make to publish any branch to staging

* revert makefile

* cleanup

* update 1

* more fixes to get it working on aws

* enabled csrf prevention protection, testing if build works

* switched to express version

* changed the healthcheck url

* added cache to restdatasources

* 3011: create a login mutation on graphql server that responds with a access token (#133)

* 3011 added login rest endpoint and general scope fixes

* changed login auth to basic auth username and password

* minor changes from CR feedback

* force update

* added tighter timeout for idle knex connection

* Refactor authentication and scopes (#134)

* big refactor of scopes in graphql

* cr fixes

* some security fixes (#135)

* some security fixes

* cleanup

* update staging

* minor readme change
This commit is contained in:
Arwid Thornström
2022-12-12 12:58:24 +01:00
committed by GitHub
parent 4248465031
commit c68c182b64
78 changed files with 3783 additions and 14606 deletions
+20 -17
View File
@@ -2,10 +2,22 @@
Apollo graphql api server for Photowall
This servers runs in two instances on AWS. `graphql.photowall.com` is used for photowall admin. `data.photowall.com` is used by the website (client).
When clients want to use the public `data.photowall.com` they use the `/login` REST endpoint to retreive a BearerToken with restricted cognito scopes. They can then access certain product and designer information with the token.
Third party systems like Unbox (Synergy) will use the `graphql.photowall.com` to read their data like they are doing now. This is to make sure the website wont be affected by larger downloads of data like unbox does. Unbox has their own cognito app client with limited scopes.
## Run it locally
Create an .env file (see .env.example for what to set).
`COGNITO_LOGIN_CLIENT_SECRET`, `COGNITO_LOGIN_CLIENT_ID` is found in cognito `photowall-test-staff` pool. In `photowall-web-test-client` app.
### Development
This project does only run in docker, so when developing start the docker environment and let it updated when changing files. Sometimes the watch for files doesnt trigger. Like when you edit the .graphql file. Then just edit a .ts file and it will reload.
Run
```
$ npm install
$ docker compose build
@@ -18,8 +30,13 @@ If you wish the Bearer Token used in prodlike environment also works.
If you dont have access to photowall shared lastpass please contact any collegaue.
If you use Insomnia ask a colleague for the queries that can be exported/imported from Insomnia.
To tests the data.photowall.com its possible to run the login rest endpoint to get a Bearer accessToken. Check code for username and password.
### Run prod-like container locally
Run
```
$ docker compose -f docker-compose-prodlike.yml build
$ docker compose -f docker-compose-prodlike.yml up
@@ -31,26 +48,12 @@ The token is valid for 2-3 hours.
## Run tests
Scripts will create the insert sql files for a randomized fake data postgres database. This database is based of the actual db in photowall project.
Tests
```
npm test
```
### Writing tests
### Force update the staging
The tests are held in testcontainers [testcontainers-node](https://github.com/testcontainers/testcontainers-node). One container holding a test postgres database and one container started from the Dockerfile containing the Apollo GraphQL server. These containers have connections with each other.
Each test is build around inserting fake data in the empty db, fetching that data through the GraphQL and with raw Sql queries and then comparing the results.
To write new inserts into the DB generate sql files with js in the src/**test**/db_generator tool. Then load the new sql file in the containerSetup.ts file.
When you have the data you need in the db, write tests in all.test.ts file following the pattern already set.
### Dump database schema
pg_dump \
--schema-only \
--no-owner \
--no-acl \
photowall > src/__test__/db/schema.sql
update 3