|
| 1 | +#! /usr/bin/env bats |
| 2 | + |
| 3 | +load '/bats-support/load.bash' |
| 4 | +load '/bats-assert/load.bash' |
| 5 | +load '/getssl/test/test_helper.bash' |
| 6 | + |
| 7 | + |
| 8 | +# This is run for every test |
| 9 | +setup() { |
| 10 | + [ ! -f $BATS_RUN_TMPDIR/failed.skip ] || skip "skipping tests after first failure" |
| 11 | + |
| 12 | + . /getssl/getssl --source |
| 13 | + export API=2 |
| 14 | + _USE_DEBUG=1 |
| 15 | +} |
| 16 | + |
| 17 | + |
| 18 | +teardown() { |
| 19 | + [ -n "$BATS_TEST_COMPLETED" ] || touch $BATS_RUN_TMPDIR/failed.skip |
| 20 | +} |
| 21 | + |
| 22 | +# First sample text where we don't want check_output_for_errors to find an error |
| 23 | +output1=( |
| 24 | +'send_signed_request:533 code 200' |
| 25 | +'send_signed_request:533 response status = invalid' |
| 26 | +'check_challenge_completion:1472 *.ubuntu-acmedns-getssl.freeddns.org:Verify error: "detail": "DNS problem: server failure at resolver looking up CAA for freeddns.org",' |
| 27 | +'del_dns_rr:1474 removing DNS RR via command: /getssl/dns_scripts/dns_del_acmedns ubuntu-acmedns-getssl.freeddns.org hEAib3ePU0s8-G3HPmPSa50ZjfdKt0A0qskHyTfBJr8' |
| 28 | +'send_signed_request:1215 url https://acme-staging-v02.api.letsencrypt.org/acme/new-order' |
| 29 | +'send_signed_request:1215 using KID=https://acme-staging-v02.api.letsencrypt.org/acme/acct/168360453' |
| 30 | +'send_signed_request:1215 payload = {"identifiers": [{"type":"dns","value":"*.ubuntu-acmedns-getssl.freeddns.org"}]}' |
| 31 | +) |
| 32 | + |
| 33 | +# Second sample text where we don't want check_output_for_errors to find an error |
| 34 | +output2=( |
| 35 | +'send_signed_request:3553 response { "identifier": { "type": "dns", "value": "ubuntu-acmedns-getssl.freeddns.org" }, "status": "invalid", "expires": "2024-10-30T15:24:16Z", "challenges": [ { "type": "dns-01", "url": "https://acme-staging-v02.api.letsencrypt.org/acme/chall-v3/14558038743/zzz8VA", "status": "invalid", "validated": "2024-10-23T15:24:18Z", "error": { "type": "urn:ietf:params:acme:error:dns", "detail": "DNS problem: server failure at resolver looking up CAA for freeddns.org", "status": 400 }, "token": "PyBVfKevM4noXq3fdsFs_0G1BY_o7Nl7eGa6mQw7oJM", "validationRecord": [ { "hostname": "ubuntu-acmedns-getssl.freeddns.org" } ] } ], "wildcard": true}' |
| 36 | +'send_signed_request:3553 code 200' |
| 37 | +'send_signed_request:3553 response status = invalid' |
| 38 | +'main:0 deactivating domain' |
| 39 | +'main:0 deactivating https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/14558038743' |
| 40 | +'send_signed_request:3557 url https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/14558038743' |
| 41 | +'send_signed_request:3557 using KID=https://acme-staging-v02.api.letsencrypt.org/acme/acct/168360453' |
| 42 | +'send_signed_request:3557 payload = {"resource": "authz", "status": "deactivated"}' |
| 43 | +) |
| 44 | + |
| 45 | +# Text that should cause check_output_for_errors to find an error |
| 46 | +output3=( |
| 47 | +'send_signed_request:3553 code 200' |
| 48 | +'send_signed_request:3553 response status = error' |
| 49 | +'main:0 deactivating domain' |
| 50 | +'main:0 deactivating https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/14558038743' |
| 51 | +'send_signed_request:3557 url https://acme-staging-v02.api.letsencrypt.org/acme/authz-v3/14558038743' |
| 52 | +'send_signed_request:3557 using KID=https://acme-staging-v02.api.letsencrypt.org/acme/acct/168360453' |
| 53 | +'send_signed_request:3557 payload = {"resource": "authz", "status": "deactivated"}' |
| 54 | +) |
| 55 | + |
| 56 | + |
| 57 | +output_test_text() { |
| 58 | + input_array=("$@") |
| 59 | + printf '%s\n' "${input_array[@]}" |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +@test "Test that 'Verify error...DNS problem' in first sample output is ignored" { |
| 64 | + # print the known output that used to break the check |
| 65 | + run output_test_text "${output1[@]}" |
| 66 | + |
| 67 | + # run the check |
| 68 | + check_output_for_errors |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | +@test "Test that 'acme:dns:error' in second sample output is ignored" { |
| 73 | + # print the known output that used to break the check |
| 74 | + run output_test_text "${output2[@]}" |
| 75 | + |
| 76 | + # run the check |
| 77 | + check_output_for_errors |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +@test "Test that generic error in third sample output is NOT ignored" { |
| 82 | + # print sample output that should cause 'check_output_for_errors' to fail a test |
| 83 | + run output_test_text "${output3[@]}" |
| 84 | + |
| 85 | + # run the function and check the output confirms that it would fail the test |
| 86 | + run check_output_for_errors |
| 87 | + assert_output --partial "-- regular expression should not match output --" |
| 88 | +} |
0 commit comments