try another cookie format, ntg submits ntgauthtoken as cookie

This commit is contained in:
Bel LaPointe
2022-01-27 14:01:13 -07:00
parent ba2156133a
commit 2e9e0c5816
9 changed files with 220 additions and 85 deletions

View File

@@ -5,6 +5,7 @@ import (
"local/storage"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"testing"
"time"
@@ -12,24 +13,33 @@ import (
"golang.org/x/time/rate"
)
func TestBrokerInterface(t *testing.T) {
var b Broker
b = NTGVision{}
_ = b
}
func TestDoCookies(t *testing.T) {
limiter = rate.NewLimiter(rate.Limit(20.0), 1)
calls := 0
db := storage.NewMap()
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
calls += 1
if calls == 1 {
http.SetCookie(w, &http.Cookie{
Name: "name",
Value: "value",
Expires: time.Now().Add(time.Hour),
})
} else {
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value") {
if calls != 1 {
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "name=value"+strconv.Itoa(calls-1)) {
w.WriteHeader(http.StatusBadRequest)
t.Error("cookie not set on calls after first")
t.Error("cookie not set as latest")
}
if !strings.Contains(fmt.Sprint(r.Header["Cookie"]), "Expires") {
w.WriteHeader(http.StatusBadRequest)
t.Error("cookie not expiration: ", r.Header["Cookie"])
}
}
http.SetCookie(w, &http.Cookie{
Name: "name",
Value: "value" + strconv.Itoa(calls),
Expires: time.Now().Add(time.Hour),
})
}))
defer s.Close()
req, _ := http.NewRequest(http.MethodGet, s.URL, nil)