Initial commit: DSH Web Manager
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var testAccessTokens sync.Map
|
||||
|
||||
func registerTestAccess(t *testing.T, a *API, sid string) {
|
||||
t.Helper()
|
||||
if a.authErr != nil {
|
||||
t.Fatal(a.authErr)
|
||||
}
|
||||
u, _, err := a.s.SessionUser(sid)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
testAccessTokens.Store(sid, a.accessJWT(sid, u.ID, time.Now().Add(accessLifetime)))
|
||||
t.Cleanup(func() { testAccessTokens.Delete(sid) })
|
||||
}
|
||||
func addTestAccess(r *http.Request, sid string) {
|
||||
if token, ok := testAccessTokens.Load(sid); ok {
|
||||
r.AddCookie(&http.Cookie{Name: "dsh_access", Value: token.(string)})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user