Implement global tokens.
This commit is contained in:
+10
-9
@@ -155,11 +155,10 @@ func apiHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func apiGroupHandler(w http.ResponseWriter, r *http.Request, pth string) {
|
||||
first, kind, rest := splitPath(pth)
|
||||
if first == "" {
|
||||
notFound(w)
|
||||
return
|
||||
g := ""
|
||||
if first != "" {
|
||||
g = first[1:]
|
||||
}
|
||||
g := first[1:]
|
||||
if g == "" && kind == "" {
|
||||
if apiCORS(w, r, "HEAD, GET") {
|
||||
return
|
||||
@@ -537,11 +536,13 @@ func tokensHandler(w http.ResponseWriter, r *http.Request, g, pth string) {
|
||||
return
|
||||
}
|
||||
|
||||
// check that the group exists
|
||||
_, err := group.GetDescription(g)
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
return
|
||||
if g != "" {
|
||||
// check that the group exists
|
||||
_, err := group.GetDescription(g)
|
||||
if err != nil {
|
||||
httpError(w, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if pth == "/" {
|
||||
if r.Method == "HEAD" || r.Method == "GET" {
|
||||
|
||||
@@ -312,6 +312,12 @@ func TestApi(t *testing.T) {
|
||||
t.Errorf("Create token: %v %v", err, resp.StatusCode)
|
||||
}
|
||||
|
||||
resp, err = do("POST", "/galene-api/v0/.groups/.tokens/",
|
||||
"application/json", "", "", "{\"includeSubgroups\": true}")
|
||||
if err != nil || resp.StatusCode != http.StatusCreated {
|
||||
t.Errorf("Create global token: %v %v", err, resp.StatusCode)
|
||||
}
|
||||
|
||||
var toknames []string
|
||||
err = getJSON("/galene-api/v0/.groups/test/.tokens/", &toknames)
|
||||
if err != nil || len(toknames) != 1 {
|
||||
@@ -319,6 +325,12 @@ func TestApi(t *testing.T) {
|
||||
}
|
||||
tokname := toknames[0]
|
||||
|
||||
var globalToknames []string
|
||||
err = getJSON("/galene-api/v0/.groups/test/.tokens/", &globalToknames)
|
||||
if err != nil || len(globalToknames) != 1 {
|
||||
t.Errorf("Get global tokens: %v %v", err, globalToknames)
|
||||
}
|
||||
|
||||
tokens, etag, err := token.List("test")
|
||||
if err != nil || len(tokens) != 1 || tokens[0].Token != tokname {
|
||||
t.Errorf("token.List: %v %v", tokens, err)
|
||||
|
||||
Reference in New Issue
Block a user