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

Function TestDispatchAccNew

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

Source from the content-addressed store, hash-verified

1044}
1045
1046func TestDispatchAccNew(t *testing.T) {
1047 ctrl := gomock.NewController(t)
1048 ss := mock_store.NewMockPersistentStorageInterface(ctrl)
1049 uu := mock_store.NewMockUsersPersistenceInterface(ctrl)
1050 aa := mock_auth.NewMockAuthHandler(ctrl)
1051
1052 uid := types.Uid(1)
1053 store.Store = ss
1054 store.Users = uu
1055 defer func() {
1056 store.Store = nil
1057 store.Users = nil
1058 ctrl.Finish()
1059 }()
1060
1061 remoteAddr := "192.168.0.1"
1062 secret := "<==auth-secret==>"
1063 tags := []string{"tag1", "tag2"}
1064 authRec := &auth.Rec{
1065 Uid: uid,
1066 AuthLevel: auth.LevelAuth,
1067 Tags: tags,
1068 State: types.StateOK,
1069 }
1070 ss.EXPECT().GetLogicalAuthHandler("basic").Return(aa)
1071 // This login is available.
1072 aa.EXPECT().IsUnique([]byte(secret), remoteAddr).Return(true, nil)
1073 uu.EXPECT().Create(gomock.Any(), gomock.Any()).DoAndReturn(
1074 func(user *types.User, private any) (*types.User, error) {
1075 user.SetUid(uid)
1076 return user, nil
1077 })
1078 aa.EXPECT().AddRecord(gomock.Any(), []byte(secret), remoteAddr).Return(authRec, nil)
1079
1080 // Token generation.
1081 ss.EXPECT().GetLogicalAuthHandler("token").Return(aa)
1082 token := "<==auth-token==>"
1083 aa.EXPECT().GenSecret(gomock.Any()).Return([]byte(token), time.Now(), nil)
1084 uu.EXPECT().UpdateTags(uid, tags, nil, nil).Return(tags, nil)
1085
1086 s := &Session{
1087 send: make(chan any, 10),
1088 authLvl: auth.LevelAuth,
1089 ver: 16,
1090 remoteAddr: remoteAddr,
1091 }
1092 wg := sync.WaitGroup{}
1093 r := responses{}
1094 wg.Add(1)
1095 go s.testWriteLoop(&r, &wg)
1096
1097 public := "public name"
1098 msg := &ClientComMessage{
1099 Acc: &MsgClientAcc{
1100 Id: "123",
1101 User: "newXYZ",
1102 Scheme: "basic",
1103 Secret: []byte(secret),

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
EXPECTMethod · 0.95
EXPECTMethod · 0.95
testWriteLoopMethod · 0.95
dispatchMethod · 0.95
NewMockAuthHandlerFunction · 0.92
UidTypeAlias · 0.92
SetUidMethod · 0.80
WaitMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…