From 173cfe9b881f18812da26201309b2473a8eeca20 Mon Sep 17 00:00:00 2001 From: Hossein Ahmadian-Yazdi Date: Wed, 20 May 2020 11:20:27 -0400 Subject: [PATCH] [MM-22644] Dont allow message export for CSV, Acadiance, Global Relay if non-E20 customer via command line (#14584) * dont allow message export for non E20 if export to csv acadiance or global relay * add tests Co-authored-by: mattermod --- cmd/mattermost/commands/export.go | 3 ++- cmd/mattermost/commands/export_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/mattermost/commands/export.go b/cmd/mattermost/commands/export.go index a837025615..076cc19142 100644 --- a/cmd/mattermost/commands/export.go +++ b/cmd/mattermost/commands/export.go @@ -145,6 +145,7 @@ func scheduleExportCmdF(command *cobra.Command, args []string) error { func buildExportCmdF(format string) func(command *cobra.Command, args []string) error { return func(command *cobra.Command, args []string) error { a, err := InitDBCommandContextCobra(command) + license := a.License() if err != nil { return err } @@ -158,7 +159,7 @@ func buildExportCmdF(format string) func(command *cobra.Command, args []string) return errors.New("exportFrom must be a positive integer") } - if a.MessageExport() == nil { + if a.MessageExport() == nil || license == nil || !*license.Features.MessageExport { return errors.New("message export feature not available") } diff --git a/cmd/mattermost/commands/export_test.go b/cmd/mattermost/commands/export_test.go index 4806a1f760..f4d5355b34 100644 --- a/cmd/mattermost/commands/export_test.go +++ b/cmd/mattermost/commands/export_test.go @@ -62,3 +62,13 @@ func TestMessageExportNegativeTimeoutSeconds(t *testing.T) { // should fail fast because timeout seconds must be a positive int require.Error(t, th.RunCommand(t, "--format", "actiance", "--exportFrom", "0", "--timeoutSeconds", "-1", "export", "schedule")) } + +func TestMessageExportFailsWithoutLicense(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + actual, _ := th.RunCommandWithOutput(t, "export", "csv", "export.csv", "--exportFrom", "0") + + // should fail fast because timeout seconds must be a positive int + require.Contains(t, actual, "message export feature not available") +}