Skip to content

Commit 3cfb484

Browse files
authored
Merge pull request #426 from gruebel/update-gha
update GHA files and add Python version test CI
2 parents 5582963 + f173130 commit 3cfb484

File tree

15 files changed

+94
-133
lines changed

15 files changed

+94
-133
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ updates:
1111
interval: "daily"
1212
# Disable all pull requests for Docker dependencies
1313
open-pull-requests-limit: 0
14+
- package-ecosystem: "github-actions"
15+
directory: "/"
16+
schedule:
17+
interval: "weekly"
18+

.github/workflows/bump-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
bump-version:
88
runs-on: ubuntu-latest
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1111
with:
1212
ref: master
1313

.github/workflows/ci.yml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,27 @@
22

33
name: continuous-integration
44

5-
on: [push, pull_request, workflow_dispatch]
5+
on:
6+
workflow_dispatch:
7+
push:
8+
branches:
9+
- master
10+
pull_request:
11+
12+
permissions:
13+
contents: read
614

715
jobs:
816
ci:
917
runs-on: ubuntu-latest
18+
timeout-minutes: 15
1019
steps:
11-
- uses: actions/checkout@v2
20+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1221

1322
- name: Setup Python
14-
uses: actions/setup-python@v1
23+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
1524
with:
16-
python-version: 3.7
25+
python-version: '3.7'
1726

1827
- name: Install dependencies
1928
run: |
@@ -30,3 +39,32 @@ jobs:
3039
- run: invoke integration.query
3140
- run: invoke integration.write-policy
3241
- run: invoke build.uninstall-package
42+
43+
python-version:
44+
if: github.event_name == 'pull_request'
45+
runs-on: ubuntu-latest
46+
timeout-minutes: 15
47+
strategy:
48+
fail-fast: true
49+
matrix:
50+
python: ['3.8', '3.9', '3.10', '3.11', '3.12']
51+
steps:
52+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
53+
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
54+
with:
55+
python-version: ${{ matrix.python }}
56+
allow-prereleases: true
57+
58+
- name: Install dependencies
59+
run: |
60+
pip install -r requirements.txt
61+
pip install -r requirements-dev.txt
62+
63+
- run: invoke build.install-package
64+
- run: invoke integration.clean
65+
- run: invoke integration.version
66+
- run: invoke integration.initialize
67+
- run: invoke unit.pytest
68+
- run: invoke integration.query
69+
- run: invoke integration.write-policy
70+
- run: invoke build.uninstall-package

.github/workflows/publish.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111
test:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1515

1616
- name: Setup Python
17-
uses: actions/setup-python@v1
17+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
1818
with:
19-
python-version: 3.7
19+
python-version: '3.7'
2020

2121
- name: Install dependencies
2222
run: |
@@ -38,11 +38,11 @@ jobs:
3838
needs: test
3939
runs-on: ubuntu-latest
4040
steps:
41-
- uses: actions/checkout@master
41+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
4242
- name: Set up Python 3.7
43-
uses: actions/setup-python@v1
43+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
4444
with:
45-
python-version: 3.7
45+
python-version: '3.7'
4646

4747
- name: Install dependencies
4848
run: |
@@ -57,20 +57,19 @@ jobs:
5757
pip install setuptools wheel twine
5858
python -m setup sdist bdist_wheel
5959
- name: Publish package
60-
uses: pypa/gh-action-pypi-publish@master
60+
uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e # v1.8.10
6161
with:
62-
user: __token__
6362
password: ${{ secrets.PYPI_PASSWORD }}
6463

6564
update-brew:
6665
needs: publish-package
6766
runs-on: ubuntu-latest
6867
steps:
69-
- uses: actions/checkout@master
68+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
7069
- name: Set up Python 3.7
71-
uses: actions/setup-python@v1
70+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
7271
with:
73-
python-version: 3.7
72+
python-version: '3.7'
7473
- name: publish brew
7574
run: |
7675
sleep 5m
@@ -92,7 +91,7 @@ jobs:
9291
needs: update-brew
9392
runs-on: ubuntu-latest
9493
steps:
95-
- uses: actions/checkout@v2
94+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
9695
with:
9796
ref: master
9897

.github/workflows/python-dependency-updater.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ on:
99
jobs:
1010
python-dependency-updater:
1111
runs-on: ubuntu-latest
12-
strategy:
13-
matrix:
14-
python-version: ['3.7']
1512
steps:
16-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1714

1815
- name: Setup Python
19-
uses: actions/setup-python@v2
16+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
2017
with:
21-
python-version: ${{ matrix.python-version }}
18+
python-version: '3.7'
2219

2320
- name: Run Pyup.io Dependency updater
2421
run: |

.github/workflows/release-drafter.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: Release Drafter
22

33
on:
44
push:
5-
branches: [ main, master ]
5+
branches: [ master ]
66

77
jobs:
88
update_release_draft:
99
runs-on: ubuntu-latest
1010
steps:
1111
# Drafts your next Release notes as Pull Requests are merged into "master"
12-
- uses: release-drafter/release-drafter@v5
12+
- uses: release-drafter/release-drafter@65c5fb495d1e69aa8c08a3317bc44ff8aabe9772 # v5.24.0
1313
env:
1414
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/update.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: checkout
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
1515
- name: Setup python
16-
uses: actions/setup-python@v2
16+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
1717
with:
1818
python-version: '3.7'
1919
- name: install dependencies
@@ -31,9 +31,9 @@ jobs:
3131
cp -rf /tmp/.policy_sentry/data/docs $(pwd)/policy_sentry/shared/data/
3232
- name: Set outputs
3333
id: vars
34-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
34+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
3535
- name: PR if files were updated
36-
uses: peter-evans/create-pull-request@v3
36+
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 #v5.0.2
3737
with:
3838
commit-message: Update database
3939
title: 'Updates database'
@@ -47,12 +47,12 @@ jobs:
4747
runs-on: ubuntu-latest
4848
needs: update-actions
4949
steps:
50-
- uses: actions/checkout@v2
50+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
5151

5252
- name: Setup Python
53-
uses: actions/setup-python@v1
53+
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
5454
with:
55-
python-version: 3.7
55+
python-version: '3.7'
5656

5757
- name: Install dependencies
5858
run: |

docs/contributing/testing.md

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ Available tasks:
5050
function.
5151
test.lint Linting with `pylint` and `autopep8`
5252
test.security Runs `bandit` and `safety check`
53-
unit.nose Unit testing: Runs unit tests using `nosetests`
5453
unit.pytest Unit testing: Runs unit tests using `pytest`
5554

5655

@@ -64,8 +63,6 @@ invoke integration.query
6463
invoke integration.write-policy
6564

6665
invoke test.security
67-
68-
invoke unit.nose
6966
```
7067

7168
Local Unit Testing and Integration Testing:
@@ -95,89 +92,37 @@ just run that quick command on your machine.
9592
Running the Test Suite
9693
----------------------
9794

98-
We use [Nose](https://nose.readthedocs.io/en/latest/) for unit testing.
99-
All tests are placed in the `tests` folder.
95+
We use [pytest](https://docs.pytest.org/en//) for unit testing.
96+
All tests are placed in the `test` folder.
10097

10198
- Just run the following:
10299

103100
```bash
104-
nosetests -v
101+
pytest -v
105102

106103
# This will output the print() statements in your test code
107-
nosetests -v --nocapture
104+
pytest -v --show-capture=no
108105

109106
# This will include the debug logging statements in the test output
110-
nosetests -v --logging-level=DEBUG
107+
pytest -v --log-level=DEBUG
111108
```
112109

113110
- Alternatively, you can use `invoke`, as mentioned above:
114111

115112
```bash
116-
invoke unit.nose
113+
invoke unit.pytest
117114
```
118115

119116
Output:
120117

121118
```text
122-
test_overrides_yml_config: Tests the format of the overrides yml file for the RAM service ... ok
123-
test_passing_overall_iam_action_override: Tests iam:CreateAccessKey ... ok
124-
test_get_dependent_actions_double (test_actions.ActionsTestCase) ... ok
125-
test_get_dependent_actions_several (test_actions.ActionsTestCase) ... ok
126-
test_get_dependent_actions_single (test_actions.ActionsTestCase) ... ok
127-
test_analyze_by_access_level: Test out calling this as a library ... ok
128-
test_determine_risky_actions_from_list: Test comparing requested actions to a list of risky actions ... ok
129-
test_get_actions_from_policy: Verify that the get_actions_from_policy function is grabbing the actions ... ok
130-
test_get_actions_from_policy_file_with_explicit_actions: Verify that we can get a list of actions from a ... ok
131-
test_get_actions_from_policy_file_with_wildcards: Verify that we can read the actions from a file, ... ok
132-
test_remove_actions_not_matching_access_level: Verify remove_actions_not_matching_access_level is working as expected ... ok
133-
test_get_findings: Ensure that finding.get_findings() combines two risk findings for one policy properly. ... ok
134-
test_get_findings_by_policy_name: Testing out the 'Findings' object ... ok
135-
test_add_s3_permissions_management_arn (test_arn_action_group.ArnActionGroupTestCase) ... ok
136-
test_get_policy_elements (test_arn_action_group.ArnActionGroupTestCase) ... ok
137-
test_update_actions_for_raw_arn_format (test_arn_action_group.ArnActionGroupTestCase) ... ok
138-
test_does_arn_match_case_1 (test_arns.ArnsTestCase) ... ok
139-
test_does_arn_match_case_2 (test_arns.ArnsTestCase) ... ok
140-
test_does_arn_match_case_4 (test_arns.ArnsTestCase) ... ok
141-
test_does_arn_match_case_5 (test_arns.ArnsTestCase) ... ok
142-
test_does_arn_match_case_6 (test_arns.ArnsTestCase) ... ok
143-
test_does_arn_match_case_bucket (test_arns.ArnsTestCase) ... ok
144-
test_determine_actions_to_expand: provide expanded list of actions, like ecr:* ... ok
145-
test_minimize_statement_actions (test_minimize_wildcard_actions.MinimizeWildcardActionsTestCase) ... ok
146-
test_get_action_data: Tests function that gets details on a specific IAM Action. ... ok
147-
test_get_actions_at_access_level_that_support_wildcard_arns_only: Test function that gets a list of ... ok
148-
test_get_actions_for_service: Tests function that gets a list of actions per AWS service. ... ok
149-
test_get_actions_matching_condition_crud_and_arn: Get a list of IAM Actions matching condition key, ... ok
150-
test_get_actions_matching_condition_crud_and_wildcard_arn: Get a list of IAM Actions matching condition key ... ok
151-
test_get_actions_matching_condition_key: Tests a function that gathers all instances in ... ok
152-
test_get_actions_that_support_wildcard_arns_only: Tests function that shows all ... ok
153-
test_get_actions_with_access_level: Tests function that gets a list of actions in a ... ok
154-
test_get_actions_with_arn_type_and_access_level: Tests a function that gets a list of ... ok
155-
test_get_all_actions_with_access_level: Get all actions with a given access level ... ok
156-
test_get_arn_type_details: Tests function that grabs details about a specific ARN name ... ok
157-
test_get_arn_types_for_service: Tests function that grabs arn_type and raw_arn pairs ... ok
158-
test_get_condition_key_details: Tests function that grabs details about a specific condition key ... ok
159-
test_get_condition_keys_for_service: Tests function that grabs a list of condition keys per service. ... ok
160-
test_get_raw_arns_for_service: Tests function that grabs a list of raw ARNs per service ... ok
161-
test_remove_actions_that_are_not_wildcard_arn_only: Tests function that removes actions from a list that ... ok
162-
test_actions_template (test_template.TemplateTestCase) ... ok
163-
test_crud_template (test_template.TemplateTestCase) ... ok
164-
test_actions_schema: Validates that the user-supplied YAML is working for CRUD mode ... ok
165-
test_actions_schema: Validates that the user-supplied YAML is working for CRUD mode ... ok
166-
test_print_policy_with_actions_having_dependencies (test_write_policy.WritePolicyActionsTestCase) ... ok
167-
test_write_policy (test_write_policy.WritePolicyCrudTestCase) ... ok
168-
test_write_policy_beijing: Tests ARNs with the partiion `aws-cn` instead of just `aws` ... ok
169-
test_write_policy_govcloud: Tests ARNs with the partition `aws-us-gov` instead of `aws` ... ok
170-
test_wildcard_when_not_necessary: Attempts bypass of CRUD mode wildcard-only ... ok
171-
test_write_actions_policy_with_library_only: Write an actions mode policy without using the command line at all (library only) ... ok
172-
test_write_crud_policy_with_library_only: Write an actions mode policy without using the command line at all (library only) ... ok
173-
test_actions_missing_actions: write-policy actions if the actions block is missing ... ok
174-
test_allow_missing_access_level_categories_in_cfg: write-policy when the YAML file ... ok
175-
test_allow_empty_access_level_categories_in_cfg: If the content of a list is an empty string, it should sysexit ... ok
176-
test_actions_missing_arn: write-policy actions command when YAML file block is missing an ARN ... ok
177-
test_actions_missing_description: write-policy when the YAML file is missing a description ... ok
178-
test_actions_missing_name: write-policy when the YAML file is missing a name ... ok
179-
180-
Ran 57 tests in 2.694s
181-
182-
OK
119+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_a_determine_actions_to_expand_not_upper_camelcase PASSED [ 0%]
120+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_analyze_by_access_level PASSED [ 1%]
121+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_analyze_statement_by_access_level PASSED [ 2%]
122+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_determine_actions_to_expand PASSED [ 2%]
123+
test/analysis/test_analyze.py::AnalysisExpandWildcardActionsTestCase::test_gh_162 PASSED [ 3%]
124+
test/analysis/test_expand.py::PolicyExpansionTestCase::test_policy_expansion PASSED [ 4%]
125+
...
126+
127+
========================================================= 134 passed in 51.04s ============================================================
183128
```

policy_sentry/shared/awsdocs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def header_matches(string, table):
4242

4343
def get_links_from_base_actions_resources_conditions_page():
4444
"""Gets the links from the actions, resources, and conditions keys page, and returns their filenames."""
45-
html = requests.get(BASE_DOCUMENTATION_URL)
45+
html = requests.get(BASE_DOCUMENTATION_URL, timeout=300)
4646
soup = BeautifulSoup(html.content, "html.parser")
4747
html_filenames = []
4848
for i in soup.find("div", {"class": "highlights"}).findAll("a"):
@@ -85,7 +85,7 @@ def update_html_docs_directory(html_docs_destination):
8585
# html_filenames = [sub.replace(".html", ".partial.html") for sub in html_filenames]
8686

8787
for page in html_filenames:
88-
response = requests.get(link_url_prefix + page, allow_redirects=False)
88+
response = requests.get(link_url_prefix + page, allow_redirects=False, timeout=300)
8989
# Replace the CSS stuff. Basically this:
9090
"""
9191
<link href='href="https://docs.aws.amazon.com/images/favicon.ico"' rel="icon" type="image/ico"/>

requirements-dev.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Unit Testing
2-
pytest==7.1.1
2+
pytest==7.4.0
33
pylint==2.13.5
4-
nose==1.3.7
5-
coverage==6.3.2
4+
coverage==7.2.7
65
# Integration tests and tasks
7-
invoke==1.7.0
6+
invoke==2.2.0
87
# Security testing
98
safety==1.10.3
10-
bandit==1.7.4
9+
bandit==1.7.5
1110
# Formatting
1211
black==22.3.0
1312
# Other? Maybe this is from the docs? Not sure.

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
click==8.1.2
33
# Web Scraping
44
beautifulsoup4==4.11.1
5-
requests==2.27.1
5+
requests==2.31.0
66
# Config files and schema validation
7-
PyYAML==6.0
7+
PyYAML==6.0.1
88
schema==0.7.5

0 commit comments

Comments
 (0)