Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ services:
timeout: 1s
retries: 20

# MailHog for email testing
mailhog:
image: mailhog/mailhog
# Mailpit for email testing
mailpit:
image: axllent/mailpit:latest
ports:
- "1025:1025" # SMTP server
- "8025:8025" # Web UI
healthcheck:
test: wget --spider --quiet http://localhost:8025
test: wget --spider --quiet http://localhost:8025/api/v1/info
interval: 10s
timeout: 5s
retries: 3
Expand Down
17 changes: 13 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,20 @@
--------------
******/

require('dotenv').config({ path: './.env.test' });

module.exports = {
testMatch: ['<rootDir>/test/**/*.test.js'],
verbose: true,
verbose: process.env.JEST_VERBOSE === 'true',
clearMocks: true,
projects: [
{
displayName: 'unit',
testMatch: ['<rootDir>/test/unit/**/*.test.js'],
setupFiles: ['<rootDir>/test/unit/test-env-setup.js'],
},
{
displayName: 'integration',
testMatch: ['<rootDir>/test/int/**/*.test.js'],
setupFiles: ['<rootDir>/test/int/test-env-setup.js'],
},
],
};

104 changes: 9 additions & 95 deletions test/functional-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,113 +2,27 @@

## Configuration

| Environment Variable | Description | Default |
| ----------------------- | --------------------------------------- | ------------------------- |
| APP_ENDPOINT | Endpoint for MCM API | http://localhost:3001/api |
| OAUTH2_ISSUER | Endpoint for Oauth Token Issuer Service | n/a |
| APP_OAUTH_CLIENT_KEY | OAuth Client-credential ID | n/a |
| APP_OAUTH_CLIENT_SECRET | OAuth Client-credential Secret | n/a |
Configuration is managed via `test-env-setup.js` (loaded automatically by Jest):

## Executing Tests

### OAuth Disabled
| Environment Variable | Description | Default |
| --------------------- | ---------------------------- | ---------------------------- |
| APP_ENDPOINT | Endpoint for MCM API | http://mcm.localhost/api |
| APP_OAUTH_USERNAME | OAuth username for login | admin |
| APP_OAUTH_PASSWORD | OAuth password for login | admin |
| MAILPIT_ENDPOINT | Endpoint for Mailpit service | http://mailpit.mcm.localhost |

1. Start the MCM API Service from root with OAuth disabled
## Executing Tests

From the root of the project open .env and set AUTH_ENABLED=false
1. Start the MCM API backend services

```bash
npm i
npm run backend:start
npm start
```

2. Run Functional Tests

```bash
cd ./test/functional-tests
```

Make sure in the local .env file and the file is empty, or if there are any oauth entries, they are commented out.

```bash
npm i
npm test
```

### OAuth Disabled with MCM API running on Docker

1. Start the MCM API Service from Docker with OAuth disabled.

From the root of the project

```bash
npm i
npm run backend:start
```

Build MCM API Service Docker image

```bash
docker build -t connection-manager-api:test .
```

Run MCM API Service Docker image

```bash
VAULT_DIR="`pwd`/.vault" &&
MCM_ENV="../docker/functional-tests.env" &&
docker run --rm -it --env-file $MCM_ENV -v $VAULT_DIR:/tmp/vault -p 3001:3001 -p 9229:9229 connection-manager-api:test
```

Note:
- if you are running on MacOS, uncomment the following lines from the [functional-test.env](../docker/functional-tests.env).

```bash
# DATABASE_HOST=host.docker.internal
# VAULT_ENDPOINT=http://host.docker.internal:8233
```

- if you are running on linux, add `--net=host` to the Docker run command

```bash
docker run --net=host --rm -it --env-file $MCM_ENV -v $VAULT_DIR:/tmp/vault -p 3001:3001 -p 9229:9229 connection-manager-api:test
```

2. See [#OAuth Disabled - 2. Run Functional Tests](#oauth-disabled) above.

### OAuth Enabled

1. Start the MCM API Service from root with OAuth enabled. Make sure you are connected to the vpn of the environment from where you plan to get the ISKM token.

From the root of the project

1.1 Open .env in this directory and set AUTH_ENABLED=true

1.2 Open Vault for product-dev environment. Go to secrets->secret->wso2->adminpwd and copy the admin password for wso2 ISKM

1.3 Open wso2 ISKM. Click List in Service Providers. Click MCM_Portal and click Edit

1.4. Open Inbound Authentication COnfiguration -> OAuth/Open ID Connect Configuration and copy OAuth Client Key and OAuth Client Secret and paste it in the APP_OAUTH_CLIENT_KEY, APP_OAUTH_CLIENT_SECRET variables in .env and functional_tests/.env file.

1.5. Fill in the OAUTH2_ISSUER with the corresponding env. For example if you are using product dev env, it should be ISKM.dev.product.mbox-dev.io/oauth2/token

1.6. Go to mcm k8s cluster, acess connection-manager-secret and copy the certificate and paste its contents as a single line in the value for EMBEDDED_CERTIFICATE variable.

1.7 Make sure the 4 env vars are updated in both .env

```bash
npm i
npm run backend:start
npm start
```

2. Run Functional Tests

2.1 Make sure APP_OAUTH_CLIENT_KEY and APP_OAUTH_CLIENT_SECRET are populated with the values from the steps described in the section above.

```bash
cd ./test/functional-tests
npm i
npm test
```
7 changes: 6 additions & 1 deletion test/functional-tests/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ module.exports = {
verbose: true,
preset: 'ts-jest',
testEnvironment: 'node',
testEnvironmentOptions: {
customExportConditions: ['node', 'node-addons'],
},
collectCoverage: false,
clearMocks: true
clearMocks: true,
setupFiles: ['<rootDir>/test-env-setup.js'],
testTimeout: 300000
};
Loading