Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve writing rules #212

Merged
merged 7 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions .github/workflows/canary_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
]
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: yarn install --frozen-lockfile
- name: Test ${{ matrix.group }}
run: BEARER_VERSION=${{matrix.version}} npm test tests/${{ matrix.group }}
run: BEARER_VERSION=${{matrix.version}} yarn test tests/${{ matrix.group }}
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
]
steps:
- uses: actions/checkout@v3
- run: npm ci
- run: yarn install --frozen-lockfile
- name: Test ${{ matrix.group }}
run: BEARER_VERSION=${{matrix.version}} npm test tests/${{ matrix.group }}
run: BEARER_VERSION=${{matrix.version}} yarn test tests/${{ matrix.group }}
shell: bash
31 changes: 23 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,37 @@ For example

Here are the basic steps to adding a new rule.

1. Create a rule YAML file following the guide [here](https://docs.bearer.com/guides/custom-rule/)
2. Add a directory of test data. This includes example code that should (or for "ok" cases, should not) trigger your new rule. See [here](/tests/ruby/lang/logger/testdata) for a simple Ruby example test.
3. Scaffold tests by running
1. Generate a rule and its associated test folder by running

```bash
node ./scripts/gen_tests.js
yarn generate_rule MY_RULE_ID
```
4. Run the test suite on your new rule, to generate snapshot data

**Example**

```bash
npm test path-to-rule-test-folder
yarn generate_rule java_lang_hardcoded_secret
```
5. Run the linter/validator to check your rule passes

This command will generate:

- a YAML file in `rules/java/lang/hardcoded_secret.yml` for the rule itself
- a test folder in `tests/java/lang/hardcoded_secret/` containing:
- a testdata folder containing a `main.java` file
- a `test.js` file to run the test

NB: you can run `yarn generate_rule --help` for more options

2. Follow the guide [here](https://docs.bearer.com/guides/custom-rule/) to complete the rule
3. Run the tests `yarn test tests/<path-to-test>`
4. Run the linter/validator to check your rule passes

```bash
./scripts/lint.sh
./scripts/validate.sh
```
6. Make a pull request containing all of the above

5. Make a pull request containing all of the above

## Have questions?

Expand Down
Loading
Loading