Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Merge pull request #192 from vania-pooh/master
Browse files Browse the repository at this point in the history
Fixed NPE when specifying directory instead of users.htpasswd (fixes …
  • Loading branch information
aandryashin authored Apr 25, 2018
2 parents b0a1371 + 2788df1 commit 574123d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
- docker

script:
- go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg .
- go test -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg .
- GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w"
- gox -os "linux darwin windows" -arch "amd64" -osarch="windows/386" -output "dist/{{.Dir}}_{{.OS}}_{{.Arch}}" -ldflags "-X main.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.gitRevision=`git describe --tags || git rev-parse HEAD` -s -w"

Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func showVersion() {
}

func fileExists(p string) bool {
_, err := os.Stat(p)
return !os.IsNotExist(err)
fileInfo, err := os.Stat(p)
return !os.IsNotExist(err) && !fileInfo.IsDir()
}

func init() {
Expand All @@ -98,7 +98,7 @@ func init() {
}
log.Printf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file is \"%s\"]\n", users)
if !fileExists(users) && !guestAccessAllowed {
log.Fatalf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file \"%s\" does not exist]\n", users)
log.Fatalf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [Users file \"%s\" does not exist or is a directory]\n", users)
}
if err := loadQuotaFiles(quotaDir); err != nil {
log.Fatalf("[-] [-] [INIT] [-] [-] [-] [-] [-] [-] [%v]\n", err)
Expand Down
11 changes: 11 additions & 0 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
. "github.com/aandryashin/matchers"
. "github.com/aandryashin/matchers/httpresp"
"golang.org/x/net/websocket"
"os"
"path/filepath"
)

var (
Expand Down Expand Up @@ -1443,3 +1445,12 @@ func doHTTPRequestWithoutAuthentication(method string, url string, body io.Reade
client := &http.Client{}
return client.Do(req)
}

func TestFileExists(t *testing.T) {
tmpDir := os.TempDir()
AssertThat(t, fileExists(tmpDir), Is{false})
AssertThat(t, fileExists(filepath.Join(tmpDir, "missing-file")), Is{false})
f, err := ioutil.TempFile(tmpDir, "testfile")
AssertThat(t, err, Is{nil})
AssertThat(t, fileExists(f.Name()), Is{true})
}

0 comments on commit 574123d

Please sign in to comment.