|
| 1 | +## Requirements |
| 2 | +- .NET 8 SDK and above |
| 3 | +- Docker (with Docker Compose) - Optional if not using the Quickstart environment |
| 4 | + |
| 5 | +## Unit + Integration Tests |
| 6 | + |
| 7 | +This project features unit and integration tests that can be run from any IDE or command line. |
| 8 | + |
| 9 | +### Setting Up Integration Tests |
| 10 | + |
| 11 | +Inside the `cyberark-conjur-pam.IntegrationTests` directory there is a [.env.test.example](./cyberark-conjur-pam.IntegrationTests/.env.test.example) file with the example environment variables. Copy the file to `.env.test` within the same directory. Fill out the environment variables. Make sure to configure `.env.test` to **always copy** to the output directory (this should already be set within the integration test's .csproj). |
| 12 | + |
| 13 | +You are welcome to fill out the `.env.test` file to set these values to point to an existing CyberArk Conjur environment. Otherwise, these integration tests can also run against the Quickstart environment. |
| 14 | + |
| 15 | +#### Running the Quickstart Environment |
| 16 | + |
| 17 | +> This section can be skipped if you do not plan to run the integration tests against a local Docker environment. |
| 18 | +
|
| 19 | +The environment variables for the Quickstart environment are already defined in the `.env.ci` file under the `cyberark-conjur-pam.IntegrationTests` directory. Copy the `.env.ci` file to `.env.test`. |
| 20 | + |
| 21 | +The Quickstart environment hosts a Docker Compose project that builds out a local CyberArk Conjur instance pre-populated with an admin account, a test user account, an example secret variable, and an example policy for the test user account to access the variable. The definition for the Quickstart environment is defined in [the quickstart directory](./quickstart/), which also includes the example policy defined under [the conf/policy](./quickstart/conf/policy) directory. |
| 22 | + |
| 23 | +To run the Quickstart environment, run the following command from the project root: |
| 24 | + |
| 25 | +```bash |
| 26 | +# Use docker-compose if you're on an older Docker version |
| 27 | +docker compose -f ./quickstart/docker-compose.yml up --build |
| 28 | +``` |
| 29 | + |
| 30 | +The output of the `conjur-init` container should provide information on how to access the local Conjur instance, including the credentials to use to access the instance. |
| 31 | + |
| 32 | +```bash |
| 33 | +docker logs conjur-init |
| 34 | + |
| 35 | +=========================================== |
| 36 | +ConjurUrl: http://localhost:8080 (or your mapped port if different) |
| 37 | +AccountId: testConjurAccount |
| 38 | + |
| 39 | +Admin Login: admin |
| 40 | +Admin API Key: [randomly generated admin api key] |
| 41 | + |
| 42 | +Test User Login: TestUser@local |
| 43 | +Test User Password: Mypassw0rD2! |
| 44 | +Test User API Key: [randomly generated user api key] |
| 45 | + |
| 46 | +Test Variable: local/MyTestVar |
| 47 | +Test Variable Value: MyTestSecretValue123 |
| 48 | +=========================================== |
| 49 | +``` |
| 50 | +
|
| 51 | +The secret value for variable `local/MyTestVar` can be accessed by either the admin or the test user, with either their respective API keys or passwords. |
| 52 | +
|
| 53 | +The Quickstart environment can be cleaned up with the following command: |
| 54 | +
|
| 55 | +```bash |
| 56 | +docker compose -f ./quickstart/docker-compose.yml down -v |
| 57 | +``` |
| 58 | +
|
| 59 | +### Running the Tests |
| 60 | +
|
| 61 | +Here are some command line scripts to run the test suites. |
| 62 | +
|
| 63 | +Restore project dependencies (optional): |
| 64 | +```bash |
| 65 | +dotnet restore |
| 66 | +``` |
| 67 | +
|
| 68 | +Run integration and unit tests: |
| 69 | +```bash |
| 70 | +dotnet test |
| 71 | +``` |
| 72 | +
|
| 73 | +Run just the unit tests: |
| 74 | +```bash |
| 75 | +dotnet test --filter "Category!=Integration" |
| 76 | +``` |
| 77 | +
|
| 78 | +Run just the integration tests: |
| 79 | +```bash |
| 80 | +dotnet test --filter "Category=Integration" |
| 81 | +``` |
0 commit comments