-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JWT, test endpoints, and service account. (#16)
* Add JWT, test endpoints, and service account. * Add tests for TDD * Add main controller and integration tests. * Update start script * Add CI tests. * Update docker-compose.yml * Update docker-compose.yml * Update docker-compose.yml * Add JWT to CI test. * Update test.yml
- Loading branch information
1 parent
d242ba4
commit ff33136
Showing
27 changed files
with
10,614 additions
and
727 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dockerComposeFile": "../docker-compose.yml", | ||
"service": "spider", | ||
"workspaceFolder": "/usr/local/bin/node" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
### | ||
# Environment variables for CI | ||
### | ||
|
||
AWS_ACCESS_KEY_ID=test-key-id | ||
AWS_SECRET_ACCESS_KEY=test-access-key | ||
S3_BUCKET_NAME=test-bucket | ||
S3_ENDPOINT=http://minio:9000 | ||
ALLOWED_AGENCIES="hq,htcts" | ||
JWT=test-jwt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Test | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
test: | ||
if: github.event.ref != 'refs/heads/main' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run tests | ||
run: | | ||
cp .env.ci .env | ||
docker compose run --rm -e JWT=${JWT} spider sh -c "npm ci && npm run test" | ||
env: | ||
JWT: ${{ secrets.JWT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/bin/bash | ||
|
||
nohup node /usr/local/bin/node/process.js & | ||
nohup node /usr/local/bin/node/server.js & | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
export const port = 2000; | ||
export const jwt = process.env.JWT; | ||
|
||
/** | ||
* S3 | ||
*/ | ||
|
||
export const s3Region = 'eu-west-2'; | ||
export const s3BucketName = process.env.S3_BUCKET_NAME; | ||
export const s3Credentials = process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY && { | ||
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | ||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, | ||
} | ||
|
||
/** | ||
* Options | ||
*/ | ||
|
||
export const corsOptions ={ | ||
methods: ["POST"], | ||
origin: [ | ||
"http://spider.intranet.docker/", | ||
"https://dev-intranet-archive.apps.live.cloud-platform.service.justice.gov.uk/", | ||
], | ||
}; | ||
|
||
/** | ||
* Defaults | ||
*/ | ||
|
||
export const defaultAgency = "hq"; | ||
export const defaultUrl = "https://intranet.justice.gov.uk/"; | ||
|
||
/** | ||
* Validation | ||
*/ | ||
|
||
export const allowedTargetHosts = [ | ||
"intranet.docker", | ||
"intranet.justice.gov.uk", | ||
"dev.intranet.justice.gov.uk", | ||
"staging.intranet.justice.gov.uk", | ||
"demo.intranet.justice.gov.uk", | ||
]; | ||
|
||
export const allowedTargetAgencies = process.env.ALLOWED_AGENCIES?.split(",") ?? []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getHttrackArgs should return an array of arguments 1`] = ` | ||
[ | ||
"-%W", | ||
"/archiver/strip_x_amz_query_param.so", | ||
"https://intranet.justice.gov.uk/", | ||
"+*.png", | ||
"+*.gif", | ||
"+*.jpg", | ||
"+*.jpeg", | ||
"+*.css", | ||
"+*.js", | ||
"-ad.doubleclick.net/*", | ||
"-*intranet.justice.gov.uk/agency-switcher/", | ||
"-*intranet.justice.gov.uk/?*agency=*", | ||
"-*intranet.justice.gov.uk/?p=*", | ||
"-*intranet.justice.gov.uk/?page_id=*", | ||
"-*intranet.justice.gov.uk/wp-json/*/embed*", | ||
"-*intranet.justice.gov.uk/wp/*", | ||
"+*intranet.justice.gov.uk/?*agency=hq", | ||
"-s0", | ||
"-V", | ||
""sed -i 's/srcset="[^"]*"//g' $0"", | ||
"-%k", | ||
"-F", | ||
"intranet-archive", | ||
"-%X", | ||
"Cookie: dw_agency=hq; jwt=***", | ||
"-O", | ||
"/tmp/test-snapshot", | ||
] | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const { getSignedCookies } = require("@aws-sdk/cloudfront-signer"); | ||
|
||
// TODO: Implement the getCookies function | ||
|
||
const getCookies = () => { | ||
const cloudfrontDistributionDomain = "https://d111111abcdef8.cloudfront.net"; | ||
const s3ObjectKey = "private-content/private.jpeg"; | ||
const url = `${cloudfrontDistributionDomain}/${s3ObjectKey}`; | ||
const privateKey = "CONTENTS-OF-PRIVATE-KEY"; | ||
const keyPairId = "PUBLIC-KEY-ID-OF-CLOUDFRONT-KEY-PAIR"; | ||
const dateLessThan = "2022-01-01"; | ||
|
||
const policy = { | ||
Statement: [ | ||
{ | ||
Resource: url, | ||
Condition: { | ||
DateLessThan: { | ||
"AWS:EpochTime": new Date(dateLessThan).getTime() / 1000, // time in seconds | ||
}, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const policyString = JSON.stringify(policy); | ||
|
||
return getSignedCookies({ | ||
keyPairId, | ||
privateKey, | ||
policy: policyString, | ||
}); | ||
}; |
Oops, something went wrong.