impl many integration tests
This commit is contained in:
@@ -61,14 +61,14 @@ func getKeyForNamespace(ctx context.Context, g storage.RateLimitedGraph, namespa
|
||||
func makeTokenForNamespace(ctx context.Context, g storage.RateLimitedGraph, namespace string) (Token, error) {
|
||||
token := Token{
|
||||
Namespace: namespace,
|
||||
Token: uuid.New().String(),
|
||||
ID: uuid.New().String(),
|
||||
}
|
||||
obf, err := token.Obfuscate()
|
||||
if err != nil {
|
||||
return Token{}, err
|
||||
}
|
||||
one := entity.One{
|
||||
ID: token.Token,
|
||||
ID: token.ID,
|
||||
Title: obf,
|
||||
}
|
||||
return token, g.Insert(ctx, namespace+"."+AuthKey, one)
|
||||
|
||||
@@ -7,7 +7,12 @@ import (
|
||||
|
||||
type Token struct {
|
||||
Namespace string
|
||||
Token string
|
||||
ID string
|
||||
}
|
||||
|
||||
func (t Token) String() string {
|
||||
s, _ := t.Obfuscate()
|
||||
return s
|
||||
}
|
||||
|
||||
func (t Token) Obfuscate() (string, error) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func TestTokenEncDec(t *testing.T) {
|
||||
token := Token{
|
||||
Namespace: "username",
|
||||
Token: uuid.New().String(),
|
||||
ID: uuid.New().String(),
|
||||
}
|
||||
key := "a"
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ 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
|
||||
return Token{Namespace: namespaces[0], ID: uuid.New().String()}, true
|
||||
}
|
||||
}
|
||||
cookie, err := r.Cookie(AuthKey)
|
||||
@@ -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.Token)
|
||||
serverTokenContainer, err := g.Get(r.Context(), token.Namespace+"."+AuthKey, token.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ func TestVerify(t *testing.T) {
|
||||
fresh := func() (storage.RateLimitedGraph, *httptest.ResponseRecorder, *http.Request, Token, string) {
|
||||
g := storage.NewRateLimitedGraph()
|
||||
token := Token{
|
||||
Token: uuid.New().String(),
|
||||
ID: uuid.New().String(),
|
||||
Namespace: uuid.New().String(),
|
||||
}
|
||||
obf, _ := token.Obfuscate()
|
||||
one := entity.One{
|
||||
ID: token.Token,
|
||||
ID: token.ID,
|
||||
Title: obf,
|
||||
}
|
||||
if err := g.Insert(context.TODO(), token.Namespace+"."+AuthKey, one); err != nil {
|
||||
@@ -102,7 +102,7 @@ func TestVerify(t *testing.T) {
|
||||
|
||||
t.Run("bad auth", func(t *testing.T) {
|
||||
g, w, r, token, _ := fresh()
|
||||
token.Token = uuid.New().String()
|
||||
token.ID = uuid.New().String()
|
||||
obf, err := token.Obfuscate()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -133,7 +133,7 @@ func TestVerify(t *testing.T) {
|
||||
if err := g.Insert(context.TODO(), token.Namespace, entity.One{ID: UserKey}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
token.Token = "gibberish-but-public-ns-so-its-ok"
|
||||
token.ID = "gibberish-but-public-ns-so-its-ok"
|
||||
obf, _ := token.Obfuscate()
|
||||
r.AddCookie(&http.Cookie{
|
||||
Name: AuthKey,
|
||||
|
||||
@@ -45,7 +45,7 @@ func NewREST(g storage.RateLimitedGraph) (*REST, error) {
|
||||
bar := foo
|
||||
bar = rest.shift(bar)
|
||||
bar = rest.scoped(bar)
|
||||
if !strings.HasPrefix(path, "users/") {
|
||||
if !strings.HasPrefix(path, "users/") && path != "version" {
|
||||
bar = rest.auth(bar)
|
||||
}
|
||||
bar = rest.defend(bar)
|
||||
|
||||
Reference in New Issue
Block a user