-
Notifications
You must be signed in to change notification settings - Fork 11
/
tests.lisp
123 lines (110 loc) · 4.99 KB
/
tests.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
(defpackage #:pzmq-test
(:use #:cl #:5am #:let-plus #:babel))
(in-package #:pzmq-test)
(def-suite :pzmq)
(in-suite :pzmq)
(test supported-version
(let+ (((major minor &ign) (pzmq:version)))
(is (or (= major 4)
(and (= major 3) (= minor 2))))))
(test request-response-string
(pzmq:with-sockets ((sender :req) (receiver :rep))
(pzmq:bind receiver "tcp://*:5555")
(pzmq:connect sender "tcp://localhost:5555")
(pzmq:send sender "")
(is (string= "" (pzmq:recv-string receiver)))))
(test request-response-octets
(pzmq:with-sockets ((sender :req) (receiver :rep))
(pzmq:bind receiver "tcp://*:5555")
(pzmq:connect sender "tcp://localhost:5555")
(pzmq:send sender "")
(is (equalp (string-to-octets "") (pzmq:recv-octets receiver)))))
(test response-request-string
(pzmq:with-sockets ((sender :req) (receiver :rep))
(pzmq:bind receiver "tcp://*:5555")
(pzmq:connect sender "tcp://localhost:5555")
(bt:make-thread (lambda () (sleep 0.01) (pzmq:send sender "")))
(is (string= "" (pzmq:recv-string receiver)))))
(test response-request-octets
(pzmq:with-sockets ((sender :req) (receiver :rep))
(pzmq:bind receiver "tcp://*:5555")
(pzmq:connect sender "tcp://localhost:5555")
(bt:make-thread (lambda () (sleep 0.01) (pzmq:send sender "")))
(is (equalp (string-to-octets "") (pzmq:recv-octets receiver)))))
(test sockopt
(pzmq:with-socket s :req
(is (= -1 (pzmq:getsockopt s :tcp-keepalive)))
(is (zerop (pzmq:setsockopt s :tcp-keepalive 0)))
(is (zerop (pzmq:getsockopt s :tcp-keepalive)))))
(defun accept-plain-auth-string (s)
(pzmq:with-messages (ign id)
(is (string= "1.0" (pzmq:recv-string s)))
(pzmq:msg-recv id s) ; request ID
(is (string= "domain" (pzmq:recv-string s)))
(pzmq:msg-recv ign s) ; client IP address
(pzmq:msg-recv ign s) ; socket identity
(is (string= "PLAIN" (pzmq:recv-string s)))
(is (string= "user" (pzmq:recv-string s)))
(is (string= "pass" (pzmq:recv-string s)))
(is-false (pzmq:getsockopt s :rcvmore))
(pzmq:send s "1.0" :sndmore t)
(pzmq:msg-send id s :sndmore t)
(pzmq:send s "200" :sndmore t)
(pzmq:send s "Welcome" :sndmore t)
(pzmq:send s "user" :sndmore t)
(pzmq:send s nil)))
(test plain-auth-string
(pzmq:with-sockets ((receiver (:rep :plain-server t
:zap-domain "domain"))
(authenticator :rep)
(sender (:req :plain-username "user"
:plain-password "pass")))
(pzmq:bind receiver "tcp://*:5555")
(pzmq:bind authenticator "inproc://zeromq.zap.01")
(pzmq:connect sender "tcp://localhost:5555")
(accept-plain-auth-string authenticator)
(pzmq:send sender "")
(is (string= "" (pzmq:recv-string receiver)))))
(defun accept-plain-auth-octets (s)
(pzmq:with-messages (ign id)
(is (equalp (string-to-octets "1.0") (pzmq:recv-octets s)))
(pzmq:msg-recv id s) ; request ID
(is (equalp (string-to-octets "domain") (pzmq:recv-octets s)))
(pzmq:msg-recv ign s) ; client IP address
(pzmq:msg-recv ign s) ; socket identity
(is (equalp (string-to-octets "PLAIN") (pzmq:recv-octets s)))
(is (equalp (string-to-octets "user") (pzmq:recv-octets s)))
(is (equalp (string-to-octets "pass") (pzmq:recv-octets s)))
(is-false (pzmq:getsockopt s :rcvmore))
(pzmq:send s (string-to-octets "1.0") :sndmore t)
(pzmq:msg-send id s :sndmore t)
(pzmq:send s (string-to-octets "200") :sndmore t)
(pzmq:send s (string-to-octets "Welcome") :sndmore t)
(pzmq:send s (string-to-octets "user") :sndmore t)
(pzmq:send s nil)))
(test plain-auth-octets
(pzmq:with-sockets ((receiver (:rep :plain-server t
:zap-domain "domain"))
(authenticator :rep)
(sender (:req :plain-username "user"
:plain-password "pass")))
(pzmq:bind receiver "tcp://*:5555")
(pzmq:bind authenticator "inproc://zeromq.zap.01")
(pzmq:connect sender "tcp://localhost:5555")
(accept-plain-auth-octets authenticator)
(pzmq:send sender (string-to-octets ""))
(is (equalp (string-to-octets "") (pzmq:recv-octets receiver)))))
(test curve ()
(multiple-value-bind (server-public server-secret) (pzmq:curve-keypair)
(multiple-value-bind (client-public client-secret) (pzmq:curve-keypair)
(pzmq:with-sockets ((server (:req :curve-server 1
:curve-publickey server-public
:curve-secretkey server-secret))
(client (:rep :curve-publickey client-public
:curve-secretkey client-secret
:curve-serverkey server-public)))
(pzmq:bind server "tcp://*:5555")
(pzmq:connect client "tcp://localhost:5555")
(let ((string "1234567"))
(pzmq:send server string)
(is (string= string (pzmq:recv-string client))))))))