Skip to content

Commit

Permalink
Update to run against persona.talis.local when running locally. (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
malcyL authored Mar 12, 2020
1 parent 2f69958 commit 75ea5c6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ RUN apt-get -y autoremove && apt-get clean && apt-get autoclean && \
RUN mkdir -p /var/talis-php
COPY . /var/talis-php

RUN echo "export PERSONA_TEST_HOST='https://staging-users.talis.com'" >> /etc/profile.d/test.sh \
RUN echo "export PERSONA_TEST_HOST='http://persona.talis.local'" >> /etc/profile.d/test.sh \
&& echo "export PERSONA_TEST_OAUTH_CLIENT='$persona_oauth_client'" >> /etc/profile.d/test.sh \
&& echo "export PERSONA_TEST_OAUTH_SECRET='$persona_oauth_secret'" >> /etc/profile.d/test.sh \
&& chmod 775 /etc/profile.d/test.sh
Expand Down
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,47 @@ git clone https://github.com/talis/talis-php.git
cd talis-php
```

# Run Persona Locally

Integration tests run locally will make requests to Persona at `http://persona.talis.local`.

Before you begin, ensure you have established `DEVELOPMENT_WORK_DIR` and the `infra` repository, as per [the shared project instructions](https://github.com/talis/infra/wiki).

Manually run persona locally:

```bash
./docker-compose-dev.sh persona-server
```

# Create an OAuth Client and Secret

To build the talis-php docker container, you need to specify an oauth client and secret to use. This client should have `su` scope. It's not possibe to create a client with `su` scope via the API.

First - create a client:

```bash
curl -v -H "Authorization:Bearer $LOCAL_TOKEN" -d "{\"scope\":[\"su@test\"]}" http://persona.talis.local/clients
```

This will return a client:

```json
{"client_id":"BXLmKR79","client_secret":"zdlbESLEFGvxBw8k"}
```

Then connect to the mongo database the local persona is using and manually give the client `su` scope.

# Build talis-php Docker Container

Manually run a docker build:

```bash
docker build -t "talis/talis-php" --network=host --build-arg persona_oauth_client=<persona-user-goes-here> --build-arg persona_oauth_secret=<persona-secret-goes-here> .
```

`persona_oauth_client` = the persona user you want to use.
`persona_oauth_client` = the persona user you want to use, "BXLmKR79" from the above example.

`persona_oauth_secret` = the password to the user specified.
`persona_oauth_secret` = the password to the user specified, "zdlbESLEFGvxBw8k" from the above example.

Initialise the environment. Run the following command which will download the required libraries.

Expand All @@ -57,3 +89,22 @@ docker-compose run test
docker-compose run unittest
docker-compose run integrationtest
```

To create a docker container where you can run commands directly, for example to run individual tests:

```bash
docker-compose run local-dev
```

When connected run:

```bash
service redis-server start
source /etc/profile.d/*
```

You can the bun ant commands individually or run individual tests:

```bash
/vendor/bin/phpunit --filter testCreateUserThenPatchOAuthClientAddScope test/integration/
```
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,31 @@ services:
command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant code-check"
test:
image: talis/talis-php
network_mode: host
volumes:
- ".:/var/talis-php"
command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant test"
unittest:
image: talis/talis-php
network_mode: host
volumes:
- ".:/var/talis-php"
command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant unittest"
integrationtest:
image: talis/talis-php
network_mode: host
volumes:
- ".:/var/talis-php"
command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant integrationtest"
local-dev:
image: talis/talis-php
network_mode: host
volumes:
- ".:/var/talis-php"
command: /bin/bash
coverage:
image: talis/talis-php
network_mode: host
volumes:
- ".:/var/talis-php"
command: /bin/bash -c "service redis-server start && source /etc/profile.d/* && ant coverage"

0 comments on commit 75ea5c6

Please sign in to comment.