From cb050c2c92892f138e79d328c1c5753a7e682927 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Sat, 3 Dec 2016 10:31:15 +0200 Subject: [PATCH] Modified returned JSON structure --- api.go | 8 ++++---- api_test.go | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/api.go b/api.go index 1b6d07c..7ed5b3b 100644 --- a/api.go +++ b/api.go @@ -58,17 +58,17 @@ func (a authMiddleware) Serve(ctx *iris.Context) { func webRegisterPost(ctx *iris.Context) { var regJSON iris.Map var regStatus int - cslice := cidrslice{} - _ = ctx.ReadJSON(&cslice) + aTXT := ACMETxt{} + _ = ctx.ReadJSON(&aTXT) // Create new user - nu, err := DB.Register(cslice) + nu, err := DB.Register(aTXT.AllowFrom) if err != nil { errstr := fmt.Sprintf("%v", err) regJSON = iris.Map{"error": errstr} regStatus = iris.StatusInternalServerError log.WithFields(log.Fields{"error": err.Error()}).Debug("Error in registration") } else { - regJSON = iris.Map{"username": nu.Username, "password": nu.Password, "fulldomain": nu.Subdomain + "." + DNSConf.General.Domain, "subdomain": nu.Subdomain, "allowfrom": nu.AllowFrom.JSON()} + regJSON = iris.Map{"username": nu.Username, "password": nu.Password, "fulldomain": nu.Subdomain + "." + DNSConf.General.Domain, "subdomain": nu.Subdomain, "allowfrom": nu.AllowFrom.ValidEntries()} regStatus = iris.StatusCreated log.WithFields(log.Fields{"user": nu.Username.String()}).Debug("Created new user") diff --git a/api_test.go b/api_test.go index 454edf5..0e7bf88 100644 --- a/api_test.go +++ b/api_test.go @@ -50,10 +50,10 @@ func TestApiRegister(t *testing.T) { ContainsKey("password"). NotContainsKey("error") - allowfrom := []interface{}{ - "123.123.123.123/32", - "1010.10.10.10/24", - "invalid", + allowfrom := map[string][]interface{}{ + "allowfrom": []interface{}{"123.123.123.123/32", + "1010.10.10.10/24", + "invalid"}, } response := e.POST("/register"). @@ -68,8 +68,7 @@ func TestApiRegister(t *testing.T) { ContainsKey("allowfrom"). NotContainsKey("error") - response.Value("allowfrom").String().Equal("[\"123.123.123.123/32\"]") - + response.Value("allowfrom").Array().Elements("123.123.123.123/32") } func TestApiRegisterWithMockDB(t *testing.T) {