Skip to content

Commit 763ca08

Browse files
authored
Added tests and Makefile (#248)
1 parent 58dff38 commit 763ca08

File tree

14 files changed

+2045
-7
lines changed

14 files changed

+2045
-7
lines changed

decentralize-rbac-app/Makefile

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
SHELL := /bin/bash
2+
3+
.PHONY: help
4+
.DEFAULT_GOAL := help
5+
6+
check_defined = \
7+
$(strip $(foreach 1,$1, \
8+
$(call __check_defined,$1,$(strip $(value 2)))))
9+
__check_defined = \
10+
$(if $(value $1),, \
11+
$(error Undefined $1$(if $2, ($2))))
12+
13+
help: ## 💬 This help message :)
14+
@grep -E '[a-zA-Z_-]+:.*?## .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
15+
16+
build: ## 🔨 Build the decentralized-rbac Application
17+
@echo -e "\e[34m$@\e[0m" || true
18+
@npm run build
19+
20+
build-virtual: build ## 📦 Build Virtual container image from Dockerfile
21+
@echo -e "\e[34m$@\e[0m" || true
22+
@../scripts/build_image.sh virtual
23+
24+
build-enclave: build ## 📦 Build Enclave container image from Dockerfile
25+
@echo -e "\e[34m$@\e[0m" || true
26+
@../scripts/build_image.sh enclave
27+
28+
test: build ## 🧪 Test the decentralized-rbac Application in the sandbox
29+
@echo -e "\e[34m$@\e[0m" || true
30+
@. ../scripts/test_sandbox.sh --nodeAddress 127.0.0.1:8000 --certificate_dir ./workspace/sandbox_common --constitution_dir ./governance/constitution
31+
32+
test-docker-virtual: build-virtual ## 🧪 Test the decentralized-rbac Application in a Docker sandbox
33+
@echo -e "\e[34m$@\e[0m" || true
34+
@. ../scripts/test_docker.sh --virtual --serverIP 127.0.0.1 --port 8080
35+
36+
test-docker-enclave: build-enclave ## 🧪 Test the decentralized-rbac Application in a Docker enclave
37+
@echo -e "\e[34m$@\e[0m" || true
38+
@. ../scripts/test_docker.sh --enclave --serverIP 127.0.0.1 --port 8080
39+
40+
# Run sandbox.
41+
# This is used in the demo scripts
42+
start-host: build ## 🏁 Start the CCF Sandbox for the demo
43+
@echo -e "\e[34m$@\e[0m" || true
44+
@/opt/ccf_virtual/bin/sandbox.sh --js-app-bundle ./dist/ --initial-member-count 1 --initial-user-count 2 --constitution-dir ./governance/constitution
45+
46+
clean: ## 🧹 Clean the working folders created during build/demo
47+
@rm -rf .venv_ccf_sandbox
48+
@rm -rf .venv_ccf_verify_receipt
49+
@rm -rf workspace
50+
@rm -rf dist

decentralize-rbac-app/README.md

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ The application consists of three parts:
1717
(iii) Authorization
1818

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

2525
### Repository Layout
2626

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

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

4754
# In the VScode terminal window
48-
cd decentralized-authz-app # Navigate to app folder
49-
npm run build # Build and create the application deployment bundle
55+
cd decentralized-authz-app # Navigate to app folder
56+
make build # Build and create the application deployment bundle
5057
```
5158

52-
## Local Deployment
59+
Now the environment is ready, and there are several scenarios that could be executed at this stage.
60+
61+
- **Run the application's [e2e-tests](./test/test.sh) in a sandbox (simulated) environment**
62+
63+
- `make test`
64+
65+
- **Run the application's [e2e-tests](./test/test.sh) on a Docker Container running a virtual (simulated) environment**
66+
67+
- `make test-docker-virtual`
68+
69+
- **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**
70+
71+
- `make start-host`
72+
73+
These are the main scenarios; more commands are available at makefile and are described in the following section.
74+
75+
### Make file
76+
77+
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:
78+
79+
```text
80+
help 💬 This help message :)
81+
build 🔨 Build the Application
82+
build-virtual 📦 Build Virtual container image from Dockerfile
83+
build-enclave 📦 Build Enclave container image from Dockerfile
84+
start-host 🏃 Start the CCF network using Sandbox.sh
85+
test 🧪 Test the Data Reconciliation Application in the sandbox
86+
test-docker-virtual 🧪 Test the Data Reconciliation Application in a Docker sandbox
87+
test-docker-enclave 🧪 Test the Data Reconciliation Application in a Docker enclave
88+
clean 🧹 Clean the working folders created during build/demo
89+
```
90+
91+
## Testing
92+
93+
```bash
94+
cd data-reconciliation-app # Navigate to reconciliation sample folder
95+
make test # Run the end-to-end(e2e) tests
96+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Build
2+
FROM mcr.microsoft.com/ccf/app/dev:4.0.14-sgx as builder
3+
4+
# Run
5+
FROM mcr.microsoft.com/ccf/app/run-js:4.0.14-sgx
6+
7+
# copy configuration into image
8+
COPY ./governance/constitution/*.js /app/
9+
COPY ./governance/nodes/cchost_config_enclave_js.json /app/
10+
COPY ./workspace/docker_certificates/member0_cert.pem /app/
11+
COPY ./workspace/docker_certificates/member0_enc_pubk.pem /app/
12+
13+
WORKDIR /app/
14+
15+
EXPOSE 8080/tcp
16+
17+
CMD ["/usr/bin/cchost", "--config", "/app/cchost_config_enclave_js.json"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Build
2+
FROM mcr.microsoft.com/ccf/app/dev:4.0.14-virtual as builder
3+
4+
# Run
5+
FROM mcr.microsoft.com/ccf/app/run-js:4.0.14-virtual
6+
7+
# Note: libjs_generic.virtual is not included in run-js container
8+
COPY --from=builder /opt/ccf_virtual/lib/libjs_generic.virtual.so /usr/lib/ccf
9+
10+
# copy configuration into image
11+
COPY ./governance/constitution/*.js /app/
12+
COPY ./governance/nodes/cchost_config_virtual_js.json /app/
13+
COPY ./workspace/docker_certificates/member0_cert.pem /app/
14+
COPY ./workspace/docker_certificates/member0_enc_pubk.pem /app/
15+
16+
WORKDIR /app/
17+
18+
EXPOSE 8080/tcp
19+
20+
CMD ["/usr/bin/cchost", "--config", "/app/cchost_config_virtual_js.json"]

0 commit comments

Comments
 (0)