From aef00ab24d126df4a2536f291427e000363ac52a Mon Sep 17 00:00:00 2001 From: Rudis Muiznieks Date: Tue, 21 Jul 2020 09:01:50 -0500 Subject: [PATCH] added test for deleting plans --- server.pl | 2 +- test/run.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server.pl b/server.pl index 876b3ba..935bfd8 100644 --- a/server.pl +++ b/server.pl @@ -359,7 +359,7 @@ EOF my $token = $body->{'auth'}; if (!defined $user->{'token'} || !defined $user->{'token_expires'} || !defined $token || $token ne $user->{'token'} || $user->{'token_expires'} < time) { print_response($cgi, 401, $not_authorized); - } elsif (length($plan) > $maximum_plan_length) { + } elsif (defined $plan && length($plan) > $maximum_plan_length) { print_json_response($cgi, 400, {error => "Plan exceeds maximum length of $maximum_plan_length."}); } elsif (defined $signature && length($signature) > $maximum_signature_length) { print_json_response($cgi, 400, {error => "Signature exceeds maximum length of $maximum_signature_length."}); diff --git a/test/run.sh b/test/run.sh index 26f2b22..de0fd52 100755 --- a/test/run.sh +++ b/test/run.sh @@ -214,6 +214,14 @@ curl_test 'Get updated plan text' 200 'text/plain' localhost:$PORT/plan/$TEST_US && assert_equal 'text content' "$TEST_CONTENT" 'some&thing else' +curl_test 'Delete a plan' 200 'application/json' -XPUT -d "{\"auth\":\"$token\"}" localhost:$PORT/plan/$TEST_USER \ + && assert_equal_jq '.success' 1 + +curl_test 'Verify deleted plan' 404 '' localhost:$PORT/plan/$TEST_USER + +curl_test 'Create another plan for future tests' 200 'application/json' -XPUT -d "{\"plan\":\"for future tests\",\"auth\":\"$token\"}" localhost:$PORT/plan/$TEST_USER \ + && assert_equal_jq '.success' 1 + curl_test 'Check missing plan in json using accept' 404 'application/json' -H 'Accept: application/json' localhost:$PORT/plan/testuser@exampl3.com curl_test 'Check missing plan in json using querystring' 404 'application/json' localhost:$PORT/plan/testuser@exampl3.com?format=json