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

Function TestRegisterSessionInvalidOwnershipTransfer

server/topic_test.go:1957–2016  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1955}
1956
1957func TestRegisterSessionInvalidOwnershipTransfer(t *testing.T) {
1958 topicName := "grpTest"
1959 numUsers := 2
1960 helper := TopicTestHelper{}
1961 helper.setUp(t, numUsers, types.TopicCatGrp, topicName, false)
1962 defer helper.tearDown()
1963 if len(helper.topic.sessions) != 0 {
1964 helper.finish()
1965 t.Fatalf("Initially attached sessions: expected 0 vs found %d", len(helper.topic.sessions))
1966 }
1967
1968 s := helper.sessions[1]
1969 uid := helper.uids[1]
1970 r := helper.results[1]
1971
1972 // User is the topic owner.
1973 pud := helper.topic.perUser[uid]
1974 pud.modeWant = types.ModeCPublic
1975 pud.modeGiven = types.ModeCPublic
1976 helper.topic.perUser[uid] = pud
1977
1978 join := &ClientComMessage{
1979 Original: topicName,
1980 Sub: &MsgClientSub{
1981 Id: "id456",
1982 Topic: topicName,
1983 Set: &MsgSetQuery{
1984 Sub: &MsgSetSub{
1985 // Want ownership.
1986 Mode: "JPRWSO",
1987 },
1988 },
1989 },
1990 AsUser: uid.UserId(),
1991 AuthLvl: int(auth.LevelAuth),
1992 sess: s,
1993 }
1994
1995 helper.topic.registerSession(join)
1996 helper.finish()
1997
1998 // Check for errors from testHubLoop
1999 if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
2000 t.Fatal(errorMsgs[0].Ctrl.Text)
2001 }
2002
2003 if len(s.subs) != 0 {
2004 t.Errorf("Session subscriptions: expected 0, found %d", len(s.subs))
2005 }
2006 online := helper.topic.perUser[uid].online
2007 if online != 0 {
2008 t.Errorf("Number of online sessions: expected 0, found %d", online)
2009 }
2010 // Session output.
2011 registerSessionVerifyOutputs(t, r, []int{http.StatusForbidden})
2012 // Presence notifications.
2013 if len(helper.hubMessages) != 0 {
2014 t.Errorf("Hub isn't expected to receive any messages, received %d", len(helper.hubMessages))

Callers

nothing calls this directly

Calls 6

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
registerSessionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…