Skip to content

Commit 534d0ea

Browse files
committed
fix: ensure we are talking to coder on first user check
1 parent 3e5d292 commit 534d0ea

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

codersdk/users.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7+
"io"
78
"net/http"
89
"strings"
910
"time"
@@ -190,7 +191,19 @@ func (c *Client) HasFirstUser(ctx context.Context) (bool, error) {
190191
return false, err
191192
}
192193
defer res.Body.Close()
194+
193195
if res.StatusCode == http.StatusNotFound {
196+
b, err := io.ReadAll(res.Body)
197+
if err != nil {
198+
return false, err
199+
}
200+
// ensure we are talking to coder and not
201+
// some other service that returns 404
202+
isCoder := strings.Contains(string(b), "initial user has not been created")
203+
if !isCoder {
204+
return false, xerrors.Errorf("unexpected response: %s", string(b))
205+
}
206+
194207
return false, nil
195208
}
196209
if res.StatusCode != http.StatusOK {

0 commit comments

Comments
 (0)