Skip to content

Commit

Permalink
Merge pull request #22 from digicatapult/feat/initial-integration-tests
Browse files Browse the repository at this point in the history
Initial integration tests
  • Loading branch information
nitro-marky authored Sep 8, 2022
2 parents 172cb20 + 59ef28b commit 35e284d
Show file tree
Hide file tree
Showing 12 changed files with 642 additions and 76 deletions.
40 changes: 21 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ jobs:
runs-on: ubuntu-latest
needs: [preconditions]
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Lint
run: npm run lint
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Lint
run: npm run lint

dependency-check:
name: Run dependency check
Expand Down Expand Up @@ -98,15 +98,17 @@ jobs:
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Build OpenAPI
run: npm run build:tsoa
- name: Setup dependencies
run: docker-compose up -d
run: docker-compose up -d
- name: Sleep
uses: kibertoad/wait-action@1.0.1
with:
time: '30s'
time: '60s'
- name: Run unit tests
run: npm run test:unit
- name: Run integration tests
- name: Run integration tests
run: npm run test:integration

check-version:
Expand Down
70 changes: 37 additions & 33 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,43 @@ jobs:
name: Run lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Lint
run: npm run lint
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Lint
run: npm run lint

build:
name: Run build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Lint
run: npm run build
- uses: actions/checkout@master
- uses: actions/setup-node@master
with:
node-version: 16.x
- name: Cache Node.js modules
uses: actions/cache@v1
with:
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Lint
run: npm run build

dependency-check:
name: Run dependency check
Expand Down Expand Up @@ -103,10 +103,14 @@ jobs:
${{ runner.OS }}-
- name: Install Packages
run: npm ci
- name: Build OpenAPI
run: npm run build:tsoa
- name: Setup dependencies
run: docker-compose up -d
- name: Sleep
uses: kibertoad/wait-action@1.0.1
with:
time: '30s'
time: '60s'
- name: Run unit tests
run: npm run test:unit
- name: Run integration tests
Expand Down
Binary file added bin/out-of-bounds-readV2-aarch64
Binary file not shown.
Binary file added bin/out-of-bounds-readV2-cheri
Binary file not shown.
66 changes: 66 additions & 0 deletions integration/helper/routeHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import request from 'supertest'
import express from 'express'

export async function getOutOfBoundsReadAarch64(
app: express.Express,
password: string | number,
firstOffset: string | number,
secondOffset: string | number
) {
return request(app)
.get(`/scenario/out-of-bounds-readV2-aarch64?params=${password}&params=${firstOffset}&params=${secondOffset}`)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.send()
.then((response) => {
return response
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(`Out of bounds read (aaarch64) ${err}`)
return err
})
}

export async function getOutOfBoundsReadCheri(
app: express.Express,
password: string | number,
firstOffset: string | number,
secondOffset: string | number
) {
return request(app)
.get(`/scenario/out-of-bounds-readV2-cheri?params=${password}&params=${firstOffset}&params=${secondOffset}`)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.send()
.then((response) => {
return response
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(`Out of bounds read (aaarch64) ${err}`)
return err
})
}

export async function getInvalidExecutable(app: express.Express, password: string | number) {
return request(app)
.get(`/scenario/out-of-bounds-readV5-aarch64?params=${password}`)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.send()
.then((response) => {
return response
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(`Out of bounds read (aaarch64) ${err}`)
return err
})
}

module.exports = {
getOutOfBoundsReadAarch64,
getOutOfBoundsReadCheri,
getInvalidExecutable,
}
82 changes: 82 additions & 0 deletions integration/out-of-bounds-read.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { describe, before, test } from 'mocha'
import { expect } from 'chai'
import express from 'express'
import { CreateHttpServer } from '../src/server'
import {
getOutOfBoundsReadCheri,
getOutOfBoundsReadAarch64,
getInvalidExecutable,
} from '../integration/helper/routeHelper'

describe('Tests aarch64 version', () => {
let app: express.Express

before(async function () {
app = await CreateHttpServer()
})

test('Happy Path - aarch64', async () => {
const response = await getOutOfBoundsReadAarch64(app, 'pass', -32, -28)

expect(response.status).to.equal(200)
expect(response.body.output).to.contain('Storing Secret...\nThe data between indices -32 and -28 is: pass\n')
expect(response.body.status).to.contain('success')
})

test('Bad Parameters - aarch64', async () => {
const response = await getOutOfBoundsReadAarch64(app, 'badpass', NaN, 'ttttttt')

expect(response.status).to.equal(200)
expect(response.body.status).to.contain('success')
})

test('Missing Parameters - aarch64', async () => {
const response = await getOutOfBoundsReadAarch64(app, 'badpass', '', '')

expect(response.status).to.equal(200)
expect(response.body.status).to.contain('success')
})
})

describe('Tests Cheri version', () => {
let app: express.Express

before(async () => {
app = await CreateHttpServer()
})

test('Happy Path - cheri', async () => {
const response = await getOutOfBoundsReadCheri(app, 'cheripass', -32, -21)

expect(response.status).to.equal(200)
expect(response.body.status).to.contain('error')
})

test('Bad Parameters - cheri', async () => {
const response = await getOutOfBoundsReadCheri(app, 'cheripass', 'cube', 'tarmac')

expect(response.status).to.equal(200)
expect(response.body.status).to.contain('success')
})

test('Missing Parameters - cheri', async () => {
const response = await getOutOfBoundsReadCheri(app, 'cheripass', '', '')

expect(response.status).to.equal(200)
expect(response.body.status).to.contain('success')
})
})

describe('Tests Invalid Executable version', () => {
let app: express.Express

before(async () => {
app = await CreateHttpServer()
})

test('Sad Path - non-existant test', async () => {
const response = await getInvalidExecutable(app, 'invalidpass')

expect(response.status).to.equal(422)
})
})
Loading

0 comments on commit 35e284d

Please sign in to comment.