Skip to content

Commit

Permalink
Merge pull request #22 from shaneu/main
Browse files Browse the repository at this point in the history
chore: fixing path handling
  • Loading branch information
grinish21 authored Jun 23, 2021
2 parents 560c2f7 + d85c7a6 commit dd82b41
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
5 changes: 3 additions & 2 deletions pkg/file/fileUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"mime/multipart"
"os"
"os/exec"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -304,12 +305,12 @@ func hasCompressionExtension(path string) bool {
}

// Read in .ge_ignore file and ignore files matching the patterns
func getIgnorePatterns(path, ignoreFile string, verbose bool) (ignorePatterns []string) {
func getIgnorePatterns(filePath, ignoreFile string, verbose bool) (ignorePatterns []string) {
ignorePatterns = append(ignorePatterns, "*.git/*")

// Loop through the files defined to contain ignore patterns (.ge_ignore, .gitignore, etc.)
for _, ignoreFile := range ignoreFiles {
path := path + "/" + ignoreFile
path := path.Join(filePath, ignoreFile)
if Exists(path) {
file, err := os.Open(path)
if err != nil {
Expand Down
27 changes: 15 additions & 12 deletions pkg/file/fileUtil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,32 @@
package file

import (
"log"
"os"
"github.com/americanexpress/earlybird/pkg/scan"
"reflect"

"os"
"path"
"strings"
"testing"

"github.com/americanexpress/earlybird/pkg/scan"
)

var userHomeDir string
var projectRoot string
var workDir string

func init() {
var err error
userHomeDir, err = os.UserHomeDir()
workingDir, err := os.Getwd()
if err != nil {
log.Fatal("Home directory doesn't exist", err)
panic("cannot get working dir")
}
ignorePatterns = getIgnorePatterns(userHomeDir+string(os.PathSeparator), ".ge_ignore", false)

workDir = workingDir
projectRoot = path.Join(workingDir, "../../")
ignorePatterns = getIgnorePatterns(projectRoot, path.Join(projectRoot, ".ge_ignore"), false)
}

func TestGetFiles(t *testing.T) {
searchDir := "test_data"
ignoreFile := userHomeDir + string(os.PathSeparator) + ".ge_ignore"
ignoreFile := path.Join(projectRoot, ".ge_ignore")
verbose := false
maxFileSize := int64(1000000)

Expand Down Expand Up @@ -117,7 +120,7 @@ func Test_getFileSizeOK(t *testing.T) {
}

func Test_getIgnorePatterns(t *testing.T) {
if gotIgnorePatterns := getIgnorePatterns(userHomeDir+string(os.PathSeparator), ".ge_ignore", false); len(ignorePatterns) == 0 {
if gotIgnorePatterns := getIgnorePatterns(projectRoot, ".ge_ignore", false); len(ignorePatterns) == 0 {
t.Errorf("getIgnorePatterns() = %v, want multiple patterns", gotIgnorePatterns)
}
}
Expand All @@ -137,7 +140,7 @@ func Test_isIgnoredFile(t *testing.T) {
{
name: "Check if file is ignored",
args: args{
fileName: "ignore.png",
fileName: "/npm-shrinkwrap.json",
},
want: true,
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/scan/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func init() {

cfg.AdjustedSeverityCategories = []cfgReader.AdjustedSeverityCategory{
{
Category: "password-secret",
Category: "password-secret",
AdjustedDisplaySeverity: "medium",
Patterns: []string{
"(?i)/lowEnv/",
Expand Down

0 comments on commit dd82b41

Please sign in to comment.