Skip to content

Commit

Permalink
Added tests and Makefile (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
msftsettiy authored Jul 22, 2024
1 parent 58dff38 commit 763ca08
Show file tree
Hide file tree
Showing 14 changed files with 2,045 additions and 7 deletions.
50 changes: 50 additions & 0 deletions decentralize-rbac-app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
SHELL := /bin/bash

.PHONY: help
.DEFAULT_GOAL := help

check_defined = \
$(strip $(foreach 1,$1, \
$(call __check_defined,$1,$(strip $(value 2)))))
__check_defined = \
$(if $(value $1),, \
$(error Undefined $1$(if $2, ($2))))

help: ## 💬 This help message :)
@grep -E '[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

build: ## 🔨 Build the decentralized-rbac Application
@echo -e "\e[34m$@\e[0m" || true
@npm run build

build-virtual: build ## 📦 Build Virtual container image from Dockerfile
@echo -e "\e[34m$@\e[0m" || true
@../scripts/build_image.sh virtual

build-enclave: build ## 📦 Build Enclave container image from Dockerfile
@echo -e "\e[34m$@\e[0m" || true
@../scripts/build_image.sh enclave

test: build ## 🧪 Test the decentralized-rbac Application in the sandbox
@echo -e "\e[34m$@\e[0m" || true
@. ../scripts/test_sandbox.sh --nodeAddress 127.0.0.1:8000 --certificate_dir ./workspace/sandbox_common --constitution_dir ./governance/constitution

test-docker-virtual: build-virtual ## 🧪 Test the decentralized-rbac Application in a Docker sandbox
@echo -e "\e[34m$@\e[0m" || true
@. ../scripts/test_docker.sh --virtual --serverIP 127.0.0.1 --port 8080

test-docker-enclave: build-enclave ## 🧪 Test the decentralized-rbac Application in a Docker enclave
@echo -e "\e[34m$@\e[0m" || true
@. ../scripts/test_docker.sh --enclave --serverIP 127.0.0.1 --port 8080

# Run sandbox.
# This is used in the demo scripts
start-host: build ## 🏁 Start the CCF Sandbox for the demo
@echo -e "\e[34m$@\e[0m" || true
@/opt/ccf_virtual/bin/sandbox.sh --js-app-bundle ./dist/ --initial-member-count 1 --initial-user-count 2 --constitution-dir ./governance/constitution

clean: ## 🧹 Clean the working folders created during build/demo
@rm -rf .venv_ccf_sandbox
@rm -rf .venv_ccf_verify_receipt
@rm -rf workspace
@rm -rf dist
56 changes: 50 additions & 6 deletions decentralize-rbac-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ The application consists of three parts:
(iii) Authorization

- Role and User Management
- API Endpoint: allow members to add a role and allowed action.
- API Endpoint: allow members to add a user and the role.
- /{role}/roles/{action}: add a role and allowed action. Requires member auth.
- /{user_id}/users/{role}: add a user and the role. Requires member auth.
- Authorization
- Check if a user exists and if an action is allowed.
- /{user_id}/action/{actionName} - Authorize a user and action. Requires user auth.

### Repository Layout

Expand All @@ -32,6 +32,13 @@ The application consists of three parts:
│ └── repositories Data repositories
│ └── services Domain services
│ └── utils utility classes
└── test end-to-end tests
└── docker Contains the Dockerfile to build the virtual and enclave image
└── governance
└── constitution Default constitution used for the tests
└── nodes Config file for the virtual and enclave sandbox deployment
└── scripts Scripts to generate member and user certs for running tests
└── vote A json file that contains the vote body to accept proposals
```

Expand All @@ -45,8 +52,45 @@ git clone https://github.com/microsoft/ccf-app-samples # Clone the samples repos
code ccf-app-samples # open samples repository in Visual studio code

# In the VScode terminal window
cd decentralized-authz-app # Navigate to app folder
npm run build # Build and create the application deployment bundle
cd decentralized-authz-app # Navigate to app folder
make build # Build and create the application deployment bundle
```

## Local Deployment
Now the environment is ready, and there are several scenarios that could be executed at this stage.

- **Run the application's [e2e-tests](./test/test.sh) in a sandbox (simulated) environment**

- `make test`

- **Run the application's [e2e-tests](./test/test.sh) on a Docker Container running a virtual (simulated) environment**

- `make test-docker-virtual`

- **Start a CCF network with 1 active member and 2 users using the sandbox and deploy the application to it, the application and network are ready to receive requests**

- `make start-host`

These are the main scenarios; more commands are available at makefile and are described in the following section.

### Make file

A Makefile provides a front-end to interact with the project. It is used both locally, during CI, and on GitHub Actions. This Makefile is self-documented, and has the following targets:

```text
help 💬 This help message :)
build 🔨 Build the Application
build-virtual 📦 Build Virtual container image from Dockerfile
build-enclave 📦 Build Enclave container image from Dockerfile
start-host 🏃 Start the CCF network using Sandbox.sh
test 🧪 Test the Data Reconciliation Application in the sandbox
test-docker-virtual 🧪 Test the Data Reconciliation Application in a Docker sandbox
test-docker-enclave 🧪 Test the Data Reconciliation Application in a Docker enclave
clean 🧹 Clean the working folders created during build/demo
```

## Testing

```bash
cd data-reconciliation-app # Navigate to reconciliation sample folder
make test # Run the end-to-end(e2e) tests
```
17 changes: 17 additions & 0 deletions decentralize-rbac-app/docker/ccf_app_js.enclave
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Build
FROM mcr.microsoft.com/ccf/app/dev:4.0.14-sgx as builder

# Run
FROM mcr.microsoft.com/ccf/app/run-js:4.0.14-sgx

# copy configuration into image
COPY ./governance/constitution/*.js /app/
COPY ./governance/nodes/cchost_config_enclave_js.json /app/
COPY ./workspace/docker_certificates/member0_cert.pem /app/
COPY ./workspace/docker_certificates/member0_enc_pubk.pem /app/

WORKDIR /app/

EXPOSE 8080/tcp

CMD ["/usr/bin/cchost", "--config", "/app/cchost_config_enclave_js.json"]
20 changes: 20 additions & 0 deletions decentralize-rbac-app/docker/ccf_app_js.virtual
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Build
FROM mcr.microsoft.com/ccf/app/dev:4.0.14-virtual as builder

# Run
FROM mcr.microsoft.com/ccf/app/run-js:4.0.14-virtual

# Note: libjs_generic.virtual is not included in run-js container
COPY --from=builder /opt/ccf_virtual/lib/libjs_generic.virtual.so /usr/lib/ccf

# copy configuration into image
COPY ./governance/constitution/*.js /app/
COPY ./governance/nodes/cchost_config_virtual_js.json /app/
COPY ./workspace/docker_certificates/member0_cert.pem /app/
COPY ./workspace/docker_certificates/member0_enc_pubk.pem /app/

WORKDIR /app/

EXPOSE 8080/tcp

CMD ["/usr/bin/cchost", "--config", "/app/cchost_config_virtual_js.json"]
Loading

0 comments on commit 763ca08

Please sign in to comment.