@@ -29,6 +29,8 @@ import (
2929 "github.com/keybase/client/go/chat/types"
3030 "github.com/keybase/client/go/chat/utils"
3131 "github.com/keybase/client/go/chat/wallet"
32+ "github.com/keybase/client/go/gregor"
33+ grutils "github.com/keybase/client/go/gregor/utils"
3234 "github.com/keybase/client/go/kbtest"
3335 "github.com/keybase/client/go/libkb"
3436 "github.com/keybase/client/go/logger"
@@ -129,6 +131,34 @@ func (g *gregorTestConnection) BroadcastMessage(ctx context.Context, m gregor1.M
129131 return nil
130132}
131133
134+ func (g * gregorTestConnection ) State (ctx context.Context ) (gregor.State , error ) {
135+ return gregor1.IncomingClient {Cli : g .cli }.State (ctx , gregor1.StateArg {
136+ Uid : g .uid ,
137+ })
138+ }
139+
140+ func (g * gregorTestConnection ) DismissItem (ctx context.Context , cli gregor1.IncomingInterface , id gregor.MsgID ) error {
141+ msg , err := grutils .FormMessageForDismissItem (ctx , g .uid , id )
142+ if err != nil {
143+ return err
144+ }
145+ return gregor1.IncomingClient {Cli : g .cli }.ConsumeMessage (ctx , msg .(gregor1.Message ))
146+ }
147+
148+ func (g * gregorTestConnection ) InjectItem (ctx context.Context , cat string , body []byte ,
149+ dtime gregor1.TimeOrOffset ) (gregor1.MsgID , error ) {
150+ msg , err := grutils .FormMessageForInjectItem (ctx , g .uid , cat , body , dtime )
151+ if err != nil {
152+ return nil , err
153+ }
154+ retMsgID := gregor1 .MsgID (msg .ToInBandMessage ().Metadata ().MsgID ().Bytes ())
155+ return retMsgID , gregor1.IncomingClient {Cli : g .cli }.ConsumeMessage (ctx , msg .(gregor1.Message ))
156+ }
157+
158+ func (g * gregorTestConnection ) LocalDismissItem (ctx context.Context , id gregor.MsgID ) error {
159+ return nil
160+ }
161+
132162func (g * gregorTestConnection ) OnConnectError (err error , reconnectThrottleDuration time.Duration ) {
133163}
134164
@@ -311,6 +341,7 @@ func (c *chatTestContext) as(t *testing.T, user *kbtest.FakeUser) *chatTestUserC
311341 require .NoError (t , err )
312342 sessionToken := nist .Token ().String ()
313343 gh := newGregorTestConnection (tc .Context (), uid , sessionToken )
344+ g .GregorState = gh
314345 require .NoError (t , gh .Connect (ctx ))
315346 ri = gh .GetClient ()
316347 }
@@ -4362,14 +4393,11 @@ func TestChatSrvRetentionSweepConv(t *testing.T) {
43624393 require .NoError (t , err )
43634394 require .Len (t , tvres .Thread .Messages , 1 , "the TEXTs should be deleted" )
43644395
4365- // If we are using an ephemeral policy make sure non-ephemeral
4366- // messages and message with a lifetime exceeding the policy age
4367- // are blocked.
4396+ // If we are using an ephemeral policy make sure messages with a lifetime exceeding
4397+ // the policy age are blocked.
43684398 if ephemeralLifetime != nil {
4369- _ , err := postLocalForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }))
4370- require .Error (t , err )
43714399 badLifetime := * ephemeralLifetime + 1
4372- _ , err = postLocalEphemeralForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }), & badLifetime )
4400+ _ , err : = postLocalEphemeralForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }), & badLifetime )
43734401 require .Error (t , err )
43744402
43754403 _ , err = postLocalEphemeralForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }), ephemeralLifetime )
@@ -4481,14 +4509,10 @@ func TestChatSrvRetentionSweepTeam(t *testing.T) {
44814509 checkThread (convC .Id , false )
44824510 if ephemeralLifetime != nil {
44834511 for _ , conv := range []chat1.ConversationInfoLocal {convA , convB } {
4484- // If we are using an ephemeral policy make sure non-ephemeral
4485- // messages and message with a lifetime exceeding the policy age
4486- // are blocked.
4487- _ , err := postLocalForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }))
4488- require .Error (t , err )
4489-
4512+ // If we are using an ephemeral policy make sure messages with a lifetime exceeding
4513+ // the policy age are blocked.
44904514 badLifetime := * ephemeralLifetime + 1
4491- _ , err = postLocalEphemeralForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }), & badLifetime )
4515+ _ , err : = postLocalEphemeralForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }), & badLifetime )
44924516 require .Error (t , err )
44934517
44944518 _ , err = postLocalEphemeralForTest (t , ctc , users [0 ], conv , chat1 .NewMessageBodyWithText (chat1.MessageText {Body : "hello!" }), ephemeralLifetime )
@@ -5865,6 +5889,73 @@ func TestChatSrvStellarUI(t *testing.T) {
58655889 consumeNewPendingMsg (t , listener )
58665890}
58675891
5892+ func TestChatSrvEphemeralPolicy (t * testing.T ) {
5893+ ctc := makeChatTestContext (t , "TestChatSrvEphemeralPolicy" , 1 )
5894+ defer ctc .cleanup ()
5895+ users := ctc .users ()
5896+ useRemoteMock = false
5897+ defer func () { useRemoteMock = true }()
5898+
5899+ timeout := 20 * time .Second
5900+ ctx := ctc .as (t , users [0 ]).startCtx
5901+ tc := ctc .world .Tcs [users [0 ].Username ]
5902+ listener0 := newServerChatListener ()
5903+ ctc .as (t , users [0 ]).h .G ().NotifyRouter .SetListener (listener0 )
5904+ getMsg := func (ctx context.Context , convID chat1.ConversationID , msgID chat1.MessageID ) chat1.MessageUnboxed {
5905+ res , err := ctc .as (t , users [0 ]).chatLocalHandler ().GetMessagesLocal (ctx , chat1.GetMessagesLocalArg {
5906+ ConversationID : convID ,
5907+ MessageIDs : []chat1.MessageID {msgID },
5908+ })
5909+ require .NoError (t , err )
5910+ require .Equal (t , 1 , len (res .Messages ))
5911+ return res .Messages [0 ]
5912+ }
5913+ checkEph := func (convID chat1.ConversationID , exp int ) {
5914+ select {
5915+ case rmsg := <- listener0 .newMessageRemote :
5916+ msg := getMsg (ctx , convID , rmsg .Message .GetMessageID ())
5917+ require .True (t , msg .IsValid ())
5918+ require .NotNil (t , msg .Valid ().ClientHeader .EphemeralMetadata )
5919+ require .Equal (t , gregor1 .DurationSec (exp ), msg .Valid ().ClientHeader .EphemeralMetadata .Lifetime )
5920+ case <- time .After (timeout ):
5921+ require .Fail (t , "no message" )
5922+ }
5923+ }
5924+
5925+ impconv := mustCreateConversationForTest (t , ctc , users [0 ], chat1 .TopicType_CHAT ,
5926+ chat1 .ConversationMembersType_IMPTEAMNATIVE )
5927+ mustSetConvRetentionPolicy (t , ctc , users [0 ], impconv .Id , chat1 .NewRetentionPolicyWithEphemeral (chat1.RpEphemeral {
5928+ Age : gregor1 .DurationSec (86400 ),
5929+ }), 0 )
5930+ consumeSetConvRetention (t , listener0 )
5931+ mustPostLocalForTest (t , ctc , users [0 ], impconv ,
5932+ chat1 .NewMessageBodyWithText (chat1.MessageText {
5933+ Body : "HI" ,
5934+ }))
5935+ checkEph (impconv .Id , 86400 )
5936+ _ , err := tc .Context ().GregorState .InjectItem (ctx , fmt .Sprintf ("exploding:%s" , impconv .Id ),
5937+ []byte ("3600" ), gregor1.TimeOrOffset {})
5938+ require .NoError (t , err )
5939+ mustPostLocalForTest (t , ctc , users [0 ], impconv ,
5940+ chat1 .NewMessageBodyWithText (chat1.MessageText {
5941+ Body : "HI" ,
5942+ }))
5943+ checkEph (impconv .Id , 3600 )
5944+
5945+ teamconv := mustCreateConversationForTest (t , ctc , users [0 ], chat1 .TopicType_CHAT ,
5946+ chat1 .ConversationMembersType_TEAM )
5947+ mustSetTeamRetentionPolicy (t , ctc , users [0 ], keybase1 .TeamID (teamconv .Triple .Tlfid .String ()),
5948+ chat1 .NewRetentionPolicyWithEphemeral (chat1.RpEphemeral {
5949+ Age : gregor1 .DurationSec (86400 ),
5950+ }), 0 )
5951+ consumeSetTeamRetention (t , listener0 )
5952+ mustPostLocalForTest (t , ctc , users [0 ], teamconv ,
5953+ chat1 .NewMessageBodyWithText (chat1.MessageText {
5954+ Body : "HI" ,
5955+ }))
5956+ checkEph (teamconv .Id , 86400 )
5957+ }
5958+
58685959func TestChatSrvStellarMessages (t * testing.T ) {
58695960 runWithMemberTypes (t , func (mt chat1.ConversationMembersType ) {
58705961 runWithEphemeral (t , mt , func (ephemeralLifetime * gregor1.DurationSec ) {
0 commit comments