MCPcopy Index your code
hub / github.com/coder/coder / TestGetCryptoKeys

Function TestGetCryptoKeys

enterprise/coderd/workspaceproxy_test.go:995–1136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

993}
994
995func TestGetCryptoKeys(t *testing.T) {
996 t.Parallel()
997
998 t.Run("OK", func(t *testing.T) {
999 t.Parallel()
1000
1001 ctx := testutil.Context(t, testutil.WaitMedium)
1002 db, pubsub := dbtestutil.NewDB(t)
1003 cclient, _, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
1004 Options: &coderdtest.Options{
1005 Database: db,
1006 Pubsub: pubsub,
1007 IncludeProvisionerDaemon: true,
1008 },
1009 LicenseOptions: &coderdenttest.LicenseOptions{
1010 Features: license.Features{
1011 codersdk.FeatureWorkspaceProxy: 1,
1012 },
1013 },
1014 })
1015
1016 now := time.Now()
1017
1018 expectedKey1 := dbgen.CryptoKey(t, db, database.CryptoKey{
1019 Feature: database.CryptoKeyFeatureWorkspaceAppsAPIKey,
1020 StartsAt: now.Add(-time.Hour),
1021 Sequence: 2,
1022 })
1023 encryptionKey := db2sdk.CryptoKey(expectedKey1)
1024
1025 expectedKey2 := dbgen.CryptoKey(t, db, database.CryptoKey{
1026 Feature: database.CryptoKeyFeatureWorkspaceAppsToken,
1027 StartsAt: now,
1028 Sequence: 3,
1029 })
1030 signingKey := db2sdk.CryptoKey(expectedKey2)
1031
1032 // Create a deleted key.
1033 _ = dbgen.CryptoKey(t, db, database.CryptoKey{
1034 Feature: database.CryptoKeyFeatureWorkspaceAppsAPIKey,
1035 StartsAt: now.Add(-time.Hour),
1036 Secret: sql.NullString{
1037 String: "secret1",
1038 Valid: false,
1039 },
1040 Sequence: 4,
1041 })
1042
1043 proxy := coderdenttest.NewWorkspaceProxyReplica(t, api, cclient, &coderdenttest.ProxyOptions{
1044 Name: testutil.GetRandomName(t),
1045 })
1046
1047 keys, err := proxy.SDKClient.CryptoKeys(ctx, codersdk.CryptoKeyFeatureWorkspaceAppsAPIKey)
1048 require.NoError(t, err)
1049 require.NotEmpty(t, keys)
1050 // 1 key is generated on startup, the other we manually generated.
1051 require.Equal(t, 2, len(keys.CryptoKeys))
1052 requireContainsKeys(t, keys.CryptoKeys, encryptionKey)

Callers

nothing calls this directly

Calls 15

StatusCodeMethod · 0.95
ContextFunction · 0.92
NewDBFunction · 0.92
NewWithAPIFunction · 0.92
CryptoKeyFunction · 0.92
CryptoKeyFunction · 0.92
NewWorkspaceProxyReplicaFunction · 0.92
GetRandomNameFunction · 0.92
NewFunction · 0.92
requireContainsKeysFunction · 0.85
requireNotContainsKeysFunction · 0.85
CryptoKeysMethod · 0.80

Tested by

no test coverage detected