Skip to content

Commit 15597a0

Browse files
committed
Merge branch 'main' of https://github.com/coder/coder into bq/improve-build-logs-page
2 parents e4340d9 + 94cbc2a commit 15597a0

File tree

19 files changed

+293
-147
lines changed

19 files changed

+293
-147
lines changed

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ issues:
211211
run:
212212
skip-dirs:
213213
- node_modules
214+
- .git
214215
skip-files:
215216
- scripts/rules.go
216217
timeout: 10m

agent/agent_test.go

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package agent_test
22

33
import (
4-
"bufio"
54
"bytes"
65
"context"
76
"encoding/json"
@@ -1588,10 +1587,6 @@ func TestAgent_Startup(t *testing.T) {
15881587
})
15891588
}
15901589

1591-
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
1592-
1593-
var re = regexp.MustCompile(ansi)
1594-
15951590
//nolint:paralleltest // This test sets an environment variable.
15961591
func TestAgent_ReconnectingPTY(t *testing.T) {
15971592
if runtime.GOOS == "windows" {
@@ -1635,17 +1630,14 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16351630
//nolint:dogsled
16361631
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0)
16371632
id := uuid.New()
1638-
netConn1, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1633+
netConn1, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16391634
require.NoError(t, err)
16401635
defer netConn1.Close()
16411636

1642-
scanner1 := bufio.NewScanner(netConn1)
1643-
16441637
// A second simultaneous connection.
1645-
netConn2, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1638+
netConn2, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16461639
require.NoError(t, err)
16471640
defer netConn2.Close()
1648-
scanner2 := bufio.NewScanner(netConn2)
16491641

16501642
// Brief pause to reduce the likelihood that we send keystrokes while
16511643
// the shell is simultaneously sending a prompt.
@@ -1658,17 +1650,6 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16581650
_, err = netConn1.Write(data)
16591651
require.NoError(t, err)
16601652

1661-
hasLine := func(scanner *bufio.Scanner, matcher func(string) bool) bool {
1662-
for scanner.Scan() {
1663-
line := scanner.Text()
1664-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1665-
if matcher(line) {
1666-
return true
1667-
}
1668-
}
1669-
return false
1670-
}
1671-
16721653
matchEchoCommand := func(line string) bool {
16731654
return strings.Contains(line, "echo test")
16741655
}
@@ -1683,25 +1664,23 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
16831664
}
16841665

16851666
// Once for typing the command...
1686-
require.True(t, hasLine(scanner1, matchEchoCommand), "find echo command")
1667+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoCommand), "find echo command")
16871668
// And another time for the actual output.
1688-
require.True(t, hasLine(scanner1, matchEchoOutput), "find echo output")
1669+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn1, matchEchoOutput), "find echo output")
16891670

16901671
// Same for the other connection.
1691-
require.True(t, hasLine(scanner2, matchEchoCommand), "find echo command")
1692-
require.True(t, hasLine(scanner2, matchEchoOutput), "find echo output")
1672+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoCommand), "find echo command")
1673+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn2, matchEchoOutput), "find echo output")
16931674

16941675
_ = netConn1.Close()
16951676
_ = netConn2.Close()
1696-
netConn3, err := conn.ReconnectingPTY(ctx, id, 100, 100, "bash")
1677+
netConn3, err := conn.ReconnectingPTY(ctx, id, 80, 80, "bash")
16971678
require.NoError(t, err)
16981679
defer netConn3.Close()
16991680

1700-
scanner3 := bufio.NewScanner(netConn3)
1701-
17021681
// Same output again!
1703-
require.True(t, hasLine(scanner3, matchEchoCommand), "find echo command")
1704-
require.True(t, hasLine(scanner3, matchEchoOutput), "find echo output")
1682+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoCommand), "find echo command")
1683+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchEchoOutput), "find echo output")
17051684

17061685
// Exit should cause the connection to close.
17071686
data, err = json.Marshal(codersdk.ReconnectingPTYRequest{
@@ -1712,26 +1691,19 @@ func TestAgent_ReconnectingPTY(t *testing.T) {
17121691
require.NoError(t, err)
17131692

17141693
// Once for the input and again for the output.
1715-
require.True(t, hasLine(scanner3, matchExitCommand), "find exit command")
1716-
require.True(t, hasLine(scanner3, matchExitOutput), "find exit output")
1694+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitCommand), "find exit command")
1695+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn3, matchExitOutput), "find exit output")
17171696

17181697
// Wait for the connection to close.
1719-
for scanner3.Scan() {
1720-
line := scanner3.Text()
1721-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1722-
}
1698+
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
17231699

17241700
// Try a non-shell command. It should output then immediately exit.
1725-
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 100, 100, "echo test")
1701+
netConn4, err := conn.ReconnectingPTY(ctx, uuid.New(), 80, 80, "echo test")
17261702
require.NoError(t, err)
17271703
defer netConn4.Close()
17281704

1729-
scanner4 := bufio.NewScanner(netConn4)
1730-
require.True(t, hasLine(scanner4, matchEchoOutput), "find echo output")
1731-
for scanner4.Scan() {
1732-
line := scanner4.Text()
1733-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1734-
}
1705+
require.NoError(t, testutil.ReadUntil(ctx, t, netConn4, matchEchoOutput), "find echo output")
1706+
require.ErrorIs(t, testutil.ReadUntil(ctx, t, netConn3, nil), io.EOF)
17351707
})
17361708
}
17371709
}

agent/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"sync"
66
"time"
77

8-
"github.com/go-chi/chi"
8+
"github.com/go-chi/chi/v5"
99

1010
"github.com/coder/coder/coderd/httpapi"
1111
"github.com/coder/coder/codersdk"

coderd/telemetry/telemetry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99
"time"
1010

11-
"github.com/go-chi/chi"
11+
"github.com/go-chi/chi/v5"
1212
"github.com/google/uuid"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"

coderd/userauth.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ func (api *API) postConvertLoginType(rw http.ResponseWriter, r *http.Request) {
184184
Expires: claims.ExpiresAt.Time,
185185
Secure: api.SecureAuthCookie,
186186
HttpOnly: true,
187-
SameSite: http.SameSiteStrictMode,
187+
// Must be SameSite to work on the redirected auth flow from the
188+
// oauth provider.
189+
SameSite: http.SameSiteLaxMode,
188190
})
189191
httpapi.Write(ctx, rw, http.StatusCreated, codersdk.OAuthConversionResponse{
190192
StateString: stateString,

coderd/workspaceapps/apptest/apptest.go

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net/http/httputil"
1313
"net/url"
1414
"path"
15-
"regexp"
1615
"runtime"
1716
"strconv"
1817
"strings"
@@ -32,10 +31,6 @@ import (
3231
"github.com/coder/coder/testutil"
3332
)
3433

35-
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
36-
37-
var re = regexp.MustCompile(ansi)
38-
3934
// Run runs the entire workspace app test suite against deployments minted
4035
// by the provided factory.
4136
//
@@ -70,8 +65,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
7065
testReconnectingPTY(ctx, t, client, codersdk.WorkspaceAgentReconnectingPTYOpts{
7166
AgentID: appDetails.Agent.ID,
7267
Reconnect: uuid.New(),
73-
Height: 80,
74-
Width: 80,
68+
Height: 100,
69+
Width: 100,
7570
Command: "bash",
7671
})
7772
})
@@ -104,8 +99,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
10499
testReconnectingPTY(ctx, t, unauthedAppClient, codersdk.WorkspaceAgentReconnectingPTYOpts{
105100
AgentID: appDetails.Agent.ID,
106101
Reconnect: uuid.New(),
107-
Height: 80,
108-
Width: 80,
102+
Height: 100,
103+
Width: 100,
109104
Command: "bash",
110105
SignedToken: issueRes.SignedToken,
111106
})
@@ -1407,16 +1402,6 @@ func (r *fakeStatsReporter) Report(_ context.Context, stats []workspaceapps.Stat
14071402
}
14081403

14091404
func testReconnectingPTY(ctx context.Context, t *testing.T, client *codersdk.Client, opts codersdk.WorkspaceAgentReconnectingPTYOpts) {
1410-
hasLine := func(scanner *bufio.Scanner, matcher func(string) bool) bool {
1411-
for scanner.Scan() {
1412-
line := scanner.Text()
1413-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1414-
if matcher(line) {
1415-
return true
1416-
}
1417-
}
1418-
return false
1419-
}
14201405
matchEchoCommand := func(line string) bool {
14211406
return strings.Contains(line, "echo test")
14221407
}
@@ -1437,13 +1422,12 @@ func testReconnectingPTY(ctx context.Context, t *testing.T, client *codersdk.Cli
14371422
// First attempt to resize the TTY.
14381423
// The websocket will close if it fails!
14391424
data, err := json.Marshal(codersdk.ReconnectingPTYRequest{
1440-
Height: 250,
1441-
Width: 250,
1425+
Height: 80,
1426+
Width: 80,
14421427
})
14431428
require.NoError(t, err)
14441429
_, err = conn.Write(data)
14451430
require.NoError(t, err)
1446-
scanner := bufio.NewScanner(conn)
14471431

14481432
// Brief pause to reduce the likelihood that we send keystrokes while
14491433
// the shell is simultaneously sending a prompt.
@@ -1456,8 +1440,8 @@ func testReconnectingPTY(ctx context.Context, t *testing.T, client *codersdk.Cli
14561440
_, err = conn.Write(data)
14571441
require.NoError(t, err)
14581442

1459-
require.True(t, hasLine(scanner, matchEchoCommand), "find echo command")
1460-
require.True(t, hasLine(scanner, matchEchoOutput), "find echo output")
1443+
require.NoError(t, testutil.ReadUntil(ctx, t, conn, matchEchoCommand), "find echo command")
1444+
require.NoError(t, testutil.ReadUntil(ctx, t, conn, matchEchoOutput), "find echo output")
14611445

14621446
// Exit should cause the connection to close.
14631447
data, err = json.Marshal(codersdk.ReconnectingPTYRequest{
@@ -1468,12 +1452,9 @@ func testReconnectingPTY(ctx context.Context, t *testing.T, client *codersdk.Cli
14681452
require.NoError(t, err)
14691453

14701454
// Once for the input and again for the output.
1471-
require.True(t, hasLine(scanner, matchExitCommand), "find exit command")
1472-
require.True(t, hasLine(scanner, matchExitOutput), "find exit output")
1455+
require.NoError(t, testutil.ReadUntil(ctx, t, conn, matchExitCommand), "find exit command")
1456+
require.NoError(t, testutil.ReadUntil(ctx, t, conn, matchExitOutput), "find exit output")
14731457

14741458
// Ensure the connection closes.
1475-
for scanner.Scan() {
1476-
line := scanner.Text()
1477-
t.Logf("bash tty stdout = %s", re.ReplaceAllString(line, ""))
1478-
}
1459+
require.ErrorIs(t, testutil.ReadUntil(ctx, t, conn, nil), io.EOF)
14791460
}

docs/admin/users.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ In the Coder UI, you can filter your users using pre-defined filters or by utili
158158

159159
- To find active users, use the filter `status:active`.
160160
- To find admin users, use the filter `role:admin`.
161+
- To find users have not been active since July 2023: `status:active last_seen_before:"2023-07-01T00:00:00Z"`
161162

162163
The following filters are supported:
163164

164165
- `status` - Indicates the status of the user. It can be either `active`, `dormant` or `suspended`.
165166
- `role` - Represents the role of the user. You can refer to the [TemplateRole documentation](https://pkg.go.dev/github.com/coder/coder/codersdk#TemplateRole) for a list of supported user roles.
167+
- `last_seen_before` and `last_seen_after` - The last time a used has used the platform (e.g. logging in, any API requests, connecting to workspaces). Uses the RFC3339Nano format.

0 commit comments

Comments
 (0)