From 09af9fc40b695a22cb6a3f59d61b3c23aed6fa79 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Sat, 24 Aug 2019 22:49:48 -0400 Subject: [PATCH] [core] Add "unit" and functional tests for archvie verification --- tests/core/core-configuration-layer-ftest.el | 45 +++++++++++++++++- tests/core/core-configuration-layer-utest.el | 41 ++++++++++++++++ .../core/data/signed-test-stable-elpa.tar.gz | Bin 0 -> 2248 bytes .../data/signed-test-stable-elpa.tar.gz.sig | Bin 0 -> 336 bytes tests/core/data/test-stable-elpa.tar.gz | Bin 0 -> 712 bytes 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 tests/core/data/signed-test-stable-elpa.tar.gz create mode 100644 tests/core/data/signed-test-stable-elpa.tar.gz.sig create mode 100644 tests/core/data/test-stable-elpa.tar.gz diff --git a/tests/core/core-configuration-layer-ftest.el b/tests/core/core-configuration-layer-ftest.el index 752a99167..be460860f 100644 --- a/tests/core/core-configuration-layer-ftest.el +++ b/tests/core/core-configuration-layer-ftest.el @@ -46,5 +46,48 @@ (should (eq 'spacemacs-base (third configuration-layer--used-layers))))) ;; --------------------------------------------------------------------------- -;; Lazy installation of layers +;; configuration-layer//stable-elpa-verify-archive ;; --------------------------------------------------------------------------- + +(ert-deftest test-stable-elpa-verify-archive--verification-ok () + (cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file) + (lambda () + (concat spacemacs-test-directory + "core/data/signed-test-stable-elpa.tar.gz"))) + ((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file) + (lambda () + (concat spacemacs-test-directory + "core/data/signed-test-stable-elpa.tar.gz.sig"))) + ((symbol-function 'configuration-layer//stable-elpa-ask-to-continue) + (lambda (x) + (message "Verification Error: %s" x) + nil)) + ((symbol-function 'configuration-layer//error) + (lambda (x) + (message "Fatal Error: %s" x) + nil)) + ((symbol-function 'message) 'ignore)) + (should (equal t (configuration-layer//stable-elpa-verify-archive))))) + +(ert-deftest test-stable-elpa-verify-archive--verification-failed () + (let (verification-error) + (cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file) + (lambda () + (concat spacemacs-test-directory + "core/data/test-stable-elpa.tar.gz"))) + ((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file) + (lambda () + (concat spacemacs-test-directory + "core/data/signed-test-stable-elpa.tar.gz.sig"))) + ((symbol-function 'configuration-layer//stable-elpa-ask-to-continue) + (lambda (x) + (setq verification-error x) + nil)) + ((symbol-function 'configuration-layer//error) + (lambda (x) + (message "Fatal Error: %s" x) + nil)) + ((symbol-function 'message) 'ignore)) + (should (and (null (configuration-layer//stable-elpa-verify-archive)) + (string-match-p "^Verification failed!.*" + verification-error)))))) diff --git a/tests/core/core-configuration-layer-utest.el b/tests/core/core-configuration-layer-utest.el index 0d300142b..df8a94fda 100644 --- a/tests/core/core-configuration-layer-utest.el +++ b/tests/core/core-configuration-layer-utest.el @@ -3016,3 +3016,44 @@ :reqs '((foo 7))))) (let ((patched-pkg (configuration-layer//package-install-org 'identity pkg))) (should (equal pkg patched-pkg))))) + +;; --------------------------------------------------------------------------- +;; configuration-layer//stable-elpa-verify-archive +;; --------------------------------------------------------------------------- + +(ert-deftest test-stable-elpa-verify-archive--archive-not-found-is-fatal-error () + (mocker-let + ((configuration-layer//stable-elpa-tarball-local-file + nil ((:record-cls 'mocker-stub-record + :output + (concat spacemacs-test-directory + "core/data/not-found.tar.gz") + :occur 1))) + (configuration-layer//stable-elpa-tarball-local-sign-file + nil ((:record-cls 'mocker-stub-record + :output + (concat spacemacs-test-directory + "core/data/stable-elpa.sig") + :occur 1))) + (configuration-layer//error + (msg &rest args) ((:record-cls 'mocker-stub-record :occur 1)))) + (should (null (configuration-layer//stable-elpa-verify-archive))))) + + +(ert-deftest test-stable-elpa-verify-archive--signature-not-found-is-fatal-error () + (mocker-let + ((configuration-layer//stable-elpa-tarball-local-file + nil ((:record-cls 'mocker-stub-record + :output + (concat spacemacs-test-directory + "core/data/signed-stable-elpa.tar.gz") + :occur 1))) + (configuration-layer//stable-elpa-tarball-local-sign-file + nil ((:record-cls 'mocker-stub-record + :output + (concat spacemacs-test-directory + "core/data/not-found.sig") + :occur 1))) + (configuration-layer//error + (msg &rest args) ((:record-cls 'mocker-stub-record :occur 1)))) + (should (null (configuration-layer//stable-elpa-verify-archive))))) diff --git a/tests/core/data/signed-test-stable-elpa.tar.gz b/tests/core/data/signed-test-stable-elpa.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..f08c7c8e1540f7980cc893790b70de475ae7ac06 GIT binary patch literal 2248 zcmV;(2sig1iwFR>>|tF11MON{iyJo-&a;1oIxn)pBYB%-1Iv<^z&yBqZJ{tAIlE3{ zx|gtaN&-WFdv(7{quEUAe4VcW4iHU-szy z?fmLTVYAs>zIg-q=ex_d;&bz}{LR0;+q}B~7q8#G-n_oNyx45O=7L??yaJmara=K; z*{GkGDyQ#vf9;PC*>7h*VDpMc0Q+I|>II2M6Mf^#A$-BWj?XzUfTLTE6a z+@|Op-b7E~DCw_ou`pqQIH5sLL+jm@ktElzV^%(h2OEou!w`K#YMMduXHgt<5y+~C zTJ&t5)|d-l+|@K5YnIsh691o~;lVt487iM)w#>{#PAW{Yh_=KrZ>0clE|&s^B9YT$ zv9fEakXQtp?s9K*J*)xkT9gMxvC;-@qvW|2-;{{j+;^M$Qx(i>H++* zdRV|g(tpmos;Ci9Vs{w%inGJMSVhRT&i?N3}cxq)me$4li!O~XbN8MQj}crE)HwuwCJv{uBrEL?>Ppj8 zOFNcS-KAqfzD$?PyPkvkWe{IAnlLMtNPJW6gP_Ds$t??5hK4lm*x`!Em=v+a>nw; zwQC51)@+}PtGyjLsf7l`pR-p8gu<24<|32p7B`4)~c!HW8a@lhZ7lWFeKC{<)F)eK;w_GMw5b%Vciv&BT87p>| zK(30R;ajg&z>=*Zqb(@)j!d)yp>3o#^0Fw82qOy|nilrDS?}^89nOMEo%&l`5ac~J z^V?op7ZaC^gQaNVouE-npBMQ7Vdof7Bi1$8CD6uiU91C^03npz3~TfZas2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ig new file mode 100644 index 0000000000000000000000000000000000000000..d4e50736853e940bce5cfbb63138232ec2cb713d GIT binary patch literal 336 zcmV-W0k8gv0Zjw|0SEv$79j*&jb}OM!44I8u3uKlJWo~X|azJNoVQFkGV{dH$3JDNHuUb59&1q`w76<(v*aS>Db5&bQ5@l&cl_WUO zPrj%{SGBnD;I)*-f1vq%(E|xO=}*!e8J+y)U8R}kXp-j2X+UDFnbs>HS=@up z3+RS0y7EFl5*7D;^zNpuhWnJORuU;9uHU}?2!PhZVr3p%UF0r)wW64nLs4cm@k3^p i1Obcd8=ECxUE2;Rv@NU{BnbMaDTI5%84(Jk=9S-KKbar^ literal 0 HcmV?d00001 diff --git a/tests/core/data/test-stable-elpa.tar.gz b/tests/core/data/test-stable-elpa.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..7609213fbc2aba8c14e9e8d5b47b32af33684c7c GIT binary patch literal 712 zcmV;(0yq61iwFR!>|tF11MOE`Z`v>v?Q?#`RUd+lmN=A;PL=YsXWsf!$-<;GjBHRU z5+*7|{_V4!lG-HUqeI#{e6Z|m`}oEV=O#BFfMglsq@`1Z_Iq z^JZxi*4TjSL6I9T5KB=^<4O z3H9sZFbua2^otQyQ~mNq?d(tt65URTAx7w1VY2hytrkale=A5HDBn{IwzvoQcs61u z`94$x`^We6XtovZ8$t}DhY_GqchD?cDXUQ-suDPCe^|FUsGqJ|HNbL0i@#LqQb?A7 z-1(8h1g?O)DTKU+4_T8&t{a((J|SKvUy=QWj0voA2ozY;~S$~3HsVH z>nUwsn*m9i7xP4m0W%w7oK-WU=4=S#L(0>#Awmx6RLh1CI!V-6A#sC;$Mx>Qx~C literal 0 HcmV?d00001