Skip to content

Commit 1a4e7e1

Browse files
committed
Unit tests use 403 vs 401
1 parent e68fdbf commit 1a4e7e1

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

cli/autostart_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func TestAutostart(t *testing.T) {
110110
clitest.SetupConfig(t, client, root)
111111

112112
err := cmd.Execute()
113-
require.ErrorContains(t, err, "status code 404: no workspace found by name", "unexpected error")
113+
require.ErrorContains(t, err, "status code 403: forbidden", "unexpected error")
114114
})
115115

116116
t.Run("Disable_NotFound", func(t *testing.T) {
@@ -128,7 +128,7 @@ func TestAutostart(t *testing.T) {
128128
clitest.SetupConfig(t, client, root)
129129

130130
err := cmd.Execute()
131-
require.ErrorContains(t, err, "status code 404: no workspace found by name", "unexpected error")
131+
require.ErrorContains(t, err, "status code 403: forbidden", "unexpected error")
132132
})
133133

134134
t.Run("Enable_DefaultSchedule", func(t *testing.T) {

cli/autostop_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func TestAutostop(t *testing.T) {
127127
clitest.SetupConfig(t, client, root)
128128

129129
err := cmd.Execute()
130-
require.ErrorContains(t, err, "status code 404: no workspace found by name", "unexpected error")
130+
require.ErrorContains(t, err, "status code 403: forbidden", "unexpected error")
131131
})
132132

133133
t.Run("Enable_DefaultSchedule", func(t *testing.T) {

coderd/httpmw/organizationparam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func ExtractOrganizationParam(db database.Store) func(http.Handler) http.Handler
6363
UserID: apiKey.UserID,
6464
})
6565
if errors.Is(err, sql.ErrNoRows) {
66-
httpapi.Write(rw, http.StatusUnauthorized, httpapi.Response{
66+
httpapi.Write(rw, http.StatusForbidden, httpapi.Response{
6767
Message: "not a member of the organization",
6868
})
6969
return

coderd/httpmw/organizationparam_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestOrganizationParam(t *testing.T) {
141141
rtr.ServeHTTP(rw, r)
142142
res := rw.Result()
143143
defer res.Body.Close()
144-
require.Equal(t, http.StatusUnauthorized, res.StatusCode)
144+
require.Equal(t, http.StatusForbidden, res.StatusCode)
145145
})
146146

147147
t.Run("Success", func(t *testing.T) {

coderd/roles_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func TestListRoles(t *testing.T) {
112112
})
113113
require.NoError(t, err, "create org")
114114

115-
const unauth = "unauthorized"
115+
const unauth = "forbidden"
116116
const notMember = "not a member of the organization"
117117

118118
testCases := []struct {
@@ -191,7 +191,7 @@ func TestListRoles(t *testing.T) {
191191
if c.AuthorizedError != "" {
192192
var apiErr *codersdk.Error
193193
require.ErrorAs(t, err, &apiErr)
194-
require.Equal(t, http.StatusUnauthorized, apiErr.StatusCode())
194+
require.Equal(t, http.StatusForbidden, apiErr.StatusCode())
195195
require.Contains(t, apiErr.Message, c.AuthorizedError)
196196
} else {
197197
require.NoError(t, err)

0 commit comments

Comments
 (0)