This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
forked from acmesh-official/acmetest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
letest.sh
executable file
·1702 lines (1359 loc) · 43.5 KB
/
letest.sh
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
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env sh
STAGE=1
lezip="https://github.com/acmesh-official/acme.sh/archive"
legit="https://github.com/acmesh-official/acme.sh.git"
PROJECT="https://github.com/acmesh-official/acmetest"
NGROK_WIKI="https://github.com/acmesh-official/acmetest"
DEFAULT_HOME="$HOME/.acme.sh"
PROJECT_ENTRY="acme.sh"
FILE_NAME="letest.sh"
ENV_FILE="./loadenv.sh"
if [ -f "$ENV_FILE" ]; then
. "$ENV_FILE"
fi
BEGIN_CERT="-----BEGIN CERTIFICATE-----"
END_CERT="-----END CERTIFICATE-----"
if [ -z "$CA" ]; then
CA="(STAGING) Artificial Apricot R3"
fi
if [ -z "$CA_ECDSA" ]; then
CA_ECDSA="(STAGING) Ersatz Edamame E1"
fi
if [ -z "$TEST_ACME_Server" ]; then
export TEST_ACME_Server="letsencrypt_test"
fi
if [ "$TEST_CA" ]; then
CA="$TEST_CA"
CA_ECDSA="$TEST_CA"
fi
ECC_SEP="_"
ECC_SUFFIX="${ECC_SEP}ecc"
STAGE_CA="https://acme-staging.api.letsencrypt.org"
_API_HOST="$(echo "$STAGE_CA" | cut -d : -f 2 | tr -d '/')"
_isIPv4() {
for seg in $(echo "$1" | tr '.' ' '); do
if [ "$(echo "$seg" | tr -d [0-9])" ]; then
#not all number
return 1
fi
if [ $seg -ge 0 ] && [ $seg -lt 256 ]; then
continue
fi
return 1
done
return 0
}
#ip6
_isIPv6() {
_contains "$1" ":"
}
#ip
_isIP() {
_isIPv4 "$1" || _isIPv6 "$1"
}
_startswith(){
_str="$1"
_sub="$2"
echo "$_str" | grep -- "^$_sub" >/dev/null 2>&1
}
if [ -z "$LOG_FILE" ] ; then
LOG_FILE="letest.log"
else
if ! _startswith "$LOG_FILE" "/" ; then
LOG_FILE="$(pwd)/$LOG_FILE"
export LOG_FILE
fi
fi
export LOG_FILE
if [ -z "$LOG_LEVEL" ] ; then
LOG_LEVEL=2
fi
export LOG_LEVEL
#we need color in travis
if [ "$TRAVIS" = "true" ] || [ "$GITHUB_REF" ]; then
export ACME_FORCE_COLOR=1
elif [ "$CI" = "1" ]; then
#In our cron testing server
export ACME_NO_COLOR=1
fi
__INTERACTIVE=""
if [ -t 1 ]; then
__INTERACTIVE="1"
fi
__green() {
if [ "${__INTERACTIVE}${ACME_NO_COLOR:-0}" = "10" -o "${ACME_FORCE_COLOR}" = "1" ]; then
printf '\033[1;31;32m%b\033[0m' "$1"
return
fi
printf -- "%b" "$1"
}
__red() {
if [ "${__INTERACTIVE}${ACME_NO_COLOR:-0}" = "10" -o "${ACME_FORCE_COLOR}" = "1" ]; then
printf '\033[1;31;40m%b\033[0m' "$1"
return
fi
printf -- "%b" "$1"
}
__ok() {
__green " [PASS]"
printf "\n"
}
__fail() {
__red " [FAIL] $1" >&2
printf "\n" >&2
return 1
}
_head_n() {
head -n "$1"
}
_dlgVersions() {
if _exists openssl ; then
openssl version
fi
if _exists curl ; then
curl -V
fi
if _exists wget ; then
wget -V
fi
}
_date_u () {
date -u +"%a, %d %b %Y %T %Z"
}
#a + b
_math() {
_m_opts="$@"
printf "%s" "$(($_m_opts))"
}
_log() {
if [ "$LOG_FILE" ] ; then
echo "$@" >> "$LOG_FILE"
fi
}
_info() {
if [ -z "$2" ] ; then
echo "$1"
_log "$1"
else
echo "$1"="'$2'"
_log "$1"="'$2'"
fi
}
_err() {
__red "$(_info "$@")\n" >&2
return 1
}
_debug() {
if [ -z "$DEBUG" ] ; then
return
fi
_info "$@" >&2
return 0
}
_exists() {
cmd="$1"
if [ -z "$cmd" ] ; then
_err "Usage: _exists cmd"
return 1
fi
command -v $cmd >/dev/null 2>&1
ret="$?"
_debug "$cmd exists=$ret"
return $ret
}
_contains() {
_str="$1"
_sub="$2"
echo "$_str" | grep -- "$_sub" >/dev/null 2>&1
}
_mktemp() {
if _exists mktemp; then
if mktemp 2>/dev/null; then
return 0
elif _contains "$(mktemp 2>&1)" "-t prefix" && mktemp -t "$PROJECT_NAME" 2>/dev/null; then
#for Mac osx
return 0
fi
fi
if [ -d "/tmp" ]; then
echo "/tmp/${PROJECT_NAME}wefADf24sf.$(_time).tmp"
return 0
elif [ "$LE_TEMP_DIR" ] && mkdir -p "$LE_TEMP_DIR"; then
echo "/$LE_TEMP_DIR/wefADf24sf.$(_time).tmp"
return 0
fi
_err "Can not create temp file."
}
_egrep_o() {
if ! egrep -o "$1" 2>/dev/null; then
sed -n 's/.*\('"$1"'\).*/\1/p'
fi
}
_ss() {
_port="$1"
if _exists "ss" ; then
_debug "Using: ss"
ss -ntpl | grep ":$_port "
return 0
fi
if _exists "netstat" ; then
_debug "Using: netstat"
if netstat -h 2>&1 | grep "\-p proto" >/dev/null ; then
#for windows version netstat tool
netstat -anb -p tcp | grep "LISTENING" | grep ":$_port "
else
if netstat -help 2>&1 | grep "\-p protocol" >/dev/null ; then
netstat -an -p tcp | grep LISTEN | grep ":$_port "
elif netstat -help 2>&1 | grep -- '-P protocol' >/dev/null ; then
#for solaris
netstat -an -P tcp | grep "\.$_port " | grep "LISTEN"
else
netstat -ntpl | grep ":$_port "
fi
fi
return 0
fi
return 1
}
#Usage: multiline
_base64() {
if [ "$1" ] ; then
openssl base64 -e
else
openssl base64 -e | tr -d '\r\n'
fi
}
#Usage: hashalg [outputhex]
#Output Base64-encoded digest
_digest() {
alg="$1"
if [ -z "$alg" ] ; then
_usage "Usage: _digest hashalg"
return 1
fi
outputhex="$2"
if [ "$alg" = "sha256" ] ; then
if [ "$outputhex" ] ; then
echo $(openssl dgst -sha256 -hex | cut -d = -f 2)
else
openssl dgst -sha256 -binary | _base64
fi
else
_err "$alg is not supported yet"
return 1
fi
}
_hasfield() {
_str="$1"
_field="$2"
_sep="$3"
if [ -z "$_field" ]; then
_usage "Usage: str field [sep]"
return 1
fi
if [ -z "$_sep" ]; then
_sep=","
fi
for f in $(echo "$_str" | tr "$_sep" ' '); do
if [ "$f" = "$_field" ]; then
_debug "'$_str' contains '$_field'"
return 0 #contains ok
fi
done
_debug "'$_str' does not contain '$_field'"
return 1 #not contains
}
NGROK_MAC="https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-darwin-amd64.zip"
NGROK_Linux="https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip"
NGROK_Win="https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-windows-amd64.zip"
NGROK_BSD="https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-freebsd-amd64.zip"
CF_Linux="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64"
CF_MAC="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64.tgz"
CF_Win="https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe"
if [ -z "$TestingDomain" ]; then
if [ -z "$CF_BIN" ] || [ ! -x "$CF_BIN" ]; then
if _exists "cloudflared" ; then
_info "Command cloudflared is found, so, use it."
CF_BIN="cloudflared"
else
_os_name="$(uname)"
_info _os_name "$_os_name"
case "$_os_name" in
CYGWIN_NT* | MINGW*)
_debug "cygwin"
export CF_BIN="$(pwd)/cloudflared.exe"
CF_LINK="$CF_Win"
;;
Linux)
_debug "Linux"
export CF_BIN="$(pwd)/cloudflared"
CF_LINK="$CF_Linux"
;;
Darwin)
_debug "Darwin"
export CF_BIN="$(pwd)/cloudflared"
CF_LINK="$CF_MAC"
;;
*)
_err "Not supported: $_os_name"
exit 1
;;
esac
if [ ! -f "$CF_BIN" ]; then
_info "Download from $CF_LINK"
if [ "$CF_LINK" = "$CF_Linux" ]; then
if ! curl -L "$CF_LINK" >"$CF_BIN"; then
_err "Download error."
exit 1
fi
chmod +x "$CF_BIN"
elif [ "$CF_LINK" = "$CF_MAC" ]; then
if ! curl -L "$CF_LINK" >cf.tgz; then
_err "Download error."
exit 1
fi
if ! tar -xzf cf.tgz; then
_err "unzip error."
exit 1
fi
else
if ! curl -L "$CF_LINK" > cloudflared.exe; then
_err "can not download: $latest_url"
exit 1
fi
chmod +x "$CF_BIN"
fi
fi
if [ ! -f "$CF_BIN" ]; then
_err "Please install cloudflared command, or specify CF_BIN=$CF_BIN pointing to the ngrok binary. see: $NGROK_WIKI"
exit 1
fi
fi
fi
ng_temp_1="cf.tmp"
_info "ng_temp_1" "$ng_temp_1"
$CF_BIN update
if [ "$Le_HTTPPort" ]; then
$CF_BIN tunnel --url http://localhost:$Le_HTTPPort >$ng_temp_1 2>&1 &
else
$CF_BIN tunnel --url http://localhost >$ng_temp_1 2>&1 &
fi
CF_PID="$!"
_debug "cf pid: $CF_PID"
MaxWait=60;#seconds
_wait=0;
while [ $_wait -le $MaxWait ]; do
sleep 10
_wait=$((_wait + 10))
ng_domain_1="$(cat "$ng_temp_1" | grep https:// | grep trycloudflare.com | grep -v api.trycloudflare.com | head -1 | cut -d '|' -f 2 | tr -d ' ' | cut -d '/' -f 3)"
_info "ng_domain_1" "$ng_domain_1"
if [ -z "$ng_domain_1" ] ; then
cat "$ng_temp_1"
_err "Can not get cf domain."
continue
fi
TestingDomain="$ng_domain_1"
while ! grep "connIndex=2" "$ng_temp_1"; do
_info "wait for connection to establish..."
cat "$ng_temp_1"
sleep 3
done
sleep 3
cat "$ng_temp_1"
break
done;
if [ -z "$TestingDomain" ] ; then
cat "$ng_temp_1"
_err "Can not get cf domain."
exit 1
fi
#TEST_NGROK=1
# if [ -z "$NGROK_TOKEN" ]; then
# if [ -f "$USERPROFILE/.ngrok2/ngrok.yml" ]; then
# #cygwin
# NGROK_TOKEN=$(grep "authtoken:" "$USERPROFILE/.ngrok2/ngrok.yml" | cut -d : -f 2| tr -d " '")
# fi
# if [ -z "$NGROK_TOKEN" ] && [ -f "$HOME/.ngrok2/ngrok.yml" ]; then
# #linux
# NGROK_TOKEN=$(grep "authtoken:" "$HOME/.ngrok2/ngrok.yml" | cut -d : -f 2 | tr -d " '")
# fi
# fi
#
# if [ -z "$NGROK_TOKEN" ]; then
# _err "The TestingDomain or TestingAltDomains is not specified, see: $PROJECT"
# _err "You can also specify NGROK_TOKEN to test automatically, see: $NGROK_WIKI"
# exit 1
# fi
#
# if [ "$NGROK_TOKEN" ]; then
# if [ -z "$NGROK_BIN" ] || [ ! -x "$NGROK_BIN" ]; then
# if _exists "ngrok" ; then
# _info "Command ngrok is found, so, use it."
# NGROK_BIN="ngrok"
# else
# _os_name="$(uname)"
# _info _os_name "$_os_name"
# case "$_os_name" in
# FreeBSD | OpenBSD)
# _debug "BSD"
# export NGROK_BIN="$(pwd)/ngrok"
# NGROK_LINK="$NGROK_BSD"
# ;;
# CYGWIN_NT* | MINGW*)
# _debug "cygwin"
# export NGROK_BIN="$(pwd)/ngrok.exe"
# NGROK_LINK="$NGROK_Win"
# ;;
# Linux)
# _debug "Linux"
# export NGROK_BIN="$(pwd)/ngrok"
# NGROK_LINK="$NGROK_Linux"
# ;;
# Darwin)
# _debug "Darwin"
# export NGROK_BIN="$(pwd)/ngrok"
# NGROK_LINK="$NGROK_MAC"
# ;;
# *)
# _err "Not supported: $_os_name"
# exit 1
# ;;
# esac
#
# if [ ! -f "$NGROK_BIN" ]; then
# _info "Download from $NGROK_LINK"
# if ! curl "$NGROK_LINK" >ngrok.zip; then
# _err "Download error."
# exit 1
# fi
# if ! unzip ngrok.zip; then
# _err "unzip error."
# exit 1
# fi
# fi
#
# if [ ! -f "$NGROK_BIN" ]; then
# _err "The NGROK_TOKEN is specified, it seems that you want to use ngrok to test, but the executable ngrok is not found."
# _err "Please install ngrok command, or specify NGROK_BIN=$NGROK_BIN pointing to the ngrok binary. see: $NGROK_WIKI"
# exit 1
# fi
# fi
# fi
#
# _info "Using ngrok, register auth token first."
# if ! $NGROK_BIN authtoken "$NGROK_TOKEN" ; then
# _err "Register ngrok auth token failed."
# exit 1
# fi
#
# ng_temp_1="ngrok.tmp"
# _info "ng_temp_1" "$ng_temp_1"
# if [ "$Le_HTTPPort" ]; then
# $NGROK_BIN http $Le_HTTPPort --log stdout --log-format logfmt --log-level debug > "$ng_temp_1" &
# else
# $NGROK_BIN http 80 --log stdout --log-format logfmt --log-level debug > "$ng_temp_1" &
# fi
# NGROK_PID="$!"
# _debug "ngrok pid: $NGROK_PID"
#
# sleep 20
#
# ng_domain_1="$(_egrep_o 'Hostname:.+.ngrok.io' <"$ng_temp_1" | _head_n 1 | cut -d':' -f2)"
# _info "ng_domain_1" "$ng_domain_1"
#
# if [ -z "$ng_domain_1" ] ; then
# cat "$ng_temp_1"
# _err "Can not get ngrok domain."
# exit 1
# fi
# TestingDomain="$ng_domain_1"
# TEST_NGROK=1
# fi
fi
if [ -z "$TestingDomain" ] && [ -z "$TEST_DNS" ]; then
_err "The TestingDomain or TestingAltDomains is not specified, see: $PROJECT"
_err "You can also specify NGROK_TOKEN to test automatically, see: $NGROK_WIKI"
exit 1
fi
if [ "$TEST_IDN" ] ; then
if [ -z "$TestingIDNDomain" ] ; then
TestingIDNDomain="中$TestingDomain"
fi
fi
if [ "$DOCKER_OS" = "centos:5" ] \
|| [ "$DOCKER_OS" = "gentoo/stage3" ] ; then
NO_ECC_CASES="1"
if ! grep "insecure" ~/.curlrc >/dev/null 2>&1; then
echo insecure >>~/.curlrc
fi
NO_HMAC_CASES="1"
TEST_DNS=""
fi
#file subname issuername
_assertcert() {
filename="$1"
subname="$2"
issuername="$3"
printf "$filename is cert ? "
subj="$(echo $(openssl x509 -in $filename -text -noout | grep 'Subject:.*CN *=' | _egrep_o " CN *=.*" | cut -d '=' -f 2 | cut -d / -f 1))"
printf "'$subj'"
if _contains "$subj" "$subname" || _isIP "$subname"; then
if [ "$issuername" ] ; then
issuer="$(echo $(openssl x509 -in $filename -text -noout | grep 'Issuer:' | _egrep_o "CN *=[^,]*" | cut -d = -f 2))"
printf " '$issuer'"
if ! _contains "$issuer" "$issuername"; then
__fail "Expected issuer is: '$issuername', but was: '$issuer'"
return 1
fi
fi
__ok ""
return 0
else
__fail "Expected subject is: '$subname', but was: '$subj'"
return 1
fi
}
#cmd
_assertcmd() {
__cmd="$1"
printf "%s" "$__cmd"
eval "$__cmd > \"cmd.log\" 2>&1"
if [ "$?" = "0" ] ; then
__ok ""
else
__fail ""
if [ "$DEBUG" ] ; then
cat "cmd.log" >&2
fi
return 1
fi
return 0
}
#file
_assertexists() {
__file="$1"
if [ -e "$__file" ] ; then
printf "$__file exists."
__ok ""
else
printf "$__file missing."
__fail ""
return 1
fi
return 0
}
#file
_assertnotexists() {
__file="$1"
if [ ! -e "$__file" ] ; then
printf "$__file no exists."
__ok ""
else
printf "$__file is there."
__fail ""
return 1
fi
return 0
}
_assertequals() {
if [ "$1" = "$2" ] ; then
printf "equals $1"
__ok ""
else
__fail "Failed"
_err "Expected:$1"
_err "But was:$2"
fi
}
#file1 file2
_assertfileequals(){
file1="$1"
file2="$2"
if [ "$(cat "$file1" | _digest sha256)" = "$(cat "$file2" | _digest sha256)" ] ; then
printf -- "'$file1' equals '$2'"
__ok
else
__fail "Failed"
fi
}
_run() {
_test="$1"
_info "==Running $_test please wait"
lehome="$DEFAULT_HOME"
export STAGE
export DEBUG
if [ "$_test" != "le_test_installtodir" ] && [ "$_test" != "le_test_uninstalltodir" ] && [ "$_test" != "le_test_install_config_home" ]; then
cd acme.sh;
./$PROJECT_ENTRY install > /dev/null
cd ..
fi
_r="0"
__CASE_SKIPPED=""
if ! ( $_test ) ; then
_r="1"
fi
if [ "$_r" = "0" ]; then
_debug "Run Success"
else
_err "Run Failed"
fi
DEFAULT_CA_HOME="$lehome/ca"
if [ -z "$CA_HOME" ] ; then
CA_HOME="$DEFAULT_CA_HOME"
fi
CA_DIR="$CA_HOME/$_API_HOST"
if _contains "$_test" "SAN"; then
_deactivateDomains="$TestingDomain$TestingAltDomains"
else
_deactivateDomains="$TestingDomain"
fi
_debug "_deactivateDomains" "$_deactivateDomains"
if [ ! "$DEBUG" ] ; then
rm -rf "$lehome/$TestingDomain"
rm -rf "$lehome/$TestingDomain$ECC_SUFFIX"
if [ -f "$lehome/$PROJECT_ENTRY" ] ; then
if [ -z "$__CASE_SKIPPED" ] && [ -f "$CA_DIR/account.key" ] ; then
$lehome/$PROJECT_ENTRY --deactivate -d "$_deactivateDomains" >deactivate.log 2>&1
fi
__dr="$?"
if [ "$__dr" != "0" ]; then
_err "deactivate failed"
cat deactivate.log
fi
if [ "$_r" = "0" ] ; then
_r="$__dr"
fi
$lehome/$PROJECT_ENTRY --uninstall >/dev/null
fi
else
if [ -f "$CA_DIR/account.key" ] ; then
$lehome/$PROJECT_ENTRY --deactivate -d "$_deactivateDomains" >/dev/null 2>&1
fi
fi
rm -f "$lehome/account.conf"
_debug "_r" "$_r"
_info "------------------------------------------"
return $_r
}
####################################################
_setup() {
if [ "$TEST_LOCAL" = "1" ] ; then
_info "TEST_LOCAL skip setup."
return 0
fi
if [ -d acme.sh ] ; then
rm -rf acme.sh
fi
if [ ! "$BRANCH" ] ; then
BRANCH="master"
fi
_info "Testing branch: $BRANCH"
if command -v tar > /dev/null ; then
link="$lezip/$BRANCH.tar.gz"
curl -OL "$link" >/dev/null 2>&1
tar xzf "$BRANCH.tar.gz" >/dev/null 2>&1
mv "acme.sh-$BRANCH" acme.sh
elif command -v git > /dev/null ; then
rm -rf acme.sh
git clone $legit -b $BRANCH
else
_err "Can not get acme.sh source code. tar or git must be installed"
return 1
fi
lehome="$DEFAULT_HOME"
if [ -f "$lehome/$PROJECT_ENTRY" ] ; then
$lehome/$PROJECT_ENTRY --uninstall >/dev/null 2>&1
fi
if [ -d $DEFAULT_HOME ] ; then
rm -rf $DEFAULT_HOME
fi
#reuse ca account keys for the low acount rate limit
if [ -d "ca" ]; then
mkdir -p "$DEFAULT_HOME"
cp -r ca "$DEFAULT_HOME/"
rm -f "$DEFAULT_HOME/ca/*/ca.conf"
fi
}
le_test_dependencies() {
dependencies="curl crontab openssl socat"
for cmd in $dependencies
do
if command -v $cmd > /dev/null ; then
printf "$cmd installed."
__ok
else
printf "$cmd not installed"
__fail
return 1
fi
done
}
le_test_install() {
lehome="$DEFAULT_HOME"
cd acme.sh;
_assertcmd "./$PROJECT_ENTRY --install" || return
cd ..
_assertexists "$lehome/$PROJECT_ENTRY" || return
_c_entry="$(crontab -l | grep $PROJECT_ENTRY)"
_assertcmd "_contains '$_c_entry' '0 \\* \\* \\* \"$lehome\"/$PROJECT_ENTRY --cron --home \"$lehome\" > /dev/null'" || return
_assertcmd "$lehome/$PROJECT_ENTRY --uninstall > /dev/null" || return
}
le_test_uninstall() {
lehome="$DEFAULT_HOME"
cd acme.sh;
_assertcmd "./$PROJECT_ENTRY --install" || return
cd ..
_assertcmd "$lehome/$PROJECT_ENTRY --uninstall" || return
_assertnotexists "$lehome/$PROJECT_ENTRY" || return
_assertequals "" "$(crontab -l | grep $PROJECT_ENTRY)"|| return
}
le_test_installtodir() {
lehome="$HOME/myle"
if [ -d $lehome ] ; then
rm -rf $lehome
fi
cd acme.sh;
LE_WORKING_DIR=$lehome
export LE_WORKING_DIR
_assertcmd "./$PROJECT_ENTRY --install" || return
LE_WORKING_DIR=""
cd ..
_assertexists "$lehome/$PROJECT_ENTRY" || return
_c_entry="$(crontab -l | grep $PROJECT_ENTRY)"
_assertcmd "_contains '$_c_entry' '0 \\* \\* \\* \"$lehome\"/$PROJECT_ENTRY --cron --home \"$lehome\" > /dev/null'" || return
_assertcmd "$lehome/$PROJECT_ENTRY --uninstall" || return
if [ -z "$DEBUG" ]; then
rm -rf $lehome
fi
}
le_test_uninstalltodir() {
lehome="$HOME/myle"
if [ -d $lehome ] ; then
rm -rf $lehome
fi
cd acme.sh;
LE_WORKING_DIR=$lehome
export LE_WORKING_DIR
_assertcmd "./$PROJECT_ENTRY --install" || return
LE_WORKING_DIR=""
cd ..
_assertcmd "$lehome/$PROJECT_ENTRY --uninstall" || return
_assertnotexists "$lehome/$PROJECT_ENTRY" || return
_assertequals "" "$(crontab -l | grep $PROJECT_ENTRY)" || return
if [ -z "$DEBUG" ]; then
rm -rf $lehome
fi
}
le_test_install_config_home() {
lehome="$DEFAULT_HOME"
confighome="$HOME/etc/acme"
cd acme.sh;
_assertcmd "./$PROJECT_ENTRY --install --config-home $confighome" || return
cd ..
_assertexists "$lehome/$PROJECT_ENTRY" || return
_c_entry="$(crontab -l | grep $PROJECT_ENTRY)"
_assertcmd "_contains '$_c_entry' '0 \\* \\* \\* \"$lehome\"/$PROJECT_ENTRY --cron --home \"$lehome\" --config-home \"$confighome\" > /dev/null'" || return
_assertexists "$confighome/account.conf" || return
_assertnotexists "$lehome/account.conf" || return
_assertcmd "$lehome/$PROJECT_ENTRY --cron --config-home $confighome > /dev/null" || return
_assertcmd "$lehome/$PROJECT_ENTRY --uninstall --config-home $confighome > /dev/null" || return
_assertexists "$confighome/account.conf" || return
_assertnotexists "$lehome/account.conf" || return
if [ -z "$DEBUG" ]; then
rm -rf "$confighome"
fi
}
#
le_test_standandalone_renew_v2() {
lehome="$DEFAULT_HOME"
if [ -z "$TestingDomain" ] ; then
__fail "Please define TestingDomain and try again."
return 1
fi
rm -rf "$lehome/$TestingDomain"
certdir="$(pwd)/certs"
mkdir -p "$certdir"
cert="$certdir/domain.cer"
key="$certdir/domain.key"
ca="$certdir/ca.cer"
full="$certdir/full.cer"
_assertcmd "$lehome/$PROJECT_ENTRY --server \"$TEST_ACME_Server\" --issue -d $TestingDomain --standalone --certpath '$cert' --keypath '$key' --capath '$ca' --reloadcmd 'echo this is reload' --fullchainpath '$full'" || return
_assertfileequals "$lehome/$TestingDomain/$TestingDomain.cer" "$cert" || return
_assertfileequals "$lehome/$TestingDomain/$TestingDomain.key" "$key" || return
_assertfileequals "$lehome/$TestingDomain/ca.cer" "$ca" || return
_assertfileequals "$lehome/$TestingDomain/fullchain.cer" "$full" || return
if [ -z "$NO_REVOKE" ]; then
sleep 5
_assertcmd "$lehome/$PROJECT_ENTRY --revoke -d $TestingDomain" || return
rm -f "$lehome/$TestingDomain/$TestingDomain.key"
rm -f "$lehome/$TestingDomain/$TestingDomain.csr"
fi
rm -rf "$certdir"
mkdir -p "$certdir"
sleep 5
_assertcmd "$lehome/$PROJECT_ENTRY --renew --server \"$TEST_ACME_Server\" -d $TestingDomain --force" || return
_assertcert "$lehome/$TestingDomain/$TestingDomain.cer" "$TestingDomain" "$CA" || return
_assertcert "$lehome/$TestingDomain/ca.cer" "$CA" || return
_assertfileequals "$lehome/$TestingDomain/$TestingDomain.cer" "$cert" || return
_assertfileequals "$lehome/$TestingDomain/$TestingDomain.key" "$key" || return
_assertfileequals "$lehome/$TestingDomain/ca.cer" "$ca" || return
_assertfileequals "$lehome/$TestingDomain/fullchain.cer" "$full" || return
if [ -z "$NO_REVOKE" ]; then
sleep 5
_assertcmd "$lehome/$PROJECT_ENTRY --revoke -d $TestingDomain" || return
fi
rm -rf "$certdir"
}
#
le_test_standandalone_renew_localaddress_v2() {
lehome="$DEFAULT_HOME"
if [ -z "$TestingDomain" ] ; then
__fail "Please define TestingDomain and try again."
return 1
fi
rm -rf "$lehome/$TestingDomain"
certdir="$(pwd)/certs"
mkdir -p "$certdir"
cert="$certdir/domain.cer"
key="$certdir/domain.key"
ca="$certdir/ca.cer"
full="$certdir/full.cer"
_assertcmd "$lehome/$PROJECT_ENTRY --server \"$TEST_ACME_Server\" --issue -d $TestingDomain --standalone --local-address 0.0.0.0 --certpath '$cert' --keypath '$key' --capath '$ca' --reloadcmd 'echo this is reload' --fullchainpath '$full'" || return
_assertfileequals "$lehome/$TestingDomain/$TestingDomain.cer" "$cert" || return
_assertfileequals "$lehome/$TestingDomain/$TestingDomain.key" "$key" || return
_assertfileequals "$lehome/$TestingDomain/ca.cer" "$ca" || return
_assertfileequals "$lehome/$TestingDomain/fullchain.cer" "$full" || return
if [ -z "$NO_REVOKE" ]; then
sleep 5
_assertcmd "$lehome/$PROJECT_ENTRY --revoke -d $TestingDomain" || return
rm -f "$lehome/$TestingDomain/$TestingDomain.key"
rm -f "$lehome/$TestingDomain/$TestingDomain.csr"
fi
rm -rf "$certdir"
mkdir -p "$certdir"
if [ "$QUICK_TEST" ] ; then
_info "Skipped by QUICK_TEST"
return 0
fi
sleep 5
_assertcmd "$lehome/$PROJECT_ENTRY --renew --server \"$TEST_ACME_Server\" -d $TestingDomain --force" || return