diff options
| author | Ahmet Oeztuerk <Ahmet.Oeztuerk@consol.de> | 2025-12-11 10:05:25 +0100 |
|---|---|---|
| committer | Ahmet Oeztuerk <Ahmet.Oeztuerk@consol.de> | 2025-12-11 10:37:05 +0100 |
| commit | 737af667a212f7058143b34770f7f0af70aa8d9b (patch) | |
| tree | 4a98aa5824b58c8f9ef639eb9f429a93732fe0e6 /plugins | |
| parent | feeade08178ed4874207c90b43e411d986d10cb9 (diff) | |
| download | monitoring-plugins-737af667a212f7058143b34770f7f0af70aa8d9b.tar.gz | |
clairfy new check_curl tests
use the parameters in the last redirected URI that that server returns
HTTP OK to. matches the incrementation count of redirection_count from 0
to 3, as they also get incremented three times alongside it. add
comments about what is happening in the test cases, no need to
understand the endpoint completely
Diffstat (limited to 'plugins')
| -rwxr-xr-x | plugins/tests/check_curl.t | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/plugins/tests/check_curl.t b/plugins/tests/check_curl.t index af01c97e..374c74b3 100755 --- a/plugins/tests/check_curl.t +++ b/plugins/tests/check_curl.t | |||
| @@ -224,12 +224,13 @@ sub run_server { | |||
| 224 | #$content .= " before_slash: ${before_slash}\n"; | 224 | #$content .= " before_slash: ${before_slash}\n"; |
| 225 | #$content .= " after_slash: ${after_slash}\n"; | 225 | #$content .= " after_slash: ${after_slash}\n"; |
| 226 | 226 | ||
| 227 | # split the uri part and parameters. uri package cannot do this | 227 | # split the URI part and parameters. URI package cannot do this |
| 228 | # group 1 is captured: anything without a semicolon: ([^;]) | 228 | # group 1 is captured: anything without a semicolon: ([^;]*) |
| 229 | # group 2 is uncaptured: (?:;(.*))? | 229 | # group 2 is uncaptured: (?:;(.*))? |
| 230 | # (? )? prevents the capture | 230 | # (?: ... )? prevents capturing the parameter section |
| 231 | # in between the ';' matches the first ever semicolon | 231 | # inside group 2, ';' matches the first ever semicolon |
| 232 | # group3 is captured: any character string : (.*) | 232 | # group3 is captured: any character string : (.*) |
| 233 | # \? matches an actual ? mark, which starts the query parameters | ||
| 233 | my ($before_params, $params) = $uri =~ m{^([^;]*)(?:;(.*))?\?}; | 234 | my ($before_params, $params) = $uri =~ m{^([^;]*)(?:;(.*))?\?}; |
| 234 | $before_params //= ''; | 235 | $before_params //= ''; |
| 235 | $params //= ''; | 236 | $params //= ''; |
| @@ -639,40 +640,53 @@ sub run_common_tests { | |||
| 639 | is( $result->return_code, 1, $cmd); | 640 | is( $result->return_code, 1, $cmd); |
| 640 | like( $result->output, '/.*HTTP/1.1 403 Forbidden - \d+ bytes in [\d\.]+ second.*/', "Output correct, redirect_count was not present, got redirected to / : ".$result->output ); | 641 | like( $result->output, '/.*HTTP/1.1 403 Forbidden - \d+ bytes in [\d\.]+ second.*/', "Output correct, redirect_count was not present, got redirected to / : ".$result->output ); |
| 641 | 642 | ||
| 643 | # redirect_count=0 is parsed as a parameter and incremented. When it goes up to 3, the redirection returns HTTP OK | ||
| 642 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | 644 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; |
| 643 | $result = NPTest->testCmd( "$cmd" ); | 645 | $result = NPTest->testCmd( "$cmd" ); |
| 644 | is( $result->return_code, 0, $cmd); | 646 | is( $result->return_code, 0, $cmd); |
| 645 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, redirect_count went up to 3: ".$result->output ); | 647 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, redirect_count went up to 3, and returned OK: ".$result->output ); |
| 646 | 648 | ||
| 649 | # location_redirect_count=0 goes up to 3, which uses the HTTP 302 style of redirection with 'Location' header | ||
| 647 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;location_redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | 650 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;location_redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; |
| 648 | $result = NPTest->testCmd( "$cmd" ); | 651 | $result = NPTest->testCmd( "$cmd" ); |
| 649 | is( $result->return_code, 0, $cmd); | 652 | is( $result->return_code, 0, $cmd); |
| 650 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | 653 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); |
| 651 | 654 | ||
| 655 | # fail_count parameter may also go up to 3, which returns a HTTP 403 | ||
| 652 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;fail_count=2' --onredirect=follow -vvv"; | 656 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;fail_count=2' --onredirect=follow -vvv"; |
| 653 | $result = NPTest->testCmd( "$cmd" ); | 657 | $result = NPTest->testCmd( "$cmd" ); |
| 654 | is( $result->return_code, 1, $cmd); | 658 | is( $result->return_code, 1, $cmd); |
| 655 | like( $result->output, '/.*HTTP/1.1 403 Forbidden - \d+ bytes in [\d\.]+ second.*/', "Output correct, early due to fail_count reaching 3: ".$result->output ); | 659 | like( $result->output, '/.*HTTP/1.1 403 Forbidden - \d+ bytes in [\d\.]+ second.*/', "Output correct, early due to fail_count reaching 3: ".$result->output ); |
| 656 | 660 | ||
| 661 | # redirect_count=0, p1=1 , p2=ab => redirect_count=1, p1=2 , p2=bc => redirect_count=2, p1=3 , p2=cd => redirect_count=3 , p1=4 , p2=de | ||
| 662 | # Last visited URI returns HTTP OK instead of redirect, and the one before that contains the new_uri in its content | ||
| 657 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | 663 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; |
| 658 | $result = NPTest->testCmd( "$cmd" ); | 664 | $result = NPTest->testCmd( "$cmd" ); |
| 659 | is( $result->return_code, 0, $cmd); | 665 | is( $result->return_code, 0, $cmd); |
| 660 | like( $result->output, '/.*;p1=3;p2=cd\?*/', "Output correct, parsed and incremented both parameters p1 and p2 : ".$result->output ); | 666 | like( $result->output, '/.*redirect_count=3;p1=4;p2=de\?*/', "Output correct, parsed and incremented both parameters p1 and p2 : ".$result->output ); |
| 667 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 661 | 668 | ||
| 669 | # Same incrementation as before, uses the query parameters that come after the first '?' : qp1 and qp2 | ||
| 662 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | 670 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; |
| 663 | $result = NPTest->testCmd( "$cmd" ); | 671 | $result = NPTest->testCmd( "$cmd" ); |
| 664 | is( $result->return_code, 0, $cmd); | 672 | is( $result->return_code, 0, $cmd); |
| 665 | like( $result->output, '/.*\?qp1=12&qp2=mn*/', "Output correct, parsed and incremented both query parameters qp1 and qp2 : ".$result->output ); | 673 | like( $result->output, '/.*\?qp1=13&qp2=no*/', "Output correct, parsed and incremented both query parameters qp1 and qp2 : ".$result->output ); |
| 674 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 666 | 675 | ||
| 676 | # Check if the query parameter order is kept intact | ||
| 667 | $cmd = "$command -p $port_http -u '/redirect_with_increment;redirect_count=0;?qp0=0&qp1=1&qp2=2&qp3=3&qp4=4&qp5=5' --onredirect=follow -vvv"; | 677 | $cmd = "$command -p $port_http -u '/redirect_with_increment;redirect_count=0;?qp0=0&qp1=1&qp2=2&qp3=3&qp4=4&qp5=5' --onredirect=follow -vvv"; |
| 668 | $result = NPTest->testCmd( "$cmd" ); | 678 | $result = NPTest->testCmd( "$cmd" ); |
| 669 | is( $result->return_code, 0, $cmd); | 679 | is( $result->return_code, 0, $cmd); |
| 670 | like( $result->output, '/.*\?qp0=2&qp1=3&qp2=4&qp3=5&qp4=6&qp5=7*/', "Output correct, parsed and incremented query parameters qp1,qp2,qp3,qp4,qp5 in order : ".$result->output ); | 680 | like( $result->output, '/.*\?qp0=3&qp1=4&qp2=5&qp3=6&qp4=7&qp5=8*/', "Output correct, parsed and incremented query parameters qp1,qp2,qp3,qp4,qp5 in order : ".$result->output ); |
| 681 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 671 | 682 | ||
| 683 | # The fragment is a single item, and it should be kept during redirections as well. | ||
| 684 | # Increase the chars in strings. 'test' => 'uftu' => 'vguv' => 'whvw' | ||
| 672 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; | 685 | $cmd = "$command -p $port_http -u '/redirect_with_increment/path1/path2;redirect_count=0;p1=1;p2=ab?qp1=10&qp2=kl#f1=test' --onredirect=follow -vvv"; |
| 673 | $result = NPTest->testCmd( "$cmd" ); | 686 | $result = NPTest->testCmd( "$cmd" ); |
| 674 | is( $result->return_code, 0, $cmd); | 687 | is( $result->return_code, 0, $cmd); |
| 675 | like( $result->output, '/.*#f1=vguv*/', "Output correct, parsed and incremented fragment f1 : ".$result->output ); | 688 | like( $result->output, '/.*#f1=whvw*/', "Output correct, parsed and incremented fragment f1 : ".$result->output ); |
| 689 | like( $result->output, '/.*HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second.*/', "Output correct, location_redirect_count went up to 3: ".$result->output ); | ||
| 676 | 690 | ||
| 677 | # These tests may block | 691 | # These tests may block |
| 678 | # stickyport - on full urlS port is set back to 80 otherwise | 692 | # stickyport - on full urlS port is set back to 80 otherwise |
