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