@@ -62,12 +62,13 @@ def test_push_event_queues_to_db(self):
62
62
body = filter_by_fields ('13.14.15.16' , ['ip_dest' ])
63
63
)['hits' ]['hits' ]
64
64
65
- self .assertEqual (len (honeypot_records ), 1 )
66
- self .assertEqual (len (network_records ), 1 )
67
65
# Find the records in the DB
68
66
honeypot_record = honeypot_records [0 ]['_source' ]
69
67
network_record = network_records [0 ]['_source' ]
70
68
69
+ self .assertGreater (len (honeypot_records ), 0 )
70
+ self .assertGreater (len (network_records ), 0 )
71
+
71
72
# Compare the record found in the DB with the one pushed
72
73
self .assertEqual (honeypot_record ["ip_src" ], honeypot_event .ip_src )
73
74
self .assertEqual (honeypot_record ["ip_dest" ], honeypot_event .ip_dest )
@@ -76,13 +77,13 @@ def test_push_event_queues_to_db(self):
76
77
self .assertEqual (network_record ["ip_dest" ], network_event .ip_dest )
77
78
78
79
# Delete test events from the database
79
- connector .elasticsearch_events .delete_by_query (
80
+ connector .elasticsearch_events .delete (
80
81
index = 'honeypot_events' ,
81
- body = filter_by_fields ( '11.22.33.44' , [ 'ip_dest' ])
82
+ id = honeypot_records [ 0 ][ "_id" ]
82
83
)
83
- connector .elasticsearch_events .delete_by_query (
84
+ connector .elasticsearch_events .delete (
84
85
index = 'network_events' ,
85
- body = filter_by_fields ( '13.14.15.16' , [ 'ip_dest' ])
86
+ id = network_records [ 0 ][ "_id" ]
86
87
)
87
88
88
89
def test_insert_to_credential_events (self ):
@@ -106,9 +107,10 @@ def test_insert_to_credential_events(self):
106
107
index = 'credential_events' ,
107
108
body = filter_by_fields ('88.99.11.22' , ['ip_src' ])
108
109
)['hits' ]['hits' ]
109
- self .assertEqual (len (credential_events ), 1 )
110
110
credential_record = credential_events [0 ]['_source' ]
111
111
112
+ self .assertGreater (len (credential_events ), 0 )
113
+
112
114
# Compare the record found in the DB with the one pushed
113
115
self .assertEqual (
114
116
credential_record ["ip_src" ],
@@ -126,9 +128,9 @@ def test_insert_to_credential_events(self):
126
128
)
127
129
128
130
# Delete test events from the database
129
- connector .elasticsearch_events .delete_by_query (
131
+ connector .elasticsearch_events .delete (
130
132
index = 'credential_events' ,
131
- body = filter_by_fields ( '88.99.11.22' , [ 'ip_src' ])
133
+ id = credential_events [ 0 ][ "_id" ]
132
134
)
133
135
134
136
def test_insert_events_data (self ):
@@ -146,23 +148,24 @@ def test_insert_events_data(self):
146
148
# wait for insert
147
149
time .sleep (1 )
148
150
149
- records = connector .elasticsearch_events .search (
151
+ # Find the records in the DB
152
+ event_records = connector .elasticsearch_events .search (
150
153
index = 'data_events' ,
151
154
body = filter_by_fields ('55.66.77.88' , ['ip_src' ])
152
155
)['hits' ]['hits' ]
153
- # Compare number of records present
154
- self .assertEqual (len (records ), 1 )
155
- # Find the record in the DB
156
- event_record_data = records [0 ]['_source' ]
156
+
157
+ self .assertGreater (len (event_records ), 0 )
158
+
159
+ event_record_data = event_records [0 ]['_source' ]
157
160
# Compare the record found in the DB with the one pushed
158
161
self .assertEqual (event_record_data ["ip_src" ], event_data .ip_src )
159
162
self .assertEqual (
160
163
event_record_data ["data" ],
161
164
event_data .data
162
165
)
163
- connector .elasticsearch_events .delete_by_query (
166
+ connector .elasticsearch_events .delete (
164
167
index = 'data_events' ,
165
- body = filter_by_fields ( '55.66.77.88' , [ 'ip_src' ])
168
+ id = event_records [ 0 ][ "_id" ]
166
169
)
167
170
168
171
0 commit comments