mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-08 07:10:56 +03:00
version: only git commit and build date must be modifiable
Improved some test cases too
This commit is contained in:
11
README.md
11
README.md
@@ -45,10 +45,17 @@ Version info can be embedded populating the following variables at build time:
|
|||||||
- `github.com/drakkan/sftpgo/utils.commit`
|
- `github.com/drakkan/sftpgo/utils.commit`
|
||||||
- `github.com/drakkan/sftpgo/utils.date`
|
- `github.com/drakkan/sftpgo/utils.date`
|
||||||
|
|
||||||
For example on Linux you can build using the following ldflags:
|
For example you can build using the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
-ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --tags --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date --utc +%FT%TZ`"
|
go build -i -ldflags "-s -w -X github.com/drakkan/sftpgo/utils.commit=`git describe --tags --always --dirty` -X github.com/drakkan/sftpgo/utils.date=`date --utc +%FT%TZ`" -o sftpgo
|
||||||
|
```
|
||||||
|
|
||||||
|
and you will get a version that includes git commit and build date like this one:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./sftpgo -v
|
||||||
|
SFTPGo version: 0.9.0-dev-90607d4-dirty-2019-08-08T19:28:36Z
|
||||||
```
|
```
|
||||||
|
|
||||||
A systemd sample [service](https://github.com/drakkan/sftpgo/tree/master/init/sftpgo.service "systemd service") can be found inside the source tree.
|
A systemd sample [service](https://github.com/drakkan/sftpgo/tree/master/init/sftpgo.service "systemd service") can be found inside the source tree.
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/drakkan/sftpgo/dataprovider"
|
"github.com/drakkan/sftpgo/dataprovider"
|
||||||
|
"github.com/go-chi/chi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -211,3 +214,15 @@ func TestApiCallToNotListeningServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
SetBaseURL(oldBaseURL)
|
SetBaseURL(oldBaseURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCloseSFTPConnectionHandler(t *testing.T) {
|
||||||
|
req, _ := http.NewRequest(http.MethodDelete, activeConnectionsPath+"/connectionID", nil)
|
||||||
|
rctx := chi.NewRouteContext()
|
||||||
|
rctx.URLParams.Add("connectionID", "")
|
||||||
|
req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
handleCloseSFTPConnection(rr, req)
|
||||||
|
if rr.Code != http.StatusBadRequest {
|
||||||
|
t.Errorf("Expected response code 400. Got %d", rr.Code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,16 +40,7 @@ func initializeRouter() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.Delete(activeConnectionsPath+"/{connectionID}", func(w http.ResponseWriter, r *http.Request) {
|
router.Delete(activeConnectionsPath+"/{connectionID}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
connectionID := chi.URLParam(r, "connectionID")
|
handleCloseSFTPConnection(w, r)
|
||||||
if connectionID == "" {
|
|
||||||
sendAPIResponse(w, r, nil, "connectionID is mandatory", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if sftpd.CloseActiveConnection(connectionID) {
|
|
||||||
sendAPIResponse(w, r, nil, "Connection closed", http.StatusOK)
|
|
||||||
} else {
|
|
||||||
sendAPIResponse(w, r, nil, "Not Found", http.StatusNotFound)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.Get(quotaScanPath, func(w http.ResponseWriter, r *http.Request) {
|
router.Get(quotaScanPath, func(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -80,3 +71,16 @@ func initializeRouter() {
|
|||||||
deleteUser(w, r)
|
deleteUser(w, r)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func handleCloseSFTPConnection(w http.ResponseWriter, r *http.Request) {
|
||||||
|
connectionID := chi.URLParam(r, "connectionID")
|
||||||
|
if connectionID == "" {
|
||||||
|
sendAPIResponse(w, r, nil, "connectionID is mandatory", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sftpd.CloseActiveConnection(connectionID) {
|
||||||
|
sendAPIResponse(w, r, nil, "Connection closed", http.StatusOK)
|
||||||
|
} else {
|
||||||
|
sendAPIResponse(w, r, nil, "Not Found", http.StatusNotFound)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -310,6 +310,10 @@ func TestSymlink(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error creating symlink: %v", err)
|
t.Errorf("error creating symlink: %v", err)
|
||||||
}
|
}
|
||||||
|
err = client.Symlink(testFileName, testFileName+".link")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("creating a symlink to an existing one must fail")
|
||||||
|
}
|
||||||
err = client.Remove(testFileName + ".link")
|
err = client.Remove(testFileName + ".link")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error removing symlink: %v", err)
|
t.Errorf("error removing symlink: %v", err)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
const version = "0.9.0-dev"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "0.9.0-dev"
|
|
||||||
commit = ""
|
commit = ""
|
||||||
date = ""
|
date = ""
|
||||||
versionInfo VersionInfo
|
versionInfo VersionInfo
|
||||||
|
|||||||
Reference in New Issue
Block a user