MCPcopy
hub / github.com/tinode/chat / TestDispatchLogin

Function TestDispatchLogin

server/session_test.go:144–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestDispatchLogin(t *testing.T) {
145 ctrl := gomock.NewController(t)
146 ss := mock_store.NewMockPersistentStorageInterface(ctrl)
147 aa := mock_auth.NewMockAuthHandler(ctrl)
148
149 uid := types.Uid(1)
150 store.Store = ss
151 defer func() {
152 store.Store = nil
153 ctrl.Finish()
154 }()
155
156 secret := "<==auth-secret==>"
157 authRec := &auth.Rec{
158 Uid: uid,
159 AuthLevel: auth.LevelAuth,
160 Tags: []string{"tag1", "tag2"},
161 State: types.StateOK,
162 }
163 ss.EXPECT().GetLogicalAuthHandler("basic").Return(aa)
164 aa.EXPECT().Authenticate([]byte(secret), gomock.Any()).Return(authRec, nil, nil)
165 // Token generation.
166 ss.EXPECT().GetLogicalAuthHandler("token").Return(aa)
167 token := "<==auth-token==>"
168 expires, _ := time.Parse(time.RFC822, "01 Jan 50 00:00 UTC")
169 aa.EXPECT().GenSecret(authRec).Return([]byte(token), expires, nil)
170
171 s := &Session{
172 send: make(chan any, 10),
173 authLvl: auth.LevelAuth,
174 ver: 16,
175 }
176 wg := sync.WaitGroup{}
177 r := responses{}
178 wg.Add(1)
179 go s.testWriteLoop(&r, &wg)
180
181 msg := &ClientComMessage{
182 Login: &MsgClientLogin{
183 Id: "123",
184 Scheme: "basic",
185 Secret: []byte(secret),
186 },
187 }
188
189 s.dispatch(msg)
190 close(s.send)
191 wg.Wait()
192
193 if len(r.messages) != 1 {
194 t.Errorf("responses: expected 1, received %d.", len(r.messages))
195 }
196 resp := r.messages[0].(*ServerComMessage)
197 if resp == nil {
198 t.Fatal("Response must be ServerComMessage")
199 }
200 if resp.Ctrl != nil {
201 if resp.Ctrl.Id != "123" {

Callers

nothing calls this directly

Calls 13

EXPECTMethod · 0.95
EXPECTMethod · 0.95
testWriteLoopMethod · 0.95
dispatchMethod · 0.95
NewMockAuthHandlerFunction · 0.92
UidTypeAlias · 0.92
WaitMethod · 0.80
ErrorMethod · 0.80
GetLogicalAuthHandlerMethod · 0.65
AuthenticateMethod · 0.65
GenSecretMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…