From b48dd2c89a45ea44480aa7a0a2c6826558fda2de Mon Sep 17 00:00:00 2001 From: Daniel LaCosse <3759828+daniellacosse@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:34:37 -0500 Subject: [PATCH 1/2] feat: add autoformatting/linting to vscode (#2320) --- .gitignore | 3 +-- .vscode/extensions.json | 5 +++++ .vscode/settings.json | 18 ++++++++++++++++++ CONTRIBUTING.md | 6 +++++- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json diff --git a/.gitignore b/.gitignore index 02e3dad2b4..0af6defd96 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ node_modules .idea .task .vs/ -.vscode *.DS_Store *.env *.pdb @@ -13,4 +12,4 @@ node_modules /output /build -*storybook.log \ No newline at end of file +*storybook.log diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000000..b308e58914 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + "recommendations": [ + "dbaeumer.vscode-eslint" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..095a698a13 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,18 @@ +{ + "eslint.run": "onSave", + "eslint.validate": ["javascript", "typescript"], + "files.insertFinalNewline": true, + "[go]": { + "editor.formatOnSave": true + }, + "[javascript]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "always" + }, + }, + "[typescript]": { + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "always" + }, + }, +} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6d364e1dda..ca9d6f7653 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,4 +20,8 @@ again. All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more -information on using pull requests. \ No newline at end of file +information on using pull requests. + +## Setup: VSCode + +Make sure to go to the `Extensions` tab and install the recommended extensions! From 19aab4ed6cbe6ebdc79e5b53d963a1b0c0ca6a63 Mon Sep 17 00:00:00 2001 From: "J. Yi" <93548144+jyyi1@users.noreply.github.com> Date: Mon, 13 Jan 2025 10:36:04 -0500 Subject: [PATCH 2/2] feat(client): add timeout to `fetchResource` to prevent hangs (#2322) --- client/go/outline/fetch.go | 8 +++++++- client/go/outline/fetch_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/client/go/outline/fetch.go b/client/go/outline/fetch.go index 64d360a4fa..9b000103ce 100644 --- a/client/go/outline/fetch.go +++ b/client/go/outline/fetch.go @@ -17,16 +17,22 @@ package outline import ( "io" "net/http" + "time" "github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors" ) +const fetchTimeout = 10 * time.Second + // fetchResource fetches a resource from the given URL. // // The function makes an HTTP GET request to the specified URL and returns the response body as a // string. If the request fails or the server returns a non-2xx status code, an error is returned. func fetchResource(url string) (string, error) { - resp, err := http.Get(url) + client := &http.Client{ + Timeout: fetchTimeout, + } + resp, err := client.Get(url) if err != nil { return "", platerrors.PlatformError{ Code: platerrors.FetchConfigFailed, diff --git a/client/go/outline/fetch_test.go b/client/go/outline/fetch_test.go index 703b376a3b..2174aa523a 100644 --- a/client/go/outline/fetch_test.go +++ b/client/go/outline/fetch_test.go @@ -19,6 +19,7 @@ import ( "net/http" "net/http/httptest" "testing" + "time" "github.com/Jigsaw-Code/outline-apps/client/go/outline/platerrors" "github.com/stretchr/testify/require" @@ -100,3 +101,29 @@ func TestFetchResource_BodyReadError(t *testing.T) { require.Equal(t, platerrors.FetchConfigFailed, perr.Code) require.Error(t, perr.Cause) } + +func TestFetchResource_Timeout(t *testing.T) { + const ( + MaxFetchWaitTime = 12 * time.Second + ServerDelay = 20 * time.Second + ) + + testDone := make(chan bool) + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + select { + case <-time.After(ServerDelay): + w.WriteHeader(http.StatusNoContent) + case <-testDone: + } + })) + defer server.Close() + + start := time.Now() + content, err := fetchResource(server.URL) + duration := time.Since(start) + testDone <- true + + require.LessOrEqual(t, duration, MaxFetchWaitTime, "fetchResource should time out in 10s") + require.Error(t, err, "fetchResource should return a non-nil timeout error") + require.Empty(t, content) +}