(define-test-module (test module sph storage dg authentication) (import (sph random-data) (sph storage dg) (rnrs bytevectors) (sph list) (test helper sph storage dg) (sph storage dg authentication)) (define-test (dg-auth-authenticate) (dg-txn-call-write (l (txn) (let* ( (size-before (test-helper-dg-count-btree-entries)) (entities (dg-id-create txn 2)) (contexts (dg-id-create txn 2)) (custom-values (list (list "123" (random-bytevector 3)) (list " "))) (valid-hash? (l (a) (and (bytevector? a) (= (bytevector-length a) dg-auth-hash-size-octets) (not (every zero? (bytevector->u8-list a)))))) (hashes (map (l (a b c) (apply dg-auth-authorise txn dg-auth-cost-low #f a b c)) contexts entities custom-values))) (assert-and (assert-true "authorise result" (and (every valid-hash? hashes) (not (apply equal? hashes)))) (assert-true "by hash" (equal? (list #t #f #f #f #f #f #f #t) (map integer? (produce (l (a b c) (apply dg-auth-authenticate-hash txn a b c)) contexts hashes custom-values)))) (assert-true "by-entity" (equal? (list #t #f #f #f #f #f #f #t) (map valid-hash? (produce (l (a b c) (apply dg-auth-authenticate-entity txn a b c)) contexts entities custom-values))))))))) (define-procedure-tests tests (dg-auth-authenticate)) (l (settings) (let* ( (settings (test-helper-dg-default-test-settings settings)) (result (test-execute-procedures settings tests))) (test-helper-dg-database-exit) result)))