This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyzer_test.go
135 lines (120 loc) · 3.33 KB
/
analyzer_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package cortex
import (
"context"
"net/http"
"reflect"
"testing"
)
func TestListAnalyzers(t *testing.T) {
client, mux, _, closer := setup()
defer closer()
mux.HandleFunc("/"+analyzersURL, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(analyzersJSON)
})
got, _, err := client.Analyzers.List(context.Background())
if err != nil {
t.Errorf("Analyzer.List returned error: %v", err)
}
if want := wantList; !reflect.DeepEqual(got, want) {
t.Errorf("Analyzer.List = %+v, want %+v", got, want)
}
}
func TestListByTypeAnalyzers(t *testing.T) {
client, mux, _, closer := setup()
defer closer()
mux.HandleFunc("/"+analyzersByType+analyzerType, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(analyzersJSON)
})
got, _, err := client.Analyzers.ListByType(context.Background(), analyzerType)
if err != nil {
t.Errorf("Analyzer.ListByType returned error: %v", err)
}
if want := wantList; !reflect.DeepEqual(got, want) {
t.Errorf("Analyzer.ListByType = %+v, want %+v", got, want)
}
}
func TestDataTypes(t *testing.T) {
client, mux, _, closer := setup()
defer closer()
mux.HandleFunc("/"+analyzersURL, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write(analyzersJSON)
})
got, err := client.Analyzers.DataTypes(context.Background())
if err != nil {
t.Errorf("Analyzer.DataTypes returned error: %v", err)
}
if want := dataTypes; !reflect.DeepEqual(want, got) {
t.Errorf("Analyzer.DataTypes = %+v, want %+v", got, want)
}
}
var analyzerType = "ip"
var analyzersJSON = []byte(`
[
{
"createdBy": "test1",
"analyzerDefinitionId": "MaxMind_GeoIP_3_0",
"dataTypeList": [
"ip"
],
"createdAt": 1527178197172,
"name": "MaxMind_GeoIP_3_0",
"description": "Use MaxMind to geolocate an IP address.",
"jobCache": null,
"_type": "analyzer",
"_routing": "test",
"_parent": "test",
"_id": "c0b3f12a64d3fa2010ef2df4950d17b4",
"_version": 1,
"id": "c0b3f12a64d3fa2010ef2df4950d17b4",
"version": "3.0",
"author": "CERT-BDF",
"url": "https://github.com/TheHive-Project/Cortex-Analyzers",
"license": "AGPL-V3",
"baseConfig": "MaxMind",
"configuration": {
"proxy_http": null,
"proxy_https": null,
"auto_extract_artifacts": false,
"check_tlp": true,
"check_pap": true,
"max_tlp": 3,
"max_pap": 2
}
}
]
`)
var config = map[string]interface{}{
"proxy_http": nil,
"proxy_https": nil,
"auto_extract_artifacts": false,
"check_tlp": true,
"check_pap": true,
"max_tlp": float64(3),
"max_pap": float64(2),
}
var wantList = []Analyzer{
{
Author: "CERT-BDF",
BaseConfig: "MaxMind",
Configuration: config,
CreatedAt: 1527178197172,
CreatedBy: "test1",
DataTypeList: []string{"ip"},
DefinitionID: "MaxMind_GeoIP_3_0",
Description: "Use MaxMind to geolocate an IP address.",
ID: "c0b3f12a64d3fa2010ef2df4950d17b4",
JobCache: nil,
License: "AGPL-V3",
Name: "MaxMind_GeoIP_3_0",
Rate: 0,
RateUnit: "",
URL: "https://github.com/TheHive-Project/Cortex-Analyzers",
UpdatedAt: 0,
UpdatedBy: "",
Version: "3.0",
},
}
var dataTypes = []string{"ip"}