Skip to content

Commit

Permalink
authoring: request validation (#1659)
Browse files Browse the repository at this point in the history
* authoring: request validation

* updated workflow to work around github actions runner

* Bumped the version of authoring

Co-authored-by: Michael Kruglos <michael@kruglos.com>
  • Loading branch information
AleF83 and michaelkruglos committed Dec 13, 2021
1 parent d7e2d92 commit b724896
Show file tree
Hide file tree
Showing 12 changed files with 1,315 additions and 740 deletions.
25 changes: 8 additions & 17 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
DOCKERHUB_USER: ${{ secrets.DOCKER_USER }}
run: echo $DOCKERHUB_TOKEN | docker login --username $DOCKERHUB_USER --password-stdin
- name: build
working-directory: .github/workflows
run: |
echo $GITHUB_REPOSITORY
docker buildx create --use && docker buildx bake ${{ matrix.image }}
yarn docker-compose build ${{ matrix.image }} && \
docker save -o ${{ matrix.image }}-${{ github.sha }}.tar soluto/tweek-${{ matrix.image }} && \
echo cp -a ${{ matrix.image }}-${{ github.sha }}.tar .github/workflows/
cp -a ${{ matrix.image }}-${{ github.sha }}.tar .github/workflows/
- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
with:
Expand All @@ -42,15 +44,8 @@ jobs:
name: build-images
- name: load images into docker
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker load -i {}-$GITHUB_SHA.tar
- name: tag all images
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker tag tweek-{}:ref-$GITHUB_SHA soluto/tweek-{}
- name: setup e2e
working-directory: e2e/ui
run: yarn && yarn docker-compose up -d editor
- name: run tests
uses: DevExpress/testcafe-action@latest
with:
args: "-q -c 4 -S -s screenshots chrome:headless e2e/ui/spec"
run: yarn && yarn test:docker:ui
run-e2e-integration:
needs: ["build-images"]
runs-on: ubuntu-latest
Expand All @@ -62,10 +57,10 @@ jobs:
name: build-images
- name: load images into docker
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker load -i {}-$GITHUB_SHA.tar
- name: tag all images
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker tag tweek-{}:ref-$GITHUB_SHA soluto/tweek-{}
- name: run integration tests
run: yarn && yarn test:docker:integration
working-directory: e2e/integration
run: |
yarn && yarn start gateway && yarn test:docker
run-net-tests:
needs: ["build-images"]
runs-on: ubuntu-latest
Expand All @@ -77,8 +72,6 @@ jobs:
name: build-images
- name: load images into docker
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker load -i {}-$GITHUB_SHA.tar
- name: tag all images
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker tag tweek-{}:ref-$GITHUB_SHA soluto/tweek-{}
- name: run smoke tests
run: yarn && yarn test:docker:smoke
push-images:
Expand All @@ -101,8 +94,6 @@ jobs:
name: build-images
- name: load images into docker
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker load -i {}-$GITHUB_SHA.tar
- name: tag all images
run: echo api publishing editor gateway authoring | xargs -n 1 | xargs -I {} docker tag tweek-{}:ref-$GITHUB_SHA soluto/tweek-{}
- name: push branch
if: ${{ github.ref != 'refs/heads/master' }}
run: |
Expand Down
47 changes: 27 additions & 20 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"version": "2.0.0",
"tasks": [
{
"taskName": "dev-env",
"label": "dev-env",
"type": "shell",
"command": "docker-compose",
"isShellCommand": true,
"args": [
"-f",
"./deployments/dev/docker-compose.yml",
"-f",
"./deployments/dev/docker-compose.override.yml",
"up",
"-d"
]
],
"problemMatcher": []
},
{
"taskName": "e2e-env",
"label": "e2e-env",
"type": "shell",
"command": "docker-compose",
"isShellCommand": true,
"args": [
"-f",
"./deployments/dev/docker-compose.yml",
Expand All @@ -29,34 +30,40 @@
"./deployments/dev/docker-compose.e2e.yml",
"up",
"-d"
]
],
"problemMatcher": []
},
{
"taskName": "teardown-env",
"label": "teardown-env",
"type": "shell",
"command": "docker-compose",
"isShellCommand": true,
"args": ["-f", "./deployments/dev/docker-compose.yml", "down", "--remove-orphans"]
"args": ["-f", "./deployments/dev/docker-compose.yml", "down", "--remove-orphans"],
"problemMatcher": []
},
{
"taskName": "api-build",
"label": "api-build",
"type": "shell",
"command": "dotnet",
"isShellCommand": true,
"args": ["build", "services/api/Tweek.ApiService/Tweek.ApiService.csproj"],
"isBuildCommand": true,
"showOutput": "always",
"problemMatcher": "$msCompile"
"problemMatcher": "$msCompile",
"group": {
"_id": "build",
"isDefault": false
}
},
{
"taskName": "publishing-verifier-build",
"label": "publishing-verifier-build",
"type": "shell",
"command": "dotnet",
"isShellCommand": true,
"args": [
"build",
"services/publishing/Tweek.Publishing.Verifier/Tweek.Publishing.Verifier.csproj"
],
"isBuildCommand": true,
"showOutput": "always",
"problemMatcher": "$msCompile"
"problemMatcher": "$msCompile",
"group": {
"_id": "build",
"isDefault": false
}
}
]
}
5 changes: 3 additions & 2 deletions deployments/dev/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ services:
- "4006:6379"

minio:
image: minio/minio
image: minio/minio:RELEASE.2021-11-24T23-19-33Z
ports:
- "4007:9000"
command: server /data
- "4077:1337"
command: server --console-address ":1337" /data
secrets:
- source: minio_access_key
target: access_key
Expand Down
4 changes: 2 additions & 2 deletions e2e/integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
"chai": "^4.2.0",
"mocha": "^8.3.2",
"nconf": "^0.11.2",
"supertest": "^6.1.3"
"supertest": "^6.1.6"
},
"dependencies": {
"fast-json-patch": "^3.0.0-1",
"minio": "^7.0.5",
"minio": "^7.0.25",
"uuid": "^8.3.2"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('authoring api - /PUT /bulk-keys-upload', () => {
.expect(204);

await pollUntil(
() => client.get('/api/v1/keys/test_key1?user.Country=country&user.ClientVersion=1.0.0'),
() => client.get('/api/v2/values/test_key1?user.Country=country&user.ClientVersion=1.0.0'),
(res) => expect(JSON.parse(res.body)).to.eql(true),
);
});
Expand Down
105 changes: 105 additions & 0 deletions e2e/integration/spec/authoring-api/write-validation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,50 @@ describe('authoring api write validation', () => {
);
});

it('should accept a const key', async () => {
const key = '@tests/integration/new_valid_key';
await client
.put(
'/api/v2/keys/@tests/integration/new_valid_key?author.name=test&author.email=test@soluto.com',
)
.send({
manifest: {
key_path: key,
valueType: 'number',
meta: {
name: key,
tags: [],
description: '',
},
implementation: { type: 'const', value: 5 },
dependencies: [],
},
})
.expect(200);

await pollUntil(
() => client.get('/api/v2/values/@tests/integration/new_valid_key'),
(res) => expect(res.body).to.eql(5),
);
});

it('should accept a minimal key', async () => {
const key = '@tests/integration/new_valid_key';
const aliasedKey = '@tests/integration/new_invalid_key';
await client
.put(
'/api/v2/keys/@tests/integration/new_valid_key?author.name=test&author.email=test@soluto.com',
)
.send({
manifest: {
key_path: key,
meta: { archived: false },
implementation: { type: 'alias', aliasedKey },
},
})
.expect(200);
});

it('should reject an invalid key with 400 error', async () => {
const key = '@tests/integration/new_invalid_key';
await client
Expand All @@ -46,6 +90,67 @@ describe('authoring api write validation', () => {
.expect(400);
});

it('should reject a key having invalid implementation format with error 400', async () => {
const key = '@tests/integration/new_invalid_key';
const manifest = createManifestForJPadKey(key);
manifest.implementation.type = 'file';
manifest.implementation.format = '../../../../../etc/passwd';
await client
.put(
'/api/v2/keys/@tests/integration/new_invalid_key?author.name=test&author.email=test@soluto.com',
)
.send({
manifest,
implementation: JSON.stringify({
partitions: [],
defaultalue: 'test',
valuType: 'string',
ruls: [],
}),
})
.expect(400);
});

it('should reject a key having invalid key path error 400', async () => {
const key = '@tests/integration/new_invalid_key';
const manifest = createManifestForJPadKey(key);
manifest.key_path = '../../../../../etc/passwd';
await client
.put(
'/api/v2/keys/@tests/integration/new_invalid_key?author.name=test&author.email=test@soluto.com',
)
.send({
manifest,
implementation: JSON.stringify({
partitions: [],
defaultalue: 'test',
valuType: 'string',
ruls: [],
}),
})
.expect(400);
});

it('should reject a key starting with / error 400', async () => {
const key = '@tests/integration/new_invalid_key';
const manifest = createManifestForJPadKey(key);
manifest.key_path = '/etc/passwd';
await client
.put(
'/api/v2/keys/@tests/integration/new_invalid_key?author.name=test&author.email=test@soluto.com',
)
.send({
manifest,
implementation: JSON.stringify({
partitions: [],
defaultalue: 'test',
valuType: 'string',
ruls: [],
}),
})
.expect(400);
});

it('should not create new commit for duplicate definition', async () => {
const key = '@tests/integration/duplicate';

Expand Down

0 comments on commit b724896

Please sign in to comment.