forked from dashingsoft/pyarmor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration-test.sh
More file actions
executable file
·1108 lines (998 loc) · 38.6 KB
/
integration-test.sh
File metadata and controls
executable file
·1108 lines (998 loc) · 38.6 KB
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
#! /bin/bash
#
# DEPRECATED from v6.3.0, runtime files are embedded into dynamic
# library, it doesn't work with old version
#
UNAME=$(uname)
if [[ ${UNAME:0:5} == Linux ]] ; then
if [[ $(arch) == x86_64 ]] ; then
PLATFORM=linux_x86_64
else
PLATFORM=linux_i386
fi
PKGEXT=tar.bz2
else
if [[ $(uname) == Darwin ]] ; then
PLATFORM=macosx_x86_64
PKGEXT=tar.bz2
else
if [[ $(arch) == x86_64 ]] ; then
PLATFORM=win_amd64
else
PLATFORM=win32
fi
PKGEXT=zip
fi
fi
# From pyarmor 3.5.1, dist is moved to top level
DIST="../dist"
[[ -d "../dist" ]] || DIST="../src/dist"
filename=$(cd ${DIST}; ls -t pyarmor-*.${PKGEXT}) || exit 1
version=${filename:8:6}
if [[ "${version:5:1}" == "." ]] ; then
version=${filename:8:5}
fi
extchar=${PYARMOR_EXTRA_CHAR:-e}
workpath=__runtest__
datafile=$(pwd)/data/pyarmor-data.tar.gz
pkgfile=$(pwd)/${DIST}/pyarmor-${version}.${PKGEXT}
declare -i _bug_counter=0
case ${PLATFORM} in
win32)
PYTHON=${PYTHON:-C:/Python26/python}
declare -r harddisk_sn=013040BP2N80S13FJNT5
declare -r ifmac_address=70:f1:a1:23:f0:94
declare -r ifip_address=192.168.121.101
declare -r domain_name=
;;
win_amd64)
PYTHON=${PYTHON:-C:/Python26/python}
declare -r harddisk_sn=VBa2fd0ee8-4482c1ad
declare -r ifmac_address=08:00:27:51:d9:fe
declare -r ifip_address=192.168.121.112
# Dell Win7
# declare -r ifip_address=169.254.225.168
declare -r domain_name=
;;
linux_i386)
PYTHON=${PYTHON:-python}
declare -r harddisk_sn=VB07ab3ff6-81eb5787
declare -r ifmac_address=08:00:27:88:4b:88
declare -r ifip_address=192.168.121.106
declare -r domain_name=
;;
linux_x86_64)
PYTHON=${PYTHON:-python}
declare -r harddisk_sn=9WK3FEMQ
declare -r ifmac_address=00:23:8b:e0:4f:a7
declare -r ifip_address=192.168.121.103
declare -r domain_name=
;;
macosx_x86_64)
PYTHON=python
# declare -r harddisk_sn=VB85de09d4-23402b07
# declare -r ifmac_address=08:00:27:b0:b3:94
declare -r harddisk_sn=FV994730S6LLF07AY
declare -r ifmac_address=f8:ff:c2:27:00:7f
declare -r ifip_address=$(ipconfig getifaddr en0)
declare -r domain_name=
;;
*)
echo Unknown platform "${PLATFORM}"
exit 1
esac
# ======================================================================
# Initial setup, csih routines, etc. PART 1
# ======================================================================
_csih_trace=
_csih_ERROR_STR_COLOR="\e[1;31m*** ERROR:\e[0;0m"
_csih_WARN_STR_COLOR="\e[1;33m*** Warning:\e[0;0m"
_csih_INFO_STR_COLOR="\e[1;32m*** Info:\e[0;0m"
_csih_QUERY_STR_COLOR="\e[1;35m*** Query:\e[0;0m"
_csih_STACKTRACE_STR_COLOR="\e[1;36m*** STACKTRACE:\e[0;0m"
readonly _csih_ERROR_STR_COLOR _csih_WARN_STR_COLOR
readonly _csih_INFO_STR_COLOR _csih_QUERY_STR_COLOR _csih_STACKTRACE_STR_COLOR
_csih_ERROR_STR_PLAIN="*** ERROR:"
_csih_WARN_STR_PLAIN="*** Warning:"
_csih_INFO_STR_PLAIN="*** Info:"
_csih_QUERY_STR_PLAIN="*** Query:"
_csih_STACKTRACE_STR_PLAIN="*** STACKTRACE:"
readonly _csih_ERROR_STR_PLAIN _csih_WARN_STR_PLAIN
readonly _csih_INFO_STR_PLAIN _csih_QUERY_STR_PLAIN _csih_STACKTRACE_STR_PLAIN
_csih_ERROR_STR="${_csih_ERROR_STR_COLOR}"
_csih_WARN_STR="${_csih_WARN_STR_COLOR}"
_csih_INFO_STR="${_csih_INFO_STR_COLOR}"
_csih_QUERY_STR="${_csih_QUERY_STR_COLOR}"
_csih_STACKTRACE_STR="${_csih_STACKTRACE_STR_COLOR}"
# ======================================================================
# Routine: csih_disable_color
# Provided so that scripts which are invoked via postinstall
# can prevent escape codes from showing up in /var/log/setup.log
# ======================================================================
csih_disable_color()
{
_csih_ERROR_STR="${_csih_ERROR_STR_PLAIN}"
_csih_WARN_STR="${_csih_WARN_STR_PLAIN}"
_csih_INFO_STR="${_csih_INFO_STR_PLAIN}"
_csih_QUERY_STR="${_csih_QUERY_STR_PLAIN}"
_csih_STACKTRACE_STR="${_csih_STACKTRACE_STR_PLAIN}"
} # === End of csih_disable_color() === #
readonly -f csih_disable_color
# ======================================================================
# Routine: csih_stacktrace
# ======================================================================
csih_stacktrace()
{
set +x # don''t trace this!
local -i n=$(( ${#FUNCNAME} - 1 ))
local val=""
if [ -n "$_csih_trace" ]
then
while [ $n -gt 0 ]
do
if [ -n "${FUNCNAME[$n]}" ]
then
if [ -z "$val" ]
then
val="${FUNCNAME[$n]}[${BASH_LINENO[$(($n-1))]}]"
else
val="${val}->${FUNCNAME[$n]}[${BASH_LINENO[$(($n-1))]}]"
fi
fi
n=$(($n-1))
done
echo -e "${_csih_STACKTRACE_STR} ${val} ${@}"
fi
} # === End of csih_stacktrace() === #
readonly -f csih_stacktrace
# ======================================================================
# Routine: csih_trace_on
# turns on shell tracing of csih functions
# ======================================================================
csih_trace_on()
{
_csih_trace='set -x'
trap 'csih_stacktrace "returning with" $?; set -x' RETURN
set -T
csih_stacktrace "${@}"
} # === End of csih_trace_on() === #
readonly -f csih_trace_on
# ======================================================================
# Routine: csih_trace_off
# turns off shell tracing of csih functions
# ======================================================================
csih_trace_off()
{
trap '' RETURN
csih_stacktrace "${@}"
_csih_trace=
set +x
set +T
} # === End of csih_trace_off() === #
readonly -f csih_trace_off
# ======================================================================
# Routine: csih_error
# Prints the (optional) error message $1, then
# Exits with the error code contained in $? if $? is non-zero, otherwise
# exits with status 1
# All other arguments are ignored
# Example: csih_error "missing file"
# NEVER RETURNS
# ======================================================================
csih_error()
{
local errorcode=$?
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
if ((errorcode == 0))
then
errorcode=1
fi
echo -e "${_csih_ERROR_STR} ${1:-no error message provided}"
exit ${errorcode};
} # === End of csih_error() === #
readonly -f csih_error
# ======================================================================
# Routine: csih_error_multi
# Prints the (optional) error messages in the positional arguments, one
# per line, and then
# Exits with the error code contained in $? if $? is non-zero, otherwise
# exits with status 1
# All other arguments are ignored
# Example: csih_error_multi "missing file" "see documentation"
# NEVER RETURNS
# ======================================================================
csih_error_multi()
{
local errorcode=$?
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
if ((errorcode == 0))
then
errorcode=1
fi
while test $# -gt 1
do
echo -e "${_csih_ERROR_STR} ${1}"
shift
done
echo -e "${_csih_ERROR_STR} ${1:-no error message provided}"
exit ${errorcode};
} # === End of csih_error_multi() === #
readonly -f csih_error_multi
# ======================================================================
# Routine: csih_error_recoverable
# Prints the supplied errormessage, and propagates the $? value
# Example: csih_error_recoverable "an error message"
# ======================================================================
csih_error_recoverable()
{
local errorcode=$?
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_ERROR_STR} ${1}"
$_csih_trace
return $errorcode
} # === End of csih_error_recoverable() === #
readonly -f csih_error_recoverable
# ======================================================================
# Routine: csih_warning
# Prints the supplied warning message
# Example: csih_warning "replacing default file foo"
# ======================================================================
csih_warning()
{
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_WARN_STR} ${1}"
$_csih_trace
} # === End of csih_warning() === #
readonly -f csih_warning
# ======================================================================
# Routine: csih_inform
# Prints the supplied informational message
# Example: csih_inform "beginning dependency analysis..."
# ======================================================================
csih_inform()
{
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_INFO_STR} ${1}"
$_csih_trace
} # === End of csih_inform() === #
readonly -f csih_inform
# ======================================================================
# Routine: csih_bug
# Prints the supplied warning message and increase bug counter
# ======================================================================
csih_bug()
{
let _bug_counter++
set +x # don't trace this, but we are interested in who called
csih_stacktrace # we'll see the arguments in the next statement
echo -e "${_csih_WARN_STR} ${1}"
$_csih_trace
} # === End of csih_bug() === #
readonly -f csih_bug
# ======================================================================
# Routine: next_month
# Print next month
# ======================================================================
next_month()
{
let -i _year=10#$(date +%Y)
let -i _month=10#$(date +%m)
if (( _month == 12 )) ; then
let _year++
let _month=1
else
let _month++
fi
if (( _month > 9 )) ; then
month="${_month}"
else
month="0${_month}"
fi
echo -e "${_year}-${month}-01"
} # === End of next_month() === #
readonly -f next_month
# ======================================================================
# Initial setup, default values, etc. PART 2
#
# This part of the setup has to build pyarmor test enviroments.
#
# ======================================================================
csih_inform "Python is $PYTHON"
csih_inform "Tested Package: $pkgfile"
csih_inform "Make workpath ${workpath}"
rm -rf ${workpath}
mkdir -p ${workpath} || csih_error "Make workpath FAILED"
cd ${workpath}
[[ ${pkgfile} == *.zip ]] && unzip ${pkgfile} > /dev/null 2>&1
[[ ${pkgfile} == *.tar.bz2 ]] && tar xjf ${pkgfile}
cd pyarmor-$version || csih_error "Invalid pyarmor package file"
# From pyarmor 3.5.1, main scripts are moved to src
[[ -d src ]] && mv src/* ./
# From pyarmor 5.3.3, license.lic is renamed as license.tri
[[ -f license.lic ]] || cp license.tri license.lic
tar xzf ${datafile} || csih_error "Extract data files FAILED"
cp -a ../../data/package ./ || csih_error "Copy package files FAILED"
cp ../../data/project.zip ./ && \
cp ../../data/foo.zip ./ && \
cp ../../data/foo-key.zip ./ || csih_error "Copy capsule files FAILED"
# From pyarmor v5.7.2, pyarmor-deprecated.py has been removed from source package
cp ../../../src/pyarmor-deprecated.py .|| csih_error "Copy pyarmor-deprecated.py FAILED"
# From pyarmor 4.5.4, platform name is renamed
if [[ -d platforms/windows32 ]] ; then
csih_inform "Restore the name of platforms"
(cd platforms;
mv windows32 win32;
mv windows64 win_amd64;
mv linux32 linux_i386;
mv linux64 linux_x86_64;
mv darwin64 macosx_x86_64;)
fi
# From pyarmor 5.7.5, platform name is changed
if [[ -d platforms/windows ]] ; then
csih_inform "Restore the name of platforms"
(cd platforms;
mv windows/x86 win32;
mv windows/x86_64 win_amd64;
mv linux/x86 linux_i386;
mv linux/x86_64 linux_x86_64;
mv darwin/x86_64 macosx_x86_64;)
fi
PYARMOR="$PYTHON pyarmor-deprecated.py"
[[ -f pyarmor-deprecated.py ]] || csih_error "No pyarmor-deprecated.py found"
csih_inform "PYARMOR is $PYARMOR"
csih_inform "Prepare for testing"
echo ""
# ======================================================================
# Test functions in normal license. PART 3
#
# ======================================================================
echo ""
echo "-------------------- Start Normal License Test --------------------"
echo ""
#
# Command: capsule
#
echo ""
csih_inform "Test command: capsule"
echo ""
csih_inform "Case 1.1: show help and import pytransform"
$PYARMOR --help >result.log 2>&1 \
|| csih_bug "Case 1.1 FAILED"
[[ -f _pytransform.so ]] \
|| [[ -f _pytransform.dll ]] \
|| [[ -f _pytransform.dylib ]] \
|| csih_error "Case 1.1 FAILED: no pytransform extension found"
#
# From PyArmor 5.6, the capsule could not be generated.
#
# csih_inform "Case 1.2: generate anonymous capsule"
# $PYARMOR capsule >result.log 2>&1 \
# || csih_bug "Case 1.2 FAILED: return non-zero code"
# [[ -f project.zip ]] \
# || csih_bug "Case 1.2 FAILED: no project.zip found"
# csih_inform "Case 1.3: generate named capsule foo.zip"
# $PYARMOR capsule foo >result.log 2>&1 \
# || csih_bug "Case 1.3 FAILED: return non-zero code"
# [[ -f foo.zip ]] \
# || csih_bug "Case 1.3 FAILED: no foo.zip found"
# csih_inform "Case 1.4: generate capsule with output path"
# $PYARMOR capsule -O dist foo2 >result.log 2>&1 \
# || csih_bug "Case 1.4 FAILED: return non-zero code"
# [[ -f dist/foo2.zip ]] \
# || csih_bug "Case 1.4 FAILED: no dist/foo2.zip found"
# csih_inform "Case 1.5: generate capsule for next tests"
# $PYARMOR capsule foo-key >result.log 2>&1 \
# || csih_bug "Case 1.5 FAILED: return non-zero code"
# [[ -f foo-key.zip ]] \
# || csih_bug "Case 1.5 FAILED: no foo-key.zip found"
#
# Command: encrypt
#
echo ""
csih_inform "Test command: encrypt"
echo ""
csih_inform "Case 2.1: encrypt script"
$PYARMOR encrypt --mode=0 -C project.zip -O dist \
foo.py >result.log 2>&1 \
|| csih_bug "Case 2.1 FAILED: return non-zero code"
[[ -f dist/foo.py${extchar} ]] \
|| csih_bug "Case 2.1 FAILED: no dist/foo.py${extchar} found"
csih_inform "Case 2.2: encrypt script with named capsule"
$PYARMOR encrypt --mode=0 --with-capsule=project.zip \
--output=build main.py foo.py >result.log 2>&1 \
|| csih_bug "Case 2.2 FAILED: return non-zero code"
[[ -f build/main.py${extchar} ]] \
|| csih_bug "Case 2.2 FAILED: no build/main.py${extchar} found"
[[ -f build/foo.py${extchar} ]] \
|| csih_bug "Case 2.2 FAILED: no build/foo.py${extchar} found"
csih_inform "Case 2.3: encrypt script with key capsule"
$PYARMOR encrypt --mode=0 --with-capsule=foo-key.zip \
--output=foo-key foo.py >result.log 2>&1 \
|| csih_bug "Case 2.3 FAILED: return non-zero code"
[[ -f foo-key/foo.py${extchar} ]] \
|| csih_bug "Case 2.3 FAILED: no build-key/foo.py${extchar} found"
csih_inform "Case 2.4: encrypt scripts in place"
mkdir -p test_in_place/a
cp foo.py test_in_place/foo.py
cp foo.py test_in_place/a/foo.py
echo "test_in_place/foo.py" > filelist.txt
echo "test_in_place/a/foo.py" >> filelist.txt
$PYARMOR encrypt --mode=0 --with-capsule=foo-key.zip \
--output=foo-key -i @filelist.txt >result.log 2>&1 \
|| csih_bug "Case 2.4 FAILED: return non-zero code"
[[ -f test_in_place/foo.py${extchar} ]] || [[ -f test_in_place/a/foo.py${extchar} ]] \
|| csih_bug "Case 2.4 FAILED: no in-place encrypted foo.py${extchar} found"
csih_inform "Case 2.5: verify co_filename of code object in encrypt script"
cat <<EOF > co_hello.py
i = 1 / 0.
EOF
$PYARMOR encrypt --mode=3 -C project.zip -O test_filename co_hello.py >result.log 2>&1
if [[ -f test_filename/co_hello.pyc ]] ; then
cd test_filename
cat <<EOF > main.py
import pyimcore
import co_hello
EOF
$PYTHON main.py >result.log 2>&1
grep -q 'File "<frozen co_hello>"' result.log || csih_bug "Case 2.5 FAILED: script name isn't right"
cd ..
else
csih_bug "Case 2.5 FAILED: no encrypted script found"
fi
csih_inform "Case 2.6: verify constant is obfucated"
# Generate license which disable restrict mode, "A" == 0x41
$PYARMOR license --with-capsule=project.zip -O license-no-restrict.txt "*FLAGS:A*CODE:TestCode" >result.log 2>&1
cat << EOF > co_consts.py
'''Module comment'''
title = "Hello"
def hello(arg="first"):
'''Function comment'''
name = "jondy"
users = [ "bob", "time", 3]
return "%s,%s,%s" % (name, arg, users[0])
EOF
$PYARMOR encrypt --mode=5 -C project.zip -O test_const co_consts.py >result.log 2>&1
if [[ -f test_const/co_consts.pyc ]] ; then
cd test_const
cp ../license-no-restrict.txt license.lic
grep -q "\(Module comment\|Hello\|Function comment\|jondy\|bob\|time\)" co_consts.pyc \
&& csih_bug "Case 2.6 FAILED: co_consts still in clear text"
cat <<EOF > main.py
import pyimcore
import sys
import co_consts
sys.stdout.write("%s:%s:%s" % (co_consts.title, co_consts.__doc__, co_consts.hello("second")))
EOF
$PYTHON main.py >result.log 2>&1 || csih_bug "Case 2.6 FAILED: run script return non-zero code"
grep -q "Hello:Module comment:jondy,second,bob" result.log \
|| csih_bug "Case 2.6 FAILED: python script returns unexpected result"
cd ..
else
csih_bug "Case 2.6 FAILED: no test_consts/co_consts.pyc found"
fi
csih_inform "Case 2.7: verify mode 6 works"
$PYARMOR encrypt --mode=6 -C project.zip -O test_mode6 co_consts.py >result.log 2>&1
if [[ -f test_mode6/co_consts.pyc ]] ; then
cd test_mode6
cp ../license-no-restrict.txt license.lic
grep -q "\(Module comment\|Hello\|Function comment\|jondy\|time\)" co_consts.pyc \
&& csih_bug "Case 2.7 FAILED: co_consts still in clear text"
cat <<EOF > main.py
import pyimcore
import sys
import co_consts
sys.stdout.write("%s:%s:%s" % (co_consts.title, co_consts.__doc__, co_consts.hello("second")))
EOF
$PYTHON main.py >result.log 2>&1 || csih_bug "Case 2.7 FAILED: run script return non-zero code"
grep -q "Hello:Module comment:jondy,second,bob" result.log \
|| csih_bug "Case 2.7 FAILED: python script returns unexpected result"
cd ..
else
csih_bug "Case 2.7 FAILED: no test_mode6/co_consts.pyc found"
fi
csih_inform "Case 2.8: verify mode 7 works"
$PYARMOR encrypt --mode=7 -C project.zip -O test_mode7 co_consts.py >result.log 2>&1
if [[ -f test_mode7/co_consts.py ]] ; then
cd test_mode7
cp ../license-no-restrict.txt license.lic
grep -q "\(Module comment\|Hello\|Function comment\|jondy\|bob\|time\)" co_consts.py \
&& csih_bug "Case 2.8 FAILED: co_consts still in clear text"
cat <<EOF > main.py
import pyimcore
import sys
import co_consts
sys.stdout.write("%s:%s:%s" % (co_consts.title, co_consts.__doc__, co_consts.hello("second")))
EOF
$PYTHON main.py >result.log 2>&1 || csih_bug "Case 2.8 FAILED: run script return non-zero code"
grep -q "Hello:Module comment:jondy,second,bob" result.log \
|| csih_bug "Case 2.8 FAILED: python script returns unexpected result"
cd ..
else
csih_bug "Case 2.8 FAILED: no test_mode8/co_consts.py found"
fi
csih_inform "Case 2.9: verify mode 8 works"
$PYARMOR encrypt --mode=8 -C project.zip -O test_mode8 co_consts.py >result.log 2>&1
if [[ -f test_mode8/co_consts.py ]] ; then
cd test_mode8
cp ../license-no-restrict.txt license.lic
grep -q "\(Module comment\|Hello\|Function comment\|jondy\|bob\|time\)" co_consts.py \
&& csih_bug "Case 2.9 FAILED: co_consts still in clear text"
cat <<EOF > main.py
import pyimcore
import sys
import co_consts
sys.stdout.write("%s:%s:%s" % (co_consts.title, co_consts.__doc__, co_consts.hello("second")))
EOF
$PYTHON main.py >result.log 2>&1 || csih_bug "Case 2.9 FAILED: run script return non-zero code"
grep -q "Hello:Module comment:jondy,second,bob" result.log \
|| csih_bug "Case 2.9 FAILED: python script returns unexpected result"
cd ..
else
csih_bug "Case 2.9 FAILED: no test_mode8/co_consts.py found"
fi
csih_inform "Case 2.10: obfuscate empty script with mode 7"
cat <<EOF > empty.py
EOF
$PYARMOR encrypt --mode=7 -C project.zip -O test_mode7 empty.py >result.log 2>&1
if [[ ! -f test_mode7/empty.py ]] ; then
csih_bug "Case 2.10 FAILED: no test_mode7/empty.py found"
fi
csih_inform "Case 2.11: obfuscate empty script with mode 8"
$PYARMOR encrypt --mode=8 -C project.zip -O test_mode8 empty.py >result.log 2>&1
if [[ ! -f test_mode8/empty.py ]] ; then
csih_bug "Case 2.11 FAILED: no test_mode8/empty.py found"
fi
csih_inform "Case 2.12: test main script with mode 8"
cp empty.py empty2.py
$PYARMOR encrypt --mode=8 -C project.zip -O test_mode8 -m empty2 empty2.py >result.log 2>&1
if [[ -f test_mode8/empty2.py ]] ; then
grep -q "import pyimcore" test_mode8/empty2.py || csih_bug "Case 2.12 FAILED: no main entry generated"
else
csih_bug "Case 2.12 FAILED: no test_mode8/empty2.py found"
fi
csih_inform "Case 2.13: test obfuscate scripts with mode 9, 10, 11, 12, 13, 14"
for mode in 9 10 11 12 13 14 ; do
$PYARMOR encrypt --mode=$mode -C project.zip -O test_mode$mode foo.py >result.log 2>&1
if [[ -f test_mode${mode}/foo.py ]] ; then
grep -q "__pyarmor__" test_mode${mode}/foo.py \
|| csih_bug "Case 2.13 FAILED: no __pyarmor__ found in obfuscated script for mode $mode"
else
csih_bug "Case 2.13 FAILED: no test_mode${mode}/foo.py found"
fi
done
#
# Import encrypted module and run encrypted scripts
#
echo ""
csih_inform "Test import and run encrypted scripts"
echo ""
csih_inform "Case 3.1: import encrypted module"
(cd dist ;
cp ../startup.py ./ ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.1 FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.1 FAILED: python script returns unexpected result"
csih_inform "Case 3.1T: import encrypted module in other thread"
cat <<EOF > dist/t_startup.py
import sys
import pyimcore
import foo
import threading
def target():
sys.stderr.write("foo.hello(2) = %d\n" % foo.hello(2))
threading.Thread(target=target).start()
EOF
(cd dist ;
$PYTHON t_startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.1T FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.1T FAILED: python script returns unexpected result"
csih_inform "Case 3.2: run encrypted script"
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 3.2 FAILED: return non-zero code"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 3.2 FAILED: python script returns unexpected result"
csih_inform "Case 3.3: import encrypted module with module key"
(cd foo-key ;
cp ../startup.py ./ ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.3 FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.3 FAILED: python script returns unexpected result"
csih_inform "Case 3.4: run encrypted code from __future__"
echo "from __future__ import with_statement" > foo-future.py
cat foo.py >> foo-future.py
$PYARMOR encrypt --mode=0 --with-capsule=foo-key.zip \
--output=foo-future foo-future.py >result.log 2>&1 \
|| csih_bug "Case 3.4 FAILED: return non-zero code"
(cd foo-future ;
cp ../startup.py ./ ;
mv foo-future.pye foo.pye ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.4 FAILED: return non-zero code"
)
csih_inform "Case 3.5: import encrypted code with mode 1"
$PYARMOR encrypt --with-capsule=project.zip --mode=1 \
--output=build_m1 foo.py >result.log 2>&1 \
|| csih_bug "Case 3.5 FAILED: return non-zero code"
(cd build_m1 ;
cp ../startup.py ./ ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.5 FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.5 FAILED: python script returns unexpected result"
csih_inform "Case 3.6: import encrypted code with mode 2"
$PYARMOR encrypt --with-capsule=project.zip --mode=2 \
--output=build_m2 foo.py >result.log 2>&1 \
|| csih_bug "Case 3.6 FAILED: return non-zero code"
(cd build_m2 ;
cp ../startup.py ./ ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.6 FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.6 FAILED: python script returns unexpected result"
csih_inform "Case 3.7: import encrypted package"
$PYARMOR encrypt --mode=0 --with-capsule=project.zip --in-place \
--output=build_pkg package/*.py >result.log 2>&1 \
|| csih_bug "Case 3.7 FAILED: return non-zero code"
(cp -a package build_pkg;
cd build_pkg && rm package/*.py ;
cp ../startup.py ./ ;
sed -i -e 's/import foo/from package import foo/g' startup.py ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.7 FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.7 FAILED: python script returns unexpected result"
csih_inform "Case 3.8: import encrypted code with mode 3"
$PYARMOR encrypt --with-capsule=project.zip --mode=3 \
--output=build_m3 foo.py >result.log 2>&1 \
|| csih_bug "Case 3.8 FAILED: return non-zero code"
(cd build_m3 ;
cp ../startup.py ./ ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 3.8 FAILED: return non-zero code"
)
grep -q "foo.hello(2) = 7" result.log \
|| csih_bug "Case 3.8 FAILED: python script returns unexpected result"
csih_inform "Case 3.9: run encrypted code with mode 3"
$PYARMOR encrypt --with-capsule=project.zip --mode=3 \
--output=build_m3a -m main:start.py main.py foo.py >result.log 2>&1 \
|| csih_bug "Case 3.9 FAILED: return non-zero code"
(cd build_m3a ;
$PYTHON start.py >../result.log 2>&1 \
|| csih_bug "Case 3.9 FAILED: return non-zero code"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 3.9 FAILED: python script returns unexpected result"
#
# Cross publish
#
echo ""
csih_inform "Test cross publish"
echo ""
csih_inform "Case 4.1: cross publish for windows"
$PYARMOR encrypt --mode=0 \
--output=others \
--plat-name=win_amd64 \
foo.py >result.log 2>&1 \
|| csih_bug "Case 4.1 FAILED: return non-zero code"
[[ -f others/foo.py${extchar} ]] \
|| csih_bug "Case 4.1 FAILED: no others/foo.py${extchar} found"
[[ -f others/_pytransform.dll ]] \
|| csih_bug "Case 4.1 FAILED: no others/_pytransform.dll found"
csih_inform "Case 4.2: cross publish for linux"
$PYARMOR encrypt --mode=0 \
--output=others \
--plat-name=linux_x86_64 \
main.py >result.log 2>&1 \
|| csih_bug "Case 4.2 FAILED: return non-zero code"
[[ -f others/main.py${extchar} ]] \
|| csih_bug "Case 4.2 FAILED: no others/main.py${extchar} found"
[[ -f others/_pytransform.so ]] \
|| csih_bug "Case 4.2 FAILED: no others/_pytransform.so found"
#
# Command: license
#
echo ""
csih_inform "Test command: license"
echo ""
csih_inform "Case 5.1: generate license"
$PYARMOR license --with-capsule=project.zip \
-O license.txt TESTCODE >result.log 2>&1 \
|| csih_bug "Case 5.1 FAILED: return non-zero code"
[[ -f license.txt ]] \
|| csih_bug "Case 5.1 FAILED: no license.txt found"
cp license.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.1 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.1 FAILED: python script returns unexpected result"
csih_inform "Case 5.2: generate license bind to fixed machine"
$PYARMOR license --with-capsule=project.zip \
--bind-disk="${harddisk_sn}" -O license.txt >result.log 2>&1 \
|| csih_bug "Case 5.2 FAILED: return non-zero code"
[[ -f license.txt ]] \
|| csih_bug "Case 5.2 FAILED: no license.txt found"
cp license.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.2 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.2 FAILED: python script returns unexpected result"
csih_inform "Case 5.3: generate period license bind to fixed machine"
$PYARMOR license --with-capsule=project.zip -e $(next_month) \
--bind-disk="${harddisk_sn}" -O license1.txt >result.log 2>&1 \
|| csih_bug "Case 5.3 FAILED: return non-zero code"
[[ -f license1.txt ]] \
|| csih_bug "Case 5.3 FAILED: no license.txt found"
cp license1.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.3 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.3 FAILED: python script returns unexpected result"
csih_inform "Case 5.4: generate expired license"
$PYARMOR license --with-capsule=project.zip -e 2014-01-01 \
-O license2.txt whoami@unknown.com >result.log 2>&1 \
|| csih_bug "Case 5.4 FAILED: return non-zero code"
[[ -f license2.txt ]] \
|| csih_bug "Case 5.4 FAILED: no license.txt found"
cp license2.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
&& csih_bug "Case 5.4 FAILED: return zero code when license is expired"
)
grep -q "License is expired" result.log \
|| csih_bug "Case 5.4 FAILED: expired license still work"
csih_inform "Case 5.5: generate bind file license"
# --bind-file has been changed from v6.1.0
if false; then
$PYARMOR license --with-capsule=project.zip --bind-file id_rsa \
-O license3.txt my_id_rsa >result.log 2>&1 \
|| csih_bug "Case 5.5 FAILED: return non-zero code"
[[ -f license3.txt ]] \
|| csih_bug "Case 5.5 FAILED: no license.txt found"
cp license3.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
cp ../id_rsa my_id_rsa ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.5 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.5 FAILED: python script returns unexpected result"
fi
csih_inform "Case 5.6: generate bind file license with expired date"
# --bind-file has been changed from v6.1.0
if false; then
$PYARMOR license --with-capsule=project.zip -e $(next_month) \
--bind-file id_rsa -O license4.txt my_id_rsa >result.log 2>&1 \
|| csih_bug "Case 5.6 FAILED: return non-zero code"
[[ -f license4.txt ]] \
|| csih_bug "Case 5.6 FAILED: no license.txt found"
cp license4.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
cp ../id_rsa my_id_rsa ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.6 FAILED: return zero code when license is expired"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.6 FAILED: python script returns unexpected result"
fi
csih_inform "Case 5.7: generate license bind to mac address"
$PYARMOR license --with-capsule=project.zip \
--bind-mac="${ifmac_address}" -O license-ifmac.txt >result.log 2>&1 \
|| csih_bug "Case 5.7 FAILED: return non-zero code"
[[ -f license-ifmac.txt ]] \
|| csih_bug "Case 5.7 FAILED: no license-ifmac.txt found"
cp license-ifmac.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.7 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.7 FAILED: python script returns unexpected result"
csih_inform "Case 5.7-1: generate license bind to other mac address"
$PYARMOR license --with-capsule=project.zip \
--bind-mac="xx:yy" -O license-ifmac2.txt >result.log 2>&1 \
|| csih_bug "Case 5.7-1 FAILED: return non-zero code"
[[ -f license-ifmac2.txt ]] \
|| csih_bug "Case 5.7-1 FAILED: no license-ifmac2.txt found"
cp license-ifmac2.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
&& csih_bug "Case 5.7-1 FAILED: return 0 when run script by invalid license"
)
grep -q "License is not for this machine" result.log \
|| csih_bug "Case 5.7-1 FAILED: no failed message found"
csih_inform "Case 5.8: generate license bind to ip address"
$PYARMOR license --with-capsule=project.zip \
--bind-ip="${ifip_address}" -O license-ifip.txt >result.log 2>&1 \
|| csih_bug "Case 5.8 FAILED: return non-zero code"
[[ -f license-ifip.txt ]] \
|| csih_bug "Case 5.8 FAILED: no license-ifip.txt found"
cp license-ifip.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.8 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.8 FAILED: python script returns unexpected result"
csih_inform "Case 5.8-1: generate license bind to other ip address"
$PYARMOR license --with-capsule=project.zip \
--bind-ip="192.188.2.2" -O license-ifip2.txt >result.log 2>&1 \
|| csih_bug "Case 5.8-1 FAILED: return non-zero code"
[[ -f license-ifip2.txt ]] \
|| csih_bug "Case 5.8-1 FAILED: no license-ifip2.txt found"
cp license-ifip2.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
&& csih_bug "Case 5.8-1 FAILED: return 0 when run script by invalid license"
)
grep -q "License is not for this machine" result.log \
|| csih_bug "Case 5.8-1 FAILED: no failed message found"
csih_inform "Case 5.8-2: generate license bind to both mac and ip address"
$PYARMOR license --with-capsule=project.zip \
--bind-mac="${ifmac_address}" --bind-ip="${ifip_address}" -O license-macip.txt >result.log 2>&1 \
|| csih_bug "Case 5.8-2 FAILED: return non-zero code"
[[ -f license-macip.txt ]] \
|| csih_bug "Case 5.8-2 FAILED: no license-macip.txt found"
cp license-macip.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
|| csih_bug "Case 5.8-2 FAILED: return non-zero code when run script"
)
grep -q "Result is 10" result.log \
|| csih_bug "Case 5.8-2 FAILED: python script returns unexpected result"
csih_inform "Case 5.9-1: generate license bind to other domain name"
$PYARMOR license --with-capsule=project.zip \
--bind-domain="snsoffice.com" -O license-domain2.txt >result.log 2>&1 \
|| csih_bug "Case 5.9-1 FAILED: return non-zero code"
[[ -f license-domain2.txt ]] \
|| csih_bug "Case 5.9-1 FAILED: no license-domain.txt found"
cp license-domain2.txt build/license.lic
(cd build ;
cp ../bootstrap.py ./ ;
$PYTHON bootstrap.py >../result.log 2>&1 \
&& csih_bug "Case 5.9-1 FAILED: return 0 when run script by invalid license"
)
grep -q "License is not for this machine" result.log \
|| csih_bug "Case 5.9-1 FAILED: no failed message found"
#
# AST/PYC Hole
#
echo ""
csih_inform "Test crack: ast node / pyc"
echo ""
$PYARMOR encrypt --mode=0 --with-capsule=project.zip \
--output=hole sky.py >result.log 2>&1 \
|| csih_bug "Case 6 FAILED: return non-zero code"
[[ -f hole/sky.py${extchar} ]] \
|| csih_bug "Case 6 FAILED: no hole/sky.py${extchar} found"
csih_inform "Case 6.1: run encrypted func_code"
(cd hole ;
echo "import pyimcore
import pytransform
pytransform.exec_file('sky.py${extchar}')" > startup.py ;
$PYTHON startup.py >../result.log 2>&1 \
|| csih_bug "Case 6.1 FAILED: return non-zero code"
)
grep -q "star 3 is 9" result.log \
|| csih_bug "Case 6.1 FAILED: can not run encrypted func_code"
csih_inform "Case 6.2: crack encrypted func_code"