Skip to content

Commit 5ae3d6c

Browse files
fix: tests (again)
1 parent 386e488 commit 5ae3d6c

File tree

5 files changed

+150
-62
lines changed

5 files changed

+150
-62
lines changed

cli/testdata/server-config.yaml.golden

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -518,51 +518,6 @@ userQuietHoursSchedule:
518518
# compatibility reasons, this will be removed in a future release.
519519
# (default: false, type: bool)
520520
allowWorkspaceRenames: false
521-
# Configure how emails are sent.
522-
email:
523-
# The sender's address to use.
524-
# (default: <unset>, type: string)
525-
from: ""
526-
# The intermediary SMTP host through which emails are sent.
527-
# (default: <unset>, type: string)
528-
smarthost: ""
529-
# The hostname identifying the SMTP server.
530-
# (default: <unset>, type: string)
531-
hello: ""
532-
# Force a TLS connection to the configured SMTP smarthost.
533-
# (default: <unset>, type: bool)
534-
forceTLS: false
535-
# Configure SMTP authentication options.
536-
emailAuth:
537-
# Identity to use with PLAIN authentication.
538-
# (default: <unset>, type: string)
539-
identity: ""
540-
# Username to use with PLAIN/LOGIN authentication.
541-
# (default: <unset>, type: string)
542-
username: ""
543-
# File from which to load password for use with PLAIN/LOGIN authentication.
544-
# (default: <unset>, type: string)
545-
passwordFile: ""
546-
# Configure TLS for your SMTP server target.
547-
emailTLS:
548-
# Enable STARTTLS to upgrade insecure SMTP connections using TLS.
549-
# (default: <unset>, type: bool)
550-
startTLS: false
551-
# Server name to verify against the target certificate.
552-
# (default: <unset>, type: string)
553-
serverName: ""
554-
# Skip verification of the target server's certificate (insecure).
555-
# (default: <unset>, type: bool)
556-
insecureSkipVerify: false
557-
# CA certificate file to use.
558-
# (default: <unset>, type: string)
559-
caCertFile: ""
560-
# Certificate file to use.
561-
# (default: <unset>, type: string)
562-
certFile: ""
563-
# Certificate key file to use.
564-
# (default: <unset>, type: string)
565-
certKeyFile: ""
566521
# Configure how notifications are processed and delivered.
567522
notifications:
568523
# Which delivery method to use (available options: 'smtp', 'webhook').
@@ -654,3 +609,48 @@ notifications:
654609
# How often to query the database for queued notifications.
655610
# (default: 15s, type: duration)
656611
fetchInterval: 15s
612+
# Configure how emails are sent.
613+
email:
614+
# The sender's address to use.
615+
# (default: <unset>, type: string)
616+
from: ""
617+
# The intermediary SMTP host through which emails are sent.
618+
# (default: <unset>, type: string)
619+
smarthost: ""
620+
# The hostname identifying the SMTP server.
621+
# (default: <unset>, type: string)
622+
hello: ""
623+
# Force a TLS connection to the configured SMTP smarthost.
624+
# (default: <unset>, type: bool)
625+
forceTLS: false
626+
# Configure SMTP authentication options.
627+
emailAuth:
628+
# Identity to use with PLAIN authentication.
629+
# (default: <unset>, type: string)
630+
identity: ""
631+
# Username to use with PLAIN/LOGIN authentication.
632+
# (default: <unset>, type: string)
633+
username: ""
634+
# File from which to load password for use with PLAIN/LOGIN authentication.
635+
# (default: <unset>, type: string)
636+
passwordFile: ""
637+
# Configure TLS for your SMTP server target.
638+
emailTLS:
639+
# Enable STARTTLS to upgrade insecure SMTP connections using TLS.
640+
# (default: <unset>, type: bool)
641+
startTLS: false
642+
# Server name to verify against the target certificate.
643+
# (default: <unset>, type: string)
644+
serverName: ""
645+
# Skip verification of the target server's certificate (insecure).
646+
# (default: <unset>, type: bool)
647+
insecureSkipVerify: false
648+
# CA certificate file to use.
649+
# (default: <unset>, type: string)
650+
caCertFile: ""
651+
# Certificate file to use.
652+
# (default: <unset>, type: string)
653+
certFile: ""
654+
# Certificate key file to use.
655+
# (default: <unset>, type: string)
656+
certKeyFile: ""

coderd/notifications/dispatch/smtp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ func (s *SMTPHandler) smarthost() (string, string, error) {
526526

527527
host, port, err := net.SplitHostPort(s.cfg.Smarthost.String())
528528
if err != nil {
529-
return "", "", fmt.Errorf("split host port: %w", err)
529+
return "", "", xerrors.Errorf("split host port: %w", err)
530530
}
531531

532532
return host, port, nil

coderd/notifications/dispatch/smtp_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ func TestSMTP(t *testing.T) {
440440

441441
var hp serpent.HostPort
442442
require.NoError(t, hp.Set(listen.Addr().String()))
443-
tc.cfg.Smarthost = hp
443+
tc.cfg.Smarthost = serpent.String(hp.String())
444444

445445
handler := dispatch.NewSMTPHandler(tc.cfg, logger.Named("smtp"))
446446

codersdk/deployment.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,21 +2578,6 @@ Write out the current server config as YAML to stdout.`,
25782578
YAML: "thresholdDatabase",
25792579
Annotations: serpent.Annotations{}.Mark(annotationFormatDuration, "true"),
25802580
},
2581-
// Email options
2582-
emailFrom,
2583-
emailSmarthost,
2584-
emailHello,
2585-
emailForceTLS,
2586-
emailAuthIdentity,
2587-
emailAuthUsername,
2588-
emailAuthPassword,
2589-
emailAuthPasswordFile,
2590-
emailTLSStartTLS,
2591-
emailTLSServerName,
2592-
emailTLSSkipCertVerify,
2593-
emailTLSCertAuthorityFile,
2594-
emailTLSCertFile,
2595-
emailTLSCertKeyFile,
25962581
// Notifications Options
25972582
{
25982583
Name: "Notifications: Method",
@@ -2854,6 +2839,21 @@ Write out the current server config as YAML to stdout.`,
28542839
Annotations: serpent.Annotations{}.Mark(annotationFormatDuration, "true"),
28552840
Hidden: true, // Hidden because most operators should not need to modify this.
28562841
},
2842+
// Email options
2843+
emailFrom,
2844+
emailSmarthost,
2845+
emailHello,
2846+
emailForceTLS,
2847+
emailAuthIdentity,
2848+
emailAuthUsername,
2849+
emailAuthPassword,
2850+
emailAuthPasswordFile,
2851+
emailTLSStartTLS,
2852+
emailTLSServerName,
2853+
emailTLSSkipCertVerify,
2854+
emailTLSCertAuthorityFile,
2855+
emailTLSCertFile,
2856+
emailTLSCertKeyFile,
28572857
}
28582858

28592859
return opts

codersdk/deployment_test.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,91 @@ func TestPremiumSuperSet(t *testing.T) {
568568
require.NotContains(t, enterprise.Features(), "", "enterprise should not contain empty string")
569569
require.NotContains(t, premium.Features(), "", "premium should not contain empty string")
570570
}
571+
572+
func TestEmailValuesTakeCorrectPrecedent(t *testing.T) {
573+
t.Parallel()
574+
575+
tests := []struct {
576+
name string
577+
envs []serpent.EnvVar
578+
oldEnv string
579+
newEnv string
580+
expectedValue string
581+
}{
582+
{
583+
name: "CODER_NOTIFICATIONS_EMAIL_SMARTHOST is not discarded",
584+
envs: []serpent.EnvVar{
585+
{
586+
Name: "CODER_NOTIFICATIONS_EMAIL_SMARTHOST",
587+
Value: "localhost:999",
588+
},
589+
},
590+
oldEnv: "CODER_NOTIFICATIONS_EMAIL_SMARTHOST",
591+
newEnv: "CODER_EMAIL_SMARTHOST",
592+
expectedValue: "localhost:999",
593+
},
594+
{
595+
name: "CODER_EMAIL_SMARTHOST is not discarded",
596+
envs: []serpent.EnvVar{
597+
{
598+
Name: "CODER_EMAIL_SMARTHOST",
599+
Value: "localhost:999",
600+
},
601+
},
602+
oldEnv: "CODER_NOTIFICATIONS_EMAIL_SMARTHOST",
603+
newEnv: "CODER_EMAIL_SMARTHOST",
604+
expectedValue: "localhost:999",
605+
},
606+
{
607+
name: "CODER_EMAIL_SMARTHOST is prioritized",
608+
envs: []serpent.EnvVar{
609+
{
610+
Name: "CODER_NOTIFICATIONS_EMAIL_SMARTHOST",
611+
Value: "localhost:999",
612+
},
613+
{
614+
Name: "CODER_EMAIL_SMARTHOST",
615+
Value: "localhost:1000",
616+
},
617+
},
618+
oldEnv: "CODER_NOTIFICATIONS_EMAIL_SMARTHOST",
619+
newEnv: "CODER_EMAIL_SMARTHOST",
620+
expectedValue: "localhost:1000",
621+
},
622+
}
623+
624+
for _, tt := range tests {
625+
tt := tt
626+
t.Run(tt.name, func(t *testing.T) {
627+
t.Parallel()
628+
629+
dv := codersdk.DeploymentValues{}
630+
opts := dv.Options()
631+
632+
err := opts.ParseEnv(tt.envs)
633+
require.NoError(t, err)
634+
635+
err = opts.SetDefaults()
636+
require.NoError(t, err)
637+
638+
var oldEnvValue string
639+
var newEnvValue string
640+
641+
for _, opt := range opts {
642+
switch {
643+
case opt.Env == tt.oldEnv:
644+
oldEnvValue = opt.Value.String()
645+
case opt.Env == tt.newEnv:
646+
newEnvValue = opt.Value.String()
647+
}
648+
649+
if oldEnvValue != "" && newEnvValue != "" {
650+
break
651+
}
652+
}
653+
654+
require.Equal(t, tt.expectedValue, oldEnvValue)
655+
require.Equal(t, tt.expectedValue, newEnvValue)
656+
})
657+
}
658+
}

0 commit comments

Comments
 (0)