Mock auth forreal back to query param. go run . is functional, woot
This commit is contained in:
@@ -10,6 +10,9 @@ import (
|
||||
|
||||
func Register(g storage.RateLimitedGraph, r *http.Request) error {
|
||||
namespaceRequested := readRequestedNamespace(r)
|
||||
if namespaceRequested == "" {
|
||||
return errors.New("namespace not found")
|
||||
}
|
||||
keyRequested := readRequestedKey(r)
|
||||
_, err := getKeyForNamespace(r.Context(), g, namespaceRequested)
|
||||
if err == nil {
|
||||
|
||||
@@ -54,3 +54,34 @@ func TestRegister(t *testing.T) {
|
||||
t.Fatal(one)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegisterEmpty(t *testing.T) {
|
||||
g := storage.NewRateLimitedGraph()
|
||||
key := uuid.New().String()
|
||||
r := httptest.NewRequest(
|
||||
http.MethodPost,
|
||||
"/",
|
||||
strings.NewReader(
|
||||
fmt.Sprintf(
|
||||
"%s=&%s=%s",
|
||||
UserKey,
|
||||
AuthKey,
|
||||
key,
|
||||
),
|
||||
),
|
||||
)
|
||||
r.Header.Set("content-type", "application/x-www-form-urlencoded")
|
||||
if err := r.ParseForm(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := readRequested(r, UserKey); v != "" {
|
||||
t.Fatal(UserKey, v)
|
||||
}
|
||||
if v := readRequested(r, AuthKey); v == "" {
|
||||
t.Fatal(AuthKey, v)
|
||||
}
|
||||
err := Register(g, r)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@ import (
|
||||
"local/dndex/storage"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func Verify(g storage.RateLimitedGraph, w http.ResponseWriter, r *http.Request) error {
|
||||
@@ -24,6 +26,12 @@ func Verify(g storage.RateLimitedGraph, w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func getToken(r *http.Request) (Token, bool) {
|
||||
if !config.New().Auth {
|
||||
namespaces, ok := r.URL.Query()["ns"]
|
||||
if ok && len(namespaces) > 0 {
|
||||
return Token{Namespace: namespaces[0], Token: uuid.New().String()}, true
|
||||
}
|
||||
}
|
||||
cookie, err := r.Cookie(AuthKey)
|
||||
if err != nil {
|
||||
return Token{}, false
|
||||
|
||||
Reference in New Issue
Block a user