/
ipv6.t
569 lines (493 loc) · 22.7 KB
/
ipv6.t
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
#!/usr/bin/perl
use strict;
use warnings;
use RT::IR::Test tests => 772;
RT::Test->started_ok;
my $agent = default_agent();
use_ok('RT::IR');
my %valid = (
'abcd:' x 7 . 'abcd' => 'abcd:' x 7 . 'abcd',
'034:' x 7 . '034' => '0034:' x 7 . '0034',
'abcd::' => 'abcd:' . '0000:' x 6 . '0000',
'::abcd' => '0000:' x 7 . 'abcd',
'abcd::034' => 'abcd:' . '0000:' x 6 . '0034',
'abcd::192.168.1.1' => 'abcd:' . '0000:' x 5 . 'c0a8:0101',
'::192.168.1.1' => '0000:' x 6 . 'c0a8:0101',
);
my %test_set = (
'abcd:' x 7 . 'abcd' => 'abcd:' x 7 . 'abcd',
'abcd::034' => 'abcd:' . '0000:' x 6 . '0034',
'::192.168.1.1' => '0000:' x 6 . 'c0a8:0101',
);
my %test_cidr = (
'abcd:' x 7 . 'abcd/32' => 'abcd:abcd'. ':0000' x 6 .'-'. 'abcd:abcd'. ':ffff' x 6,
'::192.168.1.1/120' => '0000:' x 6 . 'c0a8:0100' .'-'. '0000:' x 6 . 'c0a8:01ff',
);
my %shorten = (
'abcd:' x 7 . 'abcd' => 'abcd:' x 7 . 'abcd',
'034:' x 7 . '034' => '34:' x 7 . '34',
'abcd::' => 'abcd::',
'::abcd' => '::abcd',
'abcd::034' => 'abcd::34',
'abcd::192.168.1.1' => 'abcd::c0a8:101',
'::192.168.1.1' => '::c0a8:101',
'abcd:' x 7 . 'abcd/32' => 'abcd:abcd::-abcd:abcd'. ':ffff' x 6,
'::192.168.1.1/120' => '::c0a8:100-::c0a8:1ff',
'abcd::034' => 'abcd::34',
);
my $cf;
diag "load and check basic properties of the IP CF" if $ENV{'TEST_VERBOSE'};
{
my $cfs = RT::CustomFields->new( $RT::SystemUser );
$cfs->Limit( FIELD => 'Name', VALUE => 'IP' );
is( $cfs->Count, 1, "found one CF with name 'IP'" );
$cf = $cfs->First;
is( $cf->Type, 'Freeform', 'type check' );
is( $cf->LookupType, 'RT::Queue-RT::Ticket', 'lookup type check' );
ok( !$cf->MaxValues, "unlimited number of values" );
ok( !$cf->Disabled, "not disabled" );
}
diag "check that CF applies to all RTIR's queues" if $ENV{'TEST_VERBOSE'};
{
foreach ( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
my $queue = RT::Queue->new( $RT::SystemUser );
$queue->Load( $_ );
ok( $queue->id, 'loaded queue '. $_ );
my $cfs = $queue->TicketCustomFields;
$cfs->Limit( FIELD => 'id', VALUE => $cf->id, ENTRYAGGREGATOR => 'AND' );
is( $cfs->Count, 1, 'field applies to queue' );
}
}
my $rtir_user = RT::CurrentUser->new( rtir_user() );
diag "create a ticket via web and set IP" if $ENV{'TEST_VERBOSE'};
while ( my ($short, $full) = each %valid ) {
my $incident_id; # block couldn't be created without incident id
foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
my $id = $agent->create_rtir_ticket_ok(
$queue,
{
Subject => "test ip",
( $queue eq 'Blocks' ? ( Incident => $incident_id ) : () ),
},
{ IP => $short },
);
$incident_id = $id if $queue eq 'Incidents';
$agent->display_ticket( $id);
$agent->content_like( qr/\Q$shorten{$short}/, "IP on the page" );
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
is( $ticket->FirstCustomFieldValue('IP'), $shorten{$short}, 'correct value' );
}
}
diag "create a ticket via web with IP in message" if $ENV{'TEST_VERBOSE'};
while ( my ($short, $full) = each %test_set ) {
my $incident_id; # block couldn't be created without incident id
foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
my $id = $agent->create_rtir_ticket_ok(
$queue,
{
Subject => "test ip in message",
($queue eq 'Blocks'? (Incident => $incident_id): ()),
Content => "$short",
},
);
$incident_id = $id if $queue eq 'Incidents';
$agent->display_ticket( $id );
$agent->content_like( qr/\Q$shorten{$short}/, "IP on the page" );
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
is( $ticket->FirstCustomFieldValue('IP'), $shorten{$short}, 'correct value' );
}
}
diag "create a ticket via web with CIDR" if $ENV{'TEST_VERBOSE'};
while ( my ($short, $full) = each %test_cidr ) {
my $incident_id; # block couldn't be created without incident id
foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
my $id = $agent->create_rtir_ticket_ok(
$queue,
{
Subject => "test ip",
($queue eq 'Blocks'? (Incident => $incident_id): ()),
},
{ IP => $short },
);
$incident_id = $id if $queue eq 'Incidents';
$agent->display_ticket( $id);
$agent->content_like( qr/\Q$shorten{$short}/, "IP range on the page" );
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
my $values = $ticket->CustomFieldValues('IP');
my %has = map { $_->Content => 1 } @{ $values->ItemsArrayRef };
ok( $has{ $shorten{$short} }, "has value" )
or diag "but has values ". join ", ", keys %has;
}
}
diag "create a ticket via web with CIDR in message" if $ENV{'TEST_VERBOSE'};
while ( my ($short, $full) = each %test_cidr ) {
my $incident_id; # block couldn't be created without incident id
foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
my $id = $agent->create_rtir_ticket_ok(
$queue,
{
Subject => "test ip in message",
($queue eq 'Blocks'? (Incident => $incident_id): ()),
Content => "$short",
},
);
$incident_id = $id if $queue eq 'Incidents';
$agent->display_ticket( $id);
$agent->content_like( qr/\Q$shorten{$short}/, "IP range on the page" );
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
my $values = $ticket->CustomFieldValues('IP');
my %has = map { $_->Content => 1 } @{ $values->ItemsArrayRef };
ok( $has{ $shorten{$short} }, "has value" )
or diag "but has values ". join ", ", keys %has;
}
}
diag "create a ticket and edit IP field using Edit page" if $ENV{'TEST_VERBOSE'};
{
my $i = 0;
my $incident_id; # block couldn't be created without incident id
foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Blocks' ) {
diag "create a ticket in the '$queue' queue" if $ENV{'TEST_VERBOSE'};
my $id = $agent->create_rtir_ticket_ok(
$queue,
{
Subject => "test ip in message",
($queue eq 'Blocks'? (Incident => $incident_id): ()),
},
);
$incident_id = $id if $queue eq 'Incidents';
$agent->display_ticket( $id);
my $field_name = "Object-RT::Ticket-$id-CustomField-". $cf->id ."-Values";
diag "set IP" if $ENV{'TEST_VERBOSE'};
my $val = 'abcd::192.168.1.1';
$agent->follow_link_ok({text => 'Edit', n => "1"}, "Followed 'Edit' link");
$agent->form_number(3);
like( $agent->value($field_name), qr/^\s*$/, 'IP is empty' );
$agent->field( $field_name => $val );
$agent->click('SaveChanges');
$agent->content_like( qr/\Q$shorten{$val}/, "IP on the page" );
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
my $values = $ticket->CustomFieldValues('IP');
my %has = map { $_->Content => 1 } @{ $values->ItemsArrayRef };
is( scalar values %has, 1, "one IP were added");
ok( $has{ $shorten{ $val } }, "has value" )
or diag "but has values ". join ", ", keys %has;
diag "set IP with spaces around" if $ENV{'TEST_VERBOSE'};
$val = " ::192.168.1.1 \n ";
$agent->follow_link_ok({text => 'Edit', n => "1"}, "Followed 'Edit' link");
$agent->form_number(3);
like( $agent->value($field_name), qr/^\s*\Q$shorten{'abcd::192.168.1.1'}\E\s*$/, 'IP is in input box' );
$agent->field( $field_name => $val );
$agent->click('SaveChanges');
$agent->content_like( qr/\Q$shorten{'::192.168.1.1'}/, "IP on the page" );
$ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
$values = $ticket->CustomFieldValues('IP');
%has = map { $_->Content => 1 } @{ $values->ItemsArrayRef };
is( scalar values %has, 1, "one IP were added");
ok( $has{ $shorten{'::192.168.1.1'} }, "has value" )
or diag "but has values ". join ", ", keys %has;
diag "replace IP with a range" if $ENV{'TEST_VERBOSE'};
$val = '::192.168.1.1/120';
$agent->follow_link_ok({text => 'Edit', n => "1"}, "Followed 'Edit' link");
$agent->form_number(3);
like( $agent->value($field_name), qr/^\s*\Q$shorten{'::192.168.1.1'}\E\s*$/, 'old IP is in input box' );
$agent->field( $field_name => $val );
$agent->click('SaveChanges');
$agent->content_like( qr/\Q$shorten{ $val }/, "IP on the page" );
$ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
$values = $ticket->CustomFieldValues('IP');
%has = map { $_->Content => 1 } @{ $values->ItemsArrayRef };
is( scalar values %has, 1, "one IP were added");
ok( $has{ $shorten{ $val } }, "has value" )
or diag "but has values ". join ", ", keys %has;
}
}
#diag "check that we parse correct IPs only" if $ENV{'TEST_VERBOSE'};
# XXX: waiting for regressions
diag "check that IPs in messages don't add duplicates" if $ENV{'TEST_VERBOSE'};
{
my $id = $agent->create_ir( {
Subject => "test ip",
Content => 'abcd::192.168.1.1 abcd::192.168.1.1 abcd::192.168.1.1/128'
} );
ok($id, "created first ticket");
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $id );
ok( $ticket->id, 'loaded ticket' );
my $values = $ticket->CustomFieldValues('IP');
my %has;
$has{ $_->Content }++ foreach @{ $values->ItemsArrayRef };
is(scalar values %has, 1, "one IP were added");
ok(!grep( $_ != 1, values %has ), "no duplicated values")
or diag "duplicates: ". join ',', grep $has{$_}>1, keys %has;
ok($has{ $shorten{ 'abcd::192.168.1.1' } }, "IP is there")
or diag "but has values ". join ", ", keys %has;
}
diag "search tickets by IP" if $ENV{'TEST_VERBOSE'};
{
my $id = $agent->create_ir( {
Subject => "test ip",
Content => '::192.168.1.1/120',
} );
ok($id, "created first ticket");
my $tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("id = $id AND CF.{IP} = '::192.168.1.1'");
ok( $tickets->Count, "found tickets" );
my $flag = 1;
while ( my $ticket = $tickets->Next ) {
my %has = map { $_->Content => 1 } @{ $ticket->CustomFieldValues('IP')->ItemsArrayRef };
next if $has{ $shorten{'::192.168.1.1/120'} };
$flag = 0;
ok(0, "ticket #". $ticket->id ." has no range ::192.168.1.1/120, but should")
or diag "but has values ". join ", ", keys %has;
last;
}
ok(1, "all tickets has IP ::192.168.1.1/120") if $flag;
}
diag "search tickets by IP range" if $ENV{'TEST_VERBOSE'};
{
my $id = $agent->create_ir( {
Subject => "test ip",
Content => '::c0a8:01a0'
} );
ok($id, "created first ticket");
my $tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("id = $id AND CF.{IP} = '::c0a8:0101-::c0a8:01ff'");
ok( $tickets->Count, "found tickets" );
my $flag = 1;
while ( my $ticket = $tickets->Next ) {
my %has = map { $_->Content => 1 } @{ $ticket->CustomFieldValues('IP')->ItemsArrayRef };
next if grep /^::c0a8:1/, keys %has;
$flag = 0;
ok(0, "ticket #". $ticket->id ." has no IP from '::c0a8::-::c0a8:01ff', but should");
last;
}
ok(1, "all tickets have at least one IP from the range") if $flag;
}
diag "create two tickets with different IPs and check several searches" if $ENV{'TEST_VERBOSE'};
{
my $id1 = $agent->create_ir( { Subject => "test ip" }, { IP => '::c0a8:3310' } );
ok($id1, "created first ticket");
my $id2 = $agent->create_ir( { Subject => "test ip" }, { IP => '::c0a8:aa10' } );
ok($id2, "created second ticket");
my $tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("id = $id1 OR id = $id2");
is( $tickets->Count, 2, "found both tickets by 'id = x OR y'" );
# IP
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:3310'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:aa10'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# IP/32 - one address
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:3310/128'");
is( $tickets->Count, 1, "found one ticket" ) or diag $tickets->BuildSelectQuery;
is( $tickets->First->id, $id1, "correct value" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:aa10/128'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# IP range
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:3300-::c0a8:33ff'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:aa00-::c0a8:aaff'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# IP range, with start IP greater than end
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:33ff-::c0a8:3300'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:aaff-::c0a8:aa00'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# CIDR/120
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:3300/120'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:aa00/120'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# IP is not in CIDR/120
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} != '::c0a8:3300/120'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} != '::c0a8:aa00/120'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
# CIDR or CIDR
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND "
."(CF.{IP} = '::c0a8:3300/120' OR CF.{IP} = '::c0a8:aa00/120')");
is( $tickets->Count, 2, "found both tickets" );
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::c0a8:0000/0'");
is( $tickets->Count, 2, "found both tickets" ) or diag $tickets->BuildSelectQuery;
}
diag "create two tickets with different IP ranges and check several searches" if $ENV{'TEST_VERBOSE'};
{
my $id1 = $agent->create_ir( { Subject => "test ip" }, { IP => '::192.168.21.0-::192.168.21.127' } );
ok($id1, "created first ticket");
my $id2 = $agent->create_ir( { Subject => "test ip" }, { IP => '::192.168.21.128-::192.168.21.255' } );
ok($id2, "created second ticket");
my $tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("id = $id1 OR id = $id2");
is( $tickets->Count, 2, "found both tickets by 'id = x OR y'" );
# IP
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.0'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.64'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.127'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.128'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.191'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.255'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# IP/32 - one address
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.63/128'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.191/128'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id2, "correct value" );
# IP range, lower than both
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.20.0-::192.168.20.255'");
is( $tickets->Count, 0, "didn't finnd ticket" ) or diag "but found ". $tickets->First->id;
# IP range, intersect with the first range
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.20.0-::192.168.21.63'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
# IP range, equal to the first range
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.0-::192.168.21.127'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
# IP range, lay inside the first range
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.31-::192.168.21.63'");
is( $tickets->Count, 1, "found one ticket" );
is( $tickets->First->id, $id1, "correct value" );
# IP range, intersect with the ranges
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.31-::192.168.21.191'");
is( $tickets->Count, 2, "found both tickets" );
# IP range, equal to range from the starting IP of the first ticket to the ending IP of the second
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.21.0-::192.168.21.255'");
is( $tickets->Count, 2, "found both tickets" );
# IP range, has the both ranges inside it
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.0.0/112'");
is( $tickets->Count, 2, "found both tickets" );
# IP range, greater than both
$tickets = RT::Tickets->new( $rtir_user );
$tickets->FromSQL("(id = $id1 OR id = $id2) AND CF.{IP} = '::192.168.22.0/120'");
is( $tickets->Count, 0, "didn't finnd ticket" ) or diag "but found ". $tickets->First->id;
}
diag "merge ticket, IPs should be merged";
{
my $incident_id = $agent->create_rtir_ticket_ok(
'Incidents',
{ Subject => "test" },
);
my $b1_id = $agent->create_block(
{
Subject => "test ip",
Incident => $incident_id,
},
{ IP => '::172.16.0.1' },
);
my $b2_id = $agent->create_block(
{
Subject => "test ip",
Incident => $incident_id,
},
{ IP => '::172.16.0.2' },
);
$agent->display_ticket( $b1_id);
$agent->follow_link_ok({ text => 'Merge' }, "Followed merge link");
$agent->form_number(3);
$agent->field('SelectedTicket', $b2_id);
$agent->submit;
$agent->ok_and_content_like( qr{Merge Successful}, 'Merge Successful');
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $b1_id );
ok $ticket->id, 'loaded ticket';
my $values = $ticket->CustomFieldValues('IP');
my %has = map { $_->Content => 1 } @{ $values->ItemsArrayRef };
is( scalar values %has, 2, "both IPs are there");
ok( $has{ '::ac10:1' }, "has value" )
or diag "but has values ". join ", ", keys %has;
ok( $has{ '::ac10:2' }, "has value" )
or diag "but has values ". join ", ", keys %has;
}
diag "merge ticket with the same IP";
{
my $incident_id = $agent->create_rtir_ticket_ok(
'Incidents',
{ Subject => "test" },
);
my $b1_id = $agent->create_block(
{
Subject => "test ip",
Incident => $incident_id,
},
{ IP => '::172.16.0.1' },
);
my $b2_id = $agent->create_block(
{
Subject => "test ip",
Incident => $incident_id,
},
{ IP => '::172.16.0.1' },
);
$agent->display_ticket( $b1_id);
$agent->follow_link_ok({ text => 'Merge' }, "Followed merge link");
$agent->form_number(3);
$agent->field('SelectedTicket', $b2_id);
$agent->submit;
$agent->ok_and_content_like( qr{Merge Successful}, 'Merge Successful');
my $ticket = RT::Ticket->new( $RT::SystemUser );
$ticket->Load( $b1_id );
ok $ticket->id, 'loaded ticket';
my $values = $ticket->CustomFieldValues('IP');
my @has = map $_->Content, @{ $values->ItemsArrayRef };
is( scalar @has, 1, "only one IP") or diag "values: @has";
is( $has[0], '::ac10:1', "has value" );
}