From 0788cdcadfb5d76b08758f42f01521b45ea76362 Mon Sep 17 00:00:00 2001 From: Jesse Hallam Date: Tue, 31 Jul 2018 16:29:52 -0400 Subject: MM-11420: plugins: compute bundle hash on load (#9172) * plugins: compute bundle hash on load Use this hash to bust client caches whenever the plugin bundle changes. * eliminate redundant pluginHandler * switch to 64-bit FNV-1a * Fix test --- model/manifest.go | 6 +++++- model/manifest_test.go | 10 ++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'model') diff --git a/model/manifest.go b/model/manifest.go index 705cc740e..6a7df59f4 100644 --- a/model/manifest.go +++ b/model/manifest.go @@ -5,6 +5,7 @@ package model import ( "encoding/json" + "fmt" "io" "io/ioutil" "os" @@ -151,6 +152,9 @@ type ManifestWebapp struct { // The path to your webapp bundle. This should be relative to the root of your bundle and the // location of the manifest file. BundlePath string `json:"bundle_path" yaml:"bundle_path"` + + // BundleHash is the 64-bit FNV-1a hash of the webapp bundle, computed when the plugin is loaded + BundleHash []byte `json:"-"` } func (m *Manifest) ToJson() string { @@ -188,7 +192,7 @@ func (m *Manifest) ClientManifest() *Manifest { if cm.Webapp != nil { cm.Webapp = new(ManifestWebapp) *cm.Webapp = *m.Webapp - cm.Webapp.BundlePath = "/static/" + m.Id + "/" + m.Id + "_bundle.js" + cm.Webapp.BundlePath = "/static/" + m.Id + "/" + fmt.Sprintf("%s_%x_bundle.js", m.Id, m.Webapp.BundleHash) } return cm } diff --git a/model/manifest_test.go b/model/manifest_test.go index c6b31e5df..80d22a3ad 100644 --- a/model/manifest_test.go +++ b/model/manifest_test.go @@ -255,6 +255,7 @@ func TestManifestClientManifest(t *testing.T) { }, Webapp: &ManifestWebapp{ BundlePath: "thebundlepath", + BundleHash: []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, }, SettingsSchema: &PluginSettingsSchema{ Header: "theheadertext", @@ -281,10 +282,11 @@ func TestManifestClientManifest(t *testing.T) { sanitized := manifest.ClientManifest() - assert.NotEmpty(t, sanitized.Id) - assert.NotEmpty(t, sanitized.Version) - assert.NotEmpty(t, sanitized.Webapp) - assert.NotEmpty(t, sanitized.SettingsSchema) + assert.Equal(t, manifest.Id, sanitized.Id) + assert.Equal(t, manifest.Version, sanitized.Version) + assert.Equal(t, "/static/theid/theid_000102030405060708090a0b0c0d0e0f_bundle.js", sanitized.Webapp.BundlePath) + assert.Equal(t, manifest.Webapp.BundleHash, sanitized.Webapp.BundleHash) + assert.Equal(t, manifest.SettingsSchema, sanitized.SettingsSchema) assert.Empty(t, sanitized.Name) assert.Empty(t, sanitized.Description) assert.Empty(t, sanitized.Server) -- cgit v1.2.3-1-g7c22