Skip to content

Commit 73b21eb

Browse files
committed
Misc fixes for CI tests
1 parent 1838953 commit 73b21eb

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

getssl

+8-6
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ check_challenge_completion_dns() { # perform validation via DNS challenge
568568

569569
# add +noidnout if idn-domain so search for domain in results works
570570
if [[ "${d}" == xn--* || "${d}" == *".xn--"* ]]; then
571-
if [[ "$DNS_CHECK_FUNC" == "nslookup" || "$DNS_CHECK_FUNC" == "host" || ("$DNS_CHECK_FUNC" == "dig" && "$DIG_SUPPORTS_NOIDNOUT" == "false") ]]; then
571+
if [[ "$DNS_CHECK_FUNC" == "nslookup" || "$DNS_CHECK_FUNC" == "host" || ("$DNS_CHECK_FUNC" == "$HAS_DIG_OR_DRILL" && "$DIG_SUPPORTS_NOIDNOUT" == "false") ]]; then
572572
info "Info: idn domain but $DNS_CHECK_FUNC doesn't support +noidnout"
573573
else
574574
debug "adding +noidnout to DNS_CHECK_OPTIONS"
@@ -1418,6 +1418,8 @@ for d in "${alldomains[@]}"; do
14181418
# get the token and uri from the dns-01 component
14191419
token=$(json_get "$response" "challenges" "type" "dns-01" "token")
14201420
uri=$(json_get "$response" "challenges" "type" "dns-01" "url")
1421+
# when using pebble this sometimes appears to have a newline which causes problems in send_signed_request
1422+
uri=$(echo "$uri" | tr -d '\r')
14211423
debug uri "$uri"
14221424
fi
14231425

@@ -2516,7 +2518,7 @@ send_signed_request() { # Sends a request to the ACME server, signed with your p
25162518

25172519
code="500"
25182520
loop_limit=5
2519-
while [[ "$code" -eq 500 ]]; do
2521+
while [[ "$code" == 5* ]]; do
25202522
if [[ "$outfile" ]] ; then
25212523
$CURL -X POST -H "Content-Type: application/jose+json" --data "$body" "$url" > "$outfile"
25222524
errcode=$?
@@ -2562,13 +2564,13 @@ send_signed_request() { # Sends a request to the ACME server, signed with your p
25622564
fi
25632565
fi
25642566
debug "response status = $response_status"
2565-
if [[ "$code" -eq 500 ]]; then
2566-
info "_error on acme server - trying again ...."
2567+
if [[ "$code" == 5* ]]; then
2568+
info "_error on acme server - waiting 30s then trying again ...."
25672569
debug "loop_limit = $loop_limit"
2568-
sleep 5
2570+
sleep 30
25692571
loop_limit=$((loop_limit - 1))
25702572
if [[ $loop_limit -lt 1 ]]; then
2571-
error_exit "500 error from ACME server: $response"
2573+
error_exit "$code error from ACME server: $response"
25722574
fi
25732575
fi
25742576
done

test/0-test-usage.bats

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ setup() {
4040
if [ -n "$STAGING" ]; then
4141
skip "Using staging server, skipping internal test"
4242
fi
43+
44+
# Feb-23 Getting semi-repeatable "can't check for upgrades: ''" errors which are because the limit is being exceeded (re-use of github action ip?)
45+
check_github_quota 7
4346
run ${CODE_DIR}/getssl --upgrade
4447
refute_output
4548
assert_success

test/32-test-upgrade.bats

-33
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,6 @@ load '/bats-support/load.bash'
44
load '/bats-assert/load.bash'
55
load '/getssl/test/test_helper.bash'
66

7-
LIMIT_API="https://api.github.com/rate_limit"
8-
9-
# Quota generally shouldn't be an issue - except for tests
10-
# Rate limits are per-IP address
11-
check_github_quota() {
12-
local need remaining reset limits now
13-
need="$1"
14-
while true ; do
15-
limits="$(curl ${_NOMETER:---silent} --user-agent "$CURL_USERAGENT" -H 'Accept: application/vnd.github.v3+json' "$LIMIT_API" | sed -e's/\("[^:]*": *\("[^""]*",\|[^,]*[,}]\)\)/\r\n\1/g' | sed -ne'/"core":/,/}/p')"
16-
errcode=$?
17-
if [[ $errcode -eq 60 ]]; then
18-
error_exit "curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
19-
elif [[ $errcode -gt 0 ]]; then
20-
error_exit "curl error checking releases: $errcode"
21-
fi
22-
limits="$(sed -e's/^ *//g' <<<"${limits}")"
23-
remaining="$(sed -e'/^"remaining": *[0-9]/!d;s/^"remaining": *\([0-9][0-9]*\).*$/\1/' <<<"${limits}")"
24-
reset="$(sed -e'/^"reset": *[0-9]/!d;s/^"reset": *\([0-9][0-9]*\).*$/\1/' <<<"${limits}")"
25-
if [[ "$remaining" -ge "$need" ]] ; then return 0 ; fi
26-
limit="$(sed -e'/^"limit": *[0-9]/!d;s/^"limit": *\([0-9][0-9]*\).*$/\1/' <<<"${limits}")"
27-
if [[ "$limit" -lt "$need" ]] ; then
28-
error_exit "GitHub API request $need exceeds limit $limit"
29-
fi
30-
now="$(date +%s)"
31-
while [[ "$now" -lt "$reset" ]] ; do
32-
info "sleeping $(( "$reset" - "$now" )) seconds for GitHub quota"
33-
sleep "$(( "$reset" - "$now" ))"
34-
now="$(date +%s)"
35-
done
36-
done
37-
}
38-
39-
407
setup_file() {
418
if [ -n "$STAGING" ]; then
429
echo "Using staging server, skipping internal test" >&3

test/test_helper.bash

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
INSTALL_DIR=/root
22
CODE_DIR=/getssl
3+
LIMIT_API="https://api.github.com/rate_limit"
34

45
check_certificates()
56
{
@@ -8,6 +9,42 @@ check_certificates()
89
assert [ -e "${INSTALL_DIR}/.getssl/${GETSSL_CMD_HOST}/${GETSSL_CMD_HOST}.crt" ]
910
}
1011

12+
# Quota generally shouldn't be an issue - except for tests
13+
# Rate limits are per-IP address
14+
check_github_quota() {
15+
local need remaining reset limits now
16+
need="$1"
17+
echo "# Checking github limits"
18+
while true ; do
19+
limits="$(curl ${_NOMETER:---silent} --user-agent "srvrco/getssl/github-actions" -H 'Accept: application/vnd.github.v3+json' "$LIMIT_API")"
20+
echo "# limits = $limits"
21+
errcode=$?
22+
if [[ $errcode -eq 60 ]]; then
23+
echo "curl needs updating, your version does not support SNI (multiple SSL domains on a single IP)"
24+
exit 1
25+
elif [[ $errcode -gt 0 ]]; then
26+
echo "curl error checking releases: $errcode"
27+
exit 1
28+
fi
29+
remaining="$(jq -r '.resources.core.remaining' <<<"$limits")"
30+
echo "# Remaining: $remaining"
31+
reset="$(jq -r '.resources.core.reset' <<<"$limits")"
32+
if [[ "$remaining" -ge "$need" ]] ; then return 0 ; fi
33+
limit="$(jq -r '.resources.core.limit' <<<"$limits")"
34+
echo "# Limit: $limit"
35+
if [[ "$limit" -lt "$need" ]] ; then
36+
echo "GitHub API request $need exceeds limit $limit"
37+
exit 1
38+
fi
39+
now="$(date +%s)"
40+
while [[ "$now" -lt "$reset" ]] ; do
41+
echo "# sleeping $(( reset - now )) seconds for GitHub quota"
42+
sleep "$(( reset - now ))"
43+
now="$(date +%s)"
44+
done
45+
done
46+
}
47+
1148
# Only nginx > 1.11.0 support dual certificates in a single configuration file
1249
# https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script
1350
check_nginx() {
@@ -24,7 +61,7 @@ check_nginx() {
2461

2562
check_output_for_errors() {
2663
refute_output --regexp '[Ff][Aa][Ii][Ll][Ee][Dd]'
27-
refute_output --regexp '[^_][Ee][Rr][Rr][Oo][Rr][^:nonce]'
64+
refute_output --regexp '[^_][Ee][Rr][Rr][Oo][Rr][^:badNonce]'
2865
refute_output --regexp '[^_][Ww][Aa][Rr][Nn][Ii][Nn][Gg]'
2966
refute_line --partial 'command not found'
3067
}

0 commit comments

Comments
 (0)