-
Notifications
You must be signed in to change notification settings - Fork 244
fix(web): enforce asset compilation at build-time and fix runtime 404s #219
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -27,6 +27,7 @@ import ( | |||||||||
| "time" | ||||||||||
|
|
||||||||||
| "github.com/GoogleCloudPlatform/scion/pkg/store" | ||||||||||
| "github.com/GoogleCloudPlatform/scion/web" | ||||||||||
| "github.com/gorilla/securecookie" | ||||||||||
| "github.com/stretchr/testify/assert" | ||||||||||
| "github.com/stretchr/testify/require" | ||||||||||
|
|
@@ -40,6 +41,15 @@ type mockWebStore struct { | |||||||||
|
|
||||||||||
| func newTestWebServer(t *testing.T, cfg WebServerConfig) *WebServer { | ||||||||||
| t.Helper() | ||||||||||
| // Ensure hasWebAssets() returns true for tests unless they explicitly want | ||||||||||
| // to test the "no assets" case. | ||||||||||
| if cfg.AssetsDir == "" && !web.AssetsEmbedded { | ||||||||||
| tmpDir := t.TempDir() | ||||||||||
| assetsDir := filepath.Join(tmpDir, "assets") | ||||||||||
| os.MkdirAll(assetsDir, 0755) | ||||||||||
| os.WriteFile(filepath.Join(assetsDir, "main.js"), []byte("// test"), 0644) | ||||||||||
|
Comment on lines
+49
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error handling is missing for these file operations. Using
Suggested change
|
||||||||||
| cfg.AssetsDir = tmpDir | ||||||||||
| } | ||||||||||
| return NewWebServer(cfg) | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -53,7 +63,7 @@ func newDevAuthWebServer(t *testing.T, overrides ...func(*WebServerConfig)) *Web | |||||||||
| for _, fn := range overrides { | ||||||||||
| fn(&cfg) | ||||||||||
| } | ||||||||||
| return NewWebServer(cfg) | ||||||||||
| return newTestWebServer(t, cfg) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func TestSPAShellHandler(t *testing.T) { | ||||||||||
|
|
@@ -286,8 +296,13 @@ func TestSPAHandler_NoAssets_APIStillWorks(t *testing.T) { | |||||||||
| } | ||||||||||
|
|
||||||||||
| func TestSPAHandler_WithAssets_ServesNormalShell(t *testing.T) { | ||||||||||
| tmpDir := t.TempDir() | ||||||||||
| assetsDir := filepath.Join(tmpDir, "assets") | ||||||||||
| os.MkdirAll(assetsDir, 0755) | ||||||||||
| os.WriteFile(filepath.Join(assetsDir, "main.js"), []byte("// test"), 0644) | ||||||||||
|
Comment on lines
+301
to
+302
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error handling is missing for these file operations. Using
Suggested change
|
||||||||||
|
|
||||||||||
| ws := newDevAuthWebServer(t, func(cfg *WebServerConfig) { | ||||||||||
| cfg.AssetsDir = t.TempDir() | ||||||||||
| cfg.AssetsDir = tmpDir | ||||||||||
| }) | ||||||||||
|
|
||||||||||
| req := httptest.NewRequest("GET", "/", nil) | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.