mirror of
https://github.com/joohoi/acme-dns.git
synced 2025-07-04 15:27:27 +07:00
Modified returned JSON structure
This commit is contained in:
8
api.go
8
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")
|
||||
|
11
api_test.go
11
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) {
|
||||
|
Reference in New Issue
Block a user