Skip to content

Commit

Permalink
Merge pull request #2 from soda480/0.2.0
Browse files Browse the repository at this point in the history
0.2.0
  • Loading branch information
soda480 authored Mar 7, 2021
2 parents a8bb6a1 + 44cb83f commit 0e40533
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
pull_request:
branches:
- master
env:
CRYPTOGRAPHY_DONT_BUILD_RUST: 1

jobs:
build:
runs-on: ubuntu-16.04
Expand All @@ -14,8 +17,11 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Install required packages
run: apk --update --no-cache add gcc libc-dev libffi-dev openssl-dev

- name: Install pybuilder
run: pip install pybuilder==0.11.17
run: pip install pybuilder

- name: Install dependencies
run: pyb install_dependencies
Expand All @@ -27,7 +33,7 @@ jobs:
run: |
apk update
apk add bash curl
sed -e 's,filename="pybuilder-bandit/,filename="src/main/python/pybuilder_bandit/,g' target/reports/coverage.xml > coverage.xml
sed -e 's,filename="pybuilder-bandit/,filename="src/main/python/pybuilder_bandit/,g' target/reports/pybuilder-bandit_coverage.xml > coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM python:3.6-alpine

ENV PYTHONDONTWRITEBYTECODE 1
ENV CRYPTOGRAPHY_DONT_BUILD_RUST 1

WORKDIR /pybuilder-bandit

COPY . /pybuilder-bandit/

RUN apk --update --no-cache add gcc libc-dev libffi-dev openssl-dev
RUN pip install pybuilder==0.11.17
RUN pyb install_dependencies
RUN pyb install
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ A pybuilder plugin that analyzes your project for common security issues using `

To add this plugin into your pybuilder project, add the following line near the top of your build.py:
```python
use_plugin('pypi:pybuilder_bandit', '~=0.1.1')
use_plugin('pypi:pybuilder_bandit')
```

**NOTE** version `v0.1.x` of this plugin will only work with version `v0.11.x` of Pybuilder.
**NOTE** if you are using Pybuilder version `v0.11.x`, then specify the following version of the plugin:
```python
use_plugin('pypi:pybuilder_bandit', '~=0.1.1')
```

### Pybuilder bandit properties ###

Expand Down
4 changes: 2 additions & 2 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
authors = [Author('Emilio Reyes', 'soda480@gmail.com')]
summary = 'Pybuilder plugin for bandit security linter'
url = '/~https://github.com/soda480/pybuilder-bandit'
version = '0.1.1'
version = '0.2.0'
default_task = ['clean', 'analyze']
license = 'Apache License, Version 2.0'
description = summary
Expand Down Expand Up @@ -54,4 +54,4 @@ def set_properties(project):
# project.set_property('bandit_break_build', True)
# project.set_property('bandit_confidence_level', 'LOW')
# project.set_property('bandit_severity_level', 'MEDIUM')
# project.set_property('bandit_skip_ids', 'B311,B315')
# project.set_property('bandit_skip_ids', 'B311,B110')
8 changes: 4 additions & 4 deletions src/main/python/pybuilder_bandit/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ def init_bandit(project):

@task('bandit', description='execute bandit security linter')
@depends('prepare')
def bandit(project, logger):
def bandit(project, logger, reactor):
""" execute bandit security linter
"""
set_verbose_property(project)
command = get_command(project)
command = get_command(project, reactor)
logger.info(f'Executing bandit security linter: \"{command.as_string}\"')
result = command.run_on_production_source_files(logger, include_dirs_only=True)
process_result(project, result, logger)


def get_command(project):
def get_command(project, reactor):
""" return bandit command
"""
command = ExternalCommandBuilder('bandit', project)
command = ExternalCommandBuilder('bandit', project, reactor)
command.use_argument('--recursive')
command.use_argument('--format')
command.use_argument('custom')
Expand Down
12 changes: 7 additions & 5 deletions src/unittest/python/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test__bandit_Should_CallExpected_When_VerifyResultFalse(self, process_result
get_command_patch.return_value = command_mock
project_mock = Mock()
logger_mock = Mock()
bandit(project_mock, logger_mock)
bandit(project_mock, logger_mock, Mock())
process_result_patch.assert_called_once_with(project_mock, command_mock.run_on_production_source_files.return_value, logger_mock)

@patch('pybuilder_bandit.task.translate_severity_level')
Expand All @@ -54,8 +54,9 @@ def test__get_command_Should_CallAndReturnExpected_When_Skip(self, external_comm
external_command_builder_patch.return_value = command_mock
project_mock = Mock()
project_mock.get_property.return_value = 'id1,id2,id3'
result = get_command(project_mock)
external_command_builder_patch.assert_called_once_with('bandit', project_mock)
reactor_mock = Mock()
result = get_command(project_mock, reactor_mock)
external_command_builder_patch.assert_called_once_with('bandit', project_mock, reactor_mock)
self.assertEqual(result, external_command_builder_patch.return_value)
self.assertTrue(call('--skip') in command_mock.use_argument.mock_calls)
self.assertTrue(call('id1,id2,id3') in command_mock.use_argument.mock_calls)
Expand All @@ -68,8 +69,9 @@ def test__get_command_Should_CallAndReturnExpected_When_NoSkip(self, external_co
external_command_builder_patch.return_value = command_mock
project_mock = Mock()
project_mock.get_property.return_value = None
result = get_command(project_mock)
external_command_builder_patch.assert_called_once_with('bandit', project_mock)
reactor_mock = Mock()
result = get_command(project_mock, reactor_mock)
external_command_builder_patch.assert_called_once_with('bandit', project_mock, reactor_mock)
self.assertEqual(result, external_command_builder_patch.return_value)
self.assertFalse(call('--skip') in command_mock.use_argument.mock_calls)

Expand Down

0 comments on commit 0e40533

Please sign in to comment.