package rules

import (
	"encoding/json"
	"testing"
)

func TestArmaBoolToInterface1(t *testing.T) {
	ar := ArmaBool(true)

	v := ar.ToInterface()

	if v != 1 {
		t.Errorf("Bad interface value, expect 1, got %v", v)
	}
}

func TestArmaBoolToInterface2(t *testing.T) {
	ar := ArmaBool(false)

	v := ar.ToInterface()

	if v != 0 {
		t.Errorf("Bad interface value, expect 0, got %v", v)
	}
}

func TestArmaBoolParseInterface1(t *testing.T) {
	var v interface{}
	var ar ArmaBool

	v = 1
	err := ar.ParseInterface(v)
	if err != nil {
		t.Errorf("Got parse error: %v", err)
	}

	if bool(ar) != true {
		t.Errorf("Got bad parse interface result, expect true, got %v", ar)
	}
}

func TestArmaBoolParseInterface2(t *testing.T) {
	var v interface{}
	var ar ArmaBool

	v = 10
	err := ar.ParseInterface(v)
	if err != nil {
		t.Errorf("Got parse error: %v", err)
	}

	if bool(ar) != true {
		t.Errorf("Got bad parse interface result, expect true, got %v", ar)
	}
}

func TestArmaBoolParseInterface3(t *testing.T) {
	var v interface{}
	var ar ArmaBool

	v = 0
	err := ar.ParseInterface(v)
	if err != nil {
		t.Errorf("Got parse error: %v", err)
	}

	if bool(ar) != false {
		t.Errorf("Got bad parse interface result, expect false, got %v", ar)
	}
}

func TestArmaBoolParseInterface4(t *testing.T) {
	var v interface{}
	var ar ArmaBool

	v = true
	err := ar.ParseInterface(v)
	if err != nil {
		t.Errorf("Got parse error: %v", err)
	}

	if bool(ar) != true {
		t.Errorf("Got bad parse interface result, expect true, got %v", ar)
	}
}

func TestArmaBoolParseInterface5(t *testing.T) {
	var v interface{}
	var ar ArmaBool

	v = false
	err := ar.ParseInterface(v)
	if err != nil {
		t.Errorf("Got parse error: %v", err)
	}

	if bool(ar) != false {
		t.Errorf("Got bad parse interface result, expect false, got %v", ar)
	}
}

func TestArmaBoolParseInterface6(t *testing.T) {
	var v interface{}
	var ar ArmaBool

	v = "true"
	err := ar.ParseInterface(v)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", v)
	}
}

func TestFirewallActionGetType(t *testing.T) {
	var action FirewallAction

	if action.GetType() != FirewallActionType {
		t.Errorf("Bad type, expect %v, got %v", FirewallActionType, action.GetType())
	}
}

func TestFiewallActionToInterface(t *testing.T) {
	m, err := FirewallAction{
		Enabled:         true,
		Action:          "pass",
		Quick:           true,
		Interface:       "lan",
		Description:     "ddd",
		IPProtocol:      "inet",
		Protocol:        "TCP",
		SourceNet:       "any",
		SourceNot:       false,
		SourcePort:      "",
		DestinationNet:  "any",
		DestinationNot:  false,
		DestinationPort: "",
		Log:             true,
		Gateway:         "",
	}.ToInterface()

	if err != nil {
		t.Errorf("Can't create interface: %v", err)
	}

	testMap(m, "type", FirewallActionType, t)
	testMap(m, "enabled", 1, t)
	testMap(m, "action", "pass", t)
	testMap(m, "quick", 1, t)
	testMap(m, "interface", "[lan]", t)
	testMap(m, "description", "ddd", t)
	testMap(m, "ipprotocol", "inet", t)
	testMap(m, "protocol", "TCP", t)
	testMap(m, "source_net", "any", t)
	testMap(m, "source_not", 0, t)
	testMap(m, "source_port", "", t)
	testMap(m, "destination_net", "any", t)
	testMap(m, "destination_port", "", t)
	testMap(m, "destination_not", 0, t)
	testMap(m, "log", 1, t)
	testMap(m, "gateway", "", t)
}

func TestFirewallActionParseInterface1(t *testing.T) {
	var i interface{}
	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface2(t *testing.T) {
	i := make(map[string]interface{})

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface3(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = "ass"

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface4(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface5(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface6(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface7(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = struct{ Name string }{}

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface8(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface9(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface10(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface11(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface12(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = struct{ Name string }{}

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface13(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface14(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0
	i["destination_net"] = ""
	i["destination_not"] = struct{ Name string }{}

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface15(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0
	i["destination_net"] = ""
	i["destination_not"] = 0
	i["direction"] = "ass"

	url := make(map[string]interface{})
	url["ip"] = "127.0.0.1"
	url["key"] = "ass"
	url["scheme"] = "http"
	url["secret"] = "ass"

	i["sensor"] = url

	var action FirewallAction

	err := action.ParseInterface(i)
	if err != nil {
		t.Errorf("Got error, when mustn't \"%v\" interface: %v", err, i)
	}
}

func TestFirewallActionParseInterface16(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0
	i["destination_net"] = ""
	i["destination_not"] = 0
	i["log"] = struct{ Name string }{}

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionParseInterface17(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0
	i["destination_net"] = ""
	i["destination_not"] = 0
	i["log"] = 1
	i["sequence"] = "a"
	i["direction"] = "ass"

	url := make(map[string]interface{})
	url["ip"] = "127.0.0.1"
	url["key"] = "ass"
	url["scheme"] = "http"
	url["secret"] = "ass"

	i["sensor"] = url

	var action FirewallAction

	err := action.ParseInterface(i)
	if err != nil {
		t.Errorf("Got error, when mustn't (%v) interface: %v", err, i)
	}
}

func TestFirewallActionParseInterface18(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0
	i["destination_net"] = ""
	i["destination_not"] = 0
	i["log"] = 1
	i["sequence"] = 12
	i["direction"] = "ass"

	url := make(map[string]interface{})
	url["ip"] = "127.0.0.1"
	url["key"] = "ass"
	url["scheme"] = "http"
	url["secret"] = "ass"

	i["sensor"] = url

	var action FirewallAction

	err := action.ParseInterface(i)
	if err != nil {
		t.Errorf("Got error, when mustn't %v interface: %v", err, i)
	}
}

func TestFirewallActionParseInterface19(t *testing.T) {
	i := make(map[string]interface{})
	i["type"] = FirewallActionType
	i["enabled"] = 1
	i["action"] = "pass"
	i["quick"] = 1
	i["interface"] = "lan"
	i["ipprotocol"] = "inet"
	i["protocol"] = "TCP"
	i["source_net"] = ""
	i["source_not"] = 0
	i["destination_net"] = ""
	i["destination_not"] = 0
	i["log"] = 1
	i["sequence"] = struct{ Name string }{}

	var action FirewallAction

	err := action.ParseInterface(i)
	if err == nil {
		t.Errorf("Can parse bad interface: %v", i)
	}
}

func TestFirewallActionUnmarshal(t *testing.T) {
	s := `{
		"type": "firewall",
		"quick": true,
		"action": "pass",
		"armaif": "2",
		"sensor": {
		  "ip": "192.168.56.104",
		  "key": "3uIhK/pCIKaLhkv9cmYg4V7DQ1Adt4zZLovThtbfaYzqr1YUdG4DdK6lKuqEjq0vfrDac2KczPbm7dwW",
		  "scheme": "http",
		  "secret": "5bYfRxkmDwFFY3WL/AHIooFTVQwHdDYSGT8I/6zvzwiSPAMrc9YNNS1CMRoSerxtUnkXRm2ZTEe4LtWo"
		},
		"enabled": true,
		"gateway": "",
		"protocol": "any",
		"sequence": "5000",
		"direction": "in",
		"interface": "LAN",
		"ipprotocol": "inet",
		"source_net": "any",
		"source_not": true,
		"description": "{{.EventSrcMsg}}",
		"source_port": "",
		"destination_net": "any",
		"destination_not": true,
		"destination_port": ""
	  }`

	var action FirewallAction
	err := json.Unmarshal([]byte(s), &action)
	if err != nil {
		t.Errorf("Can't parse json: %v", err)
	}

	if action.Quick != true {
		t.Errorf("Bad quick value: %v", action.Quick)
	}

	if action.Action != "pass" {
		t.Errorf("Bad action value: %v", action.Action)
	}

	if action.url.ip != "192.168.56.104" {
		t.Errorf("Bad url ip: %v", action.url.ip)
	}

	if action.url.scheme != "http" {
		t.Errorf("Bad url scheme: %v", action.url.scheme)
	}

	if action.url.key != "3uIhK/pCIKaLhkv9cmYg4V7DQ1Adt4zZLovThtbfaYzqr1YUdG4DdK6lKuqEjq0vfrDac2KczPbm7dwW" {
		t.Errorf("Bad url key: %v", action.url.key)
	}

	if action.url.secret != "5bYfRxkmDwFFY3WL/AHIooFTVQwHdDYSGT8I/6zvzwiSPAMrc9YNNS1CMRoSerxtUnkXRm2ZTEe4LtWo" {
		t.Errorf("Bad secret value: %v", action.url.secret)
	}

	if action.Enabled != true {
		t.Errorf("Bad enabled value: %v", action.Enabled)
	}

	if action.Gateway != "" {
		t.Errorf("Bad gateway value: %v", action.Gateway)
	}

	if action.Protocol != "any" {
		t.Errorf("Bad protocol value: %v", action.Protocol)
	}

	if action.Sequence != "5000" {
		t.Errorf("Bad sequence number: %v", action.Sequence)
	}

	if action.Direction != "in" {
		t.Errorf("Bad direction value: %v", action.Direction)
	}

	if action.Interface != "LAN" {
		t.Errorf("Bad interface value: %v", action.Interface)
	}

	if action.IPProtocol != "inet" {
		t.Errorf("Bad ipprotocol value: %v", action.IPProtocol)
	}

	if action.SourceNet != "any" {
		t.Errorf("Bad source net value: %v", action.SourceNet)
	}

	if action.Description != "{{.EventSrcMsg}}" {
		t.Errorf("Bad description value: %v", action.Description)
	}

	if action.SourcePort != "" {
		t.Errorf("Bad source port value: %v", action.SourcePort)
	}

	if action.SourceNot != true {
		t.Errorf("Bad source not value: %v", action.SourceNot)
	}

	if action.DestinationNet != "any" {
		t.Errorf("Bad destination net value: %v", action.DestinationNet)
	}

	if action.DestinationNot != true {
		t.Errorf("Bad destination not value: %v", action.DestinationNot)
	}

	if action.DestinationPort != "" {
		t.Errorf("Bad destination port value: %v", action.DestinationPort)
	}
}

func TestFirewallActionMarshal(t *testing.T) {
	action := FirewallAction{
		Quick:  true,
		Action: "pass",
		url: struct {
			ip     string
			scheme string
			key    string
			secret string
		}{
			ip:     "192.168.56.104",
			scheme: "http",
			key:    "3uIhK/pCIKaLhkv9cmYg4V7DQ1Adt4zZLovThtbfaYzqr1YUdG4DdK6lKuqEjq0vfrDac2KczPbm7dwW",
			secret: "5bYfRxkmDwFFY3WL/AHIooFTVQwHdDYSGT8I/6zvzwiSPAMrc9YNNS1CMRoSerxtUnkXRm2ZTEe4LtWo",
		},
		Enabled:        true,
		Protocol:       "any",
		Sequence:       "5000",
		Direction:      "in",
		Interface:      "LAN",
		IPProtocol:     "inet",
		SourceNet:      "any",
		SourceNot:      true,
		Description:    "{{.EventSrcMsg}}",
		DestinationNet: "any",
		DestinationNot: true,
	}

	data, err := json.Marshal(action)
	if err != nil {
		t.Errorf("Can't marshall: %v", err)
	}

	if string(data) != `{"action":"pass","description":"{{.EventSrcMsg}}","destination_net":"any","destination_not":1,"destination_port":"","direction":"in","enabled":1,"gateway":"","interface":"[LAN]","ipprotocol":"inet","log":0,"protocol":"any","quick":1,"sensor":{"ip":"192.168.56.104","key":"3uIhK/pCIKaLhkv9cmYg4V7DQ1Adt4zZLovThtbfaYzqr1YUdG4DdK6lKuqEjq0vfrDac2KczPbm7dwW","scheme":"http","secret":"5bYfRxkmDwFFY3WL/AHIooFTVQwHdDYSGT8I/6zvzwiSPAMrc9YNNS1CMRoSerxtUnkXRm2ZTEe4LtWo"},"sequence":"5000","source_net":"any","source_not":1,"source_port":"","type":"firewall"}` {
		t.Errorf("Bad result: %v", string(data))
	}
}

func TestFirewallActionParseInterface20(t *testing.T) {
	inputText := `{
		"type":"firewall",
		"quick":true,
		"action":"pass",
		"armaif":"2",
		"sensor":{
			"ip":"192.168.56.104",
			"key":"4J0FSrWI2cknxRQb38xESVnupeJ8q1nuRMriHTJgiwM9653Da9XNRq9nZ9XUZH5TksORFoS8AwW0i/fc",
			"scheme":"http",
			"secret":"nxAZPULMyE731eBHAEcH+XMAdJhfZ3zk8eNuTmNjbE8E58pOnwUFzh8Nho/NU+LQ4uEYBOyjfARP63Qv"
		},
		"gateway":"",
		"protocol":"any",
		"sequence":"5000",
		"direction":"in",
		"interface":"LAN",
		"ipprotocol":"inet",
		"source_net":"any",
		"description":"",
		"source_port":"",
		"destination_net":"any",
		"destination_port":"",
		"enabled": false
	}`

	var input map[string]interface{}
	err := json.Unmarshal([]byte(inputText), &input)
	if err != nil {
		t.Errorf("Can't unmarshall interface: %v", err)
	}

	var action FirewallAction

	err = action.ParseInterface(input)
	if err != nil {
		t.Errorf("Can't parse interface: %v", err)
	}
}

func TestFirewallActionParseInterface21(t *testing.T) {
	inputText := `{
		"log":false,
		"type":"firewall",
		"quick":true,
		"action":"pass",
		"armaif":"2",
		"sensor":{
		   "ip":"192.168.56.104",
		   "key":"4J0FSrWI2cknxRQb38xESVnupeJ8q1nuRMriHTJgiwM9653Da9XNRq9nZ9XUZH5TksORFoS8AwW0i/fc",
		   "scheme":"http",
		   "secret":"nxAZPULMyE731eBHAEcH+XMAdJhfZ3zk8eNuTmNjbE8E58pOnwUFzh8Nho/NU+LQ4uEYBOyjfARP63Qv"
		},
		"enabled":true,
		"gateway":"",
		"protocol":"any",
		"sequence":"1",
		"direction":"in",
		"interface":[
		   "lan"
		],
		"ipprotocol":"inet",
		"source_net":"any",
		"source_not":false,
		"description":"",
		"source_port":"",
		"destination_net":"any",
		"destination_not":false,
		"destination_port":""
	 }`

	var input map[string]interface{}
	err := json.Unmarshal([]byte(inputText), &input)
	if err != nil {
		t.Errorf("Can't unmarshall interface: %v", err)
	}

	var action FirewallAction

	err = action.ParseInterface(input)
	if err != nil {
		t.Errorf("Can't parse interface: %v", err)
	}

	if action.Interface != "lan" {
		t.Errorf("Bad interface value. Expect lan, got %v ", action.Interface)
	}
}

//func TestActionRequest(t *testing.T) {
//
//	testServer := util.NewTestServer(":8080")
//	testServer.AddUrl("/api/firewall/filter/addRule/", []byte("{\"result\":\"saved\"}"), map[string]string{"Content-Type": "application/json"})
//	testServer.AddUrl("/api/firewall/filter/apply/", []byte("{\"status\":\"OK\"}"), map[string]string{"Content-Type": "application/json"})
//
//	go func() {
//		if err := testServer.Start(); err != http.ErrServerClosed {
//			t.Errorf("Can't start test server: %v", err)
//		}
//	}()
//
//	// Prepare action
//	inputText := `{
//		"log":false,
//		"type":"firewall",
//		"quick":true,
//		"action":"pass",
//		"armaif":"2",
//		"sensor":{
//		   "ip":"localhost:8080",
//		   "key":"4J0FSrWI2cknxRQb38xESVnupeJ8q1nuRMriHTJgiwM9653Da9XNRq9nZ9XUZH5TksORFoS8AwW0i/fc",
//		   "scheme":"http",
//		   "secret":"nxAZPULMyE731eBHAEcH+XMAdJhfZ3zk8eNuTmNjbE8E58pOnwUFzh8Nho/NU+LQ4uEYBOyjfARP63Qv"
//		},
//		"enabled":true,
//		"gateway":"",
//		"protocol":"any",
//		"sequence":"1",
//		"direction":"in",
//		"interface":[
//		   "lan"
//		],
//		"ipprotocol":"inet",
//		"source_net":"{{.source_ip}}",
//		"source_not":false,
//		"description":"",
//		"source_port":"{{.source_port}}",
//		"destination_net":"any",
//		"destination_not":false,
//		"destination_port":"{{.destination_port}}"
//	 }`
//
//	var input map[string]interface{}
//	err := json.Unmarshal([]byte(inputText), &input)
//	if err != nil {
//		t.Errorf("Can't unmarshall interface: %v", err)
//	}
//
//	var action FirewallAction
//
//	err = action.ParseInterface(input)
//	if err != nil {
//		t.Errorf("Can't parse interface: %v", err)
//	}
//
//	// Prepare events
//	eventsArray := make([]*events.Event, 1)
//	eventsArray[0] = &events.Event{
//		events.Hash:         "",
//		events.FirstEvent:   fmt.Sprintf("%v", time.Now().UTC()),
//		events.LastEvent:    fmt.Sprintf("%v", time.Now().UTC()),
//		events.EventCount:   5,
//		events.Created:      fmt.Sprintf("%v", time.Now().UTC()),
//		events.Tags:         make([]string, 0),
//		events.AggregatedId: "",
//		events.CeleryDone:   false,
//
//		"event_severity":   5,
//		"source_ip":        "127.0.0.1",
//		"source_port":      443,
//		"destination_ip":   "127.0.0.2",
//		"destination_port": 9090,
//	}
//
//	err = action.Perform(&eventsArray)
//	if err != nil {
//		t.Errorf("Got error in perform: %v", err)
//	}
//
//	err = testServer.Stop()
//	if err != nil {
//		t.Errorf("Can't stop server: %v", err)
//	}
//
//	if testServer.Urls[0].CallCount != 1 {
//		t.Errorf("Bad url call count: %v", testServer.Urls[0].CallCount)
//	}
//
//	if testServer.Urls[0].Error != nil {
//		t.Errorf("Got some error in url: %v", testServer.Urls[0].Error.Error())
//	}
//
//	if testServer.Urls[0].GetRequestAsString() != `{"rule":{"action":"pass","description":"","destination_net":"any","destination_not":0,"destination_port":"9090","direction":"in","enabled":1,"gateway":"","interface":"lan","ipprotocol":"inet","log":0,"protocol":"any","quick":1,"sequence":1,"source_net":"127.0.0.1","source_not":0,"source_port":"443"}}` {
//		t.Errorf("Got bad action request: %v", testServer.Urls[0].GetRequestAsString())
//	}
//}
