added ability to disable third-party verification
This commit is contained in:
parent
4f0fa895c1
commit
36350f83dc
17 changed files with 211 additions and 69 deletions
|
|
@ -88,8 +88,14 @@ func (s *Service) HandlesBot(botUserID int64) bool {
|
|||
return false
|
||||
}
|
||||
switch botUserID {
|
||||
case domain.VerifierBotUserID:
|
||||
// @marksbot fronts THIRD-PARTY verification, which is hidden by default
|
||||
// (config.HideThirdPartyVerification) because the feature is not fully
|
||||
// finished -- while hidden, the bot doesn't exist as far as the message
|
||||
// pipeline is concerned.
|
||||
return !s.hideThirdPartyVerification
|
||||
case domain.BotFatherUserID, domain.StickersBotUserID, domain.ChatBotUserID,
|
||||
domain.VerifyBotUserID, domain.VerifierBotUserID:
|
||||
domain.VerifyBotUserID:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -119,6 +119,11 @@ type Service struct {
|
|||
now func() time.Time
|
||||
chatBotStreamThrottle time.Duration
|
||||
publicBaseURL string
|
||||
// hideThirdPartyVerification mirrors config.HideThirdPartyVerification: while
|
||||
// true, HandlesBot refuses VerifierBotUserID so @marksbot never answers a
|
||||
// message. The feature is not fully finished and defaults to hidden; see the
|
||||
// config field's doc comment.
|
||||
hideThirdPartyVerification bool
|
||||
// dialogLimiter bounds how often one applicant can drive a service-bot dialog.
|
||||
// The verification service already rate-limits application creation; this is the
|
||||
// separate bound on dialog traffic itself, so a script cannot spin the state
|
||||
|
|
@ -234,6 +239,15 @@ func WithCustomVerification(v customVerifications) Option {
|
|||
}
|
||||
}
|
||||
|
||||
// WithHideThirdPartyVerification mirrors config.HideThirdPartyVerification:
|
||||
// while true, HandlesBot refuses VerifierBotUserID, so @marksbot never
|
||||
// receives or answers a message.
|
||||
func WithHideThirdPartyVerification(hidden bool) Option {
|
||||
return func(s *Service) {
|
||||
s.hideThirdPartyVerification = hidden
|
||||
}
|
||||
}
|
||||
|
||||
// WithVerifierTargets injects the directory of an applicant's own peers used by
|
||||
// @verifierbot's subject picker. It is optional: with nothing injected the bot
|
||||
// falls back to the official verification service's EligibleTargets, which
|
||||
|
|
|
|||
|
|
@ -415,6 +415,28 @@ func TestVerifierBotStartWithoutVerifierStatusIsHonest(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestVerifierBotHiddenByThirdPartyVerificationFlag proves
|
||||
// config.HideThirdPartyVerification actually silences @marksbot: with the
|
||||
// option set, HandlesBot must refuse the bot's id entirely, so
|
||||
// OnPrivateMessage never even reaches the dialog logic -- not just an error
|
||||
// reply, no reply at all, matching every other unhandled bot id.
|
||||
func TestVerifierBotHiddenByThirdPartyVerificationFlag(t *testing.T) {
|
||||
cv := newFakeCustomVerification()
|
||||
svc, users, messages := newVerifierBotTestService(t, cv, WithHideThirdPartyVerification(true))
|
||||
owner := newOwner(t, users, "+7201")
|
||||
|
||||
if svc.HandlesBot(domain.VerifierBotUserID) {
|
||||
t.Fatal("service should refuse @verifierbot while third-party verification is hidden")
|
||||
}
|
||||
svc.OnPrivateMessage(context.Background(), domain.VerifierBotUserID, domain.Message{
|
||||
From: domain.Peer{Type: domain.PeerTypeUser, ID: owner.ID},
|
||||
Body: "/start",
|
||||
})
|
||||
if replies := verifierReplies(t, messages, owner.ID); len(replies) != 0 {
|
||||
t.Fatalf("hidden @verifierbot replied: %+v", replies)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifierBotStartWithActiveVerifierShowsCompanyAndMark(t *testing.T) {
|
||||
cv := newFakeCustomVerification().activated()
|
||||
svc, users, messages := newVerifierBotTestService(t, cv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue