package event

import (
	"encoding/json"
	"testing"
)

func TestEvent(t *testing.T) {
	data := []byte("{\n  \"id\": \"1\",\n  \"orgc_id\": \"1\",\n  \"org_id\": \"1\",\n  \"date\": \"2020-04-23\",\n  \"threat_level_id\": \"1\",\n  \"info\": \"Test description\",\n  \"published\": false,\n  \"uuid\": \"5ea1d827-7550-4d0d-9a27-04b2c0a88b90\",\n  \"attribute_count\": \"8\",\n  \"analysis\": \"2\",\n  \"timestamp\": \"1587665502\",\n  \"distribution\": \"1\",\n  \"proposal_email_lock\": false,\n  \"locked\": false,\n  \"publish_timestamp\": \"0\",\n  \"sharing_group_id\": \"0\",\n  \"disable_correlation\": false,\n  \"extends_uuid\": \"\",\n  \"event_creator_email\": \"admin@admin.test\",\n  \"Org\": {\n    \"id\": \"1\",\n    \"name\": \"ORGNAME\",\n    \"uuid\": \"5ea14a5d-6b94-4530-95ee-41f51f3ec496\",\n    \"local\": true\n  },\n  \"Orgc\": {\n    \"id\": \"1\",\n    \"name\": \"ORGNAME\",\n    \"uuid\": \"5ea14a5d-6b94-4530-95ee-41f51f3ec496\",\n    \"local\": true\n  },\n  \"Attribute\": [\n    {\n      \"id\": \"7\",\n      \"type\": \"md5\",\n      \"category\": \"Payload delivery\",\n      \"to_ids\": true,\n      \"uuid\": \"5ea1d9f4-7cfc-4bfa-afc3-0324c0a88b90\",\n      \"event_id\": \"1\",\n      \"distribution\": \"5\",\n      \"timestamp\": \"1587665396\",\n      \"comment\": \"test attribute comment\",\n      \"sharing_group_id\": \"0\",\n      \"deleted\": false,\n      \"disable_correlation\": false,\n      \"object_id\": \"0\",\n      \"object_relation\": null,\n      \"first_seen\": \"2020-02-11T23:00:00.000000+00:00\",\n      \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n      \"value\": \"5d41402abc4b2a76b9719d911017c592\",\n      \"Galaxy\": [],\n      \"ShadowAttribute\": []\n    },\n    {\n      \"id\": \"8\",\n      \"type\": \"filename|sha1\",\n      \"category\": \"Artifacts dropped\",\n      \"to_ids\": true,\n      \"uuid\": \"5ea1da5e-a68c-48b5-89a0-0326c0a88b90\",\n      \"event_id\": \"1\",\n      \"distribution\": \"5\",\n      \"timestamp\": \"1587665502\",\n      \"comment\": \"foo bar hash\",\n      \"sharing_group_id\": \"0\",\n      \"deleted\": false,\n      \"disable_correlation\": false,\n      \"object_id\": \"0\",\n      \"object_relation\": null,\n      \"first_seen\": \"2020-04-13T22:00:00.000000+00:00\",\n      \"last_seen\": \"2020-04-14T22:00:00.000000+00:00\",\n      \"value\": \"foo|62cdb7020ff920e5aa642c3d4066950dd1f01f4d\",\n      \"Galaxy\": [],\n      \"ShadowAttribute\": []\n    }\n  ],\n  \"ShadowAttribute\": [],\n  \"RelatedEvent\": [],\n  \"Galaxy\": [],\n  \"Object\": [\n    {\n      \"id\": \"1\",\n      \"name\": \"dns-record\",\n      \"meta-category\": \"network\",\n      \"description\": \"A set of dns records observed for a specific domain.\",\n      \"template_uuid\": \"f023c8f0-81ab-41f3-9f5d-fa597a34a9b9\",\n      \"template_version\": \"1\",\n      \"event_id\": \"1\",\n      \"uuid\": \"5ea1d95b-3c94-4dce-8c8e-04adc0a88b90\",\n      \"timestamp\": \"1587665243\",\n      \"distribution\": \"5\",\n      \"sharing_group_id\": \"0\",\n      \"comment\": \"Test DNS record object\",\n      \"deleted\": false,\n      \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n      \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n      \"ObjectReference\": [],\n      \"Attribute\": [\n        {\n          \"id\": \"1\",\n          \"type\": \"text\",\n          \"category\": \"Other\",\n          \"to_ids\": false,\n          \"uuid\": \"5ea1d95b-391c-450c-8a96-04adc0a88b90\",\n          \"event_id\": \"1\",\n          \"distribution\": \"5\",\n          \"timestamp\": \"1587665243\",\n          \"comment\": \"\",\n          \"sharing_group_id\": \"0\",\n          \"deleted\": false,\n          \"disable_correlation\": false,\n          \"object_id\": \"1\",\n          \"object_relation\": \"text\",\n          \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"value\": \"A malicious record\",\n          \"Galaxy\": [],\n          \"ShadowAttribute\": []\n        },\n        {\n          \"id\": \"2\",\n          \"type\": \"domain\",\n          \"category\": \"Network activity\",\n          \"to_ids\": true,\n          \"uuid\": \"5ea1d95b-4630-48f6-a610-04adc0a88b90\",\n          \"event_id\": \"1\",\n          \"distribution\": \"5\",\n          \"timestamp\": \"1587665243\",\n          \"comment\": \"test comment\",\n          \"sharing_group_id\": \"0\",\n          \"deleted\": false,\n          \"disable_correlation\": false,\n          \"object_id\": \"1\",\n          \"object_relation\": \"queried-domain\",\n          \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"value\": \"foo-bar.com\",\n          \"Galaxy\": [],\n          \"ShadowAttribute\": []\n        },\n        {\n          \"id\": \"3\",\n          \"type\": \"ip-dst\",\n          \"category\": \"Network activity\",\n          \"to_ids\": true,\n          \"uuid\": \"5ea1d95b-c258-4dae-b8db-04adc0a88b90\",\n          \"event_id\": \"1\",\n          \"distribution\": \"5\",\n          \"timestamp\": \"1587665243\",\n          \"comment\": \"\",\n          \"sharing_group_id\": \"0\",\n          \"deleted\": false,\n          \"disable_correlation\": false,\n          \"object_id\": \"1\",\n          \"object_relation\": \"a-record\",\n          \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"value\": \"127.0.0.1\",\n          \"Galaxy\": [],\n          \"ShadowAttribute\": []\n        },\n        {\n          \"id\": \"4\",\n          \"type\": \"ip-dst\",\n          \"category\": \"Network activity\",\n          \"to_ids\": true,\n          \"uuid\": \"5ea1d95b-cf50-4467-9c29-04adc0a88b90\",\n          \"event_id\": \"1\",\n          \"distribution\": \"5\",\n          \"timestamp\": \"1587665243\",\n          \"comment\": \"\",\n          \"sharing_group_id\": \"0\",\n          \"deleted\": false,\n          \"disable_correlation\": false,\n          \"object_id\": \"1\",\n          \"object_relation\": \"a-record\",\n          \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"value\": \"255.255.255.255\",\n          \"Galaxy\": [],\n          \"ShadowAttribute\": []\n        },\n        {\n          \"id\": \"5\",\n          \"type\": \"domain\",\n          \"category\": \"Network activity\",\n          \"to_ids\": true,\n          \"uuid\": \"5ea1d95b-0a3c-4b97-abac-04adc0a88b90\",\n          \"event_id\": \"1\",\n          \"distribution\": \"5\",\n          \"timestamp\": \"1587665243\",\n          \"comment\": \"comment test 2\",\n          \"sharing_group_id\": \"0\",\n          \"deleted\": false,\n          \"disable_correlation\": false,\n          \"object_id\": \"1\",\n          \"object_relation\": \"mx-record\",\n          \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"value\": \"mx1.foo-bar.com\",\n          \"Galaxy\": [],\n          \"ShadowAttribute\": []\n        },\n        {\n          \"id\": \"6\",\n          \"type\": \"domain\",\n          \"category\": \"Network activity\",\n          \"to_ids\": true,\n          \"uuid\": \"5ea1d95b-6934-49c7-9159-04adc0a88b90\",\n          \"event_id\": \"1\",\n          \"distribution\": \"5\",\n          \"timestamp\": \"1587665243\",\n          \"comment\": \"\",\n          \"sharing_group_id\": \"0\",\n          \"deleted\": false,\n          \"disable_correlation\": false,\n          \"object_id\": \"1\",\n          \"object_relation\": \"ns-record\",\n          \"first_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"last_seen\": \"2020-04-22T22:00:00.000000+00:00\",\n          \"value\": \"ns1.foo-bar.com\",\n          \"Galaxy\": [],\n          \"ShadowAttribute\": []\n        }\n      ]\n    }\n  ]\n}")
	var v Event
	err := json.Unmarshal(data, &v)
	if err != nil {
		t.Error(err)
	}
	d, err := json.Marshal(v)
	if err != nil {
		t.Error(err)
	}
	println(string(d))
}
