2016-10-17 14:07:17 +02:00
|
|
|
package host
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2016-10-17 19:21:17 +02:00
|
|
|
"strconv"
|
2016-10-17 14:07:17 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"dev.sum7.eu/sum7/warehost/system"
|
|
|
|
"dev.sum7.eu/sum7/warehost/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIDomain(t *testing.T) {
|
|
|
|
|
|
|
|
assertion, db, router := test.Init(t)
|
|
|
|
defer db.Close()
|
|
|
|
|
|
|
|
//load system Models to database
|
|
|
|
system.SyncModels(db)
|
|
|
|
db.Unscoped().Delete(Profil{})
|
|
|
|
SyncModels(db)
|
|
|
|
|
|
|
|
// Bind API
|
|
|
|
system.BindAPI(db, router, "")
|
|
|
|
BindAPI(db, router, "/host")
|
|
|
|
session := test.NewSession(router)
|
|
|
|
|
|
|
|
loginTest(session, assertion)
|
|
|
|
|
|
|
|
result, w := session.JSONRequest("DELETE", "/host/delete", nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
2016-10-17 14:07:17 +02:00
|
|
|
|
|
|
|
// Need a Profile for Next tests
|
|
|
|
result, w = session.JSONRequest("POST", "/host/signup", nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.Equal(true, result.Data)
|
2016-10-17 14:07:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TEST domainList
|
|
|
|
*/
|
|
|
|
session.Clean()
|
|
|
|
result, w = session.JSONRequest("GET", "/host/domain", nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 14:07:17 +02:00
|
|
|
|
|
|
|
loginTest(session, assertion)
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("GET", "/host/domain", nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.NotEqual(false, result.Data)
|
2016-10-17 14:07:17 +02:00
|
|
|
|
2016-10-18 19:28:57 +02:00
|
|
|
result, w = session.JSONRequest("GET", "/host/domain?filter=all", nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.NotEqual(false, result.Data)
|
2016-10-18 19:28:57 +02:00
|
|
|
|
2016-10-17 14:07:17 +02:00
|
|
|
/*
|
|
|
|
* TEST domainAdd
|
|
|
|
*/
|
2016-10-17 19:21:17 +02:00
|
|
|
session.Clean()
|
|
|
|
result, w = session.JSONRequest("POST", "/host/domain", Domain{
|
|
|
|
FQDN: "example.de",
|
|
|
|
})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
|
|
|
loginTest(session, assertion)
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("POST", "/host/domain", []byte{2, 3})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusBadRequest, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
2016-10-17 14:07:17 +02:00
|
|
|
result, w = session.JSONRequest("POST", "/host/domain", Domain{
|
|
|
|
FQDN: "example.de",
|
|
|
|
})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.NotEqual(false, result.Data)
|
2016-10-17 14:07:17 +02:00
|
|
|
|
2016-10-17 19:21:17 +02:00
|
|
|
result, w = session.JSONRequest("POST", "/host/domain", Domain{
|
|
|
|
FQDN: "example.de",
|
|
|
|
})
|
2016-12-19 12:52:43 +01:00
|
|
|
assertion.Equal(http.StatusInternalServerError, w.StatusCode)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* TEST domainEdit
|
|
|
|
*/
|
|
|
|
result, w = session.JSONRequest("GET", "/host/domain", nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.NotEqual(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
var domain int
|
|
|
|
for _, obj := range result.Data.([]interface{}) {
|
|
|
|
item := obj.(map[string]interface{})
|
|
|
|
if item["fqdn"] == "example.de" {
|
|
|
|
domain = int(item["ID"].(float64))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
session.Clean()
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain), Domain{
|
|
|
|
Mail: true,
|
|
|
|
})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
|
|
|
loginTest(session, assertion)
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain), Domain{
|
|
|
|
Mail: true,
|
|
|
|
})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.Equal(true, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
2016-10-21 21:32:30 +02:00
|
|
|
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(-1), Domain{
|
|
|
|
Mail: true,
|
|
|
|
})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusNotFound, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-21 21:32:30 +02:00
|
|
|
|
2016-10-17 19:21:17 +02:00
|
|
|
result, w = session.JSONRequest("PATCH", "/host/domain/"+strconv.Itoa(domain), []byte{2, 3})
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusBadRequest, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
2016-10-22 21:20:21 +02:00
|
|
|
/*
|
|
|
|
* TEST domainShow
|
|
|
|
*/
|
|
|
|
session.Clean()
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("GET", "/host/domain/"+strconv.Itoa(domain), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-22 21:20:21 +02:00
|
|
|
|
|
|
|
loginTest(session, assertion)
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("GET", "/host/domain/"+strconv.Itoa(-1), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusNotFound, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-22 21:20:21 +02:00
|
|
|
|
|
|
|
result, w = session.JSONRequest("GET", "/host/domain/"+strconv.Itoa(domain), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.NotEqual(false, result.Data)
|
2016-10-22 21:20:21 +02:00
|
|
|
|
2016-10-17 19:21:17 +02:00
|
|
|
/*
|
|
|
|
* TEST domainDelete
|
|
|
|
*/
|
|
|
|
session.Clean()
|
|
|
|
|
|
|
|
result, w = session.JSONRequest("DELETE", "/host/domain/"+strconv.Itoa(domain), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusUnauthorized, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
|
|
|
loginTest(session, assertion)
|
|
|
|
|
2016-10-21 21:32:30 +02:00
|
|
|
result, w = session.JSONRequest("DELETE", "/host/domain/"+strconv.Itoa(-1), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusNotFound, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-21 21:32:30 +02:00
|
|
|
|
2016-10-17 19:21:17 +02:00
|
|
|
result, w = session.JSONRequest("DELETE", "/host/domain/"+strconv.Itoa(domain), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusOK, w.StatusCode)
|
|
|
|
assertion.Equal(true, result.Data)
|
2016-10-17 19:21:17 +02:00
|
|
|
|
|
|
|
result, w = session.JSONRequest("DELETE", "/host/domain/"+strconv.Itoa(domain), nil)
|
2016-12-19 12:24:18 +01:00
|
|
|
assertion.Equal(http.StatusNotFound, w.StatusCode)
|
|
|
|
assertion.Equal(false, result.Data)
|
2016-10-21 21:32:30 +02:00
|
|
|
|
|
|
|
// CLEANUP
|
|
|
|
|
2016-10-17 14:07:17 +02:00
|
|
|
}
|