Skip to content

Commit

Permalink
chore(ci): add postman collection and newman github CI runner (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkhinvasara authored Jan 28, 2025
1 parent e4dc7b3 commit cff19cf
Show file tree
Hide file tree
Showing 28 changed files with 583 additions and 0 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/postman-collection-runner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Run postman tests

on:
workflow_dispatch:
push:
branches:
- main
- "releases/*"
pull_request:
merge_group:
types: [checks_requested]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DATABASE_URL: postgres://db_user:db_pass@localhost/encryption_db
USER: db_user
PASSWORD: db_pass
DB_NAME: encryption_db
RUN_TESTS: ${{ ((github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name)) || (github.event_name == 'merge_group') }}

jobs:
runner:
name: Run postman tests
runs-on: ubuntu-latest
services:
postgres:
image: "postgres:14.5"
env:
POSTGRES_USER: db_user
POSTGRES_PASSWORD: db_pass
POSTGRES_DB: encryption_db

options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Repository checkout
uses: actions/checkout@v4

- name: Skip tests for PRs from forks
shell: bash
if: ${{ env.RUN_TESTS == 'false' }}
run: echo 'Skipping tests for PRs from forks'

- name: Install Rust
if: ${{ env.RUN_TESTS == 'true' }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable 2 weeks ago
components: clippy

- name: Build and Cache Rust Dependencies
if: ${{ env.RUN_TESTS == 'true' }}
uses: Swatinem/[email protected]

- name: Install Diesel CLI with Postgres Support
if: ${{ env.RUN_TESTS == 'true' }}
uses: baptiste0928/[email protected]
with:
crate: diesel_cli
features: postgres
args: "--no-default-features"

- name: Diesel migration run
if: ${{ env.RUN_TESTS == 'true' }}
shell: bash
env:
DATABASE_URL: postgres://db_user:db_pass@localhost:5432/encryption_db
run: diesel migration run

- name: Install newman from fork
if: ${{ env.RUN_TESTS == 'true' }}
run: npm install -g 'git+ssh://[email protected]:knutties/newman.git#feature/newman-dir'

- name: Build project
if: ${{ env.RUN_TESTS == 'true' }}
run: cargo build --package cripta --bin cripta

- name: Setup Local Server
if: ${{ env.RUN_TESTS == 'true' }}
run: |
target/debug/cripta &
SERVER_PID=$!
COUNT=0
while ! nc -z localhost 5000; do
if [ $COUNT -gt 12 ]; then
echo "Server did not start within a reasonable time. Exiting."
kill ${SERVER_PID}
exit 1
else
COUNT=$((COUNT+1))
sleep 10
fi
done
- name: Run Tests
if: ${{ env.RUN_TESTS == 'true' }}
env:
BASE_URL: "http://localhost:5000"
shell: bash
run: newman dir-run postman/collection-dir
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/target
node_modules/
.env
12 changes: 12 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "hyperswitch-encryption-utility",
"version": "0.1.0",
"private": true,
"description": "This is just to run automated newman tests for this service"
}
8 changes: 8 additions & 0 deletions postman/collection-dir/.info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"info": {
"_postman_id": "811976d7-1bd9-4e8d-ab77-4f903d6652f7",
"name": "collection-dir",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json",
"_exporter_id": "17145261"
}
}
9 changes: 9 additions & 0 deletions postman/collection-dir/.meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"childrenOrder": [
"Create Key",
"Encrypt Data",
"Decrypt Data",
"Rotate Key",
"Transfer Key"
]
}
14 changes: 14 additions & 0 deletions postman/collection-dir/.variable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"variable":[
{
"key": "base_url",
"value": "http://localhost:5000",
"type": "string"
},
{
"key":"tenant_id",
"value":"public",
"type":"text"
}
]
}
3 changes: 3 additions & 0 deletions postman/collection-dir/Create Key/.event.meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eventOrder": ["event.test.js"]
}
9 changes: 9 additions & 0 deletions postman/collection-dir/Create Key/event.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pm.test("Create Key - Status code is 200", function () {
pm.response.to.have.status(200);
});

(function () {
let jsonData = pm.response.json();
pm.environment.set("key_version", jsonData.key_version);
pm.environment.set("identifier", JSON.stringify(jsonData.identifier));
})();
27 changes: 27 additions & 0 deletions postman/collection-dir/Create Key/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [

{
"key": "X-Tenant-ID",
"value": "{{tenant_id}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
},
"raw_json_formatted": {
"data_identifier": "User",
"key_identifier": "123"
}
},
"url": "{{base_url}}/key/create"
}
1 change: 1 addition & 0 deletions postman/collection-dir/Create Key/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 3 additions & 0 deletions postman/collection-dir/Decrypt Data/.event.meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eventOrder": ["event.test.js"]
}
4 changes: 4 additions & 0 deletions postman/collection-dir/Decrypt Data/event.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pm.test("Decrypt Data - Status code is 200", function () {
pm.response.to.have.status(200);
});

29 changes: 29 additions & 0 deletions postman/collection-dir/Decrypt Data/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "X-Tenant-ID",
"value": "{{tenant_id}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
},
"raw_json_formatted": {
"data_identifier": "User",
"key_identifier": "123",
"data": {
"value": "{{value}}"
}
}
},
"url": "{{base_url}}/data/decrypt"
}
1 change: 1 addition & 0 deletions postman/collection-dir/Decrypt Data/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 3 additions & 0 deletions postman/collection-dir/Encrypt Data/.event.meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eventOrder": ["event.test.js"]
}
6 changes: 6 additions & 0 deletions postman/collection-dir/Encrypt Data/event.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pm.test("Decrypt Data - Status code is 200", function () {
pm.response.to.have.status(200);
});
var response = pm.response.json();

pm.environment.set("value", response.data.value);
30 changes: 30 additions & 0 deletions postman/collection-dir/Encrypt Data/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [

{
"key": "X-Tenant-ID",
"value": "{{tenant_id}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
},
"raw_json_formatted": {
"data_identifier": "User",
"key_identifier": "123",
"data": {
"value": "U2VjcmV0RGF0YQo="
}
}
},
"url": "{{base_url}}/data/encrypt"
}
1 change: 1 addition & 0 deletions postman/collection-dir/Encrypt Data/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 3 additions & 0 deletions postman/collection-dir/Rotate Key/.event.meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eventOrder": ["event.test.js"]
}
4 changes: 4 additions & 0 deletions postman/collection-dir/Rotate Key/event.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pm.test("Decrypt Data - Status code is 200", function () {
pm.response.to.have.status(200);
});

26 changes: 26 additions & 0 deletions postman/collection-dir/Rotate Key/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "X-Tenant-ID",
"value": "{{tenant_id}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
},
"raw_json_formatted": {
"data_identifier": "User",
"key_identifier": "123"
}
},
"url": "{{base_url}}/key/rotate"
}
1 change: 1 addition & 0 deletions postman/collection-dir/Rotate Key/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
3 changes: 3 additions & 0 deletions postman/collection-dir/Transfer Key/.event.meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"eventOrder": ["event.test.js"]
}
4 changes: 4 additions & 0 deletions postman/collection-dir/Transfer Key/event.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pm.test("Decrypt Data - Status code is 200", function () {
pm.response.to.have.status(200);
});

27 changes: 27 additions & 0 deletions postman/collection-dir/Transfer Key/request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "X-Tenant-ID",
"value": "{{tenant_id}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"options": {
"raw": {
"language": "json"
}
},
"raw_json_formatted": {
"data_identifier": "User",
"key_identifier": "123",
"key": "VGhpcyBpcyAzMiBieXRlcyBmb3Igc3VyZSBub3chISE="
}
},
"url": "{{base_url}}/key/transfer"
}
1 change: 1 addition & 0 deletions postman/collection-dir/Transfer Key/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Loading

0 comments on commit cff19cf

Please sign in to comment.