Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: prevent password reset notifications ending up in coder inbox#17109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 1 commit intomainfromdm-filter-password-reset-for-inbox
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletionscoderd/notifications/enqueuer.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -116,6 +116,13 @@ func (s *StoreEnqueuer) EnqueueWithData(ctx context.Context, userID, templateID

uuids := make([]uuid.UUID, 0, 2)
for _, method := range methods {
// TODO(DanielleMaywood):
// We should have a more permanent solution in the future, but for now this will work.
// We do not want password reset notifications to end up in Coder Inbox.
if method == database.NotificationMethodInbox && templateID == TemplateUserRequestedOneTimePasscode {
continue
}

id := uuid.New()
err = s.store.EnqueueNotificationMessage(ctx, database.EnqueueNotificationMessageParams{
ID: id,
Expand Down
77 changes: 77 additions & 0 deletionscoderd/notifications/notifications_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1952,6 +1952,83 @@ func TestNotificationTargetMatrix(t *testing.T) {
}
}

func TestNotificationOneTimePasswordDeliveryTargets(t *testing.T) {
t.Parallel()

t.Run("Inbox", func(t *testing.T) {
t.Parallel()

// nolint:gocritic // Unit test.
ctx := dbauthz.AsNotifier(testutil.Context(t, testutil.WaitSuperLong))
store, _ := dbtestutil.NewDB(t)
logger := testutil.Logger(t)

// Given: Coder Inbox is enabled and SMTP/Webhook are disabled.
cfg := defaultNotificationsConfig(database.NotificationMethodSmtp)
cfg.Inbox.Enabled = true
cfg.SMTP = codersdk.NotificationsEmailConfig{}
cfg.Webhook = codersdk.NotificationsWebhookConfig{}

enq, err := notifications.NewStoreEnqueuer(cfg, store, defaultHelpers(), logger.Named("enqueuer"), quartz.NewMock(t))
require.NoError(t, err)
user := createSampleUser(t, store)

// When: A one-time-passcode notification is sent, it does not enqueue a notification.
enqueued, err := enq.Enqueue(ctx, user.ID, notifications.TemplateUserRequestedOneTimePasscode,
map[string]string{"one_time_passcode": "1234"}, "test", user.ID)
require.NoError(t, err)
require.Len(t, enqueued, 0)
})

t.Run("SMTP", func(t *testing.T) {
t.Parallel()

// nolint:gocritic // Unit test.
ctx := dbauthz.AsNotifier(testutil.Context(t, testutil.WaitSuperLong))
store, _ := dbtestutil.NewDB(t)
logger := testutil.Logger(t)

// Given: Coder Inbox/Webhook are disabled and SMTP is enabled.
cfg := defaultNotificationsConfig(database.NotificationMethodSmtp)
cfg.Inbox.Enabled = false
cfg.Webhook = codersdk.NotificationsWebhookConfig{}

enq, err := notifications.NewStoreEnqueuer(cfg, store, defaultHelpers(), logger.Named("enqueuer"), quartz.NewMock(t))
require.NoError(t, err)
user := createSampleUser(t, store)

// When: A one-time-passcode notification is sent, it does enqueue a notification.
enqueued, err := enq.Enqueue(ctx, user.ID, notifications.TemplateUserRequestedOneTimePasscode,
map[string]string{"one_time_passcode": "1234"}, "test", user.ID)
require.NoError(t, err)
require.Len(t, enqueued, 1)
})

t.Run("Webhook", func(t *testing.T) {
t.Parallel()

// nolint:gocritic // Unit test.
ctx := dbauthz.AsNotifier(testutil.Context(t, testutil.WaitSuperLong))
store, _ := dbtestutil.NewDB(t)
logger := testutil.Logger(t)

// Given: Coder Inbox/SMTP are disabled and Webhook is enabled.
cfg := defaultNotificationsConfig(database.NotificationMethodWebhook)
cfg.Inbox.Enabled = false
cfg.SMTP = codersdk.NotificationsEmailConfig{}

enq, err := notifications.NewStoreEnqueuer(cfg, store, defaultHelpers(), logger.Named("enqueuer"), quartz.NewMock(t))
require.NoError(t, err)
user := createSampleUser(t, store)

// When: A one-time-passcode notification is sent, it does enqueue a notification.
enqueued, err := enq.Enqueue(ctx, user.ID, notifications.TemplateUserRequestedOneTimePasscode,
map[string]string{"one_time_passcode": "1234"}, "test", user.ID)
require.NoError(t, err)
require.Len(t, enqueued, 1)
})
}

type fakeHandler struct {
mu sync.RWMutex
succeeded, failed []string
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp