]> git.giacomolli.uk - onechat/blobdiff - telegram_test.go
Describe queued event delivery boundaries
[onechat] / telegram_test.go
index dee692d43d3f2f871c11142903f0764b3f171d44..17bea0967d6b3cf2baed40e172f67d65398d6bdf 100644 (file)
@@ -182,7 +182,7 @@ func TestBotShowsOnlyTheStartAndTheEndOfASubagent(t *testing.T) {
        }, sent)
 }
 
        }, sent)
 }
 
-func TestBotSkipsTheWorkOfWhatsAppAndTheSchedules(t *testing.T) {
+func TestBotSkipsExternalWorkAndSchedules(t *testing.T) {
        bot := &TelegramBot{
                ready: make(chan struct{}, 1),
        }
        bot := &TelegramBot{
                ready: make(chan struct{}, 1),
        }
@@ -192,11 +192,19 @@ func TestBotSkipsTheWorkOfWhatsAppAndTheSchedules(t *testing.T) {
                Source: whatsappSource,
                Text:   "[WhatsApp] Ana Souza",
        })
                Source: whatsappSource,
                Text:   "[WhatsApp] Ana Souza",
        })
+
        bot.Notify(Event{
                Kind:   "work",
                Source: scheduleSource,
                Text:   "[Schedule 1] Sunday 2026-11-08 20:05 -03:00, once",
        })
        bot.Notify(Event{
                Kind:   "work",
                Source: scheduleSource,
                Text:   "[Schedule 1] Sunday 2026-11-08 20:05 -03:00, once",
        })
+
+       bot.Notify(Event{
+               Kind:   "work",
+               Source: notifySource,
+               Text:   "Untrusted external data.",
+       })
+
        require.Empty(t, bot.queue)
 }
 
        require.Empty(t, bot.queue)
 }
 
@@ -646,6 +654,7 @@ func TestBotLogsNoTokenWhenTheNetworkFails(t *testing.T) {
        require.Eventually(t, func() bool {
                return strings.Contains(logs.String(), "<4>receive failed retry=1s: no answer: ")
        }, 10*time.Second, time.Millisecond)
        require.Eventually(t, func() bool {
                return strings.Contains(logs.String(), "<4>receive failed retry=1s: no answer: ")
        }, 10*time.Second, time.Millisecond)
+
        require.NotContains(t, logs.String(), telegramTestToken)
 }
 
        require.NotContains(t, logs.String(), telegramTestToken)
 }
 
@@ -694,6 +703,7 @@ func TestBotLogsAnOutageOnlyAtItsStartAndEnd(t *testing.T) {
                        "<4>receive failed retry=1s: 502 Bad Gateway",
                        "<6>receive back after=31s",
                }, lines)
                        "<4>receive failed retry=1s: 502 Bad Gateway",
                        "<6>receive back after=31s",
                }, lines)
+
                require.NotContains(t, logs.String(), "secret word")
                require.NotContains(t, logs.String(), strconv.FormatInt(telegramTestOwner, 10))
                cancel()
                require.NotContains(t, logs.String(), "secret word")
                require.NotContains(t, logs.String(), strconv.FormatInt(telegramTestOwner, 10))
                cancel()