Skip to content

Commit 6dbff84

Browse files
committed
add tests
1 parent 6d165a8 commit 6dbff84

File tree

2 files changed

+390
-0
lines changed

2 files changed

+390
-0
lines changed

modules/ingest-geoip/src/yamlRestTest/resources/rest-api-spec/test/ingest_geoip/20_geoip_processor.yml

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,198 @@
345345
}
346346
- length: { docs: 1 }
347347
- match: { docs.0.doc._source.source.geo.city_name: "Linköping" }
348+
349+
---
350+
"Test geoip processor with flexible field access mode":
351+
- skip:
352+
features: [ "flexible_field_access_pattern" ]
353+
reason: "Flexible field access pattern support required"
354+
- do:
355+
ingest.put_pipeline:
356+
id: "my_pipeline_flexible"
357+
body: >
358+
{
359+
"description": "Test flexible field access mode with dotted target field",
360+
"field_access_pattern": "flexible",
361+
"processors": [
362+
{
363+
"geoip" : {
364+
"field" : "ip",
365+
"target_field" : "geo.location_data"
366+
}
367+
}
368+
]
369+
}
370+
- match: { acknowledged: true }
371+
- do:
372+
index:
373+
index: test
374+
id: "1"
375+
pipeline: "my_pipeline_flexible"
376+
body: {ip: "89.160.20.128"}
377+
- do:
378+
get:
379+
index: test
380+
id: "1"
381+
- match: { _source.ip: "89.160.20.128" }
382+
# In flexible mode, fields are written as dotted keys, not nested objects
383+
- match: { _source.geo\.location_data\.city_name: "Linköping" }
384+
- match: { _source.geo\.location_data\.country_iso_code: "SE" }
385+
- match: { _source.geo\.location_data\.country_name: "Sweden" }
386+
- match: { _source.geo\.location_data\.continent_name: "Europe" }
387+
- match: { _source.geo\.location_data\.region_iso_code: "SE-E" }
388+
- match: { _source.geo\.location_data\.region_name: "Östergötland County" }
389+
# Location should remain as a composite object (geopoint)
390+
- match: { _source.geo\.location_data\.location.lon: 15.6167 }
391+
- match: { _source.geo\.location_data\.location.lat: 58.4167 }
392+
# Verify that nested object was NOT created
393+
- is_false: _source.geo
394+
---
395+
"Test geoip processor flexible mode with ASN database":
396+
- skip:
397+
features: [ "flexible_field_access_pattern" ]
398+
399+
reason: "Flexible field access pattern support required"
400+
- do:
401+
ingest.put_pipeline:
402+
id: "my_pipeline_flexible_asn"
403+
body: >
404+
{
405+
"description": "Test flexible mode with ASN database",
406+
"field_access_pattern": "flexible",
407+
"processors": [
408+
{
409+
"geoip" : {
410+
"field" : "source_ip",
411+
"target_field" : "network.asn_info",
412+
"database_file" : "GeoLite2-ASN.mmdb"
413+
}
414+
}
415+
]
416+
}
417+
- match: { acknowledged: true }
418+
- do:
419+
index:
420+
index: test
421+
id: "1"
422+
pipeline: "my_pipeline_flexible_asn"
423+
body: {source_ip: "89.160.20.128"}
424+
- do:
425+
get:
426+
index: test
427+
id: "1"
428+
- match: { _source.source_ip: "89.160.20.128" }
429+
# In flexible mode, ASN fields are written as dotted keys
430+
- match: { _source.network\.asn_info\.ip: "89.160.20.128" }
431+
- match: { _source.network\.asn_info\.asn: 29518 }
432+
- match: { _source.network\.asn_info\.organization_name: "Bredband2 AB" }
433+
- match: { _source.network\.asn_info\.network: "89.160.0.0/17" }
434+
# Verify that nested object was NOT created
435+
- is_false: _source.network
436+
---
437+
"Test geoip processor flexible mode with first_only":
438+
- skip:
439+
440+
features: [ "flexible_field_access_pattern" ]
441+
reason: "Flexible field access pattern support required"
442+
- do:
443+
ingest.put_pipeline:
444+
id: "my_pipeline_flexible_first"
445+
body: >
446+
{
447+
"description": "Test flexible mode with array and first_only",
448+
"field_access_pattern": "flexible",
449+
"processors": [
450+
{
451+
"geoip" : {
452+
"field" : "ips",
453+
"target_field" : "geo.data",
454+
"first_only" : true
455+
}
456+
}
457+
]
458+
}
459+
- match: { acknowledged: true }
460+
- do:
461+
index:
462+
index: test
463+
id: "1"
464+
pipeline: "my_pipeline_flexible_first"
465+
body: {ips: ["127.0.0.1", "89.160.20.128"]}
466+
- do:
467+
get:
468+
index: test
469+
id: "1"
470+
- match: { _source.ips.0: "127.0.0.1" }
471+
- match: { _source.ips.1: "89.160.20.128" }
472+
# Only the first valid IP should be processed
473+
- match: { _source.geo\.data\.city_name: "Linköping" }
474+
- match: { _source.geo\.data\.country_iso_code: "SE" }
475+
- match: { _source.geo\.data\.location.lon: 15.6167 }
476+
- match: { _source.geo\.data\.location.lat: 58.4167 }
477+
---
478+
"Test geoip processor classic mode vs flexible mode comparison":
479+
- skip:
480+
481+
features: [ "flexible_field_access_pattern" ]
482+
reason: "Flexible field access pattern support required"
483+
- do:
484+
ingest.put_pipeline:
485+
id: "classic_pipeline"
486+
body: >
487+
{
488+
"description": "Classic mode creates nested objects",
489+
"processors": [
490+
{
491+
"geoip" : {
492+
"field" : "ip",
493+
"target_field" : "geo.info"
494+
}
495+
}
496+
]
497+
}
498+
- match: { acknowledged: true }
499+
- do:
500+
ingest.put_pipeline:
501+
id: "flexible_pipeline"
502+
body: >
503+
{
504+
"description": "Flexible mode creates dotted fields",
505+
"field_access_pattern": "flexible",
506+
"processors": [
507+
{
508+
"geoip" : {
509+
"field" : "ip",
510+
"target_field" : "geo.info"
511+
}
512+
}
513+
]
514+
}
515+
- match: { acknowledged: true }
516+
- do:
517+
index:
518+
index: test
519+
id: "classic"
520+
pipeline: "classic_pipeline"
521+
body: {ip: "89.160.20.128"}
522+
- do:
523+
index:
524+
index: test
525+
id: "flexible"
526+
pipeline: "flexible_pipeline"
527+
body: {ip: "89.160.20.128"}
528+
- do:
529+
get:
530+
index: test
531+
id: "classic"
532+
# Classic mode creates nested objects
533+
- match: { _source.geo.info.city_name: "Linköping" }
534+
- match: { _source.geo.info.location.lon: 15.6167 }
535+
- do:
536+
get:
537+
index: test
538+
id: "flexible"
539+
# Flexible mode creates dotted fields
540+
- match: { _source.geo\.info\.city_name: "Linköping" }
541+
- match: { _source.geo\.info\.location.lon: 15.6167 }
542+
- is_false: _source.geo

modules/ingest-geoip/src/yamlRestTest/resources/rest-api-spec/test/ingest_geoip/50_ip_lookup_processor.yml

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,198 @@
7474
- match: { _source.ip_location.asn: 57344 }
7575
- match: { _source.ip_location.ip: "5.104.168.0" }
7676
- match: { _source.ip_location.network: "5.104.168.0/23" }
77+
78+
---
79+
"Test ip_location processor with flexible field access mode":
80+
- skip:
81+
features: [ "flexible_field_access_pattern" ]
82+
reason: "Flexible field access pattern support required"
83+
- do:
84+
ingest.put_pipeline:
85+
id: "my_pipeline_flexible"
86+
body: >
87+
{
88+
"description": "Test flexible field access mode with dotted target field",
89+
"field_access_pattern": "flexible",
90+
"processors": [
91+
{
92+
"ip_location" : {
93+
"field" : "ip",
94+
"target_field" : "geo.location_data"
95+
}
96+
}
97+
]
98+
}
99+
- match: { acknowledged: true }
100+
- do:
101+
index:
102+
index: test
103+
id: "1"
104+
pipeline: "my_pipeline_flexible"
105+
body: {ip: "89.160.20.128"}
106+
- do:
107+
get:
108+
index: test
109+
id: "1"
110+
- match: { _source.ip: "89.160.20.128" }
111+
# In flexible mode, fields are written as dotted keys, not nested objects
112+
- match: { _source.geo\.location_data\.city_name: "Linköping" }
113+
- match: { _source.geo\.location_data\.country_iso_code: "SE" }
114+
- match: { _source.geo\.location_data\.country_name: "Sweden" }
115+
- match: { _source.geo\.location_data\.continent_name: "Europe" }
116+
- match: { _source.geo\.location_data\.region_iso_code: "SE-E" }
117+
- match: { _source.geo\.location_data\.region_name: "Östergötland County" }
118+
# Location should remain as a composite object (geopoint)
119+
- match: { _source.geo\.location_data\.location.lon: 15.6167 }
120+
- match: { _source.geo\.location_data\.location.lat: 58.4167 }
121+
# Verify that nested object was NOT created
122+
- is_false: _source.geo
123+
---
124+
"Test ip_location processor flexible mode with ASN database":
125+
- skip:
126+
features: [ "flexible_field_access_pattern" ]
127+
128+
reason: "Flexible field access pattern support required"
129+
- do:
130+
ingest.put_pipeline:
131+
id: "my_pipeline_flexible_asn"
132+
body: >
133+
{
134+
"description": "Test flexible mode with ASN database",
135+
"field_access_pattern": "flexible",
136+
"processors": [
137+
{
138+
"ip_location" : {
139+
"field" : "source_ip",
140+
"target_field" : "network.asn_info",
141+
"database_file" : "asn.mmdb"
142+
}
143+
}
144+
]
145+
}
146+
- match: { acknowledged: true }
147+
- do:
148+
index:
149+
index: test
150+
id: "1"
151+
pipeline: "my_pipeline_flexible_asn"
152+
body: {source_ip: "5.104.168.0"}
153+
- do:
154+
get:
155+
index: test
156+
id: "1"
157+
- match: { _source.source_ip: "5.104.168.0" }
158+
# In flexible mode, ASN fields are written as dotted keys
159+
- match: { _source.network\.asn_info\.ip: "5.104.168.0" }
160+
- match: { _source.network\.asn_info\.asn: 57344 }
161+
- match: { _source.network\.asn_info\.organization_name: "Telehouse EAD" }
162+
- match: { _source.network\.asn_info\.network: "5.104.168.0/23" }
163+
# Verify that nested object was NOT created
164+
- is_false: _source.network
165+
---
166+
"Test ip_location processor flexible mode with first_only":
167+
- skip:
168+
169+
features: [ "flexible_field_access_pattern" ]
170+
reason: "Flexible field access pattern support required"
171+
- do:
172+
ingest.put_pipeline:
173+
id: "my_pipeline_flexible_first"
174+
body: >
175+
{
176+
"description": "Test flexible mode with array and first_only",
177+
"field_access_pattern": "flexible",
178+
"processors": [
179+
{
180+
"ip_location" : {
181+
"field" : "ips",
182+
"target_field" : "geo.data",
183+
"first_only" : true
184+
}
185+
}
186+
]
187+
}
188+
- match: { acknowledged: true }
189+
- do:
190+
index:
191+
index: test
192+
id: "1"
193+
pipeline: "my_pipeline_flexible_first"
194+
body: {ips: ["127.0.0.1", "89.160.20.128"]}
195+
- do:
196+
get:
197+
index: test
198+
id: "1"
199+
- match: { _source.ips.0: "127.0.0.1" }
200+
- match: { _source.ips.1: "89.160.20.128" }
201+
# Only the first valid IP should be processed
202+
- match: { _source.geo\.data\.city_name: "Linköping" }
203+
- match: { _source.geo\.data\.country_iso_code: "SE" }
204+
- match: { _source.geo\.data\.location.lon: 15.6167 }
205+
- match: { _source.geo\.data\.location.lat: 58.4167 }
206+
---
207+
"Test ip_location processor classic mode vs flexible mode comparison":
208+
- skip:
209+
210+
features: [ "flexible_field_access_pattern" ]
211+
reason: "Flexible field access pattern support required"
212+
- do:
213+
ingest.put_pipeline:
214+
id: "classic_pipeline"
215+
body: >
216+
{
217+
"description": "Classic mode creates nested objects",
218+
"processors": [
219+
{
220+
"ip_location" : {
221+
"field" : "ip",
222+
"target_field" : "geo.info"
223+
}
224+
}
225+
]
226+
}
227+
- match: { acknowledged: true }
228+
- do:
229+
ingest.put_pipeline:
230+
id: "flexible_pipeline"
231+
body: >
232+
{
233+
"description": "Flexible mode creates dotted fields",
234+
"field_access_pattern": "flexible",
235+
"processors": [
236+
{
237+
"ip_location" : {
238+
"field" : "ip",
239+
"target_field" : "geo.info"
240+
}
241+
}
242+
]
243+
}
244+
- match: { acknowledged: true }
245+
- do:
246+
index:
247+
index: test
248+
id: "classic"
249+
pipeline: "classic_pipeline"
250+
body: {ip: "89.160.20.128"}
251+
- do:
252+
index:
253+
index: test
254+
id: "flexible"
255+
pipeline: "flexible_pipeline"
256+
body: {ip: "89.160.20.128"}
257+
- do:
258+
get:
259+
index: test
260+
id: "classic"
261+
# Classic mode creates nested objects
262+
- match: { _source.geo.info.city_name: "Linköping" }
263+
- match: { _source.geo.info.location.lon: 15.6167 }
264+
- do:
265+
get:
266+
index: test
267+
id: "flexible"
268+
# Flexible mode creates dotted fields
269+
- match: { _source.geo\.info\.city_name: "Linköping" }
270+
- match: { _source.geo\.info\.location.lon: 15.6167 }
271+
- is_false: _source.geo

0 commit comments

Comments
 (0)