Put auth stuff in auth namespace
parent
e1202cec67
commit
a6f5bc3192
|
|
@ -51,7 +51,7 @@ func readRequested(r *http.Request, key string) string {
|
|||
}
|
||||
|
||||
func getKeyForNamespace(ctx context.Context, g storage.RateLimitedGraph, namespace string) (string, error) {
|
||||
namespaceOne, err := g.Get(ctx, namespace, UserKey)
|
||||
namespaceOne, err := g.Get(ctx, toAuthNamespace(namespace), UserKey)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -71,5 +71,5 @@ func makeTokenForNamespace(ctx context.Context, g storage.RateLimitedGraph, name
|
|||
ID: token.ID,
|
||||
Title: obf,
|
||||
}
|
||||
return token, g.Insert(ctx, namespace+"."+AuthKey, one)
|
||||
return token, g.Insert(ctx, toAuthNamespace(namespace), one)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ func TestGenerate(t *testing.T) {
|
|||
ID: UserKey,
|
||||
Title: key,
|
||||
}
|
||||
if err := g.Insert(context.Background(), namespace, one); err != nil {
|
||||
if err := g.Insert(context.Background(), toAuthNamespace(namespace), one); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(UserKey+`=`+namespace))
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package auth
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"local/dndex/storage"
|
||||
"local/dndex/storage/entity"
|
||||
"net/http"
|
||||
|
|
@ -25,10 +26,14 @@ func readRequestedKey(r *http.Request) string {
|
|||
return readRequested(r, AuthKey)
|
||||
}
|
||||
|
||||
func toAuthNamespace(namespace string) string {
|
||||
return fmt.Sprintf("%s.%s", namespace, AuthKey)
|
||||
}
|
||||
|
||||
func makeNamespace(ctx context.Context, g storage.RateLimitedGraph, namespace, key string) error {
|
||||
one := entity.One{
|
||||
ID: UserKey,
|
||||
Title: key,
|
||||
}
|
||||
return g.Insert(ctx, namespace, one)
|
||||
return g.Insert(ctx, toAuthNamespace(namespace), one)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ func TestRegister(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
one, err := g.Get(context.Background(), namespace, UserKey)
|
||||
one, err := g.Get(context.Background(), toAuthNamespace(namespace), UserKey)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func isPublic(token Token, g storage.RateLimitedGraph, r *http.Request) bool {
|
|||
}
|
||||
|
||||
func isPublicNamespace(ctx context.Context, g storage.RateLimitedGraph, namespace string) bool {
|
||||
maybePublicContainer, err := g.Get(ctx, namespace, UserKey)
|
||||
maybePublicContainer, err := g.Get(ctx, toAuthNamespace(namespace), UserKey)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ func isPublicNamespace(ctx context.Context, g storage.RateLimitedGraph, namespac
|
|||
}
|
||||
|
||||
func verifyToken(token Token, g storage.RateLimitedGraph, r *http.Request) error {
|
||||
serverTokenContainer, err := g.Get(r.Context(), token.Namespace+"."+AuthKey, token.ID)
|
||||
serverTokenContainer, err := g.Get(r.Context(), toAuthNamespace(token.Namespace), token.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ func TestVerify(t *testing.T) {
|
|||
ID: token.ID,
|
||||
Title: obf,
|
||||
}
|
||||
if err := g.Insert(context.Background(), token.Namespace+"."+AuthKey, one); err != nil {
|
||||
if err := g.Insert(context.Background(), toAuthNamespace(token.Namespace), one); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return g,
|
||||
|
|
@ -119,7 +119,7 @@ func TestVerify(t *testing.T) {
|
|||
|
||||
t.Run("public not ok", func(t *testing.T) {
|
||||
g, w, r, _, _ := fresh()
|
||||
if err := g.Insert(context.Background(), "public", entity.One{ID: UserKey}); err != nil {
|
||||
if err := g.Insert(context.Background(), toAuthNamespace("public"), entity.One{ID: UserKey}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err := Verify(g, w, r)
|
||||
|
|
@ -130,7 +130,7 @@ func TestVerify(t *testing.T) {
|
|||
|
||||
t.Run("public ok", func(t *testing.T) {
|
||||
g, w, r, token, _ := fresh()
|
||||
if err := g.Insert(context.Background(), token.Namespace, entity.One{ID: UserKey}); err != nil {
|
||||
if err := g.Insert(context.Background(), toAuthNamespace(token.Namespace), entity.One{ID: UserKey}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token.ID = "gibberish-but-public-ns-so-its-ok"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package server
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"local/dndex/server/auth"
|
||||
"local/dndex/storage/entity"
|
||||
"local/dndex/storage/operator"
|
||||
"net/http"
|
||||
|
|
@ -28,15 +27,6 @@ func (rest *REST) dumpOut(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
rest.respError(w, err)
|
||||
}
|
||||
for i := len(entities) - 1; i >= 0; i-- {
|
||||
if entities[i].ID == auth.UserKey {
|
||||
if i < len(entities)-1 {
|
||||
entities = append(entities[:i], entities[i+1:]...)
|
||||
} else {
|
||||
entities = entities[:i]
|
||||
}
|
||||
}
|
||||
}
|
||||
rest.respMap(w, scope.Namespace, entities)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue