Skip to content

Commit 3809cd5

Browse files
committed
fix tests caused by moving rotator initiation out of coderd
1 parent d16e98f commit 3809cd5

File tree

11 files changed

+145
-33
lines changed

11 files changed

+145
-33
lines changed

cli/server_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/coder/coder/v2/cli/clitest"
4545
"github.com/coder/coder/v2/cli/config"
4646
"github.com/coder/coder/v2/coderd/coderdtest"
47+
"github.com/coder/coder/v2/coderd/database"
4748
"github.com/coder/coder/v2/coderd/database/dbtestutil"
4849
"github.com/coder/coder/v2/coderd/httpapi"
4950
"github.com/coder/coder/v2/coderd/telemetry"
@@ -1590,6 +1591,44 @@ func TestServer(t *testing.T) {
15901591
w.RequireSuccess()
15911592
})
15921593
})
1594+
1595+
t.Run("CryptoKeysGenerated", func(t *testing.T) {
1596+
t.Parallel()
1597+
if testing.Short() {
1598+
t.SkipNow()
1599+
}
1600+
1601+
if runtime.GOOS != "linux" || testing.Short() {
1602+
// Skip on non-Linux because it spawns a PostgreSQL instance.
1603+
t.SkipNow()
1604+
}
1605+
connectionURL, closeFunc, err := dbtestutil.Open()
1606+
require.NoError(t, err)
1607+
defer closeFunc()
1608+
1609+
inv, cfg := clitest.New(t,
1610+
"server",
1611+
"--http-address", ":0",
1612+
"--access-url", "http://example.com",
1613+
"--postgres-url", connectionURL,
1614+
"--cache-dir", t.TempDir(),
1615+
)
1616+
1617+
const superDuperLong = testutil.WaitSuperLong * 3
1618+
ctx := testutil.Context(t, superDuperLong)
1619+
clitest.Start(t, inv.WithContext(ctx))
1620+
_ = waitAccessURL(t, cfg)
1621+
1622+
logger := slogtest.Make(t, nil)
1623+
sqldb, err := cli.ConnectToPostgres(ctx, logger, "postgres", connectionURL)
1624+
require.NoError(t, err)
1625+
defer sqldb.Close()
1626+
1627+
db := database.New(sqldb)
1628+
keys, err := db.GetCryptoKeys(ctx)
1629+
require.NoError(t, err)
1630+
require.Len(t, keys, len(database.AllCryptoKeyFeatureValues()))
1631+
})
15931632
}
15941633

15951634
func TestServer_Production(t *testing.T) {

coderd/cryptokeys/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ func (s StaticKey) DecryptingKey(_ context.Context, id string) (interface{}, err
406406
return s.Key, nil
407407
}
408408

409-
func (s StaticKey) Close() error {
409+
func (StaticKey) Close() error {
410410
return nil
411411
}
412412

coderd/userauth_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,11 +1309,16 @@ func TestUserOIDC(t *testing.T) {
13091309
cfg.AllowSignups = true
13101310
})
13111311

1312-
client := coderdtest.New(t, &coderdtest.Options{
1312+
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
13131313
Auditor: auditor,
13141314
OIDCConfig: cfg,
13151315
})
13161316

1317+
// Make sure there's a signing key!
1318+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
1319+
Feature: database.CryptoKeyFeatureOIDCConvert,
1320+
})
1321+
13171322
owner := coderdtest.CreateFirstUser(t, client)
13181323
user, userData := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)
13191324

coderd/workspaceapps/db_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import (
2020

2121
"github.com/coder/coder/v2/agent/agenttest"
2222
"github.com/coder/coder/v2/coderd/coderdtest"
23+
"github.com/coder/coder/v2/coderd/database"
24+
"github.com/coder/coder/v2/coderd/database/dbgen"
25+
"github.com/coder/coder/v2/coderd/database/dbtestutil"
2326
"github.com/coder/coder/v2/coderd/httpmw"
2427
"github.com/coder/coder/v2/coderd/jwtutils"
2528
"github.com/coder/coder/v2/coderd/workspaceapps"
@@ -76,6 +79,7 @@ func Test_ResolveRequest(t *testing.T) {
7679
deploymentValues.Dangerous.AllowPathAppSharing = true
7780
deploymentValues.Dangerous.AllowPathAppSiteOwnerAccess = true
7881

82+
db, pubsub := dbtestutil.NewDB(t)
7983
client, closer, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
8084
AppHostname: "*.test.coder.com",
8185
DeploymentValues: deploymentValues,
@@ -91,13 +95,18 @@ func Test_ResolveRequest(t *testing.T) {
9195
"CF-Connecting-IP",
9296
},
9397
},
98+
Database: db,
99+
Pubsub: pubsub,
94100
})
95101
t.Cleanup(func() {
96102
_ = closer.Close()
97103
})
98104

99-
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
100-
t.Cleanup(cancel)
105+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
106+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
107+
})
108+
109+
ctx := testutil.Context(t, testutil.WaitMedium)
101110

102111
firstUser := coderdtest.CreateFirstUser(t, client)
103112
me, err := client.User(ctx, codersdk.Me)

coderd/workspaceapps_test.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/coder/coder/v2/coderd/coderdtest"
1212
"github.com/coder/coder/v2/coderd/database"
1313
"github.com/coder/coder/v2/coderd/database/dbgen"
14-
"github.com/coder/coder/v2/coderd/database/dbtestutil"
1514
"github.com/coder/coder/v2/coderd/workspaceapps"
1615
"github.com/coder/coder/v2/codersdk"
1716
"github.com/coder/coder/v2/testutil"
@@ -181,19 +180,25 @@ func TestWorkspaceApplicationAuth(t *testing.T) {
181180
t.Run(c.name, func(t *testing.T) {
182181
t.Parallel()
183182

184-
db, pubsub := dbtestutil.NewDB(t)
185-
186183
accessURL, err := url.Parse(c.accessURL)
187184
require.NoError(t, err)
188185

189-
client := coderdtest.New(t, &coderdtest.Options{
190-
Database: db,
191-
Pubsub: pubsub,
186+
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
192187
AccessURL: accessURL,
193188
AppHostname: c.appHostname,
194189
})
195190
_ = coderdtest.CreateFirstUser(t, client)
196191

192+
// Make sure there's a signing key!
193+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
194+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
195+
})
196+
197+
// Make sure there's an encryption key!
198+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
199+
Feature: database.CryptoKeyFeatureWorkspaceAppsAPIKey,
200+
})
201+
197202
// Disable redirects.
198203
client.HTTPClient.CheckRedirect = func(_ *http.Request, _ []*http.Request) error {
199204
return http.ErrUseLastResponse

enterprise/coderd/workspaceproxy_test.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -608,11 +608,8 @@ func TestProxyRegisterDeregister(t *testing.T) {
608608
func TestIssueSignedAppToken(t *testing.T) {
609609
t.Parallel()
610610

611-
db, pubsub := dbtestutil.NewDB(t)
612-
client, user := coderdenttest.New(t, &coderdenttest.Options{
611+
client, db, user := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
613612
Options: &coderdtest.Options{
614-
Database: db,
615-
Pubsub: pubsub,
616613
IncludeProvisionerDaemon: true,
617614
},
618615
LicenseOptions: &coderdenttest.LicenseOptions{
@@ -622,6 +619,10 @@ func TestIssueSignedAppToken(t *testing.T) {
622619
},
623620
})
624621

622+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
623+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
624+
})
625+
625626
// Create a workspace + apps
626627
authToken := uuid.NewString()
627628
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
@@ -715,6 +716,10 @@ func TestReconnectingPTYSignedToken(t *testing.T) {
715716
closer.Close()
716717
})
717718

719+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
720+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
721+
})
722+
718723
// Create a workspace + apps
719724
authToken := uuid.NewString()
720725
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
@@ -945,16 +950,14 @@ func TestGetCryptoKeys(t *testing.T) {
945950
keys, err := proxy.SDKClient.CryptoKeys(ctx, codersdk.CryptoKeyFeatureWorkspaceAppsAPIKey)
946951
require.NoError(t, err)
947952
require.NotEmpty(t, keys)
948-
// 1 key is generated on startup, the other is the one we generated for our test.
949-
require.Equal(t, 2, len(keys.CryptoKeys))
953+
require.Equal(t, 1, len(keys.CryptoKeys))
950954
requireContainsKeys(t, keys.CryptoKeys, encryptionKey)
951-
requireNotContainsKeys(t, keys.CryptoKeys, signingKey)
952955

953956
keys, err = proxy.SDKClient.CryptoKeys(ctx, codersdk.CryptoKeyFeatureWorkspaceAppsToken)
954957
require.NoError(t, err)
955958
require.NotEmpty(t, keys)
959+
require.Equal(t, 1, len(keys.CryptoKeys))
956960
requireContainsKeys(t, keys.CryptoKeys, signingKey)
957-
requireNotContainsKeys(t, keys.CryptoKeys, encryptionKey)
958961
})
959962

960963
t.Run("InvalidFeature", func(t *testing.T) {
@@ -1027,18 +1030,6 @@ func TestGetCryptoKeys(t *testing.T) {
10271030
})
10281031
}
10291032

1030-
func requireNotContainsKeys(t *testing.T, keys []codersdk.CryptoKey, unexpected ...codersdk.CryptoKey) {
1031-
t.Helper()
1032-
1033-
for _, expectedKey := range unexpected {
1034-
for _, key := range keys {
1035-
if key.Feature == expectedKey.Feature && key.Sequence == expectedKey.Sequence {
1036-
t.Fatalf("unexpected key %+v found", expectedKey)
1037-
}
1038-
}
1039-
}
1040-
}
1041-
10421033
func requireContainsKeys(t *testing.T, keys []codersdk.CryptoKey, expected ...codersdk.CryptoKey) {
10431034
t.Helper()
10441035

enterprise/workspaceapps_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"testing"
66

77
"github.com/coder/coder/v2/coderd/coderdtest"
8+
"github.com/coder/coder/v2/coderd/database"
9+
"github.com/coder/coder/v2/coderd/database/dbgen"
10+
"github.com/coder/coder/v2/coderd/database/dbtestutil"
811
"github.com/coder/coder/v2/coderd/httpmw"
912
"github.com/coder/coder/v2/coderd/workspaceapps/apptest"
1013
"github.com/coder/coder/v2/codersdk"
@@ -36,6 +39,9 @@ func TestWorkspaceApps(t *testing.T) {
3639
flushStatsCollectorCh <- flushStatsCollectorDone
3740
<-flushStatsCollectorDone
3841
}
42+
43+
db, pubsub := dbtestutil.NewDB(t)
44+
3945
client, _, _, user := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
4046
Options: &coderdtest.Options{
4147
DeploymentValues: deploymentValues,
@@ -51,6 +57,8 @@ func TestWorkspaceApps(t *testing.T) {
5157
},
5258
},
5359
WorkspaceAppsStatsCollectorOptions: opts.StatsCollectorOptions,
60+
Database: db,
61+
Pubsub: pubsub,
5462
},
5563
LicenseOptions: &coderdenttest.LicenseOptions{
5664
Features: license.Features{
@@ -59,6 +67,13 @@ func TestWorkspaceApps(t *testing.T) {
5967
},
6068
})
6169

70+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
71+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
72+
})
73+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
74+
Feature: database.CryptoKeyFeatureWorkspaceAppsAPIKey,
75+
})
76+
6277
return &apptest.Deployment{
6378
Options: opts,
6479
SDKClient: client,

enterprise/wsproxy/wsproxy_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
"github.com/coder/coder/v2/agent/agenttest"
2626
"github.com/coder/coder/v2/buildinfo"
2727
"github.com/coder/coder/v2/coderd/coderdtest"
28+
"github.com/coder/coder/v2/coderd/database"
29+
"github.com/coder/coder/v2/coderd/database/dbgen"
30+
"github.com/coder/coder/v2/coderd/database/dbtestutil"
2831
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
2932
"github.com/coder/coder/v2/coderd/httpmw"
3033
"github.com/coder/coder/v2/coderd/workspaceapps/apptest"
@@ -932,6 +935,9 @@ func TestWorkspaceProxyWorkspaceApps(t *testing.T) {
932935
if opts.PrimaryAppHost == "" {
933936
opts.PrimaryAppHost = "*.primary.test.coder.com"
934937
}
938+
939+
db, pubsub := dbtestutil.NewDB(t)
940+
935941
client, closer, api, user := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
936942
Options: &coderdtest.Options{
937943
DeploymentValues: deploymentValues,
@@ -947,6 +953,8 @@ func TestWorkspaceProxyWorkspaceApps(t *testing.T) {
947953
},
948954
},
949955
WorkspaceAppsStatsCollectorOptions: opts.StatsCollectorOptions,
956+
Database: db,
957+
Pubsub: pubsub,
950958
},
951959
LicenseOptions: &coderdenttest.LicenseOptions{
952960
Features: license.Features{
@@ -959,6 +967,13 @@ func TestWorkspaceProxyWorkspaceApps(t *testing.T) {
959967
_ = closer.Close()
960968
})
961969

970+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
971+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
972+
})
973+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
974+
Feature: database.CryptoKeyFeatureWorkspaceAppsAPIKey,
975+
})
976+
962977
// Create the external proxy
963978
if opts.DisableSubdomainApps {
964979
opts.AppHost = ""
@@ -1002,6 +1017,8 @@ func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
10021017
if opts.PrimaryAppHost == "" {
10031018
opts.PrimaryAppHost = "*.primary.test.coder.com"
10041019
}
1020+
1021+
db, pubsub := dbtestutil.NewDB(t)
10051022
client, closer, api, user := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
10061023
Options: &coderdtest.Options{
10071024
DeploymentValues: deploymentValues,
@@ -1017,6 +1034,8 @@ func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
10171034
},
10181035
},
10191036
WorkspaceAppsStatsCollectorOptions: opts.StatsCollectorOptions,
1037+
Database: db,
1038+
Pubsub: pubsub,
10201039
},
10211040
LicenseOptions: &coderdenttest.LicenseOptions{
10221041
Features: license.Features{
@@ -1029,6 +1048,13 @@ func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
10291048
_ = closer.Close()
10301049
})
10311050

1051+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
1052+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
1053+
})
1054+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
1055+
Feature: database.CryptoKeyFeatureWorkspaceAppsAPIKey,
1056+
})
1057+
10321058
// Create the external proxy
10331059
if opts.DisableSubdomainApps {
10341060
opts.AppHost = ""

scaletest/createworkspaces/run_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
"cdr.dev/slog/sloggers/slogtest"
1616
"github.com/coder/coder/v2/agent"
1717
"github.com/coder/coder/v2/coderd/coderdtest"
18+
"github.com/coder/coder/v2/coderd/database"
19+
"github.com/coder/coder/v2/coderd/database/dbgen"
1820
"github.com/coder/coder/v2/coderd/httpapi"
1921
"github.com/coder/coder/v2/coderd/util/ptr"
2022
"github.com/coder/coder/v2/codersdk"
@@ -55,9 +57,12 @@ func Test_Runner(t *testing.T) {
5557
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
5658
defer cancel()
5759

58-
client := coderdtest.New(t, &coderdtest.Options{
60+
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
5961
IncludeProvisionerDaemon: true,
6062
})
63+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
64+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
65+
})
6166
user := coderdtest.CreateFirstUser(t, client)
6267

6368
authToken := uuid.NewString()
@@ -343,9 +348,12 @@ func Test_Runner(t *testing.T) {
343348
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
344349
defer cancel()
345350

346-
client := coderdtest.New(t, &coderdtest.Options{
351+
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{
347352
IncludeProvisionerDaemon: true,
348353
})
354+
_ = dbgen.CryptoKey(t, db, database.CryptoKey{
355+
Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
356+
})
349357
user := coderdtest.CreateFirstUser(t, client)
350358

351359
authToken := uuid.NewString()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy