1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

fix: tests

This commit is contained in:
Ferdinand Mütsch
2022-12-01 11:11:45 +01:00
parent 964405f349
commit d4945c982f
4 changed files with 919 additions and 940 deletions

View File

@ -2,13 +2,23 @@ package helpers
import (
"encoding/json"
"errors"
"github.com/muety/wakapi/config"
"github.com/muety/wakapi/utils"
"github.com/muety/wakapi/models"
"net/http"
)
func ExtractCookieAuth(r *http.Request) (username *string, err error) {
return utils.ExtractCookieAuth(r, config.Get().Security.SecureCookie)
func ExtractCookieAuth(r *http.Request, config *config.Config) (username *string, err error) {
cookie, err := r.Cookie(models.AuthCookieKey)
if err != nil {
return nil, errors.New("missing authentication")
}
if err := config.Security.SecureCookie.Decode(models.AuthCookieKey, cookie.Value, &username); err != nil {
return nil, errors.New("cookie is invalid")
}
return username, nil
}
func RespondJSON(w http.ResponseWriter, r *http.Request, status int, object interface{}) {