Skip to content

Commit

Permalink
fix: missing store
Browse files Browse the repository at this point in the history
  • Loading branch information
le-yams committed May 16, 2024
1 parent d56a4f7 commit 07bf422
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 13 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ jobs:
with:
test_path: ./example/model.fga.yaml

test_conditions_against_openfga_version:
name: Run test against given OpenFGA version
test_conditions_support:
name: Test conditions support
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -64,13 +64,28 @@ jobs:
- name: Start OpenFGA Server
shell: bash
run: openfga run &
- name: Install OpenFGA cli
uses: jaxxstorm/action-install-gh-release@v1.11.0
with:
repo: openfga/cli
cache: enable
- name: Install jq
uses: dcarbone/install-jq-action@v2
- name: Create store with model
id: 'store'
run: |
fga store create --model ./example/model_with_conditions.fga > store_response.json
cat store_response.json
store_id=$(jq -r '.store.id' store_response.json)
echo "store_id=${store_id}" >> $GITHUB_OUTPUT
- name: Run OpenFGA CLI Tests
id: 'tests'
uses: ./
continue-on-error: true
with:
test_path: ./example/model_with_conditions.fga.yaml
fga_server_url: 'http://localhost:8080'
fga_server_store_id: ${{ steps.store.outputs.store_id }}
- name: Assert expected results
run: |
if [ "${{ matrix.test.conditions_supported }}" == "true" ] && [ "${{ steps.tests.outcome }}" == "failure" ]
Expand Down
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ This action can be used to test your authorization model using store test files.

## Parameter

| Parameter | Description | Required | Default |
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|--------------|
| `test_path` | The path to your store test file or folder relative to the root of your project. | No | `.` |
| `test_files_pattern` | The pattern to match test files. | No | `*.fga.yaml` |
| `fga_server_url` | The OpenFGA server to test the Authorization Model against. If empty (which is the default value), the tests are run using the cli built-in OpenFGA instance. | No | _empty_ |
| `fga_api_token` | The api token to use for testing against an OpenFGA server. Ignored if `fga_server_url` is not provided. | No | _empty_ |
| Parameter | Description | Required | Default |
|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|--------------|
| `test_path` | The path to your store test file or folder relative to the root of your project. | No | `.` |
| `test_files_pattern` | The pattern to match test files. | No | `*.fga.yaml` |
| `fga_server_url` | The OpenFGA server to test the Authorization Model against. If empty (which is the default value), the tests are run using the cli built-in OpenFGA instance. | No | _empty_ |
| `fga_server_store_id` | The OpenFGA server store id. Must be provided if fga_server_url is configured. | No | _empty_ |
| `fga_api_token` | The api token to use for testing against an OpenFGA server. Ignored if `fga_server_url` is not provided. | No | _empty_ |

> Note: the action will fail if no test is found in the specified test path with the given pattern
Expand Down Expand Up @@ -107,10 +108,25 @@ jobs:
- name: Start OpenFGA server in background
shell: bash
run: openfga run &
- name: Install OpenFGA cli
uses: jaxxstorm/action-install-gh-release@v1.11.0
with:
repo: openfga/cli
cache: enable
- name: Install jq
uses: dcarbone/install-jq-action@v2
- name: Create store with model
id: 'store'
run: |
fga store create --model ./example/model_with_conditions.fga > store_response.json
cat store_response.json
store_id= $(jq -r '.store.id' store_response.json)
echo "store_id=${store_id}" >> $GITHUB_OUTPUT
- name: Run tests
uses: openfga/action-openfga-test@v0.1
with:
fga_server_url: 'http://localhost:8080'
fga_server_store_id: ${{ steps.store.outputs.store_id }}
```

## License
Expand Down
16 changes: 11 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ inputs:
description: 'The OpenFGA server to test the Authorization Model against. If not provided, the tests will be run using the cli built-in OpenFGA instance.'
required: false
default: ''
fga_server_store_id:
description: 'The OpenFGA server store id. Must be provided if fga_server_url is configured.'
required: false
default: ''
fga_api_token:
description: 'The api token to use for testing against an OpenFGA server. Ignored if fga_server_url is not provided.'
required: false
Expand All @@ -33,13 +37,15 @@ runs:
cache: enable
- name: Run OpenFGA CLI
shell: bash
env:
FGA_SERVER_URL: ${{ inputs.fga_server_url }}
FGA_API_TOKEN: ${{ inputs.fga_api_token }}
run: |
fga_opts=""
if [[ -n "${FGA_SERVER_URL}" ]]; then
fga_opts="--api-url ${FGA_SERVER_URL} ${FGA_API_TOKEN:+--api-token ${FGA_API_TOKEN}}"
fga_token="${{ inputs.fga_api_token }}"
if [[ -n "${{ inputs.fga_server_url }}" ]]; then
if [[ -z "${{ inputs.fga_server_store_id }}" ]]; then
echo "missing store id for specified OpenFGA server ${{ inputs.fga_server_url }}."
exit 1
fi
fga_opts="--api-url ${{ inputs.fga_server_url }} --store-id ${{ inputs.fga_server_store_id }} ${fga_token:+--api-token ${fga_token}}"
fi
while IFS= read -r -d '' test_file
Expand Down

0 comments on commit 07bf422

Please sign in to comment.