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
|
## This Source Code Form is subject to the terms of the Mozilla Public
## License, v. 2.0. If a copy of the MPL was not distributed with this
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
##
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
defmodule CoreListenersTest do
use ExUnit.Case, async: true
import RabbitMQ.CLI.Core.Listeners
import RabbitCommon.Records
test "listener record translation to a map" do
assert listener_map(listener(node: :rabbit@mercurio,
protocol: :stomp,
ip_address: {0,0,0,0,0,0,0,0},
port: 61613)) ==
%{
interface: "[::]",
node: :rabbit@mercurio,
port: 61613,
protocol: :stomp,
purpose: "STOMP"
}
end
test "[human-readable] protocol labels" do
assert protocol_label(:amqp) == "AMQP 0-9-1 and AMQP 1.0"
assert protocol_label(:'amqp/ssl') == "AMQP 0-9-1 and AMQP 1.0 over TLS"
assert protocol_label(:mqtt) == "MQTT"
assert protocol_label(:'mqtt/ssl') == "MQTT over TLS"
assert protocol_label(:stomp) == "STOMP"
assert protocol_label(:'stomp/ssl') == "STOMP over TLS"
assert protocol_label(:http) == "HTTP API"
assert protocol_label(:https) == "HTTP API over TLS (HTTPS)"
assert protocol_label(:'https/web-stomp') == "STOMP over WebSockets and TLS (HTTPS)"
assert protocol_label(:'https/web-mqtt') == "MQTT over WebSockets and TLS (HTTPS)"
assert protocol_label(:'http/prometheus') == "Prometheus exporter API over HTTP"
assert protocol_label(:'https/prometheus') == "Prometheus exporter API over TLS (HTTPS)"
end
test "listener expiring within" do
validityInDays = 10
validity = X509.Certificate.Validity.days_from_now(validityInDays)
ca_key = X509.PrivateKey.new_ec(:secp256r1)
ca = X509.Certificate.self_signed(ca_key,
"/C=US/ST=CA/L=San Francisco/O=Megacorp/CN=Megacorp Intermediate CA",
template: :root_ca,
validity: validity
)
pem = X509.Certificate.to_pem(ca)
opts = [{:certfile, {:pem, pem}}, {:cacertfile, {:pem, pem}}]
listener = listener(node: :rabbit@mercurio,
protocol: :stomp,
ip_address: {0,0,0,0,0,0,0,0},
port: 61613,
opts: opts)
assert not listener_expiring_within(listener, 86400 * (validityInDays - 5))
assert listener_expiring_within(listener, 86400 * (validityInDays + 5))
end
end
|