diff options
author | Jesse Hallam <jesse.hallam@gmail.com> | 2018-06-21 14:31:51 -0400 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2018-06-21 11:31:51 -0700 |
commit | dd35ad43caab407cc70ef3b153b3f94d57242ed9 (patch) | |
tree | 67afe0fb6ad784e740d8b2a99d5de5c04342661c /web/subpath_test.go | |
parent | 46f969e5ddbe4404dbc82dbe78ab2fa101d9922e (diff) | |
download | chat-dd35ad43caab407cc70ef3b153b3f94d57242ed9.tar.gz chat-dd35ad43caab407cc70ef3b153b3f94d57242ed9.tar.bz2 chat-dd35ad43caab407cc70ef3b153b3f94d57242ed9.zip |
MM-10370: serve subpath (#8968)
* factor out GetSubpathFromConfig
* mv web/subpath.go to utils/subpath.go
* serve up web, api and ws on /subpath if configured
* pass config to utils.RenderWeb(App)?Error
This allows the methods to extract the configured subpath and redirect
to the appropriate `/subpath/error` handler.
* ensure GetSubpathFromConfig returns trailing slashes deterministically
* fix error 404 handling
* redirect /subpath to /subpath/
This is necessary for the static handler to match, otherwise none of the
registered routes find anything. This also makes it no longer necessary
to add trailing slashes in the root router.
Diffstat (limited to 'web/subpath_test.go')
-rw-r--r-- | web/subpath_test.go | 103 |
1 files changed, 0 insertions, 103 deletions
diff --git a/web/subpath_test.go b/web/subpath_test.go deleted file mode 100644 index 92b1a5d3c..000000000 --- a/web/subpath_test.go +++ /dev/null @@ -1,103 +0,0 @@ -package web_test - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/mattermost/mattermost-server/model" - "github.com/mattermost/mattermost-server/web" -) - -func TestUpdateAssetsSubpath(t *testing.T) { - t.Run("no client dir", func(t *testing.T) { - tempDir, err := ioutil.TempDir("", "test_update_assets_subpath") - require.NoError(t, err) - defer os.RemoveAll(tempDir) - os.Chdir(tempDir) - - err = web.UpdateAssetsSubpath("/") - require.Error(t, err) - }) - - t.Run("valid", func(t *testing.T) { - tempDir, err := ioutil.TempDir("", "test_update_assets_subpath") - require.NoError(t, err) - defer os.RemoveAll(tempDir) - os.Chdir(tempDir) - - err = os.Mkdir(model.CLIENT_DIR, 0700) - require.NoError(t, err) - - testCases := []struct { - Description string - RootHTML string - MainCSS string - Subpath string - ExpectedRootHTML string - ExpectedMainCSS string - }{ - { - "no changes required, empty subpath provided", - baseRootHtml, - baseCss, - "", - baseRootHtml, - baseCss, - }, - { - "no changes required", - baseRootHtml, - baseCss, - "/", - baseRootHtml, - baseCss, - }, - { - "subpath", - baseRootHtml, - baseCss, - "/subpath", - subpathRootHtml, - subpathCss, - }, - { - "new subpath from old", - subpathRootHtml, - subpathCss, - "/nested/subpath", - newSubpathRootHtml, - newSubpathCss, - }, - { - "resetting to /", - subpathRootHtml, - subpathCss, - "/", - resetRootHtml, - baseCss, - }, - } - - for _, testCase := range testCases { - t.Run(testCase.Description, func(t *testing.T) { - ioutil.WriteFile(filepath.Join(tempDir, model.CLIENT_DIR, "root.html"), []byte(testCase.RootHTML), 0700) - ioutil.WriteFile(filepath.Join(tempDir, model.CLIENT_DIR, "main.css"), []byte(testCase.MainCSS), 0700) - err := web.UpdateAssetsSubpath(testCase.Subpath) - require.NoError(t, err) - - contents, err := ioutil.ReadFile(filepath.Join(tempDir, model.CLIENT_DIR, "root.html")) - require.NoError(t, err) - require.Equal(t, testCase.ExpectedRootHTML, string(contents)) - - contents, err = ioutil.ReadFile(filepath.Join(tempDir, model.CLIENT_DIR, "main.css")) - require.NoError(t, err) - require.Equal(t, testCase.ExpectedMainCSS, string(contents)) - - }) - } - }) -} |