Skip to content

Commit

Permalink
fix missing template file
Browse files Browse the repository at this point in the history
  • Loading branch information
dlicheva committed Jan 16, 2025
1 parent 0db1574 commit 975cfd0
Show file tree
Hide file tree
Showing 60 changed files with 24,774 additions and 3 deletions.
2 changes: 2 additions & 0 deletions new-components/reporters/pdf/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ services:
- COMPONENT_PATH=reporters/pdf
- COMPONENT_BINARY_SOURCE_PATH=cmd/main.go
platform: linux/amd64
volumes:
- ./internal/reporter/testdata:/workspace
env_file:
- .env
depends_on:
Expand Down
4 changes: 4 additions & 0 deletions new-components/reporters/pdf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/smithy-security/pkg/env v0.0.1
github.com/smithy-security/smithy v0.59.2
github.com/smithy-security/smithy/sdk v0.0.4-alpha
github.com/stretchr/testify v1.9.0
google.golang.org/protobuf v1.36.3
)

Expand All @@ -21,6 +22,7 @@ require (
github.com/aws/aws-sdk-go v1.17.7 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.7.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
Expand All @@ -45,6 +47,7 @@ require (
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/playwright-community/playwright-go v0.4901.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -63,4 +66,5 @@ require (
golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
google.golang.org/grpc v1.65.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions new-components/reporters/pdf/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjr
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
6 changes: 3 additions & 3 deletions new-components/reporters/pdf/internal/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func getScanResults(ctx context.Context, findings []*vf.VulnerabilityFinding) ([
func getPdf(findings []string) (string, []byte, error) {
pw, err := playwright.NewClient()
if err != nil {
slog.Error("could not launch playwright: %s", err)
slog.Error("could not launch playwright: %s", slog.String("err", err.Error()))
}

defer func() {
Expand All @@ -145,10 +145,10 @@ func getPdf(findings []string) (string, []byte, error) {

// buildPdf builds a PDF
func buildPdf(data any, pw playwright.Wrapper) (string, []byte, error) {
templateFile := "default.html"
templateFile := "template.html"

// process the default template into a html result
tmpl, err := template.New("default.html").Funcs(template.FuncMap{
tmpl, err := template.New("template.html").Funcs(template.FuncMap{
"formatTime": FormatTime,
}).ParseFiles(templateFile)
if err != nil {
Expand Down
35 changes: 35 additions & 0 deletions new-components/reporters/pdf/internal/reporter/reporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Package reporter of the pdf consumer implements a simple consumer for
// applying a go-template to a smithy scan, converting the result to pdf and then
// uploading the result to the S3 bucket passed as an argument
// the consumer expects the environment variables
// AWS_ACCESS_KEY_ID
// AWS_SECRET_ACCESS_KEY
// to be set along with the "bucket" and "region" arguments to be passed
package reporter

import (
"testing"

"github.com/stretchr/testify/require"

v1 "github.com/smithy-security/smithy/api/proto/v1"

playwright "github.com/smithy-security/smithy/pkg/playwright/mock"
"github.com/smithy-security/smithy/pkg/testdata"
)

func Test_buildPdf(t *testing.T) {
mockClient, err := playwright.NewMockClient()
require.NoError(t, err)

called := false
expected := []byte("this is a pdf")
mockClient.GetPDFOfPageCallBack = func(s1, s2 string) ([]byte, error) {
called = true
return expected, nil
}
_, result, err := buildPdf([]v1.EnrichedLaunchToolResponse{testdata.EnrichedLaunchToolResponse}, mockClient)
require.NoError(t, err)
require.Equal(t, called, true)
require.Equal(t, result, expected)
}
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 975cfd0

Please sign in to comment.