mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
@ -271,7 +271,7 @@ func TestMigrateUpWithFixtures(t *testing.T) {
|
||||
|
||||
db := testSQLDB(t)
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
// Prepare database for stepping up.
|
||||
err := migrations.Down(db)
|
||||
|
@ -28,7 +28,7 @@ func TestDeploymentValues(t *testing.T) {
|
||||
DeploymentValues: cfg,
|
||||
})
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
scrubbed, err := client.DeploymentValues(ctx)
|
||||
scrubbed, err := client.DeploymentConfig(ctx)
|
||||
require.NoError(t, err)
|
||||
// ensure normal values pass through
|
||||
require.EqualValues(t, true, scrubbed.Values.BrowserOnly.Value())
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gitsshkey
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto"
|
||||
"crypto/ecdsa"
|
||||
"crypto/ed25519"
|
||||
@ -9,7 +10,12 @@ import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"flag"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
insecurerand "math/rand"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
"golang.org/x/xerrors"
|
||||
@ -27,6 +33,18 @@ const (
|
||||
AlgorithmRSA4096 Algorithm = "rsa4096"
|
||||
)
|
||||
|
||||
func entropy() io.Reader {
|
||||
if flag.Lookup("test.v") != nil {
|
||||
// This helps speed along our tests, esp. in CI where entropy is
|
||||
// sparse.
|
||||
//nolint:gosec
|
||||
return insecurerand.New(insecurerand.NewSource(time.Now().UnixNano()))
|
||||
}
|
||||
// Buffering to reduce the number of system calls
|
||||
// doubles performance without any loss of security.
|
||||
return bufio.NewReader(rand.Reader)
|
||||
}
|
||||
|
||||
// ParseAlgorithm returns a valid Algorithm or error if input is not a valid.
|
||||
func ParseAlgorithm(t string) (Algorithm, error) {
|
||||
ok := []string{
|
||||
@ -61,7 +79,7 @@ func Generate(algo Algorithm) (privateKey string, publicKey string, err error) {
|
||||
|
||||
// ed25519KeyGen returns an ED25519-based SSH private key.
|
||||
func ed25519KeyGen() (privateKey string, publicKey string, err error) {
|
||||
_, privateKeyRaw, err := ed25519.GenerateKey(rand.Reader)
|
||||
_, privateKeyRaw, err := ed25519.GenerateKey(entropy())
|
||||
if err != nil {
|
||||
return "", "", xerrors.Errorf("generate ed25519 private key: %w", err)
|
||||
}
|
||||
@ -82,7 +100,7 @@ func ed25519KeyGen() (privateKey string, publicKey string, err error) {
|
||||
|
||||
// ecdsaKeyGen returns an ECDSA-based SSH private key.
|
||||
func ecdsaKeyGen() (privateKey string, publicKey string, err error) {
|
||||
privateKeyRaw, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||
privateKeyRaw, err := ecdsa.GenerateKey(elliptic.P256(), entropy())
|
||||
if err != nil {
|
||||
return "", "", xerrors.Errorf("generate ecdsa private key: %w", err)
|
||||
}
|
||||
@ -101,7 +119,7 @@ func ecdsaKeyGen() (privateKey string, publicKey string, err error) {
|
||||
//
|
||||
// Administrators may configure this for SSH key compatibility with Azure DevOps.
|
||||
func rsa4096KeyGen() (privateKey string, publicKey string, err error) {
|
||||
privateKeyRaw, err := rsa.GenerateKey(rand.Reader, 4096)
|
||||
privateKeyRaw, err := rsa.GenerateKey(entropy(), 4096)
|
||||
if err != nil {
|
||||
return "", "", xerrors.Errorf("generate RSA4096 private key: %w", err)
|
||||
}
|
||||
|
@ -55,3 +55,14 @@ func TestGitSSHKeys(t *testing.T) {
|
||||
require.Error(t, err, "empty string should fail")
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkGenerate(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
// Note that this is using dumbRand under the hood, so it will be
|
||||
// a lot slower in production.
|
||||
_, _, err := gitsshkey.Generate(gitsshkey.AlgorithmRSA4096)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func TestTemplateVersion(t *testing.T) {
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
_ = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
client1, _ := coderdtest.CreateAnotherUser(t, client, user.OrganizationID)
|
||||
|
||||
|
@ -65,7 +65,7 @@ func TestChecker_Notify(t *testing.T) {
|
||||
})
|
||||
defer c.Close()
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
for i := 0; i < len(wantVersion); i++ {
|
||||
select {
|
||||
@ -138,7 +138,7 @@ func TestChecker_Latest(t *testing.T) {
|
||||
})
|
||||
defer c.Close()
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
_ = ctx
|
||||
|
||||
gotR, err := c.Latest(ctx)
|
||||
|
@ -69,7 +69,7 @@ func TestUpdateCheck_NewVersion(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
got, err := client.UpdateCheck(ctx)
|
||||
require.NoError(t, err)
|
||||
|
@ -665,7 +665,7 @@ func TestUserOIDC(t *testing.T) {
|
||||
numLogs++ // add an audit log for login
|
||||
assert.Equal(t, tc.StatusCode, resp.StatusCode)
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
if tc.Username != "" {
|
||||
client.SetSessionToken(authCookieValue(resp.Cookies()))
|
||||
@ -712,7 +712,7 @@ func TestUserOIDC(t *testing.T) {
|
||||
|
||||
assert.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode)
|
||||
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
client.SetSessionToken(authCookieValue(resp.Cookies()))
|
||||
user, err := client.User(ctx, "me")
|
||||
|
@ -708,7 +708,7 @@ func TestUpdateUserPassword(t *testing.T) {
|
||||
|
||||
client := coderdtest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
apikey1, err := client.CreateToken(ctx, user.UserID.String(), codersdk.CreateTokenRequest{})
|
||||
require.NoError(t, err)
|
||||
@ -754,7 +754,7 @@ func TestUpdateUserPassword(t *testing.T) {
|
||||
|
||||
client := coderdtest.New(t, nil)
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
err := client.UpdateUserPassword(ctx, "me", codersdk.UpdateUserPasswordRequest{
|
||||
Password: coderdtest.FirstUserParams.Password,
|
||||
|
@ -179,8 +179,7 @@ func TestWorkspaceAgentStartupLogs(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancelFunc := testutil.Context(t)
|
||||
defer cancelFunc()
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
client := coderdtest.New(t, &coderdtest.Options{
|
||||
IncludeProvisionerDaemon: true,
|
||||
})
|
||||
@ -234,12 +233,10 @@ func TestWorkspaceAgentStartupLogs(t *testing.T) {
|
||||
require.NoError(t, ctx.Err())
|
||||
require.Len(t, logChunk, 1)
|
||||
require.Equal(t, "testing", logChunk[0].Output)
|
||||
cancelFunc()
|
||||
})
|
||||
t.Run("PublishesOnOverflow", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancelFunc := testutil.Context(t)
|
||||
defer cancelFunc()
|
||||
ctx := testutil.Context(t, testutil.WaitMedium)
|
||||
client := coderdtest.New(t, &coderdtest.Options{
|
||||
IncludeProvisionerDaemon: true,
|
||||
})
|
||||
@ -293,7 +290,6 @@ func TestWorkspaceAgentStartupLogs(t *testing.T) {
|
||||
}
|
||||
// Ensure that the UI gets an update when the logs overflow!
|
||||
require.True(t, update.LatestBuild.Resources[0].Agents[0].StartupLogsOverflowed)
|
||||
cancelFunc()
|
||||
})
|
||||
}
|
||||
|
||||
@ -985,8 +981,7 @@ func TestWorkspaceAgentsGitAuth(t *testing.T) {
|
||||
})
|
||||
t.Run("ValidateURL", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancelFunc := testutil.Context(t)
|
||||
defer cancelFunc()
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
srv := httptest.NewServer(nil)
|
||||
defer srv.Close()
|
||||
@ -1239,7 +1234,7 @@ func TestWorkspaceAgent_LifecycleState(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(string(tt.state), func(t *testing.T) {
|
||||
ctx, _ := testutil.Context(t)
|
||||
ctx := testutil.Context(t, testutil.WaitLong)
|
||||
|
||||
err := agentClient.PostLifecycle(ctx, agentsdk.PostLifecycleRequest{
|
||||
State: tt.state,
|
||||
|
@ -1436,11 +1436,11 @@ func TestAppSharing(t *testing.T) {
|
||||
siteOwnerCanAccess := !isPathApp || siteOwnerPathAppAccessEnabled
|
||||
siteOwnerCanAccessShared := siteOwnerCanAccess || pathAppSharingEnabled
|
||||
|
||||
deploymentValues, err := ownerClient.DeploymentValues(context.Background())
|
||||
deploymentConfig, err := ownerClient.DeploymentConfig(context.Background())
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, pathAppSharingEnabled, deploymentValues.Values.Dangerous.AllowPathAppSharing.Value())
|
||||
assert.Equal(t, siteOwnerPathAppAccessEnabled, deploymentValues.Values.Dangerous.AllowPathAppSiteOwnerAccess.Value())
|
||||
assert.Equal(t, pathAppSharingEnabled, deploymentConfig.Values.Dangerous.AllowPathAppSharing.Value())
|
||||
assert.Equal(t, siteOwnerPathAppAccessEnabled, deploymentConfig.Values.Dangerous.AllowPathAppSiteOwnerAccess.Value())
|
||||
|
||||
t.Run("LevelOwner", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
Reference in New Issue
Block a user