Skip to content

Commit

Permalink
make validation stricter and fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Justin Alvarez <[email protected]>
  • Loading branch information
pendo324 committed Nov 2, 2023
1 parent 568fdf0 commit ec53bee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions pkg/path/finch_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package path

import (
"fmt"
"path/filepath"
"strings"

"golang.org/x/sys/windows/registry"
Expand All @@ -23,9 +22,8 @@ func (Finch) FinchRootDir(ffd FinchFinderDeps) (string, error) {
if err != nil {
return "", err
}
// reject any paths that end with unexpected characters
fileName := filepath.Base(expandedPath)
if strings.Contains(fileName, "&") || strings.Contains(fileName, `"`) {
// reject any paths that contain unexpected characters
if strings.Contains(expandedPath, "&") || strings.Contains(expandedPath, `"`) {
return "", fmt.Errorf("unexpected LOCALAPPDATA path %q", expandedPath)
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/path/finch_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ package path

import (
"fmt"
"path/filepath"
"testing"

"github.com/golang/mock/gomock"
"github.com/runfinch/finch/pkg/mocks"
"github.com/stretchr/testify/assert"

"github.com/runfinch/finch/pkg/mocks"
)

func TestFinch_RootDir(t *testing.T) {
Expand All @@ -28,7 +28,7 @@ func TestFinch_RootDir(t *testing.T) {
{
name: "happy path",
wantErr: nil,
want: `C:\Users\User\AppData\`,
want: Finch(`C:\Users\User\AppData\`),
mockSvc: func(deps *mocks.FinchFinderDeps) {
deps.EXPECT().Env("LOCALAPPDATA").Return(`C:\Users\User\AppData\`)
},
Expand All @@ -52,7 +52,7 @@ func TestFinch_RootDir(t *testing.T) {
deps := mocks.NewFinchFinderDeps(ctrl)
tc.mockSvc(deps)
res, err := mockFinch.FinchRootDir(deps)
assert.Equal(t, res, filepath.Join("", "", ""))
assert.Equal(t, Finch(res), tc.want)
assert.Equal(t, err, tc.wantErr)
})
}
Expand Down

0 comments on commit ec53bee

Please sign in to comment.