44 lines
1.5 KiB
Common Lisp
44 lines
1.5 KiB
Common Lisp
(in-package :passepartout)
|
|
|
|
(defun validator-protocol-check (msg)
|
|
"Enforces structural schema compliance on protocol messages."
|
|
(validate-communication-protocol-schema msg))
|
|
|
|
(defskill :passepartout-security-validator
|
|
:priority 95
|
|
:trigger (lambda (ctx) (declare (ignore ctx)) t)
|
|
:deterministic (lambda (action ctx)
|
|
(declare (ignore ctx))
|
|
(handler-case
|
|
(progn (validator-protocol-check action) action)
|
|
(error (c)
|
|
(list :type :LOG :payload (list :level :error :text (format nil "Protocol Violation: ~a" c)))))))
|
|
|
|
(eval-when (:compile-toplevel :load-toplevel :execute)
|
|
(ql:quickload :fiveam :silent t))
|
|
|
|
(defpackage :passepartout-security-validator-tests
|
|
(:use :cl :fiveam :passepartout)
|
|
(:export #:validator-suite))
|
|
|
|
(in-package :passepartout-security-validator-tests)
|
|
|
|
(def-suite validator-suite :description "Verification of the Protocol Validator")
|
|
(in-suite validator-suite)
|
|
|
|
(test test-validator-passes-valid-message
|
|
"Contract 1: a valid message passes protocol check."
|
|
(let ((msg '(:type :EVENT :payload (:sensor :heartbeat))))
|
|
(handler-case
|
|
(progn
|
|
(validator-protocol-check msg)
|
|
(pass))
|
|
(error (c)
|
|
(fail "Validator rejected a valid message: ~a" c)))))
|
|
|
|
(test test-validator-rejects-missing-type
|
|
"Contract 1: a message missing :type is rejected."
|
|
(let ((msg '(:payload (:sensor :heartbeat))))
|
|
(signals error
|
|
(validator-protocol-check msg))))
|