Error messages updated. While Haha! is awesome, it is not very descriptive.

This commit is contained in:
Storm Dragon
2026-07-07 16:54:28 -04:00
parent 4e210db57a
commit e31bffd256
4 changed files with 31 additions and 6 deletions
@@ -2,7 +2,7 @@
# shellcheck shell=bash disable=SC2034,SC2154
pkgname=skald-git
pkgver=0.0.0.r1547.g506c053
pkgver=0.0.0.r1551.g4e210db
pkgrel=1
pkgdesc='Audio-only hall-based conferencing server'
arch=('x86_64' 'aarch64')
+4 -2
View File
@@ -25,7 +25,8 @@ func checkAdmin(w http.ResponseWriter, r *http.Request) bool {
ok, _ = adminMatch(username, password)
}
if !ok {
failAuthentication(w, "/skald-api/")
failAuthentication(w, "/skald-api/",
"Authentication required. Provide valid administrator credentials.")
return false
}
return true
@@ -71,7 +72,8 @@ func checkPasswordAdmin(w http.ResponseWriter, r *http.Request, hallname, user s
}
}
}
failAuthentication(w, "/skald-api/")
failAuthentication(w, "/skald-api/",
"Authentication required. Provide valid administrator credentials.")
return false
}
+4 -3
View File
@@ -505,10 +505,10 @@ func adminMatch(username, password string) (bool, error) {
return false, nil
}
func failAuthentication(w http.ResponseWriter, realm string) {
func failAuthentication(w http.ResponseWriter, realm string, message string) {
w.Header().Set("www-authenticate",
fmt.Sprintf("basic realm=\"%v\"", realm))
http.Error(w, "Haha!", http.StatusUnauthorized)
http.Error(w, message, http.StatusUnauthorized)
}
func CheckOrigin(w http.ResponseWriter, r *http.Request, admin bool) bool {
@@ -654,7 +654,8 @@ func recordingsHandler(w http.ResponseWriter, r *http.Request) {
ok := checkHallPermissions(w, r, hall)
if !ok {
failAuthentication(w, "recordings/"+hall)
failAuthentication(w, "recordings/"+hall,
"Authentication required to access recordings. Provide valid credentials with recording permission.")
return
}
+22
View File
@@ -4,8 +4,10 @@ import (
"crypto/tls"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"github.com/pion/webrtc/v4"
@@ -37,6 +39,26 @@ func TestParseHallName(t *testing.T) {
}
}
func TestRecordingsAuthenticationFailureMessage(t *testing.T) {
w := httptest.NewRecorder()
failAuthentication(w, "recordings/cavi",
"Authentication required to access recordings. Provide valid credentials with recording permission.")
resp := w.Result()
if resp.StatusCode != http.StatusUnauthorized {
t.Fatalf("status = %d, expected %d",
resp.StatusCode, http.StatusUnauthorized)
}
if got := resp.Header.Get("www-authenticate"); got != `basic realm="recordings/cavi"` {
t.Fatalf("www-authenticate = %q", got)
}
if body := w.Body.String(); !strings.Contains(body,
"Authentication required to access recordings. Provide valid credentials with recording permission.") {
t.Fatalf("body = %q", body)
}
}
func TestBase(t *testing.T) {
a := []struct {
p string