Skip to content

Commit

Permalink
add test file for docker e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
cxMiguelSilva committed Feb 1, 2024
1 parent 6e4dfee commit 2476868
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 51 deletions.
102 changes: 51 additions & 51 deletions .github/workflows/sec-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,54 +68,54 @@ jobs:
if: always()
shell: bash
run: cat ./trivy-image-results.json
grype:
name: Grype Scan
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
kics-docker: [ "Dockerfile"]
steps:
- name: Check out code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build
id: docker_build
uses: docker/build-push-action@v5.0.0
with:
load: true
context: ./
file: ./${{ matrix.kics-docker }}
builder: ${{ steps.buildx.outputs.name }}
push: false
tags: kics:sec-tests-${{ github.sha }}
build-args: |
VERSION=development
COMMIT=${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Scan image
id: grype-scan
uses: anchore/scan-action@v3
with:
image: kics:sec-tests-${{ github.sha }}
fail-build: true
severity-cutoff: medium
output-format: sarif
- name: upload Anchore scan SARIF report
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: ${{ steps.grype-scan.outputs.sarif }}
- name: upload artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: grype-scan-results
path: ${{ steps.grype-scan.outputs.sarif }}
- name: Inspect action SARIF report
if: always()
run: cat ${{ steps.grype-scan.outputs.sarif }}
#grype:
# name: Grype Scan
# runs-on: ubuntu-20.04
# strategy:
# fail-fast: false
# matrix:
# kics-docker: [ "Dockerfile"]
# steps:
# - name: Check out code
# uses: actions/checkout@v4
# with:
# persist-credentials: false
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
# - name: Build
# id: docker_build
# uses: docker/build-push-action@v5.0.0
# with:
# load: true
# context: ./
# file: ./${{ matrix.kics-docker }}
# builder: ${{ steps.buildx.outputs.name }}
# push: false
# tags: kics:sec-tests-${{ github.sha }}
# build-args: |
# VERSION=development
# COMMIT=${{ github.sha }}
# cache-from: type=local,src=/tmp/.buildx-cache
# cache-to: type=local,dest=/tmp/.buildx-cache
# - name: Scan image
# id: grype-scan
# uses: anchore/scan-action@v3
# with:
# image: kics:sec-tests-${{ github.sha }}
# fail-build: true
# severity-cutoff: medium
# output-format: sarif
# - name: upload Anchore scan SARIF report
# uses: github/codeql-action/upload-sarif@v3
# if: always()
# with:
# sarif_file: ${{ steps.grype-scan.outputs.sarif }}
# - name: upload artifact
# uses: actions/upload-artifact@v4
# if: always()
# with:
# name: grype-scan-results
# path: ${{ steps.grype-scan.outputs.sarif }}
# - name: Inspect action SARIF report
# if: always()
# run: cat ${{ steps.grype-scan.outputs.sarif }}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ RUN wget https://github.com/GoogleCloudPlatform/terraformer/releases/download/0.
COPY --from=build_env /app/bin/kics /app/bin/kics
COPY --from=build_env /app/assets/queries /app/bin/assets/queries
COPY --from=build_env /app/assets/libraries/* /app/bin/assets/libraries/
COPY --from=build_env /app/assets/test/* /app/bin/assets/test/

WORKDIR /app/bin

Expand Down
1 change: 1 addition & 0 deletions assets/test/test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, this is a test message from a text file
12 changes: 12 additions & 0 deletions pkg/scan/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type executeScanParameters struct {
extractedPaths provider.ExtractedPath
}

const testFilePath = "./assets/test/test_file.txt"

func (c *Client) initScan(ctx context.Context) (*executeScanParameters, error) {
progressBar := c.ProBarBuilder.BuildCircle("Preparing Scan Assets: ")
go progressBar.Start()
Expand All @@ -55,6 +57,16 @@ func (c *Client) initScan(ctx context.Context) (*executeScanParameters, error) {
return nil, nil
}

//load a file and log its content

Check failure on line 60 in pkg/scan/scan.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
file, err := os.Open(testFilePath)
if err != nil {
log.Err(err)
return nil, err
}
defer file.Close()

log.Info().Msgf("File content: %s", file)

Check failure on line 68 in pkg/scan/scan.go

View workflow job for this annotation

GitHub Actions / Check Go coverage

(*github.com/rs/zerolog.Event).Msgf format %s has arg file of wrong type *os.File

Check failure on line 68 in pkg/scan/scan.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21.x, ubuntu-latest)

(*github.com/rs/zerolog.Event).Msgf format %s has arg file of wrong type *os.File

Check failure on line 68 in pkg/scan/scan.go

View workflow job for this annotation

GitHub Actions / unit-tests (1.21.x, macos-latest)

(*github.com/rs/zerolog.Event).Msgf format %s has arg file of wrong type *os.File

querySource := source.NewFilesystemSource(
c.ScanParams.QueriesPath,
c.ScanParams.Platform,
Expand Down

0 comments on commit 2476868

Please sign in to comment.