sasl-scram-rfc-tests.el 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ;;; sasl-scram-rfc-tests.el --- tests for SCRAM-SHA-1 -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2014-2016 Free Software Foundation, Inc.
  3. ;; Author: Magnus Henoch <magnus.henoch@gmail.com>
  4. ;; GNU Emacs is free software: you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; GNU Emacs is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Test cases from RFC 5802.
  16. ;;; Code:
  17. (require 'sasl)
  18. (require 'sasl-scram-rfc)
  19. (ert-deftest sasl-scram-sha-1-test ()
  20. ;; The following strings are taken from section 5 of RFC 5802.
  21. (let ((client
  22. (sasl-make-client (sasl-find-mechanism '("SCRAM-SHA-1"))
  23. "user"
  24. "imap"
  25. "localhost"))
  26. (data "r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096")
  27. (c-nonce "fyko+d2lbbFgONRv9qkxdawL")
  28. (sasl-read-passphrase
  29. (lambda (_prompt) (copy-sequence "pencil"))))
  30. (sasl-client-set-property client 'c-nonce c-nonce)
  31. (should
  32. (equal
  33. (sasl-scram-sha-1-client-final-message client (vector nil data))
  34. "c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts="))
  35. ;; This should not throw an error:
  36. (sasl-scram-sha-1-authenticate-server client (vector nil "v=rmF9pqV8S7suAoZWja4dJRkFsKQ=
  37. "))))
  38. ;;; sasl-scram-rfc-tests.el ends here