Commit 183b635d authored by Nicolas Pernoud's avatar Nicolas Pernoud
Browse files

fix: windows libreoffice compatibility

parent f6a7264a
# Constants
$LOGIN="user"
$PASSWORD="password"
$LOGIN_URL="https://vestibule.127.0.0.1.nip.io:1443/Login"
$FILES_URL= "https://admindav.vestibule.127.0.0.1.nip.io:1443"
# Mount
$body = "{`"login`":`"$LOGIN`",`"password`":`"$PASSWORD`"})"
Invoke-WebRequest -Uri $LOGIN_URL -Body $body -Method POST -SessionVariable websession -UseBasicParsing
$token = $websession.Cookies.GetCookies($LOGIN_URL)["auth_token"].value
$rename = New-Object -ComObject Shell.Application
net use T: $FILES_URL $token /user:$LOGIN /persistent:No
$rename.NameSpace("T:\").Self.Name = 'Test'
......@@ -64,7 +64,7 @@ func ValidateAuthMiddleware(next http.Handler, allowedRoles []string, checkXSRF
checkXSRF, err := tokens.Manager.ExtractAndValidateToken(r, authTokenKey, &user, checkXSRF)
if err != nil {
// Handle WebDav authentication
if strings.Contains(r.UserAgent(), "vfs") || strings.Contains(r.UserAgent(), "Microsoft-WebDAV") || strings.Contains(r.UserAgent(), "Konqueror") {
if isWebdav(r.UserAgent()) {
w.Header().Set("WWW-Authenticate", `Basic realm="server"`)
http.Error(w, "webdav client authentication", 401)
return
......@@ -206,3 +206,13 @@ func GetTokenData(r *http.Request) (TokenData, error) {
}
return user, nil
}
// isWebdav works out if an user agent is a webdav user agent
func isWebdav(ua string) bool {
for _, a := range []string{"vfs", "Microsoft-WebDAV", "Konqueror", "LibreOffice"} {
if strings.Contains(ua, a) {
return true
}
}
return false
}
......@@ -108,3 +108,25 @@ func writeUsers() (name string) {
}
return f.Name()
}
func Test_isWebdav(t *testing.T) {
type args struct {
ua string
}
tests := []struct {
name string
args args
want bool
}{
{"is_exact", args{ua: "Microsoft-WebDAV"}, true},
{"contains", args{ua: "Contains-Microsoft-WebDAV-"}, true},
{"is_not", args{ua: "Microsoft-Other"}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isWebdav(tt.args.ua); got != tt.want {
t.Errorf("isWebdav() = %v, want %v", got, tt.want)
}
})
}
}
......@@ -32,7 +32,7 @@
<div class="navbar-brand">
<div class="navbar-item">
<a class="button is-primary is-rounded is-outlined" href="https://www.github.com/nicolaspernoud/Vestibule" target="_blank" rel="noopener noreferrer">
<span>4.4.0</span>
<span>4.4.1</span>
<span class="icon">
<svg
class="svg-inline--fa fa-github fa-w-16"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment