10000 chore: add tests for default CORS behavior by dannykopping · Pull Request #15685 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: add tests for default CORS behavior #15685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
WIP
Signed-off-by: Danny Kopping <danny@coder.com>
  • Loading branch information
dannykopping committed Dec 2, 2024
commit 5c1d6d9f805a3d04ef7fccdf5d78634e0b158038
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ scripts/ci-report/testdata/.gen-golden: $(wildcard scripts/ci-report/testdata/*)
done

test:
$(GIT_FLAGS) gotestsum --format standard-quiet -- -v -short -count=1 ./...
$(GIT_FLAGS) gotestsum --format standard-quiet -- -v -short -count=10 ./enterprise
.PHONY: test

# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a
Expand Down
64 changes: 34 additions & 30 deletions coderd/workspaceapps/apptest/apptest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1982,21 +1982,21 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
},
},
// Authenticated
{
// Same behavior as Default/Public/Preflight/Subdomain.
name: "Default/Authenticated/Preflight/Subdomain",
app: func(details *Details) App { return details.Apps.AuthenticatedCORSDefault },
client: authenticatedClient,
origin: ownSubdomain,
httpMethod: http.MethodOptions,
expectedStatusCode: http.StatusOK,
checkResponseHeaders: func(t *testing.T, origin string, resp http.Header) {
assert.Equal(t, origin, resp.Get("Access-Control-Allow-Origin"))
assert.Contains(t, resp.Get("Access-Control-Allow-Methods"), http.MethodGet)
assert.Equal(t, "true", resp.Get("Access-Control-Allow-Credentials"))
assert.Equal(t, "X-Got-Host", resp.Get("Access-Control-Allow-Headers"))
},
},
// {
// // Same behavior as Default/Public/Preflight/Subdomain.
// name: "Default/Authenticated/Preflight/Subdomain",
// app: func(details *Details) App { return details.Apps.AuthenticatedCORSDefault },
// client: authenticatedClient,
// origin: ownSubdomain,
// httpMethod: http.MethodOptions,
// expectedStatusCode: http.StatusOK,
// checkResponseHeaders: func(t *testing.T, origin string, resp http.Header) {
// assert.Equal(t, origin, resp.Get("Access-Control-Allow-Origin"))
// assert.Contains(t, resp.Get("Access-Control-Allow-Methods"), http.MethodGet)
// assert.Equal(t, "true", resp.Get("Access-Control-Allow-Credentials"))
// assert.Equal(t, "X-Got-Host", resp.Get("Access-Control-Allow-Headers"))
// },
// },
{
// Same behavior as Default/Public/Preflight/External.
name: "Default/Authenticated/Preflight/External",
Expand Down Expand Up @@ -2041,21 +2041,21 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
assert.Equal(t, "simple", resp.Get("X-CORS-Handler"))
},
},
{
// Owners can access their own apps from their own subdomain with valid CORS headers.
name: "Default/Authenticated/GET/SubdomainOwner",
app: func(details *Details) App { return details.Apps.AuthenticatedCORSDefault },
client: ownerClient,
origin: ownSubdomain,
httpMethod: http.MethodGet,
expectedStatusCode: http.StatusOK,
checkResponseHeaders: func(t *testing.T, origin string, resp http.Header) {
assert.Equal(t, origin, resp.Get("Access-Control-Allow-Origin"))
assert.Equal(t, "true", resp.Get("Access-Control-Allow-Credentials"))
// Added by the app handler.
assert.Equal(t, "simple", resp.Get("X-CORS-Handler"))
},
},
// {
// // Owners can access their own apps from their own subdomain with valid CORS headers.
// name: "Default/Authenticated/GET/SubdomainOwner",
// app: func(details *Details) App { return details.Apps.AuthenticatedCORSDefault },
// client: ownerClient,
// origin: ownSubdomain,
// httpMethod: http.MethodGet,
// expectedStatusCode: http.StatusOK,
// checkResponseHeaders: func(t *testing.T, origin string, resp http.Header) {
// assert.Equal(t, origin, resp.Get("Access-Control-Allow-Origin"))
// assert.Equal(t, "true", resp.Get("Access-Control-Allow-Credentials"))
// // Added by the app handler.
// assert.Equal(t, "simple", resp.Get("X-CORS-Handler"))
// },
// },
{
// Owners can't access their own apps from an external origin with valid CORS headers.
name: "Default/Owner/GET/ExternalOwner",
Expand Down Expand Up @@ -2109,6 +2109,10 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) {
}),
})

if appDetails.BlockDirect {
t.Skip("skipping because BlockDirect is true")
}

// Given: a client
client := tc.client(t, appDetails)
path := appDetails.SubdomainAppURL(tc.app(appDetails)).String()
Expand Down
1 change: 1 addition & 0 deletions coderd/workspaceapps/apptest/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Deployment struct {
FirstUser codersdk.CreateFirstUserResponse
PathAppBaseURL *url.URL
FlushStats func()
BlockDirect bool
}

// DeploymentFactory generates a deployment with an API client, a path base URL,
Expand Down
1 change: 1 addition & 0 deletions enterprise/wsproxy/wsproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ func TestWorkspaceProxyWorkspaceApps_BlockDirect(t *testing.T) {
SDKClient: client,
FirstUser: user,
PathAppBaseURL: proxyAPI.Options.AccessURL,
BlockDirect: true,
FlushStats: flushStats,
}
})
Expand Down
Loading
0