Skip to content

Commit 21ecb38

Browse files
committed
Merge branch 'main' into fastpg
2 parents 6f05b7d + dac6838 commit 21ecb38

12 files changed

+24
-23
lines changed

cli/server_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func TestServer(t *testing.T) {
170170
require.Eventually(t, func() bool {
171171
var err error
172172
accessURLRaw, err = cfg.URL().Read()
173-
return err == nil
173+
return accessURLRaw != "" && err == nil
174174
}, 15*time.Second, 25*time.Millisecond)
175175
accessURL, err := url.Parse(accessURLRaw)
176176
require.NoError(t, err)

cli/ssh_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func TestSSH(t *testing.T) {
6868
t.Run("ImmediateExit", func(t *testing.T) {
6969
t.Parallel()
7070
client, workspace, agentToken := setupWorkspaceForSSH(t)
71+
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
7172
cmd, root := clitest.New(t, "ssh", workspace.Name)
7273
clitest.SetupConfig(t, client, root)
7374
pty := ptytest.New(t)
@@ -79,7 +80,6 @@ func TestSSH(t *testing.T) {
7980
assert.NoError(t, err)
8081
})
8182
pty.ExpectMatch("Waiting")
82-
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
8383
agentClient := codersdk.New(client.URL)
8484
agentClient.SessionToken = agentToken
8585
agentCloser := agent.New(agentClient.ListenWorkspaceAgent, &agent.Options{

coderd/coderdtest/coderdtest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func AwaitWorkspaceAgents(t *testing.T, client *codersdk.Client, build uuid.UUID
394394
}
395395
}
396396
return true
397-
}, 5*time.Second, 25*time.Millisecond)
397+
}, 15*time.Second, 50*time.Millisecond)
398398
return resources
399399
}
400400

coderd/database/queries.sql.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templateversions.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ ORDER BY
2929
-- a timestamp. This is to ensure consistent pagination.
3030
(created_at, id) ASC OFFSET @offset_opt
3131
LIMIT
32-
-- A null limit means "no limit", so -1 means return all
33-
NULLIF(@limit_opt :: int, -1);
32+
-- A null limit means "no limit", so 0 means return all
33+
NULLIF(@limit_opt :: int, 0);
3434

3535
-- name: GetTemplateVersionByJobID :one
3636
SELECT

coderd/database/queries/users.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ ORDER BY
126126
-- a timestamp. This is to ensure consistent pagination.
127127
(created_at, id) ASC OFFSET @offset_opt
128128
LIMIT
129-
-- A null limit means "no limit", so -1 means return all
130-
NULLIF(@limit_opt :: int, -1);
129+
-- A null limit means "no limit", so 0 means return all
130+
NULLIF(@limit_opt :: int, 0);
131131

132132
-- name: UpdateUserStatus :one
133133
UPDATE

coderd/database/queries/workspacebuilds.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ END
6868
ORDER BY
6969
build_number desc OFFSET @offset_opt
7070
LIMIT
71-
-- A null limit means "no limit", so -1 means return all
72-
NULLIF(@limit_opt :: int, -1);
71+
-- A null limit means "no limit", so 0 means return all
72+
NULLIF(@limit_opt :: int, 0);
7373

7474
-- name: GetLatestWorkspaceBuildByWorkspaceID :one
7575
SELECT

coderd/httpmw/apikey.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
167167
// Only update LastUsed once an hour to prevent database spam.
168168
if now.Sub(key.LastUsed) > time.Hour {
169169
key.LastUsed = now
170-
remoteIP := net.ParseIP(r.RemoteAddr)
170+
host, _, _ := net.SplitHostPort(r.RemoteAddr)
171+
remoteIP := net.ParseIP(host)
171172
if remoteIP == nil {
172173
remoteIP = net.IPv4(0, 0, 0, 0)
173174
}

coderd/httpmw/apikey_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto/sha256"
66
"fmt"
7+
"net"
78
"net/http"
89
"net/http/httptest"
910
"testing"
@@ -413,13 +414,13 @@ func TestAPIKey(t *testing.T) {
413414
rw = httptest.NewRecorder()
414415
user = createUser(r.Context(), t, db)
415416
)
416-
r.RemoteAddr = "1.1.1.1"
417+
r.RemoteAddr = "1.1.1.1:3555"
417418
r.AddCookie(&http.Cookie{
418419
Name: httpmw.SessionTokenKey,
419420
Value: fmt.Sprintf("%s-%s", id, secret),
420421
})
421422

422-
sentAPIKey, err := db.InsertAPIKey(r.Context(), database.InsertAPIKeyParams{
423+
_, err := db.InsertAPIKey(r.Context(), database.InsertAPIKeyParams{
423424
ID: id,
424425
HashedSecret: hashed[:],
425426
LastUsed: database.Now().AddDate(0, 0, -1),
@@ -435,7 +436,7 @@ func TestAPIKey(t *testing.T) {
435436
gotAPIKey, err := db.GetAPIKeyByID(r.Context(), id)
436437
require.NoError(t, err)
437438

438-
require.NotEqual(t, sentAPIKey.IPAddress, gotAPIKey.IPAddress)
439+
require.Equal(t, net.ParseIP("1.1.1.1"), gotAPIKey.IPAddress.IPNet.IP)
439440
})
440441
}
441442

coderd/pagination.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func parsePagination(w http.ResponseWriter, r *http.Request) (p codersdk.Paginat
1717
params := codersdk.Pagination{
1818
AfterID: parser.UUID(queryParams, uuid.Nil, "after_id"),
1919
// Limit default to "-1" which returns all results
20-
Limit: parser.Int(queryParams, -1, "limit"),
20+
Limit: parser.Int(queryParams, 0, "limit"),
2121
Offset: parser.Int(queryParams, 0, "offset"),
2222
}
2323
if len(parser.Errors) > 0 {

coderd/pagination_internal_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,13 @@ func TestPagination(t *testing.T) {
7777
ExpectedParams: codersdk.Pagination{
7878
AfterID: uuid.Nil,
7979
Offset: 150,
80-
Limit: -1,
8180
},
8281
},
8382
{
8483
Name: "ValidAfterID",
8584
AfterID: "5f2005fc-acc4-4e5e-a7fa-be017359c60b",
8685
ExpectedParams: codersdk.Pagination{
8786
AfterID: uuid.MustParse("5f2005fc-acc4-4e5e-a7fa-be017359c60b"),
88-
Limit: -1,
8987
},
9088
},
9189
}

coderd/users.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,8 @@ func (api *API) createAPIKey(rw http.ResponseWriter, r *http.Request, params dat
782782
}
783783
}
784784

785-
ip := net.ParseIP(r.RemoteAddr)
785+
host, _, _ := net.SplitHostPort(r.RemoteAddr)
786+
ip := net.ParseIP(host)
786787
if ip == nil {
787788
ip = net.IPv4(0, 0, 0, 0)
788789
}

0 commit comments

Comments
 (0)