From 31775b6ae9749ac6095b3530480cf5c1e0d46dbd Mon Sep 17 00:00:00 2001 From: Pierre Dubouilh Date: Sun, 15 Dec 2019 19:00:26 +0100 Subject: [PATCH 1/3] refactor --- .github/workflows/go.yml | 4 +- .gitignore | 3 + .travis.yml | 5 - Makefile | 10 +- docker/caddy.Dockerfile | 22 ---- docker/download.Dockerfile | 10 -- readme.md | 44 +++---- src/gossa.go | 24 ++-- src/gossa_test.go | 153 ++++++++++++------------- support/Caddyfile | 8 ++ {docker => support}/build.Dockerfile | 0 support/caddy.Dockerfile | 8 ++ {docker => support}/docker-compose.yml | 0 {docker => support}/readme.md | 18 ++- test-fixture/.testhidden | 1 + test-fixture/ext/somefile.blank | 0 test-fixture/ext/somefile.code | 0 test-fixture/ext/somefile.db | 0 test-fixture/ext/somefile.doc | 0 test-fixture/ext/somefile.epub | 0 test-fixture/ext/somefile.gif | 0 test-fixture/ext/somefile.mp3 | 0 test-fixture/ext/somefile.mp4 | 0 test-fixture/ext/somefile.pdf | Bin test-fixture/ext/somefile.ppt | 0 test-fixture/ext/somefile.srt | 0 test-fixture/ext/somefile.xls | 0 test-fixture/ext/somefile.zip | 0 28 files changed, 138 insertions(+), 172 deletions(-) delete mode 100644 .travis.yml delete mode 100644 docker/caddy.Dockerfile delete mode 100644 docker/download.Dockerfile create mode 100644 support/Caddyfile rename {docker => support}/build.Dockerfile (100%) create mode 100644 support/caddy.Dockerfile rename {docker => support}/docker-compose.yml (100%) rename {docker => support}/readme.md (54%) create mode 100644 test-fixture/.testhidden create mode 100644 test-fixture/ext/somefile.blank create mode 100644 test-fixture/ext/somefile.code create mode 100644 test-fixture/ext/somefile.db create mode 100644 test-fixture/ext/somefile.doc create mode 100644 test-fixture/ext/somefile.epub create mode 100644 test-fixture/ext/somefile.gif create mode 100644 test-fixture/ext/somefile.mp3 create mode 100644 test-fixture/ext/somefile.mp4 create mode 100644 test-fixture/ext/somefile.pdf create mode 100644 test-fixture/ext/somefile.ppt create mode 100644 test-fixture/ext/somefile.srt create mode 100644 test-fixture/ext/somefile.xls create mode 100644 test-fixture/ext/somefile.zip diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index cbd7d15..c98914c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,4 @@ -name: Go +name: ci on: [push, pull_request] jobs: @@ -15,7 +15,7 @@ jobs: - name: Check out code into the Go module directory uses: actions/checkout@v1 - with: + with: submodules: true - name: Run diff --git a/.gitignore b/.gitignore index e9b2db6..ec40082 100755 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ gossa-windows.exe .vscode test-fixture/* test-fixture/*/* +!test-fixture/.testhidden !test-fixture/compress !test-fixture/compress/foo* !test-fixture/gzip @@ -36,3 +37,5 @@ test-fixture/*/* !test-fixture/hols/scotland-1761292_1920.jpg !test-fixture/fancy-path !test-fixture/fancy-path/* +!test-fixture/ext/* +!test-fixture/ext \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7c2b915..0000000 --- a/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: go -go: - - "1.10" -script: - - make ci diff --git a/Makefile b/Makefile index f83cf95..d18c9c7 100755 --- a/Makefile +++ b/Makefile @@ -7,17 +7,17 @@ build: run: make build - ./gossa test-fixture + ./gossa -verb=true test-fixture run-extra: make build - ./gossa -prefix="/fancy-path/" -symlinks=true test-fixture + ./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture ci: - -@cd test-fixture && ln -s ../docker . + -@cd test-fixture && ln -s ../support . make build - timeout 10 make run & - sleep 11 && timeout 10 make run-extra & + timeout 15 make run & + sleep 16 && timeout 15 make run-extra & cp src/gossa_test.go . && go test rm gossa_test.go diff --git a/docker/caddy.Dockerfile b/docker/caddy.Dockerfile deleted file mode 100644 index 9571656..0000000 --- a/docker/caddy.Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM alpine - -# download and prepare caddy -RUN apk update && apk add curl ca-certificates -RUN curl -L -o caddy.tar.gz "https://github.com/mholt/caddy/releases/download/v0.11.1/caddy_v0.11.1_linux_amd64.tar.gz" -RUN tar xvzf caddy.tar.gz && mv caddy /caddy - -# download and prepare gossa -RUN curl -L -o /gossa "https://github.com/pldubouilh/gossa/releases/download/v0.0.7/gossa-linux64" -RUN chmod +x /gossa /caddy - -# Caddy config: -# * http basic auth is implemented here, with bob as user and dylan as password -# * to enable https just set a valid domain instead of *:8001 - how simple ! -RUN echo -e '\n\ - *:8001\n\ - basicauth / bob dylan\n\ - proxy / 127.0.0.1:8000\n\ -'>> /Caddyfile - -RUN echo -e '/gossa -h 127.0.0.1 -p 8000 /shared & \n /caddy'>> /start.sh -ENTRYPOINT [ "sh", "/start.sh" ] diff --git a/docker/download.Dockerfile b/docker/download.Dockerfile deleted file mode 100644 index cd3d17c..0000000 --- a/docker/download.Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM alpine - -ENV UID="1000" GID="1000" HOST="0.0.0.0" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared" -EXPOSE 8001 - -RUN apk add --no-cache su-exec -RUN wget https://github.com/pldubouilh/gossa/releases/download/v0.0.8/gossa-linux64 && mv gossa-linux64 /gossa && chmod +x /gossa - -RUN echo -e 'exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR}'>> /start.sh -ENTRYPOINT [ "sh", "/start.sh" ] diff --git a/readme.md b/readme.md index b92ecb7..41249f4 100644 --- a/readme.md +++ b/readme.md @@ -1,9 +1,9 @@ gossa ============= -![e](https://user-images.githubusercontent.com/760637/52522293-942fa880-2c83-11e9-9f79-0a5b922bcc7f.gif) +![e](https://user-images.githubusercontent.com/760637/64541706-a3163080-d322-11e9-85ef-a4d8001fa6a5.gif) -[![build status](https://img.shields.io/travis/pldubouilh/gossa.svg?logo=travis)](https://travis-ci.org/pldubouilh/gossa) +[![build status](https://github.com/pldubouilh/gossa/workflows/ci/badge.svg)](https://github.com/pldubouilh/gossa/actions) [![docker build status](https://img.shields.io/docker/cloud/build/pldubouilh/gossa.svg?logo=docker)](https://hub.docker.com/r/pldubouilh/gossa) [![docker pulls](https://img.shields.io/docker/pulls/pldubouilh/gossa.svg?logo=docker)](https://hub.docker.com/r/pldubouilh/gossa) [![github downloads](https://img.shields.io/github/downloads/pldubouilh/gossa/total.svg?logo=github)](https://github.com/pldubouilh/gossa/releases) @@ -16,13 +16,14 @@ a [simple UI](https://github.com/pldubouilh/gossa-ui) comes as default, featurin * πŸ“© drag-and-drop file/directory uploader * πŸ—ΊοΈ files handling - move/rename/delete * πŸ“Έ picture browser - * πŸ“½οΈ video streaming from the browser + * πŸ“½οΈ video streaming * ✍️ simple text editor * ⌨️ keyboard shortcuts - * πŸ₯‚ speed - showed rates above 100MB/s + * πŸ₯‚ speed - will easily fill available bandwidth + * πŸ”’ safe - easy/secure multi account setup ### build -built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo +built blobs are available on the [release page](https://github.com/pldubouilh/gossa/releases) - or simply `make build` this repo. ### usage ```sh @@ -31,33 +32,16 @@ built blobs are available on the [release page](https://github.com/pldubouilh/go % ./gossa -h 192.168.100.33 ~/storage ``` -### ui shortcuts -|shortcut | action| -| ------------- |-------------| -|click new folder icon | create new folder| -|click pad icon | open file editor| -|click file icon | rename item| -|double click file icon | delete item| -|drag-and-drop item on UI | move item| -|drag-and-drop external item | upload file/folders| - -### keyboard shortcuts -|shortcut | action| -|-------------|-------------| -|Arrows/Enter | browse through files/directories and pictures| -|Ctrl/Meta + C | copy URL to clipboard| -|Ctrl/Meta + E | rename file/folder| -|Ctrl/Meta + Del | delete file/folder| -|Ctrl/Meta + U | upload new file/folder| -|Ctrl/Meta + D | create a new directory| -|Ctrl/Meta + X | cut selected path| -|Ctrl/Meta + V | paste previously selected paths to directory| -|\ | search| - -### using with docker -a few docker/docker-compose files are provided in the [docker folder](https://github.com/pldubouilh/gossa/tree/master/docker). release images are also pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. : +### fancier setups +release images are pushed to [dockerhub](https://hub.docker.com/r/pldubouilh/gossa), e.g. : ```sh # pull from dockerhub and run % sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 pldubouilh/gossa ``` + +in a do-one-thing-well mindset, HTTPS and authentication has been left to middlewares and proxies. for instance [caddy](https://caddyserver.com/) handles this very well - have a look at this small [caddy config](https://github.com/pldubouilh/gossa/blob/master/support/Caddyfile) with authentication and option for HTTPS that works along with gossa. + +### shortcuts +the default UI is fully usable by through keyboard/UI shortcuts - press `Ctrl/Cmd + h` to see them all. + diff --git a/src/gossa.go b/src/gossa.go index db78c8f..48091d2 100755 --- a/src/gossa.go +++ b/src/gossa.go @@ -22,8 +22,8 @@ var host = flag.String("h", "127.0.0.1", "host to listen to") var port = flag.String("p", "8001", "port to listen to") var extraPath = flag.String("prefix", "/", "url prefix at which gossa can be reached, e.g. /gossa/ (slashes of importance)") var symlinks = flag.Bool("symlinks", false, "follow symlinks \033[4mWARNING\033[0m: symlinks will by nature allow to escape the defined path (default: false)") -var verb = flag.Bool("verb", true, "verbosity") -var skipHidden = flag.Bool("k", true, "skip hidden files") +var verb = flag.Bool("verb", false, "verbosity") +var skipHidden = flag.Bool("k", true, "\nskip hidden files") var initPath = "." var fs http.Handler @@ -162,11 +162,11 @@ func rpc(w http.ResponseWriter, r *http.Request) { } func checkPath(p string) string { - p = filepath.Join(initPath, strings.TrimPrefix(p, *extraPath)) - fp, err := filepath.Abs(p) + joined := filepath.Join(initPath, strings.TrimPrefix(p, *extraPath)) + fp, err := filepath.Abs(joined) sl, _ := filepath.EvalSymlinks(fp) - if err != nil || !strings.HasPrefix(fp, initPath) || len(sl) > 0 && !*symlinks && !strings.HasPrefix(sl, initPath) { + if err != nil || !strings.HasPrefix(fp, initPath) || *skipHidden && strings.Contains(p, "/.") || !*symlinks && len(sl) > 0 && !strings.HasPrefix(sl, initPath) { panic(errors.New("invalid path")) } @@ -174,23 +174,25 @@ func checkPath(p string) string { } func main() { + var err error + flag.Usage = func() { + fmt.Printf("\nusage: ./gossa ~/directory-to-share\n\n") + flag.PrintDefaults() + } + flag.Parse() if len(flag.Args()) > 0 { initPath = flag.Args()[0] } - var err error initPath, err = filepath.Abs(initPath) check(err) - hostString := *host + ":" + *port - fmt.Println("Gossa startig on directory " + initPath) - fmt.Println("Listening on http://" + hostString + *extraPath) - http.HandleFunc(*extraPath+"rpc", rpc) http.HandleFunc(*extraPath+"post", upload) http.HandleFunc("/", doContent) fs = http.StripPrefix(*extraPath, http.FileServer(http.Dir(initPath))) - err = http.ListenAndServe(hostString, nil) + fmt.Printf("Gossa startig on directory %s\nListening on http://%s:%s%s\n", initPath, *host, *port, *extraPath) + err = http.ListenAndServe(*host+":"+*port, nil) check(err) } diff --git a/src/gossa_test.go b/src/gossa_test.go index 8847794..f755e97 100644 --- a/src/gossa_test.go +++ b/src/gossa_test.go @@ -55,39 +55,37 @@ func postJSON(t *testing.T, url string, what string) string { } func fetchAndTestDefault(t *testing.T, url string) string { - bodyStr := get(t, url) + body0 := get(t, url) - if !strings.Contains(bodyStr, `/`) { + if !strings.Contains(body0, `/`) { t.Fatal("error title") } - if !strings.Contains(bodyStr, `

./

`) { + if !strings.Contains(body0, `

./

`) { t.Fatal("error header") } - if !strings.Contains(bodyStr, `href="hols">hols/`) { + if !strings.Contains(body0, `href="hols">hols/`) { t.Fatal("error hols folder") } - if !strings.Contains(bodyStr, `href="curimit@gmail.com%20%2840%25%29">curimit@gmail.com (40%)/`) { + if !strings.Contains(body0, `href="curimit@gmail.com%20%2840%25%29">curimit@gmail.com (40%)/`) { t.Fatal("error curimit@gmail.com (40%) folder") } - if !strings.Contains(bodyStr, `href="%E4%B8%AD%E6%96%87">δΈ­ζ–‡/`) { + if !strings.Contains(body0, `href="%E4%B8%AD%E6%96%87">δΈ­ζ–‡/`) { t.Fatal("error δΈ­ζ–‡ folder") } - if !strings.Contains(bodyStr, `href="custom_mime_type.types">custom_mime_type.types`) { + if !strings.Contains(body0, `href="custom_mime_type.types">custom_mime_type.types`) { t.Fatal("error row custom_mime_type") } - return bodyStr + return body0 } -func doTest(t *testing.T, url string, symlinkEnabled bool) { - payload := "" - path := "" - bodyStr := "" +func doTest(t *testing.T, url string, testExtra bool) { + var payload, path, body0, body1, body2 string // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test fetching default path") @@ -100,41 +98,42 @@ func doTest(t *testing.T, url string, symlinkEnabled bool) { // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test fetching regular files") - bodyStr = get(t, url+"subdir_with%20space/file_with%20space.html") - bodyStr2 := get(t, url+"fancy-path/a") - fmt.Println(bodyStr2) - if !strings.Contains(bodyStr, `spacious!!`) || !strings.Contains(bodyStr2, `fancy!`) { + body0 = get(t, url+"subdir_with%20space/file_with%20space.html") + body1 = get(t, url+"fancy-path/a") + if body0 != `spacious!! ` || body1 != `fancy! ` { t.Fatal("fetching a regular file errored") } // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test fetching a invalid file") - bodyStr = get(t, url+"../../../../../../../../../../etc/passwd") - if !strings.Contains(bodyStr, `error`) { + path = "../../../../../../../../../../etc/passwd" + if !testExtra && get(t, url+path) != `error` { t.Fatal("fetching a invalid file didnt errored") + } else if testExtra { + fetchAndTestDefault(t, url+path) // extra path will just redirect to root dir } // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test mkdir rpc") - bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`) - if !strings.Contains(bodyStr, `ok`) { + body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/AAA"]}`) + if body0 != `ok` { t.Fatal("mkdir rpc errored") } - bodyStr = fetchAndTestDefault(t, url) - if !strings.Contains(bodyStr, `href="AAA">AAA/`) { + body0 = fetchAndTestDefault(t, url) + if !strings.Contains(body0, `href="AAA">AAA/`) { t.Fatal("mkdir rpc folder not created") } // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test invalid mkdir rpc") - bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["../BBB"]}`) - if !strings.Contains(bodyStr, `error`) { + body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["../BBB"]}`) + if body0 != `error` { t.Fatal("invalid mkdir rpc didnt errored #0") } - bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/../BBB"]}`) - if !strings.Contains(bodyStr, `error`) { + body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/../BBB"]}`) + if body0 != `error` { t.Fatal("invalid mkdir rpc didnt errored #1") } @@ -142,94 +141,94 @@ func doTest(t *testing.T, url string, symlinkEnabled bool) { fmt.Println("\r\n~~~~~~~~~~ test post file") path = "%2F%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1" // "α„’α…‘ α„’α…‘" encoded payload = "123 α„’α…‘" - bodyStr = postDummyFile(t, url, path, payload) - if !strings.Contains(bodyStr, `ok`) { + body0 = postDummyFile(t, url, path, payload) + body1 = get(t, url+path) + body2 = fetchAndTestDefault(t, url) + if body0 != `ok` || body1 != payload || !strings.Contains(body2, `href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">α„’α…‘ α„’α…‘`) { t.Fatal("post file errored") } - bodyStr = get(t, url+path) - if !strings.Contains(bodyStr, payload) { - t.Fatal("post file errored reaching new file") - } - - bodyStr = fetchAndTestDefault(t, url) - if !strings.Contains(bodyStr, `href="%E1%84%92%E1%85%A1%20%E1%84%92%E1%85%A1">α„’α…‘ α„’α…‘`) { - t.Fatal("post file errored checking new file row") - } - // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test post file incorrect path") - bodyStr = postDummyFile(t, url, "%2E%2E"+path, payload) - if !strings.Contains(bodyStr, `err`) { + body0 = postDummyFile(t, url, "%2E%2E"+path, payload) + if !strings.Contains(body0, `err`) { t.Fatal("post file incorrect path didnt errored") } // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test mv rpc") - bodyStr = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`) - if !strings.Contains(bodyStr, `ok`) { + body0 = postJSON(t, url+"rpc", `{"call":"mv","args":["/AAA", "/hols/AAA"]}`) + body1 = fetchAndTestDefault(t, url) + if body0 != `ok` || strings.Contains(body1, `href="AAA">AAA/ `) { t.Fatal("mv rpc errored") } - bodyStr = fetchAndTestDefault(t, url) - if strings.Contains(bodyStr, `href="AAA">AAA/ `) { - t.Fatal("mv rpc folder not moved") - } - // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test upload in new folder") - payload = "abcdef1234" - bodyStr = postDummyFile(t, url, "%2Fhols%2FAAA%2Fabcdef", payload) - if strings.Contains(bodyStr, `err`) { + payload = "test" + body0 = postDummyFile(t, url, "%2Fhols%2FAAA%2Fabcdef", payload) + body1 = get(t, url+"hols/AAA/abcdef") + if body0 != `ok` || body1 != payload { t.Fatal("upload in new folder errored") } - bodyStr = get(t, url+"hols/AAA/abcdef") - if !strings.Contains(bodyStr, payload) { - t.Fatal("upload in new folder error reaching new file") - } - // ~~~~~~~~~~~~~~~~~ - fmt.Println("\r\n~~~~~~~~~~ test symlink, should succeed: ", symlinkEnabled) - bodyStr = get(t, url+"/docker/readme.md") - hasReadme := strings.Contains(bodyStr, `the master branch is automatically built and pushed`) - if !symlinkEnabled && hasReadme { + fmt.Println("\r\n~~~~~~~~~~ test symlink, should succeed: ", testExtra) + body0 = get(t, url+"/support/readme.md") + hasReadme := strings.Contains(body0, `the master branch is automatically built and pushed`) + if !testExtra && hasReadme { t.Fatal("error symlink reached where illegal") - } else if symlinkEnabled && !hasReadme { + } else if testExtra && !hasReadme { t.Fatal("error symlink unreachable") } - if symlinkEnabled { - fmt.Println("\r\n~~~~~~~~~~ test symlink mkdir") - bodyStr = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/docker/testfolder"]}`) - if !strings.Contains(bodyStr, `ok`) { + if testExtra { + fmt.Println("\r\n~~~~~~~~~~ test symlink mkdir & cleanup") + body0 = postJSON(t, url+"rpc", `{"call":"mkdirp","args":["/support/testfolder"]}`) + if body0 != `ok` { t.Fatal("error symlink mkdir") } + + body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/support/testfolder"]}`) + if body0 != `ok` { + t.Fatal("error symlink rm") + } + } + + fmt.Println("\r\n~~~~~~~~~~ test hidden file, should succeed: ", testExtra) + body0 = get(t, url+"/.testhidden") + hasHidden := strings.Contains(body0, `test`) + if !testExtra && hasHidden { + t.Fatal("error hidden file reached where illegal") + } else if testExtra && !hasHidden { + t.Fatal("error hidden file unreachable") + } + + // + fmt.Println("\r\n~~~~~~~~~~ test upload in new folder") + payload = "test" + body0 = postDummyFile(t, url, "%2Fhols%2FAAA%2Fabcdef", payload) + body1 = get(t, url+"hols/AAA/abcdef") + if body0 != `ok` || body1 != payload { + t.Fatal("upload in new folder errored") } // ~~~~~~~~~~~~~~~~~ fmt.Println("\r\n~~~~~~~~~~ test rm rpc & cleanup") - bodyStr = postJSON(t, url+"rpc", `{"call":"rm","args":["/hols/AAA"]}`) - if !strings.Contains(bodyStr, `ok`) { + body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/hols/AAA"]}`) + if body0 != `ok` { t.Fatal("cleanup errored #0") } - bodyStr = get(t, url+"hols/AAA") - if !strings.Contains(bodyStr, `error`) { + body0 = get(t, url+"hols/AAA") + if !strings.Contains(body0, `error`) { t.Fatal("cleanup errored #1") } - bodyStr = postJSON(t, url+"rpc", `{"call":"rm","args":["/α„’α…‘ α„’α…‘"]}`) - if !strings.Contains(bodyStr, `ok`) { + body0 = postJSON(t, url+"rpc", `{"call":"rm","args":["/α„’α…‘ α„’α…‘"]}`) + if body0 != `ok` { t.Fatal("cleanup errored #2") } - - if symlinkEnabled { - bodyStr = postJSON(t, url+"rpc", `{"call":"rm","args":["/docker/testfolder"]}`) - if !strings.Contains(bodyStr, `ok`) { - t.Fatal("error symlink rm") - } - } } func TestGetFolder(t *testing.T) { diff --git a/support/Caddyfile b/support/Caddyfile new file mode 100644 index 0000000..05f97ee --- /dev/null +++ b/support/Caddyfile @@ -0,0 +1,8 @@ +# Caddy config +# to enable https just set a valid domain (e.g. mydomain.com) instead of :8080 - how simple ! +# authentication has been setup with 2 users, alice and bob + +:8080 +basicauth / alice paul +basicauth / bob dylan +proxy / 127.0.0.1:8001 \ No newline at end of file diff --git a/docker/build.Dockerfile b/support/build.Dockerfile similarity index 100% rename from docker/build.Dockerfile rename to support/build.Dockerfile diff --git a/support/caddy.Dockerfile b/support/caddy.Dockerfile new file mode 100644 index 0000000..6773196 --- /dev/null +++ b/support/caddy.Dockerfile @@ -0,0 +1,8 @@ +FROM pldubouilh/gossa + +RUN apk update && apk add curl ca-certificates caddy + +ENV UID="1000" GID="1000" HOST="127.0.0.1" PORT="8001" PREFIX="/" FOLLOW_SYMLINKS="false" SKIP_HIDDEN_FILES="true" DATADIR="/shared" +EXPOSE 443 +RUN echo -e 'exec su-exec ${UID}:${GID} /gossa -h ${HOST} -p ${PORT} -k=${SKIP_HIDDEN_FILES} --symlinks=${FOLLOW_SYMLINKS} --prefix=${PREFIX} ${DATADIR} & \n caddy' > /start.sh +ENTRYPOINT [ "sh", "/start.sh" ] diff --git a/docker/docker-compose.yml b/support/docker-compose.yml similarity index 100% rename from docker/docker-compose.yml rename to support/docker-compose.yml diff --git a/docker/readme.md b/support/readme.md similarity index 54% rename from docker/readme.md rename to support/readme.md index 3ec07b1..39c141d 100644 --- a/docker/readme.md +++ b/support/readme.md @@ -8,22 +8,20 @@ the master branch is automatically built and pushed to [dockerhub](https://hub.d if you prefer building the image yourself : ```sh -# build gossa within a build container, needs to be ran within the sources, ../ from here -% docker build -t gossa -f docker/build.Dockerfile . - -# and to run it simply +# build gossa within a build container, needs to be ran within the sources, ../ from here, and run +% docker build -t gossa -f support/build.Dockerfile . % sudo docker run -v ~/LocalDirToShare:/shared -p 8001:8001 gossa ``` +the options are settable through environment variables that can be passed starting off the docker image. -a fancy docker image using [Caddy](https://caddyserver.com/) is also provided. a simple config is embedded in the docker file, and shows how to use http basic authentication, and automatic TLS for hands-free https πŸŽ‰ +a fancy docker image using [Caddy](https://caddyserver.com/) is also provided. have a look at the simple config file `Caddyfile`, it shows how to use http basic authentication, and automatic TLS for hands-free https πŸŽ‰ ```sh -# run with caddy, checkout the config in the dockerfile -% docker build -t gossa -f caddy.Dockerfile . - -# run with caddy -% sudo docker run -v ~/LocalDirToShare:/shared --net=host gossa +# checkout the caddy config, build, and run docker image +% vim caddy.Dockerfile +% docker build -t gossa-caddy -f caddy.Dockerfile . +% sudo docker run -v ~/LocalDirToShare:/shared -v `pwd`/Caddyfile:/Caddyfile --net=host gossa-caddy ``` a docker-compose example image is also provided. running docker compose should be straightforward : `docker-compose up .` have a look in `docker-compose.yml` for further configuration. \ No newline at end of file diff --git a/test-fixture/.testhidden b/test-fixture/.testhidden new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/test-fixture/.testhidden @@ -0,0 +1 @@ +test diff --git a/test-fixture/ext/somefile.blank b/test-fixture/ext/somefile.blank new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.code b/test-fixture/ext/somefile.code new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.db b/test-fixture/ext/somefile.db new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.doc b/test-fixture/ext/somefile.doc new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.epub b/test-fixture/ext/somefile.epub new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.gif b/test-fixture/ext/somefile.gif new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.mp3 b/test-fixture/ext/somefile.mp3 new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.mp4 b/test-fixture/ext/somefile.mp4 new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.pdf b/test-fixture/ext/somefile.pdf new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test-fixture/ext/somefile.ppt b/test-fixture/ext/somefile.ppt new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.srt b/test-fixture/ext/somefile.srt new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.xls b/test-fixture/ext/somefile.xls new file mode 100644 index 0000000..e69de29 diff --git a/test-fixture/ext/somefile.zip b/test-fixture/ext/somefile.zip new file mode 100644 index 0000000..e69de29 From 5c9c8983e133bbb4e57f21bcf809369d888f41e3 Mon Sep 17 00:00:00 2001 From: Pierre Dubouilh Date: Sun, 15 Dec 2019 19:00:38 +0100 Subject: [PATCH 2/3] bump ui --- gossa-ui | 2 +- readme.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gossa-ui b/gossa-ui index 1a8e83c..6a14c31 160000 --- a/gossa-ui +++ b/gossa-ui @@ -1 +1 @@ -Subproject commit 1a8e83cc7a82ecdb3595c9dabbbd0374605c990d +Subproject commit 6a14c317ef43828b171f8478feff13bae224b3ac diff --git a/readme.md b/readme.md index 41249f4..28c00aa 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,7 @@ gossa ============= -![e](https://user-images.githubusercontent.com/760637/64541706-a3163080-d322-11e9-85ef-a4d8001fa6a5.gif) +![e](https://user-images.githubusercontent.com/760637/71449335-790a4200-274a-11ea-80be-4c536fbad8a1.gif) [![build status](https://github.com/pldubouilh/gossa/workflows/ci/badge.svg)](https://github.com/pldubouilh/gossa/actions) [![docker build status](https://img.shields.io/docker/cloud/build/pldubouilh/gossa.svg?logo=docker)](https://hub.docker.com/r/pldubouilh/gossa) From e22ef1bc12949a646415789a704f71e39a437832 Mon Sep 17 00:00:00 2001 From: Pierre Dubouilh Date: Wed, 25 Dec 2019 19:27:51 +0100 Subject: [PATCH 3/3] fix test jitter --- .github/workflows/go.yml | 4 ++-- Makefile | 22 ++++++++++++++++------ src/gossa_test.go | 15 +++++---------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c98914c..2cd7110 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -7,10 +7,10 @@ jobs: runs-on: ubuntu-latest steps: - - name: Set up Go 1.12 + - name: Set up Go 1.13 uses: actions/setup-go@v1 with: - go-version: 1.12 + go-version: 1.13 id: go - name: Check out code into the Go module directory diff --git a/Makefile b/Makefile index d18c9c7..666b42b 100755 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ build: make -C gossa-ui/ go vet && go fmt CGO_ENABLED=0 go build gossa.go - rm gossa.go + sleep 1 && rm gossa.go run: make build @@ -13,13 +13,23 @@ run-extra: make build ./gossa -verb=true -prefix="/fancy-path/" -k=false -symlinks=true test-fixture +test: + timeout 60 make run & + sleep 15 && cp src/gossa_test.go . && go test -run TestNormal + rm gossa_test.go + -killall gossa + +test-extra: + timeout 60 make run-extra & + sleep 15 && cp src/gossa_test.go . && go test -run TestExtra + rm gossa_test.go + -killall gossa + ci: -@cd test-fixture && ln -s ../support . - make build - timeout 15 make run & - sleep 16 && timeout 15 make run-extra & - cp src/gossa_test.go . && go test - rm gossa_test.go + make test + make test-extra + watch: ls src/* gossa-ui/* | entr -rc make run diff --git a/src/gossa_test.go b/src/gossa_test.go index f755e97..51ad822 100644 --- a/src/gossa_test.go +++ b/src/gossa_test.go @@ -8,7 +8,6 @@ import ( "regexp" "strings" "testing" - "time" ) func dieMaybe(t *testing.T, err error) { @@ -231,18 +230,14 @@ func doTest(t *testing.T, url string, testExtra bool) { } } -func TestGetFolder(t *testing.T) { - time.Sleep(6 * time.Second) +func TestNormal(t *testing.T) { fmt.Println("========== testing normal path ============") - url := "http://127.0.0.1:8001/" - doTest(t, url, false) - + doTest(t, "http://127.0.0.1:8001/", false) fmt.Printf("\r\n=========\r\n") - time.Sleep(10 * time.Second) +} - url = "http://127.0.0.1:8001/fancy-path/" +func TestExtra(t *testing.T) { fmt.Println("========== testing at fancy path ============") - doTest(t, url, true) - + doTest(t, "http://127.0.0.1:8001/fancy-path/", true) fmt.Printf("\r\n=========\r\n") }