MCPcopy
hub / github.com/mochi-mqtt/server / TestOnConnectAuthenticate

Function TestOnConnectAuthenticate

hooks/auth/auth_test.go:120–157  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

118}
119
120func TestOnConnectAuthenticate(t *testing.T) {
121 h := new(Hook)
122 h.SetOpts(logger, nil)
123
124 ln := new(Ledger)
125 ln.Auth = checkLedger.Auth
126 ln.ACL = checkLedger.ACL
127 err := h.Init(
128 &Options{
129 Ledger: ln,
130 },
131 )
132
133 require.NoError(t, err)
134
135 require.True(t, h.OnConnectAuthenticate(
136 &mqtt.Client{
137 Properties: mqtt.ClientProperties{
138 Username: []byte("mochi"),
139 },
140 },
141 packets.Packet{Connect: packets.ConnectParams{Password: []byte("melon")}},
142 ))
143
144 require.False(t, h.OnConnectAuthenticate(
145 &mqtt.Client{
146 Properties: mqtt.ClientProperties{
147 Username: []byte("mochi"),
148 },
149 },
150 packets.Packet{Connect: packets.ConnectParams{Password: []byte("bad-pass")}},
151 ))
152
153 require.False(t, h.OnConnectAuthenticate(
154 &mqtt.Client{},
155 packets.Packet{},
156 ))
157}
158
159func TestOnACL(t *testing.T) {
160 h := new(Hook)

Callers

nothing calls this directly

Calls 3

SetOptsMethod · 0.65
InitMethod · 0.65
OnConnectAuthenticateMethod · 0.65

Tested by

no test coverage detected