Skip to content

Commit aed38ad

Browse files
committed
Merge branch 'main' into nomagicparams
2 parents 9830266 + bd0293a commit aed38ad

File tree

7 files changed

+141
-31
lines changed

7 files changed

+141
-31
lines changed

.github/workflows/coder.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ jobs:
3838
runs-on: ubuntu-latest
3939
steps:
4040
- uses: actions/checkout@v2
41+
- uses: actions/setup-go@v2
42+
with:
43+
go-version: "^1.17"
4144
- name: golangci-lint
42-
uses: golangci/golangci-lint-action@v2
45+
uses: golangci/golangci-lint-action@v3.1.0
4346
with:
4447
version: v1.43.0
4548

cryptorand/errors_test.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package cryptorand_test
2+
3+
import (
4+
"crypto/rand"
5+
"io"
6+
"testing"
7+
"testing/iotest"
8+
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/coder/coder/cryptorand"
12+
)
13+
14+
// TestRandError checks that the code handles errors when reading from
15+
// the rand.Reader.
16+
//
17+
// This test replaces the global rand.Reader, so cannot be parallelized
18+
//nolint:paralleltest
19+
func TestRandError(t *testing.T) {
20+
var origReader = rand.Reader
21+
t.Cleanup(func() {
22+
rand.Reader = origReader
23+
})
24+
25+
rand.Reader = iotest.ErrReader(io.ErrShortBuffer)
26+
27+
t.Run("Int63", func(t *testing.T) {
28+
_, err := cryptorand.Int63()
29+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Int63 error")
30+
})
31+
32+
t.Run("Uint64", func(t *testing.T) {
33+
_, err := cryptorand.Uint64()
34+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Uint64 error")
35+
})
36+
37+
t.Run("Int31", func(t *testing.T) {
38+
_, err := cryptorand.Int31()
39+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Int31 error")
40+
})
41+
42+
t.Run("Int31n", func(t *testing.T) {
43+
_, err := cryptorand.Int31n(100)
44+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Int31n error")
45+
})
46+
47+
t.Run("Uint32", func(t *testing.T) {
48+
_, err := cryptorand.Uint32()
49+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Uint32 error")
50+
})
51+
52+
t.Run("Int", func(t *testing.T) {
53+
_, err := cryptorand.Int()
54+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Int error")
55+
})
56+
57+
t.Run("Intn_32bit", func(t *testing.T) {
58+
_, err := cryptorand.Intn(100)
59+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Intn error")
60+
})
61+
62+
t.Run("Intn_64bit", func(t *testing.T) {
63+
_, err := cryptorand.Intn(int(1 << 35))
64+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Intn error")
65+
})
66+
67+
t.Run("Float64", func(t *testing.T) {
68+
_, err := cryptorand.Float64()
69+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Float64 error")
70+
})
71+
72+
t.Run("Float32", func(t *testing.T) {
73+
_, err := cryptorand.Float32()
74+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Float32 error")
75+
})
76+
77+
t.Run("Bool", func(t *testing.T) {
78+
_, err := cryptorand.Bool()
79+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected Bool error")
80+
})
81+
82+
t.Run("StringCharset", func(t *testing.T) {
83+
_, err := cryptorand.HexString(10)
84+
require.ErrorIs(t, err, io.ErrShortBuffer, "expected HexString error")
85+
})
86+
}

cryptorand/numbers_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ func TestInt63n(t *testing.T) {
9292
require.True(t, v >= 0, "values must be positive")
9393
require.True(t, v < 1<<35, "values must be less than 1<<35")
9494
}
95+
96+
// Expect a panic if max is negative
97+
require.PanicsWithValue(t, "invalid argument to Int63n", func() {
98+
cryptorand.Int63n(0)
99+
})
95100
}
96101

97102
func TestInt31n(t *testing.T) {
@@ -116,6 +121,15 @@ func TestIntn(t *testing.T) {
116121
require.True(t, v >= 0, "values must be positive")
117122
require.True(t, v < 100, "values must be less than 100")
118123
}
124+
125+
// Ensure Intn works for int larger than 32 bits
126+
_, err := cryptorand.Intn(1 << 35)
127+
require.NoError(t, err, "expected Intn to work for 64-bit int")
128+
129+
// Expect a panic if max is negative
130+
require.PanicsWithValue(t, "n must be a positive nonzero number", func() {
131+
cryptorand.Intn(0)
132+
})
119133
}
120134

121135
func TestFloat64(t *testing.T) {

peer/conn_test.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func TestConn(t *testing.T) {
6464
t.Run("Ping", func(t *testing.T) {
6565
t.Parallel()
6666
client, server, _ := createPair(t)
67-
exchange(client, server)
67+
exchange(t, client, server)
6868
_, err := client.Ping()
6969
require.NoError(t, err)
7070
_, err = server.Ping()
@@ -74,7 +74,7 @@ func TestConn(t *testing.T) {
7474
t.Run("PingNetworkOffline", func(t *testing.T) {
7575
t.Parallel()
7676
client, server, wan := createPair(t)
77-
exchange(client, server)
77+
exchange(t, client, server)
7878
_, err := server.Ping()
7979
require.NoError(t, err)
8080
err = wan.Stop()
@@ -86,7 +86,7 @@ func TestConn(t *testing.T) {
8686
t.Run("PingReconnect", func(t *testing.T) {
8787
t.Parallel()
8888
client, server, wan := createPair(t)
89-
exchange(client, server)
89+
exchange(t, client, server)
9090
_, err := server.Ping()
9191
require.NoError(t, err)
9292
// Create a channel that closes on disconnect.
@@ -107,7 +107,7 @@ func TestConn(t *testing.T) {
107107
t.Run("Accept", func(t *testing.T) {
108108
t.Parallel()
109109
client, server, _ := createPair(t)
110-
exchange(client, server)
110+
exchange(t, client, server)
111111
cch, err := client.Dial(context.Background(), "hello", &peer.ChannelOptions{})
112112
require.NoError(t, err)
113113

@@ -123,7 +123,7 @@ func TestConn(t *testing.T) {
123123
t.Run("AcceptNetworkOffline", func(t *testing.T) {
124124
t.Parallel()
125125
client, server, wan := createPair(t)
126-
exchange(client, server)
126+
exchange(t, client, server)
127127
cch, err := client.Dial(context.Background(), "hello", &peer.ChannelOptions{})
128128
require.NoError(t, err)
129129
sch, err := server.Accept(context.Background())
@@ -140,7 +140,7 @@ func TestConn(t *testing.T) {
140140
t.Run("Buffering", func(t *testing.T) {
141141
t.Parallel()
142142
client, server, _ := createPair(t)
143-
exchange(client, server)
143+
exchange(t, client, server)
144144
cch, err := client.Dial(context.Background(), "hello", &peer.ChannelOptions{})
145145
require.NoError(t, err)
146146
sch, err := server.Accept(context.Background())
@@ -167,7 +167,7 @@ func TestConn(t *testing.T) {
167167
t.Run("NetConn", func(t *testing.T) {
168168
t.Parallel()
169169
client, server, _ := createPair(t)
170-
exchange(client, server)
170+
exchange(t, client, server)
171171
srv, err := net.Listen("tcp", "127.0.0.1:0")
172172
require.NoError(t, err)
173173
defer srv.Close()
@@ -220,7 +220,7 @@ func TestConn(t *testing.T) {
220220
t.Run("CloseBeforeNegotiate", func(t *testing.T) {
221221
t.Parallel()
222222
client, server, _ := createPair(t)
223-
exchange(client, server)
223+
exchange(t, client, server)
224224
err := client.Close()
225225
require.NoError(t, err)
226226
err = server.Close()
@@ -240,7 +240,7 @@ func TestConn(t *testing.T) {
240240
t.Run("PingConcurrent", func(t *testing.T) {
241241
t.Parallel()
242242
client, server, _ := createPair(t)
243-
exchange(client, server)
243+
exchange(t, client, server)
244244
var wg sync.WaitGroup
245245
wg.Add(2)
246246
go func() {
@@ -271,7 +271,7 @@ func TestConn(t *testing.T) {
271271
t.Run("ShortBuffer", func(t *testing.T) {
272272
t.Parallel()
273273
client, server, _ := createPair(t)
274-
exchange(client, server)
274+
exchange(t, client, server)
275275
go func() {
276276
channel, err := client.Dial(context.Background(), "test", nil)
277277
require.NoError(t, err)
@@ -345,8 +345,17 @@ func createPair(t *testing.T) (client *peer.Conn, server *peer.Conn, wan *vnet.R
345345
return channel1, channel2, wan
346346
}
347347

348-
func exchange(client, server *peer.Conn) {
348+
func exchange(t *testing.T, client, server *peer.Conn) {
349+
var wg sync.WaitGroup
350+
wg.Add(2)
351+
t.Cleanup(func() {
352+
_ = client.Close()
353+
_ = server.Close()
354+
355+
wg.Wait()
356+
})
349357
go func() {
358+
defer wg.Done()
350359
for {
351360
select {
352361
case c := <-server.LocalCandidate():
@@ -358,8 +367,8 @@ func exchange(client, server *peer.Conn) {
358367
}
359368
}
360369
}()
361-
362370
go func() {
371+
defer wg.Done()
363372
for {
364373
select {
365374
case c := <-client.LocalCandidate():

provisioner/terraform/provider/provider.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package provider
33
import (
44
"context"
55
"net/url"
6-
"os"
76
"reflect"
87
"strings"
98

@@ -29,9 +28,7 @@ func New() *schema.Provider {
2928
Optional: true,
3029
// The "CODER_URL" environment variable is used by default
3130
// as the Access URL when generating scripts.
32-
DefaultFunc: func() (interface{}, error) {
33-
return os.Getenv("CODER_URL"), nil
34-
},
31+
DefaultFunc: schema.EnvDefaultFunc("CODER_URL", ""),
3532
ValidateFunc: func(i interface{}, s string) ([]string, []error) {
3633
_, err := url.Parse(s)
3734
if err != nil {
@@ -107,8 +104,9 @@ func New() *schema.Provider {
107104
ValidateFunc: validation.StringInSlice([]string{"linux", "darwin", "windows"}, false),
108105
},
109106
"arch": {
110-
Type: schema.TypeString,
111-
Required: true,
107+
Type: schema.TypeString,
108+
Required: true,
109+
ValidateFunc: validation.StringInSlice([]string{"amd64"}, false),
112110
},
113111
"value": {
114112
Type: schema.TypeString,

site/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"eslint-plugin-jest": "26.1.1",
4545
"eslint-plugin-jsx-a11y": "6.5.1",
4646
"eslint-plugin-no-storage": "1.0.2",
47-
"eslint-plugin-react": "7.28.0",
47+
"eslint-plugin-react": "7.29.2",
4848
"eslint-plugin-react-hooks": "4.3.0",
4949
"express": "4.17.3",
5050
"formik": "2.2.9",

site/yarn.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5800,22 +5800,22 @@ eslint-plugin-react-hooks@4.3.0:
58005800
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.3.0.tgz#318dbf312e06fab1c835a4abef00121751ac1172"
58015801
integrity sha512-XslZy0LnMn+84NEG9jSGR6eGqaZB3133L8xewQo3fQagbQuGt7a63gf+P1NGKZavEYEC3UXaWEAA/AqDkuN6xA==
58025802

5803-
eslint-plugin-react@7.28.0:
5804-
version "7.28.0"
5805-
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.28.0.tgz#8f3ff450677571a659ce76efc6d80b6a525adbdf"
5806-
integrity sha512-IOlFIRHzWfEQQKcAD4iyYDndHwTQiCMcJVJjxempf203jnNLUnW34AXLrV33+nEXoifJE2ZEGmcjKPL8957eSw==
5803+
eslint-plugin-react@7.29.2:
5804+
version "7.29.2"
5805+
resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-7.29.2.tgz#2d4da69d30d0a736efd30890dc6826f3e91f3f7c"
5806+
integrity sha512-ypEBTKOy5liFQXZWMchJ3LN0JX1uPI6n7MN7OPHKacqXAxq5gYC30TdO7wqGYQyxD1OrzpobdHC3hDmlRWDg9w==
58075807
dependencies:
58085808
array-includes "^3.1.4"
58095809
array.prototype.flatmap "^1.2.5"
58105810
doctrine "^2.1.0"
58115811
estraverse "^5.3.0"
58125812
jsx-ast-utils "^2.4.1 || ^3.0.0"
5813-
minimatch "^3.0.4"
5813+
minimatch "^3.1.2"
58145814
object.entries "^1.1.5"
58155815
object.fromentries "^2.0.5"
58165816
object.hasown "^1.1.0"
58175817
object.values "^1.1.5"
5818-
prop-types "^15.7.2"
5818+
prop-types "^15.8.1"
58195819
resolve "^2.0.0-next.3"
58205820
semver "^6.3.0"
58215821
string.prototype.matchall "^4.0.6"
@@ -8895,10 +8895,10 @@ minimalistic-crypto-utils@^1.0.1:
88958895
resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a"
88968896
integrity sha1-9sAMHAsIIkblxNmd+4x8CDsrWCo=
88978897

8898-
minimatch@^3.0.2, minimatch@^3.0.4:
8899-
version "3.0.4"
8900-
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
8901-
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
8898+
minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.2:
8899+
version "3.1.2"
8900+
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"
8901+
integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==
89028902
dependencies:
89038903
brace-expansion "^1.1.7"
89048904

@@ -9931,7 +9931,7 @@ prompts@^2.0.1, prompts@^2.4.0:
99319931
kleur "^3.0.3"
99329932
sisteransi "^1.0.5"
99339933

9934-
prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2:
9934+
prop-types@^15.0.0, prop-types@^15.5.10, prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2, prop-types@^15.8.1:
99359935
version "15.8.1"
99369936
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
99379937
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==

0 commit comments

Comments
 (0)