Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions coderd/workspaceagentportshare.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ func (api *API) postWorkspaceAgentPortShare(rw http.ResponseWriter, r *http.Requ
if !req.ShareLevel.ValidPortShareLevel() {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Port sharing level not allowed.",
Validations: []codersdk.ValidationError{
{
Field: "share_level",
Detail: "Port sharing level not allowed.",
},
},
})
return
}

if req.Port < 9 || req.Port > 65535 {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Port must be between 9 and 65535.",
Validations: []codersdk.ValidationError{
{
Field: "port",
Detail: "Port must be between 9 and 65535.",
},
},
})
return
}
Expand Down
14 changes: 14 additions & 0 deletions coderd/workspaceagentportshare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ func TestPostWorkspaceAgentPortShare(t *testing.T) {
})
require.Error(t, err)

// invalid port should fail
_, err = client.UpsertWorkspaceAgentPortShare(ctx, r.Workspace.ID, codersdk.UpsertWorkspaceAgentPortShareRequest{
AgentName: agents[0].Name,
Port: 0,
ShareLevel: codersdk.WorkspaceAgentPortShareLevelPublic,
})
require.Error(t, err)
_, err = client.UpsertWorkspaceAgentPortShare(ctx, r.Workspace.ID, codersdk.UpsertWorkspaceAgentPortShareRequest{
AgentName: agents[0].Name,
Port: 90000000,
ShareLevel: codersdk.WorkspaceAgentPortShareLevelPublic,
})
require.Error(t, err)

// OK, ignoring template max port share level because we are AGPL
ps, err := client.UpsertWorkspaceAgentPortShare(ctx, r.Workspace.ID, codersdk.UpsertWorkspaceAgentPortShareRequest{
AgentName: agents[0].Name,
Expand Down
4 changes: 2 additions & 2 deletions site/src/modules/resources/PortForwardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const PortForwardButton: FC<PortForwardButtonProps> = (props) => {

const getValidationSchema = (): Yup.AnyObjectSchema =>
Yup.object({
port: Yup.number().required().min(0).max(65535),
port: Yup.number().required().min(9).max(65535),
share_level: Yup.string().required().oneOf(WorkspaceAppSharingLevels),
});

Expand Down Expand Up @@ -245,7 +245,7 @@ export const PortForwardPopoverView: FC<PortForwardPopoverViewProps> = ({
name="portNumber"
type="number"
placeholder="Connect to port..."
min={0}
min={9}
max={65535}
required
css={styles.newPortInput}
Expand Down